QQ蠕蟲的行爲檢測方法[www.freebuf.com]

QQ蠕蟲是一種利用QQ等騰訊公司相關產品進行傳播的一種特殊蠕蟲,該蠕蟲的基本原理是利用了QQ帳戶的快速登錄機制,只要當前系統中有一個QQ帳戶成功登錄,就可以通過後臺接口實現該帳戶相關應用的快速登錄而不需要再次輸入帳戶密碼。登錄後蠕蟲可以訪問QQ應用的各種網絡接口,例如:通過接口實現加QQ好友、加入QQ羣、發消息、發日誌、發微博、上傳羣共享文件等操作,且完全不需要用戶同意。借用這種技術,QQ蠕蟲可以實現非常快速的傳播。這種蠕蟲誕生於QQ體系之上,其影響和傳播主要集中在國內地區,因此國外品牌的殺軟對這類蠕蟲識別和支持非常有限,國內的殺軟品牌對該蠕蟲檢測也不是特別理想,從而導致了該QQ蠕蟲的傳播更加快速,影響範圍更廣。


基於以上信息,利用WinPcap技術抓取網絡數據包,對HTTP POST包進行分析,過濾出對域名qq.com訪問的數據包,但是由於WinPcap考慮到很多數據結構需要自己封裝且時間很少,所以決定使用sharpPcap+C# 代替常用的 WinPcap+VC來捕獲數據包

實現基本思路

(1)經典的HTTP請求方式:

GET /somedir/page.html HTTP/1.1Host:  www.someschool.eduConnection: closeUser-agent: Mozilla/4.0Accept-language: fr

(2)我們注意到HTTP請求報文中的第一行是以GET打頭的,它實際上是HTTP請求的一種方法,類似的還有POST、HEAD等等。一般熟知的大概就是GET和POST。

(3)利用這個我們就可以用 sharpPcap 技術抓取網絡數據包,在數據包中判斷TCP數據報文裏是否保存了HTTP數據。如果有HTTP數據且是請求報文,就獲得了HTTP的 GET、POST 請求數據後進行解析,數據的解析可以通過Content-Type分析數據格式,並按照相應的解析方式進行解碼,解碼過程中還有對於中文字符的處理等等。

部分功能實現

基於sharpPcap,C#寫的抓包程序源代碼

using System;using System.Collections.Generic;using System.Linq;using System.Text;using SharpPcap;namespace SharpPcapTest{class Program{static void Main(string[] args){PacketArrivalForm packArrivalForm = new PacketArrivalForm();packArrivalForm.ShowDialog();FileOperate fileOperate = new FileOperate();string ver = SharpPcap.Version.VersionString;Console.WriteLine("SharpPcap {0}, Example1.IfList.cs", ver);String strTemp = "SharpPcap" + ver + "\n";fileOperate.wtiteToTxtFile(@".\123.txt", strTemp);// Retrieve the device listvar devices = LivePcapDeviceList.Instance;// If no devices were found print an errorif (devices.Count < 1){Console.WriteLine("No devices were found on this machine");return;}Console.WriteLine("\nThe following devices are available on this machine:");Console.WriteLine("----------------------------------------------------\n");/* Scan the list printing every entry *//*獲取驅動列表*/foreach (var dev in devices){//Console.WriteLine("{0}\n", dev.ToString());fileOperate.wtiteToTxtFile(@".\123.txt", dev.ToString());strTemp += dev.ToString();}//在對話框中顯示相關的設備信息ShowForm showForm = new ShowForm();showForm.setRichTextBoxStr(strTemp);showForm.ShowDialog();/*接收數據包時間等各種數據*/int  i = int.Parse(Console.ReadLine());LivePcapDevice device = devices[i];// Register our handler function to the &#039;packet arrival&#039; eventdevice.OnPacketArrival += new PacketArrivalEventHandler(device_OnPacketArrival);// Open the device for capturingint readTimeoutMilliseconds = 1000;device.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);Console.WriteLine();Console.WriteLine("-- Listening on {0}, hit &#039;Enter&#039; to stop...",device.Description);strTemp = "Hour\tMinute\tSecond\tMillisecond\tlen\n";fileOperate.wtiteToTxtFile(@".\data.txt", strTemp);// Start the capturing processdevice.StartCapture();// Wait for &#039;Enter&#039; from the user.Console.ReadLine();// Stop the capturing processdevice.StopCapture();Console.WriteLine("-- Capture stopped.");// Print out the device statisticsConsole.WriteLine(device.Statistics().ToString());fileOperate.wtiteToTxtFile(@".\data.txt", device.Statistics().ToString());Console.Write("Hit &#039;Enter&#039; to exit...");Console.ReadLine();}private static void device_OnPacketArrival(object sender, CaptureEventArgs e){FileOperate fileOperate = new FileOperate();var time = e.Packet.Timeval.Date;var len = e.Packet.Data.Length;Console.WriteLine("{0}:{1}:{2},{3} Len={4}",time.Hour, time.Minute, time.Second, time.Millisecond, len);string strTemp = time.Hour.ToString() + "\t" + time.Minute.ToString() + "\t" +  time.Second.ToString() + "\t" + time.Millisecond.ToString() + "\t\t" +  len.ToString() + "\n";Console.WriteLine(e.Packet.ToString());strTemp += "\n" + e.Packet.ToString() + "\n";fileOperate.wtiteToTxtFile(@".\data.txt", strTemp);}}}

設備信息截圖:

17271408264335.png

獲取數據包數據截圖:

75991408264336.png

完整源碼就不附上了,附上exe下載地址

http://pan.baidu.com/s/1mgp3kWo

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章