QQ蠕蟲的行為檢測方法
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.1
- Host: www.someschool.edu
- Connection: close
- User-agent: Mozilla/4.0
- Accept-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 list
- var devices = LivePcapDeviceList.Instance;
- // If no devices were found print an error
- if (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 'packet arrival' event
- device.OnPacketArrival += new PacketArrivalEventHandler(device_OnPacketArrival);
- // Open the device for capturing
- int readTimeoutMilliseconds = 1000;
- device.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
- Console.WriteLine();
- Console.WriteLine("-- Listening on {0}, hit 'Enter' to stop...",device.Description);
- strTemp = "Hour\tMinute\tSecond\tMillisecond\tlen\n";
- fileOperate.wtiteToTxtFile(@".\data.txt", strTemp);
- // Start the capturing process
- device.StartCapture();
- // Wait for 'Enter' from the user.
- Console.ReadLine();
- // Stop the capturing process
- device.StopCapture();
- Console.WriteLine("-- Capture stopped.");
- // Print out the device statistics
- Console.WriteLine(device.Statistics().ToString());
- fileOperate.wtiteToTxtFile(@".\data.txt", device.Statistics().ToString());
- Console.Write("Hit 'Enter' 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);
- }
- }
- }
設備信息截圖:
獲取數據包數據截圖:
完整程序下載:http://pan.baidu.com/s/1i3vEX1r