๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
โœ’๏ธ Capture The Flag (CTF)

[Square CTF 2022] Alex Hanlon Has The Flag! WriteUp

by A Lim Han 2022. 11. 19.

# Alex Hanlon Has The Flag! ๋ฌธ์ œ ํ’€์ด

1. ๋ฌธ์ œ์—์„œ ์•ˆ๋‚ดํ•œ ๋งํฌ๋กœ ์ ‘์†

 

 

 

 

 

2. F12ํ‹‘ ํ†ตํ•ด ๊ฐœ๋ฐœ์ž ๋„๊ตฌ ์˜คํ”ˆ ํ›„ ์›น ํŽ˜์ด์ง€ ๊ตฌ์กฐ ๋ฐ ์ฝ”๋“œ ๋ถ„์„

ํŠน๋ณ„ํ•œ ์ ์€ ๋ฐœ๊ฒฌํ•˜์ง€ ๋ชปํ•จ

 

 

 

 

3. ๋‹ค์‹œ ์ดˆ๊ธฐ ํ™”๋ฉด์œผ๋กœ ๋Œ์•„์™€ Username์— Alex Hanlon์„, Password์— 0000์„ ์ž…๋ ฅํ•ด ๋ด„

 

์œ ์ €๋ช…๊ณผ ํŒจ์Šค์›Œ๋“œ๊ฐ€ ํ‹€๋ฆฌ๋ฉด Nope, try again! ๊ฒฝ๊ณ ๋ฌธ์„ ์ถœ๋ ฅ

 

 

 

 

4. ์ž ๊น ๋จธ๋ฆฌ๋ฅผ ์‹ํž ๊ฒธ(๋ญํ–ˆ๋‹ค๊ณ ...^^) ๋‹ค๋ฅธ ๋ฌธ์ œ๋ฅผ ๊ตฌ๊ฒฝํ•˜๋˜ ๋„์ค‘ ์˜๋ฏธ์‹ฌ์žฅํ•œ ๋ฌธ์ œ๋ฅผ ๋ฐœ๊ฒฌ

+ ๊ฐœ๋ฐœ์ž๋“ค์ด ๋˜‘๋˜‘ํ•ด์ ธ์„œ ๋กœ๊ทธ์ธ ํŽ˜์ด์ง€์—์„œ์˜ SQL injection์„ ์˜ˆ๋ฐฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋ฌ๋‹ค๊ณ  ํ•จ  -->  ์˜ˆ์ „์—๋Š” SQL injection ๊ณต๊ฒฉ์ด ๊ฐ€๋Šฅํ–ˆ๋‹ค๋Š” ์˜๋ฏธ...?

+ ์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๋” ์ด์ƒ Flag๊ฐ€ ํ•˜๋“œ์ฝ”๋”ฉ๋˜์–ด์„  ์•ˆ๋œ๋‹ค๊ณ  ๊ฒฐ์ •  -->  ์ด์ „์—๋Š” ํ•˜๋“œ์ฝ”๋”ฉ๋˜์–ด ์žˆ์—ˆ๋‹ค๋Š” ์˜๋ฏธ...?

 

 

 

 

5. ๋‹ค์‹œ ๋ฌธ์ œ ์›น ํŽ˜์ด์ง€๋กœ ์ ‘์†ํ•˜์—ฌ SQL injection ์‹œ๋„

A. ์ฒซ ๋ฒˆ์งธ ์‹œ๋„

: Username์— SELECT * FROM Users WHERE id = 'CAT' AND password = 'LOVE' ์„, Password์— LOVE ์ž…๋ ฅ

์—ญ์‹œ ๋ฐฉํ–ฅ์„ฑ์€ SQL injection์ด ๋งž์•˜๋‹ค. ํ•˜์ง€๋งŒ Flag๋Š” ์ถœ๋ ฅ๋˜์ง€ ์•Š์Œ

+ ์›น ํŽ˜์ด์ง€์˜ ์‘๋‹ต์„ ํ†ตํ•ด ์œ„ ์›น ํŽ˜์ด์ง€๊ฐ€ SQL injection์— ์ทจ์•ฝํ•˜๋‹ค๋Š” ๊ฒƒ์„ ํ™•์ธํ•˜์˜€๋‹ค,

 

 

B. ๋‘ ๋ฒˆ์งธ ์‹œ๋„

