일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- arp
- bandit
- Hastad
- cryptography
- Franklin-Reiter Related Message Attack
- dreamhack
- Bandit Level 1 → Level 2
- pycrpytodome
- 시스템해킹
- Cube Root Attack
- spoofing
- return address overflow
- 드림핵
- Crypto
- overthewire
- RSA
- dns
- rao
- weak key
- 웹해킹
- 암호학
- Montgomery Reduction
- XSS
- AES
- OverTheWire Bandit Level 1 → Level 2
- CSRF
- shellcode
- RSA Common Modulas Attack
- picoCTF
- redirect
- Today
- Total
암호(수학) 등.. 공부한 거 잊을거 같아서 만든 블로그
[Dreamhack] xss-2 본문
문제
문제 파일 : app.py
#!/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)
풀이
XSS-1 문제와 비슷한 코드이다. XSS-1을 풀었다고 가정하고 풀이를 작성하겠다.
@app.route("/vuln") 부분을 제외한 코드가 같다.
xss-1
문제 문제 파일 : app.py 더보기 app.py #!/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",
heahgo.tistory.com
vuln(xss) page 을 클릭하여 들어가보면 /vuln?param=<script>alert(1)</script> 이 주소창에 적혀있는 것을 볼 수 있다.
하지만 xss-1문제와는 다르게 param 파라미터에 들어간 스크립트가 실행이 안되는 것을 볼 수 있다. 즉 스크립트를 따로 처리하여 실행하지 못하도록 하게 만들었다는 것을 알 수 있다.
그러면 <script> 태그가 아닌 <img> 태그를 param 파라미터에 써보자.
위 이미지처럼 <img> 태그는 필터링이 되지 않는 것을 확인 할 수 있다.
그럼 이를 이용하여 공격을 시도해 볼 수 있다.
img 태그에는 onload 나 onerror 등의 이벤트를 발생시킬수 있다.
img 태그에서 onerror 이벤트는 src 를 불러올 수 없을 때, 발생되는 이벤트이다. 따라서 src 값에 이상한 값을 아무거나 넣어 onerror 이벤트를 발생시키면 onerror 에 작성한 스크립트가 실행될 것이다.
이제 memo 페이지에 cookie 를 출력하는 스크립트를 img 태그의 onerror 이벤트에 추가하여 flag 페이지에 입력하자.
memo 페이지에 플래그가 나온 것을 볼 수 있다.
'Dreamhack > Web' 카테고리의 다른 글
[Dreamhack] csrf-2 (0) | 2023.04.16 |
---|---|
[Dreamhack] csrf-1 (0) | 2023.04.14 |
[Dreamhack] xss-1 (0) | 2023.04.07 |
[Dreamhack] cookie (0) | 2023.04.04 |
[Dreamhack] session-basic (0) | 2023.04.04 |