入侵檢測課程設(shè)計(jì)_第1頁
入侵檢測課程設(shè)計(jì)_第2頁
入侵檢測課程設(shè)計(jì)_第3頁
入侵檢測課程設(shè)計(jì)_第4頁
入侵檢測課程設(shè)計(jì)_第5頁
已閱讀5頁,還剩26頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、一、Snort的安裝、配置和使用1.1 實(shí)驗(yàn)?zāi)康?(1) 掌握在linux下的snort工具的安裝、配置、使用方法,實(shí)現(xiàn)捕捉Telnet、FTP、HTTP等協(xié)議的數(shù)據(jù)包。(2) 利用snort的檢測功能,完成對一些攻擊的檢測.加深對各種攻擊軟件的了解.(3) 配合課堂授課內(nèi)容,全面了解snort這個(gè)著名的開源入侵檢測工具的實(shí)現(xiàn)方法和原理.(4) 為利用第三方軟件分析進(jìn)一步分析數(shù)據(jù)打下基礎(chǔ)。1.2 實(shí)驗(yàn)內(nèi)容(1) 進(jìn)一步熟悉linux下的基本命令,安裝配置snort(2) 掌握Snort作為嗅探器和數(shù)據(jù)包記錄器方式的使用方法, 及主要命令參數(shù)的含義。(3) 比較snort和tcpdump有何不同

2、。(4) 打開/etc/snort.conf, 理解Snort.conf文件中的相關(guān)配置參數(shù)。(5) 掌握snort的入侵檢測工作方式的命令行使用方法。(6)自已編寫一個(gè)規(guī)則, 并利用此規(guī)則進(jìn)行檢測,產(chǎn)生報(bào)警日志1.3 實(shí)驗(yàn)要求(1) 認(rèn)真完成所規(guī)定的實(shí)驗(yàn)內(nèi)容。(2) 使用Snort作為嗅探器和數(shù)據(jù)包記錄器方式的命令捕獲數(shù)據(jù)包。(3) 通過采用不同的參數(shù),進(jìn)行操作,掌握其功能。如 v, -d , -e, -l, -r等參數(shù)的使用。(4) 將所捕獲的數(shù)據(jù)包內(nèi)容存儲在文件中,文件名命名規(guī)則是lab1_學(xué)號(5) 對snort進(jìn)行配置, 完成一個(gè)入侵檢測的工作。要求檢測到TCP包中的某個(gè)特征碼, 并

3、給出應(yīng)的報(bào)警信息。(6) 認(rèn)真完成每一個(gè)實(shí)驗(yàn)步驟,并做好記錄。 1.4 實(shí)驗(yàn)準(zhǔn)備 (1) 熟悉linux基本命令 (2) 熟悉linux系統(tǒng)的安裝配置 (3) 熟悉虛擬機(jī)的安裝和操作 (4) 理解入侵檢測系統(tǒng)的基本原理和實(shí)現(xiàn)技術(shù) (5) 理解Snort的工作原理 1.5 實(shí)驗(yàn)步驟一、 安裝snort1、 更新Ubuntu軟件源,2、 進(jìn)入終端,提升用戶權(quán)限sudo su3、 更新軟件列表sudo apt-get update4、 安裝snort (Ubuntu12.04軟件列表中的snort默認(rèn)是2.9,之前版本的軟件列表的snort版本是較低版本):sudo apt-get install

4、snort5、 Snort v6、 Snort vd7、snort vdealert ip any any - any any (msg:Got an IP Packet; classtype:not-suspicious;sid:2000000; rev:1;)alert icmp any any - any any (msg:Got an ICMP Packet; classtype:not-suspicious;sid:2000001; rev:1;)alert icmp any any - any any (msg:ICMP Large ICMP Packet; dsize:800;r

5、eference:arachnids,246; classtype:bad-unknown; sid:2000499; rev:4;)前面兩個(gè)規(guī)則分別在捕獲任何IP數(shù)據(jù)包和ICMP數(shù)據(jù)包的時(shí)候產(chǎn)生一個(gè)告警。因?yàn)樗鼈冊谟龅矫恳粋€(gè)數(shù)據(jù)包的時(shí)候都觸發(fā)告警,所以在數(shù)據(jù)流量很大的網(wǎng)絡(luò)段不 適合使用這些規(guī)則!如果必要的話,請?jiān)谝粋€(gè)小網(wǎng)絡(luò)段或測試網(wǎng)絡(luò)段使用這些規(guī)則。最后一個(gè)規(guī)則是對499號簽名ID(標(biāo)準(zhǔn)規(guī)則)的拷貝進(jìn)行修改以放寬產(chǎn)生告 警的門限來滿足我們的測試目的(注意:S組織將1-1,000,000的簽名ID號留給“正式”規(guī)則使用,詳情請查看Snort的用戶使 用手冊)。正常情況下你應(yīng)該避

