XSS DOM 測試
阿新 • • 發佈:2018-12-22
dvwa DOM XSS
DOM Based XSS:是基於DOM文件物件模型的操作,通過前端指令碼修改頁面的DOM節點形成的XSS,該操作不與伺服器端進行互動,而且程式碼是可見的,從前端獲取到DOM中的資料在本地執行,從效果上來說也是反射型XSS。
- low 級別
可知Select按鈕選擇引數,資料提交是以GET請求的方式
<?php
# No protections, anything goes
?>
low 級別不存在Protect,可以非常簡單的造成XSS攻擊
構造payload
http://192.168.43.146/dvwa/vulnerabilities/xss_d/?default=%3Cscript%3Ealert%28%22XSS%22%29%3C/script%3E
當用戶觸發該URL時就會受到XSS攻擊,有彈框出現
- medium 級別
<?php // Is there any input? if ( array_key_exists( "default", $_GET ) && !is_null ($_GET[ 'default' ]) ) { $default = $_GET['default']; # Do not allow script tags if (stripos ($default, "<script") !== false) { header ("location: ?default=English"); exit; } } ?>
經過程式碼審計之後可知:array_key_exists檢查數組裡是否有指定的鍵名或索引,並且default值不為null,傳遞的資料中如果存在<script>標籤,則會進入if條件,default預設賦值為“English”
stripos(string,find,start) 函式查詢字串在另一字串中第一次出現的位置(不區分大小寫)。 引數 描述 string 必需。規定要搜尋的字串。 find 必需。規定要查詢的字元。 start 可選。規定開始搜尋的位置。 相關函式: strpos() - 查詢字串在另一字串中第一次出現的位置(區分大小寫) strripos() - 查詢字串在另一字串中最後一次出現的位置(不區分大小寫) strrpos() - 查詢字串在另一字串中最後一次出現的位置(區分大小寫)
由於stripos函式的作用所以不能使用<script>標籤,但是真的就不能使用該標籤嗎,答案是可以的,此處要利用到URL中的一個特殊字元‘#’,該字元後的資料不會發送到伺服器端,從而繞過服務端過濾
構造payload
http://192.168.43.146/dvwa/vulnerabilities/xss_d/?#default=%3Cscript%3Ealert%28%22XSS%22%29%3C/script%3E
觸發該URL,成功繞過服務端的過濾
假如真的不能使用<script>標籤,也有另一種方法進行繞過服務端的檢測
用img標籤或其他標籤的特性去執行js程式碼,比如img標籤的onerror事件
構造payload
http://192.168.43.146/dvwa/vulnerabilities/xss_d/?default=</option></select><img src=# onerror=alert("xss")>
觸發該URL,成功繞過服務端的過濾
- high 級別
<?php
// Is there any input?
if ( array_key_exists( "default", $_GET ) && !is_null ($_GET[ 'default' ]) ) {
# White list the allowable languages
switch ($_GET['default']) {
case "French":
case "English":
case "German":
case "Spanish":
# ok
break;
default:
header ("location: ?default=English");
exit;
}
}
?>
程式碼審計之後可知:在伺服器後端判斷,要求default的值必須為select選擇選單中的值,這裡繼續用上面的#符號繞過即可,構造payload
http://192.168.43.146/dvwa/vulnerabilities/xss_d/?#default=%3Cscript%3Ealert%28%22XSS%22%29%3C/script%3E
成功繞過後端switch的限制
- impossible 級別
Security level set to impossible
<?php
# Don't need to do anything, protction handled on the client side
?>