๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
โœ’๏ธ Web Hacking/Dreamhack

[Dreamhack] Simple-SSTI ๋“œ๋ฆผํ•ต ์›Œ๊ฒŒ์ž„ ๋ฌธ์ œ ํ’€์ด

by A Lim Han 2022. 11. 10.

6 - 1 - 1. Simple - SSTI ๋“œ๋ฆผํ•ต ๋ฌธ์ œ ํ’€์ด

 

 

# Simple - SSTI ๋“œ๋ฆผํ•ต ๋ฌธ์ œ ํ’€์ด

1. ๋ฌธ์ œ ์ •๋ณด ํ™•์ธ ํ›„ ๋ฌธ์ œ ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ

- SSTI(Server Side Template Injection) ์ทจ์•ฝ์ ์ด๋ž€?

: ๊ณต๊ฒฉ์ž์— ์˜ํ•ด ์‚ฝ์ž…๋œ ์•…์„ฑ ํŽ˜์ด๋กœ๋“œ๊ฐ€ ์„œ๋ฒ„ ์ธก์—์„œ ์‹คํ–‰๋˜๋ฉฐ ๋ฐœ์ƒํ•˜๋Š” ์ทจ์•ฝ์ 

+ ์•…์„ฑ ํŽ˜์ด๋กœ๋“œ๋ฅผ ์‚ฝ์ž…ํ•˜๋Š” ๊ณผ์ •์—์„œ ์„œ๋ฒ„์˜ ๊ธฐ์กด ๊ธฐ๋ณธ ํ…œํ”Œ๋ฆฟ ๊ตฌ๋ฌธ์ด ์ด์šฉ๋  ์ˆ˜ ์žˆ์Œ

 

- ํ…œํ”Œ๋ฆฟ ๋ฐ ํ…œํ”Œ๋ฆฟ ์–ธ์–ด๋ž€?

: ํŠน์ • ์–ธ์–ด์˜ ๋ณ€์ˆ˜, ๋ฌธ๋ฒ•์„ html ์•ˆ์—์„œ๋„ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜๋„๋ก ๋•๋Š” ์–ธ์–ด

ex) flask์˜ jinja2, django์˜ python๊ณผ html

 

 

 

 

2. ์ ‘์† ์ •๋ณด ํ™•์ธ ํ›„ ์•ˆ๋‚ด๋œ ๋งํฌ๋กœ ์ ‘์†

 

 

 

 

 

3. 404Error, robots.txt ํŽ˜์ด์ง€๋กœ ๊ฐ๊ฐ ์ ‘์†

 

 

 

 

 

4. ์ƒ๋‹จ url์˜ ๊ฒฝ๋กœ์— /whereflag ์ถ”๊ฐ€ํ•ด๋ณด๊ธฐ

--> ์„œ๋ฒ„๊ฐ€ ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ์ž…๋ ฅ๋ฐ›์€ ํŽ˜์ด์ง€์˜ ๊ฒฝ๋กœ๋ฅผ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•จ์„ ํ™•์ธ

 

 

 

 

5. ๋ฌธ์ œ ํŒŒ์ผ app.py์˜ ์ฝ”๋“œ ๋ถ„์„

+ << Line 19 ~ 25 >>

: Flask python์—์„œ ๋‚˜ํƒ€๋‚˜๋Š” ์ทจ์•ฝ์  ์ค‘ ํ•˜๋‚˜์ธ SSTI ์ทจ์•ฝ์ ์ด ๋ฐœ์ƒํ•จ์„ ํ™•์ธ

-->  ๋ฌธ์ œ์˜ ์‚ฌ์ดํŠธ๋Š” Flask์˜ jinja2 ๋ฌธ๋ฒ•๊ณผ ์—ฐ๊ด€๋œ ํ…œํ”Œ๋ฆฟ์„ ์ด์šฉ

 

+ << Line 26 ~ 27 >>

: % (request.path)์„ ์ด์šฉํ•˜์—ฌ ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ์ž…๋ ฅ๋ฐ›์€ ๊ฒฝ๋กœ๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ์ฝ”๋“œ

 

 

 

 

6. ๋‹ค์‹œ ์ ‘์†์ •๋ณด์˜ url๋กœ ์ ‘์†ํ•˜์—ฌ url ์ƒ๋‹จ์— /{{config.items()}} ์ž…๋ ฅ

 

+ ์œ„ ์‚ฌ์ดํŠธ์ฒ˜๋Ÿผ flask์˜ jinja2 ๋ฌธ๋ฒ•์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ, {{..}} ํ˜•ํƒœ์˜ ํ…œํ”Œ๋ฆฟ์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ณต๊ฒฉ ๊ฐ€๋Šฅ

--> ํ…œํ”Œ๋ฆฟ์˜ ํ˜•ํƒœ๋ฅผ ์ค€์ˆ˜ํ•˜๋ฉฐ  {{config.items()}} ๋ช…๋ น ์ž‘์„ฑ

 

 

 

 

7. Flag๊ฐ€ ์„ฑ๊ณต์ ์œผ๋กœ ์ถœ๋ ฅ๋จ์„ ํ™•์ธ

Flag๋Š” DH{6c74aac721d128c637eab3f11906a44b}