6、免放寬告警門限,因?yàn)檫@樣會產(chǎn)生很多的誤告警。1.6實(shí)驗(yàn)總結(jié): 通過這次的課程設(shè)計(jì)掌握在linux下的snort工具的安裝、配置、使用方法,實(shí)現(xiàn)捕捉Telnet、FTP、HTTP等協(xié)議的數(shù)據(jù)包。 利用snort的檢測功能,完成對一些攻擊的檢測.加深對各種攻擊軟件的了解.結(jié)合課堂授課內(nèi)容,全面了解snort這個(gè)著名的開源入侵檢測工具的實(shí)現(xiàn)方法和原理. 為利用第三方軟件分析進(jìn)一步分析數(shù)據(jù)打下基礎(chǔ)。二、用Snort構(gòu)建實(shí)用的入侵檢測系統(tǒng)2.1 實(shí)驗(yàn)?zāi)康?1) 網(wǎng)絡(luò)數(shù)據(jù)獲取與分析是網(wǎng)絡(luò)入侵檢測系統(tǒng)的基礎(chǔ)。通過實(shí)驗(yàn)讓同學(xué)們掌握網(wǎng)絡(luò)數(shù)據(jù)獲取及數(shù)據(jù)還原的方法和實(shí)現(xiàn)。(2) 通過實(shí)驗(yàn)讓同學(xué)們加深對網(wǎng)絡(luò)數(shù)據(jù)獲取原

7、理的理解。(3) 通過實(shí)驗(yàn)讓同學(xué)們初步了解在linux下的程序開發(fā)過程、開發(fā)環(huán)境。(4) 為利用第三方軟件分析進(jìn)一步分析數(shù)據(jù)打下基礎(chǔ)。2.2 實(shí)驗(yàn)內(nèi)容(1) 安裝除snort以外的其它軟件,如Apach、PHP、mysql、acid的安裝等相關(guān)軟件。(2) 完成相應(yīng)的配置文件的配置,如配置數(shù)據(jù)庫輸出插件、制訂入侵防范策略等(3) 能利用下載的檢測規(guī)則,檢測入侵。(4) 自已完成一條規(guī)則的編寫,并進(jìn)行正確性測試。(5) 完成對檢測規(guī)則的壓力測試。 2.3 實(shí)驗(yàn)要求(1) 認(rèn)真完成所規(guī)定的實(shí)驗(yàn)內(nèi)容。(2) 將配置文件的的改動(dòng)部分存儲下來,傳送到系ftp服務(wù)器上。文件名命名規(guī)則是Lab2_學(xué)號(3)

8、 所操作的重要步驟和結(jié)果用截屏的方法和文件的方式保存和存儲,并送到ftp服務(wù)器上(4) 認(rèn)真完成每一個(gè)實(shí)驗(yàn)步驟,并做好記錄。(5) 根據(jù)所做的全部實(shí)驗(yàn)做一個(gè)簡單總結(jié)。 2.4 實(shí)驗(yàn)準(zhǔn)備 (1) 熟悉linux基本命令 (2) 熟悉linux系統(tǒng)的安裝配置 (3) 熟悉虛擬機(jī)的安裝和操作 (4) 理解入侵檢測系統(tǒng)的基本原理和實(shí)現(xiàn)技術(shù) (5) 理解Snort的工作原理 (6) 參考教材參考資料及網(wǎng)上有關(guān)資料2.5 實(shí)驗(yàn)步驟一、LAMP服務(wù)器配置1、 提升權(quán)限用sudo su 提升用戶權(quán)限。2、 更新軟件包列表。用apt-get update 獲取最新的軟件包列表(如果不執(zhí)行這一部可能在出現(xiàn)未發(fā)現(xiàn)軟

9、件包的現(xiàn)象)3、安裝MySQL5apt-get install mysql-server mysql-client 安裝過程中會遇到如下圖的兩個(gè)界面。要求提供一個(gè)MySQL root用戶的密碼-這個(gè)密碼是為用戶有效的根本地主機(jī)以及作為root的,所以我們不會有手動(dòng)指定一個(gè)MySQL root密碼后:MySQL的“root”用戶:新密碼 - yourrootsqlpassword 重復(fù)密碼: - yourrootsqlpassword3、 安裝Apache2Apt-get install Apache2修改apache默認(rèn)目錄(不修改也可以用,這里暫時(shí)不加闡述)安裝完成重啟Apache/etc/