: Username์— 1' UNION SELECT name, pw FROM user# ์„ ์ž…๋ ฅํ•˜๊ณ , Password ๋ถ€๋ถ„์€ ๋นˆ์นธ์œผ๋กœ ์œ ์ง€

+ ๋ฐฐ์›Œ๋ณธ ๊ณต๊ฒฉ ๊ตฌ๋ฌธ์„ ์ ์šฉํ•˜์—ฌ ์‹œ๋„ํ•˜์˜€์œผ๋‚˜, Unknown column ์ด๋ผ๋Š” ์‘๋‹ต์ด ์ถœ๋ ฅ๋˜์—ˆ๋‹ค.

 

 

C. ์„ธ ๋ฒˆ์งธ ์‹œ๋„

: Username์— 1' UNION SELECT username, password FROM user# ์„, Password ๋ถ€๋ถ„์€ ๋นˆ์นธ์œผ๋กœ ์œ ์ง€ 

+ ๊ทธ๋ƒฅ name์ด ์•„๋‹ˆ๋ผ ๊ฐœ๋ฐœ์ž ๋„๊ตฌ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์—ˆ๋˜ ๋ณ€์ˆ˜์ธ username์œผ๋กœ ๋ฐ”๊ฟ” ์‹œ๋„ํ•˜์˜€๋‹ค.

 

 

D. 4๋ฒˆ์งธ ์‹œ๋„

: Username์— 1' union select # ์ž…๋ ฅ, Password๋Š” ๋นˆ์นธ์œผ๋กœ ์œ ์ง€ 

+ ์ด์ œ ๋งž๋Š” ์œ ์ €๋งŒ ์ฐพ์œผ๋ฉด ๋˜์ง€๋งŒ......

+ ๋งŒ์•ฝ ํŒŒ๋ž€ ๋ถ€๋ถ„์˜ 1 ๋Œ€์‹  ๋‹ค๋ฅธ ์ˆซ์ž๋ฅผ ๋„ฃ์œผ๋ฉด ์‘๋‹ต์— 1 ๋Œ€์‹  ๊ทธ ์ˆ˜๋ฅผ ํฌํ•จํ•˜์—ฌ ์œ„ ์‚ฌ์ง„๊ณผ ๋™์ผํ•˜๊ฒŒ ์ถœ๋ ฅ๋œ๋‹ค.

 

+ ์•ŒํŒŒ๋ฒณ์˜ ๊ฒฝ์šฐ ์›น ํŽ˜์ด์ง€๊ฐ€ ์ธ์‹ํ•˜์ง€ ๋ชปํ•ด ์•„๋ž˜์™€ ๊ฐ™์€ ์‘๋‹ต์„ ์ถœ๋ ฅํ–ˆ๋‹ค.

 

 

 

 

++ < ์ •๋‹ต >

Username์—  '  or username like "%hanlon%"#, Password๋Š” ๊ณต๋ž€์œผ๋กœ ์œ ์ง€ 

 

 

 

 

 

< ์ฐธ์—ฌ ํ›„๊ธฐ >

 ์ด CTF๊ฐ€ Overdose CTF์ฒ˜๋Ÿผ 48์‹œ๊ฐ„ ๋™์•ˆ ์ง„ํ–‰๋˜๋Š” ์ค„ ์•Œ๊ณ  ๋‹ค์Œ ๋‚  ๋‹ค์‹œ ์‹œ๋„ํ•ด๋ณด๋ ค ํ–ˆ์œผ๋‚˜......24์‹œ๊ฐ„๋ฐ–์— ์ง„ํ–‰์„ ์•ˆํ•˜๋Š” CTF์˜€๋‹ค. usernname like๋‚˜ or username์ด ํฌํ•จ๋œ ๊ตฌ๋ฌธ์œผ๋กœ๋Š” ์‹œ๋„๋ฅผ ๋ชปํ–ˆ์ง€๋งŒ, ๋‹ค๋ฅธ ๋ถ„๋“ค writeup์„ ๋ณด๋‹ˆ or username like ๊ตฌ๋ฌธ์œผ๋กœ ๊ณต๊ฒฉ์ด ๊ฐ€๋Šฅํ–ˆ๋‹ค. ๋‹ค์Œ๋ถ€ํ„ฐ๋Š” ์˜ฌ๋ ค์ฃผ์‹  ๊ณต์ง€๋ฅผ ๋” ์ž์„ธํžˆ ํ™•์ธํ•ด์•ผ๊ฒ ๋‹ค.