【正文】
, 以 太 網(wǎng) 使 用 了 CSMA/CD( Carrier Sense MultipleAccess/Collision Detection)載波偵聽多路訪問 /沖突檢測 ,這樣一來,共享線路上的所有以太網(wǎng)卡及相關(guān)設(shè) 備總是處于對線路上的信號進(jìn)行監(jiān)聽的狀態(tài)中 ,這使得每一臺機(jī)器都能夠探知并接受線路上的數(shù)據(jù)流。 當(dāng)數(shù)據(jù)經(jīng)過數(shù)據(jù)鏈路層后,就要通過操作系統(tǒng)協(xié)議棧的審核了,系統(tǒng)協(xié)議棧在 TCP/IP 網(wǎng)絡(luò)模型跨越的層次非常多,它們直接從位于系統(tǒng)的數(shù)據(jù)鏈路層提取數(shù)據(jù),通過在這一層的開發(fā)環(huán)境中設(shè)置混雜模式,就可以成功的接收從驅(qū)動層來的各種數(shù)據(jù)包。最終,所有的數(shù)據(jù)變成可以識別的文字、符號出現(xiàn)在機(jī)器的視頻輸出上。 而本設(shè)計的要求通過 網(wǎng)絡(luò)嗅探器從網(wǎng)卡接收所有經(jīng)過它的數(shù)據(jù)包, 因此,在該系統(tǒng)中將網(wǎng)卡以混雜模式替代 通常的正常模式 。至此,實(shí)際就可以開始 對網(wǎng)絡(luò)數(shù)據(jù)包進(jìn)行嗅探了,對數(shù)據(jù)包的獲取仍象流式套接字或數(shù)據(jù)報套接字那樣通過recv()函數(shù)來完成。下面先給出結(jié)構(gòu) ,數(shù)據(jù)包的總體結(jié)構(gòu) 如圖 42 所示 : 數(shù)據(jù)包 IP 頭 TCP 頭(或其他 信息頭) 數(shù)據(jù) 圖 42 數(shù)據(jù)包總體結(jié)構(gòu) 數(shù)據(jù)在從應(yīng)用層到達(dá)傳輸層時,將添加 TCP 數(shù)據(jù)段頭,或是 UDP 數(shù)據(jù)段頭。 //16 位長度 WORD ChkSum。 //目的端口 DWORD SeqNo。 //6 位標(biāo)志位 WORD WndSize。 在網(wǎng)絡(luò)層,還要給 TCP 數(shù)據(jù)包添加一個 IP 數(shù)據(jù)段頭以組成 IP 數(shù)據(jù)報。 // 8 位 服務(wù)類型 unsigned short total_len。 //8 位生存時間 unsigned char proto。 //32 位目的 IP 地址 }IPHEADER; 數(shù)據(jù)包捕獲 程序設(shè)計 根據(jù)前面的設(shè)計思路, 本文在 windows 平臺下實(shí)現(xiàn)了一個嗅探器程序,開發(fā)工具使用 visual C++。 SOCKADDR_IN sa。 if( 0 == m_threadID ) { SetDlgItemText(IDC_LOOKUP,停止捕獲 ! )。 } return 。 m_s = socket( AF_INET , SOCK_RAW , IPPROTO_IP ) 。 closesocket( m_s ) 。rcvtimeo , sizeof(rcvtimeo) ) == SOCKET_ERROR)//設(shè)置工作模式 { dwErr = WSAGetLastError() 。 return 。 //socket(本機(jī) )地址 if (bind(m_s,(PSOCKADDR)amp。 closesocket( m_s ) 。dwBufferLen, sizeof(dwBufferLen), amp。 AfxMessageBox( szErr ) 。 使用 pHost = gethostbyname(szHostName)獲取本地 IP 地址 把原始套接字 m_s 綁定到本地網(wǎng)卡地址上,具體格式如下: bind(m_s,(PSOCKADDR)amp。dwBufferLen, sizeof(dwBufferLen), amp。 MSG msg 。 IPHEADER *pIpHeader 。 int HdrLen, totallen。 struct UDPPacketHead *pUDPHead。 pDlgm_threadID = GetCurrentThreadId() 。 pDlg(TRUE) 。//接收數(shù)據(jù) ...... 數(shù)據(jù)包 的解析 數(shù)據(jù)包被捕獲后 然后就可以根據(jù)前面對 IP 數(shù)據(jù)段頭、 TCP 數(shù)據(jù)段頭的結(jié)構(gòu)描述而對捕獲的數(shù)據(jù)包進(jìn)行分析 。 sprintf( szErr , Error recv() = %ld , dwErr ) 。 WORD iLen = ntohs(pIpHeadertotal_len) 。//得到源 IP地址 = pIpHeaderdestIP 。 strProto = get_proto_name( pIpHeaderproto )。 totallen = ntohs(pIpHeadertotal_len)。 strDestPort = 。 } case IPPROTO_TCP: { pTCPHead=(struct TCPPacketHead *)(buf+HdrLen)。 (%d,destport)。 totallen = HdrLen。 destport = ntohs(pUDPHeadDestPort)。 totallen = UDP_HEAD_LEN。 (%d,totallen)。 (index,1,LVIF_TEXT,s1, 0, 0, 0,0)。 (index,5,LVIF_TEXT,s5, 0, 0, 0,0)。由圖 47 可以觀察到捕獲模塊能夠?qū)崿F(xiàn)將網(wǎng)絡(luò)接口設(shè)置為混雜模式,同時捕獲局域網(wǎng)內(nèi)的數(shù)據(jù)包,在這里還可以觀察到網(wǎng)絡(luò)狀態(tài)及網(wǎng)絡(luò)數(shù)據(jù)的流動情況,供網(wǎng)絡(luò)分析之用。 通過對該課題的研究,讓我對嗅探技術(shù)有了進(jìn)一步的了解,對其兩面性在網(wǎng)絡(luò)中產(chǎn)生的影響有了更深的認(rèn)識,為了打破以上局限性,還需要結(jié)合已學(xué)知識對網(wǎng)絡(luò)嗅探技術(shù)方面的知識作進(jìn)一步的學(xué)習(xí)。 [4] 劉志祥 . Linux系統(tǒng)安全性研究及其新型 Sniffer設(shè)計與實(shí)現(xiàn) [D]. 南昌:南昌大學(xué) [碩士論文 ], 2021。 [8] 孫晶艷 .面向校園網(wǎng)的網(wǎng) 絡(luò)監(jiān)聽技術(shù)研究 [D].黑龍江:哈爾濱工業(yè)大學(xué) [碩士論文 ],2021。除非另有說明,本文的工作是原始性工作。 ( 4)學(xué)??稍试S學(xué)位論文被查閱或借閱。 the fly sat upon the axletree of the chariot wheel, and said. What a dust do I raise? So are there some vain persons, that whatsoever goeths indeed! They could tell us something worth hearing, if they only knew how to talk. It39。t know what that is! The journey of the witches on broomsticks is well enough known that journey is taken on St. John39。 for all bravery stands upon parisons. They must needs be violent, to make good their own vaunts. Neithe r can they be secret, and therefore not effectual。 as if a man that negotiates between two pr。 beaucoup de bruit, peu de fruit: much bruit, little fruit Yet certainly there is use of this quality, in civil affairs. Where there is an opinion, and fame to be created, either of virtue, or greatness, these men are good trumpeters. Again, as Titus Livius noteth, in the case of Antiochus, and the Aetolians。 but we have a wild journey, also which is national and modern, and that is the journey to Amack on the night of the New Year. All indifferent poets and poetesses, musicians, newspaper writers, and artistic notabilities, I mean those who are no good, ride in the New Year39。s eve I was reading the book, and had lost myself in it so pletely, that I fot my usual New Year39。 除非另有科研合同和其他法律文書的制約,本論文的科研成果屬于成都信息工程學(xué)院。 ( 2)學(xué)校可以采用影印、縮印或其他復(fù)制方式保存學(xué)位論文。在此向他表示我最衷心的感謝! 在論文完成過程中,本人還得到了張仕斌老師和陳偉同學(xué)的熱心幫助,本人向他們表示深深的謝意! 最后向在百忙之中評審本文的各位專家、老師表示衷心的感謝! 作者簡介: 姓 名:鄭 莉 性別:女 出生年月: 1985 年 1 月 民族: 漢 Email: 聲 明 本論文的工作是 2021 年 2 月至 2021 年 6 月在成都信息工程學(xué)院 系完成的。 [6] 劉勝斐 .多 Agent 分布式入侵檢測系統(tǒng)中通信機(jī)制和數(shù)據(jù)分析方法研究 [D].江蘇:南開大學(xué) [碩士論文 ], 2021。 [2] 鄭莉,董淵 .C++語言程序設(shè)計(第二版) [M].北京:清華大學(xué)出版社, 2021。設(shè)計完成后經(jīng)測試能實(shí)現(xiàn)預(yù)期要求的功能。 } m_ctrList 是與列表控件 關(guān)聯(lián)的一個變量,列表控件用于顯示對數(shù)據(jù)包的分析結(jié)果。 (index,3,LVIF_TEXT,s3, 0, 0, 0,0)。 ... 數(shù)據(jù)的顯示 在完成了數(shù)據(jù)包的捕獲、分析后,我們使用 AddData 函數(shù),調(diào)用列表控件變量使分析結(jié)果顯 示在界面的列表中,結(jié)果輸出代碼如下: void CIpmonDlg::AddData(CString s0,CString s1, CString s2, CString s3, CString s4, CString s5, CString s6) { int index。 } } if(pIpHeaderproto == IPPROTO_ICMP) (type:%d code:%d data:%s,pICMPHeadType,pICMPHeadCode,pdata)。 (%d,destport)。 } case IPPROTO_UDP: { pUDPHead=(struct UDPPacketHead *)(buf+HdrLen)。 HdrLen *= 4。 destport = ntohs(pTCPHeadDestPort)。 totallen = ICMP_HEAD_LEN。 switch(pIpHeaderproto)//分析包的類型 { case IPPROTO_ICMP: { pICMPHead=(structICMPPacketHead*)(buf+HdrLen)。0xf。 strcpy( szDest , pDest ) 。 pSource = i_ntoa( ina ) 。 } else if( *buf ) { bufwork = buf 。 如圖46 所示: 圖 46 數(shù)據(jù)包解析的簡單流程 圖 46所示為 數(shù)據(jù)包的解析模塊 ,該模塊對捕獲的數(shù)據(jù)包進(jìn)行拆包分析, 根據(jù)不同的協(xié)議類型 分析其 IP地址,數(shù)據(jù)包大小,端口號等,具體代碼實(shí)現(xiàn)如下: UINT threadFunc ( LPVOID p ) { ... iRet = recv( pDlgm_s , buf , sizeof( buf ) , 0 ) 。 } memset( buf , 0 , sizeof(buf) ) 。msg , 0 , WM_CLOSE,WM_CLOSE,PM_NOREMOVE ) ) { closesocket( pDlgm_s ) 。 PeekMessage(amp。 struct TCPPacketHead *pTCPHead。 char szSource [16] , szDest[16] , szErr [ 50 ]