10、init.d/apache2 restart在瀏覽器中輸入本機(jī)ip或是localhost顯示如下午即為安裝成功。4、 安裝PHP5apt-get install php5 libapache2-mod-php5重啟Apache/etc/init.d/apache2 restart5、 測試的PHP5 /獲取PHP5安裝的詳細(xì)信息默認(rèn)網(wǎng)站的文件根目錄是/ var / www下面?,F(xiàn)在,我們將在該目錄中創(chuàng)建一個(gè)小型PHP文件(info.php的)和在瀏覽器中調(diào)用它。該文件將顯示很多關(guān)于我們的PHP安裝,如安裝的PHP版本,有用的細(xì)節(jié)。vi /var/www/info.php在瀏覽器中輸入http:

11、/本機(jī)ip/info.php或localhost/info.php正如你所看到的,PHP5的工作,它通過Apache 2.0的處理程序,在服務(wù)器API 線。如果你繼續(xù)向下滾動(dòng),你會看到所有在PHP5中已經(jīng)啟用的模塊。MySQL是沒有列出,這意味著我們不必在PHP5支持MySQL6、 安裝需要的Mysql對php支持包可以用命令查找:apt-cache search php57、 獲得MySQL支持在PHP5phpMyAdmin是一個(gè)網(wǎng)絡(luò)接口,通過它可以管理你的MySQL數(shù)據(jù)庫。安裝:apt-get install phpmyadmin你會看到以下問題點(diǎn)確定安裝完成之后在瀏覽器中輸入localh

12、ost查看是否成功。如果出現(xiàn)not found錯(cuò)誤,解決方法是進(jìn)入var/www/目錄下給phpmyadmin加一個(gè)軟連接命令如下:cd /var/www/sudo ln s /usr/share/phpmyadmin當(dāng)配置都成功了可以看到phpmyadmin的界面,下圖是我建完snort時(shí)的截圖可能會你們看的的不同。安裝、配置Snort安裝過程中需要進(jìn)行配置,配置過程如下:sudo suapt-get updateapt-get install snort-mysqlSnort-mysql軟件包安裝完成后,在/usr/share/doc/snort-mysql/目錄下放置了一些文檔,可以使用

13、如下方法查看文檔為snort創(chuàng)建數(shù)據(jù)庫過程mysql uroot pcreate database sonrtdbgrant creat,insert,select,update on snort.* to snortlocalhost;set password for snortlocalhost=PASSWOED(snortpassword);exit;測試創(chuàng)建的數(shù)據(jù)用戶:mysql usnort psnortpassword能進(jìn)入則證明創(chuàng)建成功;將snort-mysql附帶的sql文件導(dǎo)入數(shù)據(jù)庫:cd /uer/share/doc/snort-mysql/zcat creat_mysql

14、.gz |mysql snortdb usnort psnortpassword將/etc/snort/db-pending-config文件刪除:rm /etc/snort/db-pending-config配置snort在配置文件的第50行,將其修改為我們要監(jiān)控的網(wǎng)段var EXTERNAL_NET !$HOME_NET在配置文件的第700行,找到“outout database: log, mysql,”一行,如果此行沒有被注釋掉則注釋掉,按照此行格式寫一個(gè)新的;該設(shè)置使Snort將log和alert信息都寫入到指定的MySQL數(shù)據(jù)庫中。在/var/log/snort/目錄下創(chuàng)建aler

15、t文件,并更改所有者為snort,否則snort因不能寫入這個(gè)文件無法啟動(dòng),cd /var/log/snort /touch alertchown snort alert設(shè)置完成后,測試配置是否正常:snort c /etc/snort/snort.conf最后出現(xiàn)這個(gè)畫面,說明配置成功了,按“Ctrl + C”鍵即可退出。用如下命令查看/var/log/syslog日志文件:cat /var/log/syslog |grep snort |grep ERROR安裝、配置acidbase軟件包apt-get install acidbase此時(shí),數(shù)據(jù)庫選擇MySQL數(shù)據(jù)庫,如下所示:此時(shí)輸入M

16、ySQL數(shù)據(jù)庫的root用戶密碼,如下所示:此過程時(shí),直接按回車鍵即可,讓系統(tǒng)自動(dòng)生成密碼,如下所示:配置Apacheacidbase軟件包自己帶了一個(gè)Apache配置文件,位于/etc/acidbase/apache.conf,修改該文件,將其包含到當(dāng)前的虛擬主機(jī)的配置文件中Vi /etc/acidbase/apache.conf重新加載Apache配置,并重啟Apache服務(wù):Service apache2 reloadService apache2 restart配置acidbase在瀏覽器中打開:http:/ip地址/acidbase/setup/,開始配置,在第一個(gè)頁面上,點(diǎn)擊“Co

17、ntinue”,如下圖所示:在接下來的步驟中,語言選擇“simplified_chinese”,并輸入路徑“/usr/share/php/adodb”在“Step 2 of 5”界面上,輸入MySQL數(shù)據(jù)庫信息在“Step 3 of 5”界面上,輸入用戶名和密碼,用于登陸B(tài)ASE在“Step 4 of 5”界面上,點(diǎn)擊“Create BASE AG”按鈕,在數(shù)據(jù)庫中創(chuàng)建表此時(shí),如果你看到了如下所示界面,說明數(shù)據(jù)庫表創(chuàng)建成功,然后點(diǎn)擊最下方的 step 5將生成的配置文件復(fù)制下來:生成的配置文件,并保存為/etc/acidbase/base_conf.php,并在配置文件的460行左右找到$BA

18、SEE_path將其注掉,并添加一行$BASE_path=/usr/share/acidbase 保存退出文件后,修改文件權(quán)限Chmod c=/etc/acidbase/base_conf.phpChgrp www-date/etc/acidbase/base_conf.php 此時(shí)登陸http:/localdhost/acidbase/頁面,輸入用戶名、密碼,來查看Snort截獲的入侵日志:alert ip any any - any any (msg:Got an IP Packet; classtype:not-suspicious;sid:2000000; rev:1;)alert i

19、cmp any any - any any (msg:Got an ICMP Packet; classtype:not-suspicious;sid:2000001; rev:1;)alert icmp any any - any any (msg:ICMP Large ICMP Packet; dsize:800;reference:arachnids,246; classtype:bad-unknown; sid:2000499; rev:4;)這個(gè)是個(gè)用ping命令測試snort是否正常工作的規(guī)則,當(dāng)我ping此入侵檢測系統(tǒng)時(shí)就會得到警告信息Got an ICMP Packet2.6實(shí)

20、驗(yàn)總結(jié): 在上次的基礎(chǔ)上繼續(xù)這次的實(shí)驗(yàn),因?yàn)橛辛酥暗幕A(chǔ)所以對snort有了更加清楚的了解,實(shí)驗(yàn)進(jìn)行的比較順利。因?yàn)橐郧坝羞^LAMP的搭建的經(jīng)歷所以對能很好的完成實(shí)驗(yàn)。但是在寫入侵檢測規(guī)則的時(shí)候還有有些困難,因?yàn)橐雽懞靡粋€(gè)規(guī)則要對通信的協(xié)議比較清楚,還要了解入侵的手段。因?yàn)橹挥芯邆渖鲜鲆蟛拍軐懗鲆粭l有效的規(guī)則。三、簡單的基于嗅探器的入侵檢測系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)3.1 實(shí)驗(yàn)?zāi)康模?)了解和掌握基于網(wǎng)絡(luò)入侵檢測系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)原理(2)掌握網(wǎng)絡(luò)數(shù)據(jù)采集的機(jī)制和實(shí)現(xiàn)方法(3)利用模式匹配技術(shù)和協(xié)議分析技術(shù)實(shí)現(xiàn)簡單的檢測引擎3.2 實(shí)驗(yàn)內(nèi)容(1)設(shè)計(jì)并實(shí)現(xiàn)一個(gè)簡單的嗅探器(2)針對嗅探器所捕獲的數(shù)據(jù)

21、包實(shí)現(xiàn)解碼/譯碼和特征檢測3.3 實(shí)驗(yàn)要求(1) 認(rèn)真完成所規(guī)定的實(shí)驗(yàn)內(nèi)容。(2) 將源代碼,傳送到系ftp服務(wù)器上。要求源代碼有注釋,可讀性較好。文件名命名規(guī)則是Lab3_學(xué)號(3) 將程序的執(zhí)行結(jié)果通過截屏等方式記錄下來,并做簡單分析。(4) 認(rèn)真完成每一個(gè)實(shí)驗(yàn)步驟,并總結(jié)、并進(jìn)行現(xiàn)場演示和說明。 1.4 實(shí)驗(yàn)準(zhǔn)備了解基于嗅探器的入侵檢測系統(tǒng)的設(shè)計(jì)原理。1.5 實(shí)驗(yàn)步驟源碼: / xiutan.cpp : 定義控制臺應(yīng)用程序的入口點(diǎn)。/#include stdafx.h#include stdio.h #include winsock2.h#define SIO_RCVALL _WSAIO

22、W(IOC_VENDOR,1) /this removes the need of mstcpip.hvoid StartSniffing (SOCKET Sock); /This will sniff here and therevoid ProcessPacket (unsigned char* , int); /This will decide how to digestvoid PrintIpHeader (unsigned char* , int); void PrintIcmpPacket (unsigned char* , int);void PrintUdpPacket (un

23、signed char* , int);void PrintTcpPacket (unsigned char* , int);void ConvertToHex (unsigned char* , unsigned int);void PrintData (unsigned char* , int);/IP Header Structuretypedef struct ip_hdr unsigned char ip_header_len:4; / 4-bit header length (in 32-bit words) normally=5 (Means 20 Bytes may be 24

24、 also) unsigned char ip_version :4; / 4-bit IPv4 version unsigned char ip_tos; / IP type of service unsigned short ip_total_length; / Total length unsigned short ip_id; / Unique identifier unsigned char ip_frag_offset :5; / Fragment offset fieldunsigned char ip_more_fragment :1;unsigned char ip_dont

25、_fragment :1;unsigned char ip_reserved_zero :1; unsigned char ip_frag_offset1; /fragment offsetunsigned char ip_ttl; / Time to live unsigned char ip_protocol; / Protocol(TCP,UDP etc) unsigned short ip_checksum; / IP checksum unsigned int ip_srcaddr; / Source address unsigned int ip_destaddr; / Sourc

26、e address IPV4_HDR;/UDP Header Structuretypedef struct udp_hdr unsigned short source_port; / Source port no. unsigned short dest_port; / Dest. port no. unsigned short udp_length; / Udp packet length unsigned short udp_checksum; / Udp checksum (optional) UDP_HDR;/ TCP Header Structuretypedef struct t

27、cp_header unsigned short source_port; / source port unsigned short dest_port; / destination port unsigned int sequence; / sequence number - 32 bits unsigned int acknowledge; / acknowledgement number - 32 bits unsigned char ns :1; /Nonce Sum Flag Added in RFC 3540.unsigned char reserved_part1:3; /acc

28、ording to rfcunsigned char data_offset:4; /*The number of 32-bit words in the TCP header. This indicates where the data begins. The length of the TCP header is always a multiple of 32 bits.*/ unsigned char fin :1; /Finish Flagunsigned char syn :1; /Synchronise Flagunsigned char rst :1; /Reset Flagun

29、signed char psh :1; /Push Flag unsigned char ack :1; /Acknowledgement Flag unsigned char urg :1; /Urgent Flag unsigned char ecn :1; /ECN-Echo Flag unsigned char cwr :1; /Congestion Window Reduced Flag/unsigned short window; / window unsigned short checksum; / checksum unsigned short urgent_pointer;

30、/ urgent pointer TCP_HDR;/ICMP Header Structuretypedef struct icmp_hdr BYTE type; / ICMP Error type BYTE code; / Type sub code USHORT checksum; USHORT id; USHORT seq; ICMP_HDR;FILE *logfile;int tcp=0,udp=0,icmp=0,others=0,igmp=0,total=0,i,j;struct sockaddr_in source,dest;char hex2;/Its free!IPV4_HDR

31、 *iphdr;TCP_HDR *tcpheader;UDP_HDR *udpheader;ICMP_HDR *icmpheader;int main()SOCKET sniffer;struct in_addr addr;int in;char hostname100;struct hostent *local;WSADATA wsa;logfile=fopen(log.txt,w);if(logfile=NULL) printf(Unable to create file.);/Initialise Winsockprintf(nInitialising Winsock.);if (WSA

32、Startup(MAKEWORD(2,2), &wsa) != 0)printf(WSAStartup() failed.n);return 1; printf(Initialised);/Create a RAW Socketprintf(nCreating RAW Socket.);sniffer = socket(AF_INET, SOCK_RAW, IPPROTO_IP); if (sniffer = INVALID_SOCKET)printf(Failed to create raw socket.n);return 1; printf(Created.);/Retrive the

33、local hostnameif (gethostname(hostname, sizeof(hostname) = SOCKET_ERROR) printf(Error : %d,WSAGetLastError();return 1; printf(nHost name : %s n,hostname);/Retrive the available IPs of the local hostlocal = gethostbyname(hostname); printf(nAvailable Network Interfaces : n);if (local = NULL) printf(Er

34、ror : %d.n,WSAGetLastError(); return 1; for (i = 0; local-h_addr_listi != 0; +i) memcpy(&addr, local-h_addr_listi, sizeof(struct in_addr); printf(Interface Number : %d Address : %sn,i,inet_ntoa(addr); printf(Enter the interface number you would like to sniff : );scanf(%d,&in);memset(&dest, 0, sizeof

35、(dest);memcpy(&dest.sin_addr.s_addr,local-h_addr_listin,sizeof(dest.sin_addr.s_addr);dest.sin_family = AF_INET;dest.sin_port = 0; printf(nBinding socket to local system and port 0 .);if (bind(sniffer,(struct sockaddr *)&dest,sizeof(dest) = SOCKET_ERROR)printf(bind(%s) failed.n, inet_ntoa(addr);retur

36、n 1; printf(Binding successful); /Enable this socket with the power to sniff : SIO_RCVALL is the key Receive ALL ;)j=1;printf(nSetting socket to sniff.);if (WSAIoctl(sniffer, SIO_RCVALL, &j, sizeof(j), 0, 0, &in,0, 0) = SOCKET_ERROR)printf(WSAIoctl() failed.n);return 1; printf(Socket set.);/Beginpri

37、ntf(nStarted Sniffingn);printf(Packet Capture Statistics.n);StartSniffing(sniffer); /Happy Sniffing/Endclosesocket(sniffer);WSACleanup();return 0;void StartSniffing(SOCKET sniffer)unsigned char *Buffer = (char *)malloc(65536); /Its Big!int mangobyte;if (Buffer = NULL)printf(malloc() failed.n);return

38、;domangobyte = recvfrom(sniffer,Buffer,65536,0,0,0); /Eat as much as u canif(mangobyte 0)ProcessPacket(Buffer, mangobyte);else printf( recvfrom() failed.n); while (mangobyte 0);free(Buffer);void ProcessPacket(unsigned char* Buffer, int Size)iphdr = (IPV4_HDR *)Buffer;+total;switch (iphdr-ip_protocol

39、) /Check the Protocol and do accordingly.case 1: /ICMP Protocol+icmp;PrintIcmpPacket(Buffer,Size);break;case 2: /IGMP Protocol+igmp;break;case 6: /TCP Protocol+tcp;PrintTcpPacket(Buffer,Size);break;case 17: /UDP Protocol+udp;PrintUdpPacket(Buffer,Size);break;default: /Some Other Protocol like ARP et

40、c.+others;break;printf(TCP : %d UDP : %d ICMP : %d IGMP : %d Others : %d Total : %dr,tcp,udp,icmp,igmp,others,total);void PrintIpHeader (unsigned char* Buffer, int Size)unsigned short iphdrlen;iphdr = (IPV4_HDR *)Buffer;iphdrlen = iphdr-ip_header_len*4;memset(&source, 0, sizeof(source);source.sin_ad

41、dr.s_addr = iphdr-ip_srcaddr;memset(&dest, 0, sizeof(dest);dest.sin_addr.s_addr = iphdr-ip_destaddr;fprintf(logfile,n);fprintf(logfile,IP Headern);fprintf(logfile, |-IP Version : %dn,(unsigned int)iphdr-ip_version);fprintf(logfile, |-IP Header Length : %d DWORDS or %d Bytesn,(unsigned int)iphdr-ip_h

42、eader_len,(unsigned int)(iphdr-ip_header_len)*4);fprintf(logfile, |-Type Of Service : %dn,(unsigned int)iphdr-ip_tos);fprintf(logfile, |-IP Total Length : %d Bytes(Size of Packet)n,ntohs(iphdr-ip_total_length);fprintf(logfile, |-Identification : %dn,ntohs(iphdr-ip_id);fprintf(logfile, |-Reserved ZER

43、O Field : %dn,(unsigned int)iphdr-ip_reserved_zero);fprintf(logfile, |-Dont Fragment Field : %dn,(unsigned int)iphdr-ip_dont_fragment);fprintf(logfile, |-More Fragment Field : %dn,(unsigned int)iphdr-ip_more_fragment);fprintf(logfile, |-TTL : %dn,(unsigned int)iphdr-ip_ttl);fprintf(logfile, |-Protoc

44、ol : %dn,(unsigned int)iphdr-ip_protocol);fprintf(logfile, |-Checksum : %dn,ntohs(iphdr-ip_checksum);fprintf(logfile, |-Source IP : %sn,inet_ntoa(source.sin_addr);fprintf(logfile, |-Destination IP : %sn,inet_ntoa(dest.sin_addr);void PrintTcpPacket(unsigned char* Buffer, int Size)unsigned short iphdr

45、len;iphdr = (IPV4_HDR *)Buffer;iphdrlen = iphdr-ip_header_len*4;tcpheader=(TCP_HDR*)(Buffer+iphdrlen);fprintf(logfile,nn*TCP Packet*n);PrintIpHeader(Buffer,Size);fprintf(logfile,n);fprintf(logfile,TCP Headern);fprintf(logfile, |-Source Port : %un,ntohs(tcpheader-source_port);fprintf(logfile, |-Desti

46、nation Port : %un,ntohs(tcpheader-dest_port);fprintf(logfile, |-Sequence Number : %un,ntohl(tcpheader-sequence);fprintf(logfile, |-Acknowledge Number : %un,ntohl(tcpheader-acknowledge);fprintf(logfile, |-Header Length : %d DWORDS or %d BYTESn,(unsigned int)tcpheader-data_offset,(unsigned int)tcphead

47、er-data_offset*4);fprintf(logfile, |-CWR Flag : %dn,(unsigned int)tcpheader-cwr);fprintf(logfile, |-ECN Flag : %dn,(unsigned int)tcpheader-ecn);fprintf(logfile, |-Urgent Flag : %dn,(unsigned int)tcpheader-urg);fprintf(logfile, |-Acknowledgement Flag : %dn,(unsigned int)tcpheader-ack);fprintf(logfile

48、, |-Push Flag : %dn,(unsigned int)tcpheader-psh);fprintf(logfile, |-Reset Flag : %dn,(unsigned int)tcpheader-rst);fprintf(logfile, |-Synchronise Flag : %dn,(unsigned int)tcpheader-syn);fprintf(logfile, |-Finish Flag : %dn,(unsigned int)tcpheader-fin);fprintf(logfile, |-Window : %dn,ntohs(tcpheader-w

49、indow);fprintf(logfile, |-Checksum : %dn,ntohs(tcpheader-checksum);fprintf(logfile, |-Urgent Pointer : %dn,tcpheader-urgent_pointer);fprintf(logfile,n);fprintf(logfile, DATA Dump );fprintf(logfile,n);fprintf(logfile,IP Headern);PrintData(Buffer,iphdrlen);fprintf(logfile,TCP Headern);PrintData(Buffer+iphdrlen,tcpheader-data_offset*4);fprintf(logfile,Data Payloadn);PrintData(Buffer+iphdrlen+tcpheader-data_offset*4,(Size-tcpheader-data_offset*4-iphdr-ip_header_len*4);fprintf(logfile,n#);void PrintUdpPacket(unsigned char *Buffer,int S

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論