Accueil > > > ANALYSEUR DE TRAFIC (WINPCAP)
ANALYSEUR DE TRAFIC (WINPCAP)
Information sur la source
Description
Il s'agit d'un analyseur de trafic basé sur WinPcap en console et en MASM32! J�ai aussi fait les librairies PACKET.lib et PCAP.lib, ça peut servir (toutes les sources en RadASM par dossiers dans le zip)! Si y a des modifications à faire ou des optimisations, n'hésitez pas à me le dire! Bon coding! PS: c�est la première source que je poste ! Soyez clément ! Merci.
Source
- ; Liens
-
- ; http://www.frameip.com/
- ; http://www.winpcap.org/
- ; http://www.wireshark.org/
-
- ; installer WinPcap_4_0_2.exe
-
- .386
- .model flat, stdcall
-
- include C:\masm32\include\windows.inc
- include C:\masm32\include\user32.inc
- include C:\masm32\include\kernel32.inc
- include C:\masm32\include\wsock32.inc
- include C:\masm32\include\masm32.inc
- include C:\masm32\macros\macros.asm
- include ..\packet\Packet.inc
- include ..\wpcap\wpcap.inc
-
- includelib C:\masm32\lib\kernel32.lib
- includelib C:\masm32\lib\user32.lib
- includelib C:\masm32\lib\wsock32.lib
- includelib C:\masm32\lib\masm32.lib
-
- includelib ..\packet\Packet.lib
- includelib ..\wpcap\wpcap.lib
-
- include SNIFFERMASM.Inc
-
- .code
- start:
-
- ; =====================
- ; capture de packet !!!
- ; =====================
- invoke GetStdHandle,STD_OUTPUT_HANDLE ;|- handle de la fenetre dos
- mov Hconsole,eax
- invoke SetConsoleTitle,addr szTitle ;|- change le titre
-
- invoke pcap_findalldevs,addr alldevs,addr errbuf ;|- cherche les cartes réseaux
- .if (eax == -1) ;|- erreur
- print offset szErrpcap_findalldevs
- .endif
-
- assume ecx:ptr pcap_if
- mov ecx,alldevs
- inc compteur
-
- @@:
- push ecx
- invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_INTENSITY ;|- déco super tendance "gris"
- print offset szSpace
- print offset ParOpen
- invoke SetConsoleTextAttribute,Hconsole,compteur ;|- déco super tendance couleur du chiffre devant la carte
- invoke wsprintf,addr buffsz, addr szformatNb,compteur
- print offset buffsz
- invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_INTENSITY ;|- déco super tendance "gris"
- print offset ParClose
- ;|-
- print offset szSpace ;|
- ;|
- pop ecx ;|
- push ecx ;|
- invoke wsprintf,addr buffsz, addr szformat,[ecx]._name ;|
- print offset buffsz ;| afficchage des "devices"
- print offset szRet ;|
- pop ecx ;| avec leurs descripitions
- push ecx ;|
- invoke wsprintf,addr buffsz, addr szformat,[ecx].description ;|
- print offset buffsz ;|
- print offset szRet ;|
- pop ecx ;|
- push ecx ;|-
- .if ([ecx].next) ;|-
- print offset szRet ;| on test si y en a une autre sinon
- pop ecx ;| on sort
- mov ecx,[ecx].next ;|
- inc compteur ;|
- jmp @B ;|
- .else ;|
- pop ecx ;|
- .endif ;|
- @@: ;|-
- assume ecx:nothing
-
- .if(!compteur) ;|-
- print offset szNoInterfa ;| si y a pas de "dev" on exitprocess
- invoke pcap_freealldevs,alldevs ;|-
- jmp EXIT
- .else
- @@:
- print offset szQuset1
- invoke SetConsoleTextAttribute,Hconsole,1
- print offset szQuset11
- invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_INTENSITY
- print offset szAffHsep
- invoke SetConsoleTextAttribute,Hconsole,compteur
- invoke wsprintf,addr buffsz, addr szformatNb,compteur
- print offset buffsz
- invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_INTENSITY
- print offset szQuset111
-
- mov lpstring,input()
- mov eax,lpstring
- mov al,byte ptr[eax]
-
- .if (al >= "1") && (al <= "9") ;|-
- invoke DecToBin,lpstring ;| là on teste les conneries que l'utilisteurs va saisir
- mov DevSelection,eax ;| dailleur on remarque le bug suivant !
- .else ;|- si il a 10 cartes reseaux !!!! beh !!!
- jmp EXIT
-
- .endif
-
- mov ecx,compteur
- .if((eax > ecx) || (eax < 1))
- print offset szOutRange
- invoke pcap_freealldevs,alldevs
- jmp EXIT
- .endif
- .endif
-
- mov eax,1
-
- assume ecx:ptr pcap_if
- mov ecx,alldevs
- assume edx:ptr pcap_if
- mov edx,alldevs
-
- .while (eax != DevSelection)
- assume edx:ptr pcap_if
- mov edx,[ecx].next
- mov ecx,edx
- inc eax
- .endw
-
- invoke wsprintf,addr buffsz, addr szformat,[edx]._name
- print offset buffsz
- print offset szRet
-
-
- invoke pcap_open_live,addr buffsz,\ ;|- name of the device
- 65536,\ ;| portion of the packet to capture.
- ;| 65536 grants that the whole packet will be captured on all the MACs.
- 1,\ ;| promiscuous mode (nonzero means promiscuous)
- 1000,\ ;| read timeout
- addr errbuf ;|- error buffer
- mov adhandle,eax
- .if !eax
- print offset szErrOpenDev
- invoke pcap_freealldevs,alldevs
- jmp EXIT
- .endif
-
- invoke pcap_datalink,adhandle ;|- Check the link layer. We support only Ethernet for simplicity. bon je traduis pas !!
- .if( eax != 1)
- print offset szIndic ;|- en fait la je ne savais pas si j' devais sortir ou continuer l'execution !!
- .endif
-
- invoke pcap_freealldevs,alldevs ;|- la on a plus besoin de ça, on le quik !
-
- xor ecx,ecx
- .while TRUE
- invoke pcap_next_ex,adhandle,addr ph,addr packet
- .if (eax > 0)
- assume eax: ptr pcap_pkthdr
- mov eax,ph
-
- invoke wsprintf,addr buffsz, addr szformatNb,[eax].caplen
- assume eax:nothing
-
- print offset buffsz
- print offset szBytesCapture
- print offset szRet
-
- push offset iphead
- push packet
- call GetEthHeader
-
- invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_GREEN
-
- movzx edx,byte ptr [iphead.smac.byte1] ;|-
- invoke wsprintf,addr buffsz, addr szformatHex,edx ;|
- print offset buffsz ;|
- print offset szPoiMac ;|
- movzx edx,byte ptr [iphead.smac.byte2] ;|
- invoke wsprintf,addr buffsz, addr szformatHex,edx ;|
- print offset buffsz ;|
- print offset szPoiMac ;|
- movzx edx,byte ptr [iphead.smac.byte3] ;|
- invoke wsprintf,addr buffsz, addr szformatHex,edx ;|
- print offset buffsz ;|
- print offset szPoiMac ;| Affichage
- movzx edx,byte ptr [iphead.smac.byte4] ;|
- invoke wsprintf,addr buffsz, addr szformatHex,edx ;| addr
- print offset buffsz ;|
- print offset szPoiMac ;| - MAC -
- movzx edx,byte ptr [iphead.smac.byte5] ;|
- invoke wsprintf,addr buffsz, addr szformatHex,edx ;| - ETH -
- print offset buffsz ;|
- print offset szPoiMac ;|
- movzx edx,byte ptr [iphead.smac.byte6] ;|
- invoke wsprintf,addr buffsz, addr szformatHex,edx ;|
- print offset buffsz ;|-
-
- invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_INTENSITY
-
- print offset szAffHsep ;|-
- invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_RED
-
- movzx edx,byte ptr [iphead.dmac.byte1] ;|
- invoke wsprintf,addr buffsz, addr szformatHex,edx ;|
- print offset buffsz ;|
- print offset szPoiMac ;|
- movzx edx,byte ptr [iphead.dmac.byte2] ;|
- invoke wsprintf,addr buffsz, addr szformatHex,edx ;|
- print offset buffsz ;|
- print offset szPoiMac ;|
- movzx edx,byte ptr [iphead.dmac.byte3] ;|
- invoke wsprintf,addr buffsz, addr szformatHex,edx ;|
- print offset buffsz ;|
- print offset szPoiMac ;| Affichage
- movzx edx,byte ptr [iphead.dmac.byte4] ;|
- invoke wsprintf,addr buffsz, addr szformatHex,edx ;| adresse
- print offset buffsz ;|
- print offset szPoiMac ;| Mac
- movzx edx,byte ptr [iphead.dmac.byte5] ;|
- invoke wsprintf,addr buffsz, addr szformatHex,edx ;|
- print offset buffsz ;|
- print offset szPoiMac ;|
- movzx edx,byte ptr [iphead.dmac.byte6] ;|
- invoke wsprintf,addr buffsz, addr szformatHex,edx ;|
- print offset buffsz ;|-
- print offset szRet
-
- invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_INTENSITY
-
- mov dx,WORD ptr [iphead.eth_type]
- ;============================================================
- ; IPv4
- ;============================================================
- .if (dx == 00800h)
- print offset zz0800
- push offset iphead
- push packet
- call GetIpHeader
-
- xor edx, edx ;|-
- mov dl,byte ptr [iphead.protocole] ;|
- .if (dl > 1) ;|
- mov eax,TAILLE_SZPROTOCOL ;| taille d'une ligne
- mul dl ;|
- mov edx,offset szProtocol1 ;|
- add eax,edx ;|
- sub eax,45 ;| -45 pour pointer sur
- print eax ;| le debut de la ligne
- .else ;|
- mov eax,offset szProtocol1 ;|
- print eax ;|-
- .endif
-
- invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_GREEN
- movzx edx,byte ptr [iphead.sip.byte1] ;|-
- invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
- print offset buffsz ;|
- print offset szPoi ;|
- movzx edx,byte ptr [iphead.sip.byte2] ;|
- invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
- print offset buffsz ;|
- print offset szPoi ;|
- movzx edx,byte ptr [iphead.sip.byte3] ;|
- invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
- print offset buffsz ;|
- print offset szPoi ;| Affichage d'adresse
- movzx edx,byte ptr [iphead.sip.byte4] ;|
- invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
- print offset buffsz ;| IP source et
- ;|
- invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_INTENSITY
- print offset szAffHsep ;| destination
- invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_RED ;|
- ;|
- movzx edx,byte ptr [iphead.dip.byte1] ;|
- invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
- print offset buffsz ;|
- print offset szPoi ;|
- movzx edx,byte ptr [iphead.dip.byte2] ;|
- invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
- print offset buffsz ;|
- print offset szPoi ;|
- movzx edx,byte ptr [iphead.dip.byte3] ;|
- invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
- print offset buffsz ;|
- print offset szPoi ;|
- movzx edx,byte ptr [iphead.dip.byte4] ;|
- invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
- print offset buffsz ;|
- print offset szRet ;|-
- invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_INTENSITY
-
- print offset szRet
- assume eax: ptr pcap_pkthdr ;|-
- mov eax,ph ;| affiche la
- push TCP_PRINT_COLOR ;|
- push [eax].caplen ;|
- push packet ;| trame en hexa
- call PrintPacket ;|
- assume eax:nothing ;| et en ascii.
-
- ;============================================================
- ; ARP
- ;============================================================
- .elseif (dx == 00806h)
- print offset sz0806
-
- push offset iphead
- push packet
- call GetArpHeader
-
- invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_GREEN
- movzx edx,byte ptr [iphead.sip.byte1] ;|-
- invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
- print offset buffsz ;|
- print offset szPoi ;|
- movzx edx,byte ptr [iphead.sip.byte2] ;|
- invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
- print offset buffsz ;|
- print offset szPoi ;|
- movzx edx,byte ptr [iphead.sip.byte3] ;|
- invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
- print offset buffsz ;|
- print offset szPoi ;| Affichage d'adresse
- movzx edx,byte ptr [iphead.sip.byte4] ;|
- invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
- print offset buffsz ;| IP source et
- ;|
- invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_INTENSITY
- print offset szAffHsep ;| destination
- invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_RED ;|
- ;|
- movzx edx,byte ptr [iphead.dip.byte1] ;|
- invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
- print offset buffsz ;|
- print offset szPoi ;|
- movzx edx,byte ptr [iphead.dip.byte2] ;|
- invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
- print offset buffsz ;|
- print offset szPoi ;|
- movzx edx,byte ptr [iphead.dip.byte3] ;|
- invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
- print offset buffsz ;|
- print offset szPoi ;|
- movzx edx,byte ptr [iphead.dip.byte4] ;|
- invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
- print offset buffsz ;|
- print offset szRet ;|-
- invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_INTENSITY
-
- print offset szRet
- assume eax: ptr pcap_pkthdr ;|-
- mov eax,ph ;| affiche la
- push ARP_PRINT_COLOR ;|
- push [eax].caplen ;|
- push packet ;| trame en hexa
- call PrintPacket ;|
- assume eax:nothing ;| et en ascii.
-
- .elseif (dx == 08035h) ;|-
- print offset sz8035 ;|
- .elseif (dx == 0809Bh) ;|
- print offset sz809B ;|
- .elseif (dx == 080F3h) ;|
- print offset sz80F3 ;|
- .elseif (dx == 08100h) ;|
- print offset sz8100 ;|
- .elseif (dx == 08137h) ;|
- print offset sz8137 ;| les autres tu complaiteras
- .elseif (dx == 08138h) ;|
- print offset sz8138 ;|
- .elseif (dx == 086DDh) ;|
- print offset sz86DD ;|
- .elseif (dx == 08847h) ;|
- print offset sz8847 ;|
- .elseif (dx == 08848h) ;|
- print offset sz8848 ;|
- .elseif (dx == 08863h) ;|
- print offset sz8863 ;|
- .elseif (dx == 08864h) ;|
- print offset sz8864 ;|
- .elseif (dx == 088A2h) ;|
- print offset sz88A2 ;|-
- .else
- print offset szUnknowPk
- .endif
-
- print offset szRet
- print offset szRet
- .endif
- .endw
-
- invoke pcap_close,adhandle
-
-
- mov lpstring,input()
- mov eax,lpstring
-
- EXIT:
-
- invoke Sleep,500
-
- xor eax,eax
- invoke ExitProcess,eax
-
- ;==========================================================================
- ; DecToBin (decimal -> binaire)
- ;==========================================================================
-
- align 4
-
- DecToBin proc uses ecx edx esi edi lpstr:DWORD
-
- mov esi,lpstr
- xor eax,eax
-
- @@:
- xor edx,edx
- mov dl,byte ptr[esi]
- test edx,edx
- jz @F
- inc esi
-
- sub edx,'0'
-
- shl eax,1 ; eax = 10*eax + edx;
- mov ecx,eax
- shl eax,2
- add eax,ecx
- add eax,edx
- jmp @B
- @@:
-
- ret
- DecToBin endp
-
- ;==========================================================================
- ; PrintPacket
- ;==========================================================================
-
- align 4
-
- PrintPacket proc uses esi edx lpBuffPacket:DWORD,lengthPacket:DWORD,Opt:DWORD
- ;|-
- LOCAL comp :DWORD ;| variable local
- LOCAL comp16 :DWORD ;|
- LOCAL BuffAffichage [MAX_PATH]:BYTE ;|
- ;|-
- ; =====================
- ; Affichage du Packet
- ; =====================
-
- lea edi,BuffAffichage ;|-
- mov esi,DWORD ptr [lpBuffPacket] ;|-
- mov PosPointeur,esi ;|
- mov comp,0 ;|
- mov comp16,0 ;|- On initialise
- L1: ;|
- assume eax: ptr pcap_pkthdr ;|
- mov eax,ph ;|
- mov ecx,lengthPacket ;|
- cmp comp,ecx ;|
- assume eax:nothing ;|
- ;|
- je E1 ;|
- mov eax,comp ;| Si oui, on sort de la boucle
- mov dl,byte ptr [esi+eax] ;|-
-
- ;|- ASCII compris entre :
- .if ((dl >= 00020h) && (dl <= 0007eh) || \ ;|
- (dl >= 'A') && (dl <= 'Z') || \ ;| ('A' et 'Z') ou
- (dl >= 'a') && (dl <= 'z') || \ ;| ('a' et 'z') ou
- (dl >= '0') && (dl <= '9')) ;| ('0' et '9')
- mov eax,comp16 ;| on copy le char
- mov byte ptr [edi+eax],dl ;|-
- .elseif (dl == 0000Dh)
- mov eax,comp16 ;| on copy le char
- mov byte ptr [edi+eax],"." ;|-
- ;add FlagDoublRet
- .elseif (dl == 0000Ah)
-
- mov eax,comp16 ;| on copy le char
- mov byte ptr [edi+eax],"." ;|-
- .else ;|-
- mov eax,comp16 ;| sinon
- mov byte ptr [edi+eax],'.' ;| on copy
- .endif ;| un point '.'
- ;|-
-
- mov eax,comp ;|-
- mov dl,byte ptr [esi+eax] ;|
- movzx edx,byte ptr [esi+eax] ;|
- pusha ;| Afichage en couleur !! WOUAHH
- pusha ;|
- .if (Opt == TCP_PRINT_COLOR)
- .if ((comp >= 6) && (comp < 12)) || ((comp >= 26) && (comp < 30))
- invoke SetConsoleTextAttribute, Hconsole,FOREGROUND_GREEN
-
- .elseif ((comp >= 0) && (comp < 6)) || ((comp >= 30) && (comp < 34))
- invoke SetConsoleTextAttribute, Hconsole,FOREGROUND_RED;|
- .else
- invoke SetConsoleTextAttribute, Hconsole,FOREGROUND_INTENSITY
- .endif
-
- .elseif (Opt == ARP_PRINT_COLOR)
- .if ((comp >= 6) && (comp < 12)) || ((comp >= 28) && (comp < 32))
- invoke SetConsoleTextAttribute, Hconsole,FOREGROUND_GREEN;|
-
- .elseif ((comp >= 0) && (comp < 6)) || ((comp >= 38) && (comp < 42))
- invoke SetConsoleTextAttribute, Hconsole,FOREGROUND_RED;|
- .else
- invoke SetConsoleTextAttribute, Hconsole,FOREGROUND_INTENSITY
- .endif
- .endif
- popa
- invoke wsprintf,addr buffsz, addr szformatHex,edx ;| caractères, un par un !
- print offset buffsz ;|
- print offset szSpace ;|
- popa ;|
- inc comp ;| comp+1
- inc comp16 ;|
- xor edx,edx ;|
- mov eax,comp ;|
- mov ecx,16 ;|
- div ecx ;|
- .if (!edx) ;|
- invoke SetConsoleTextAttribute, Hconsole,\ ;|
- FOREGROUND_INTENSITY;|
- ;|
- print offset szSpace ;|
- mov comp16,0 ;|
- lea eax,BuffAffichage ;|
- ;|
- mov byte ptr [eax+16],0 ;|
- ;|
- print eax ;|
- print offset szRet ;|
- .endif ;|
- ;|
- jmp L1 ;| Retour au debut de la boucle
- E1: ;|-
-
- mov edx,16 ;|-
- mov ecx,comp16 ;|
- sub edx,ecx ;|
- .if (edx > 0) ;|
- .while (edx > 0) ;| calcul des espaces nécessaires
- pusha ;| pour afficher la dernière ligne.
- print offset szSpace ;|
- print offset szSpace ;|
- print offset szSpace ;|
- popa ;|
- dec edx ;|
- .endw ;|
- .endif ;|-
-
- invoke SetConsoleTextAttribute, Hconsole,\ ;|
- FOREGROUND_INTENSITY ;|
-
- print offset szSpace ;|-
- lea eax,BuffAffichage ;|
- mov ecx,comp16 ;|
- mov byte ptr [eax+ecx],0 ;| affiche la dernière ligne.
- print eax ;|
- print offset szRet ;|-
- ret
-
- PrintPacket endp
-
-
- ;==========================================================================
- ; GetIpHeader
- ;==========================================================================
-
- align 4
-
- GetArpHeader proc uses esi edx lpBuffPacket:DWORD,lpiphead:DWORD
-
- mov esi,DWORD ptr [lpBuffPacket]
-
- ;add esi,14 ;|- debut de l'entête IP (Byte : 14)
- assume ecx:ptr ip_header
- mov ecx,lpiphead
-
- ; Modifie esi et pointe ou tu veux dans le buffer. au 28ième caractère, par exemple
- ; il y a l'adresse IP de destination !! pour pour d'info va sur le site frameip.com
-
- add esi,28 ;|-
- mov dl,byte ptr [esi] ;| Bytes: 28 - 32
- mov byte ptr [[ecx].sip.byte1],dl ;|
- inc esi ;|
- mov dl,byte ptr [esi] ;|
- mov byte ptr [[ecx].sip.byte2],dl ;| Destination Address
- inc esi ;|
- mov dl,byte ptr [esi] ;|
- mov byte ptr [[ecx].sip.byte3],dl ;|
- inc esi ;|
- mov dl,byte ptr [esi] ;|
- mov byte ptr [[ecx].sip.byte4],dl ;|-
-
- add esi,7 ;|-
- mov dl,byte ptr [esi] ;| Bytes: 33 - 37
- mov byte ptr [[ecx].dip.byte1],dl ;|
- inc esi ;|
- mov dl,byte ptr [esi] ;|
- mov byte ptr [[ecx].dip.byte2],dl ;| Destination Address
- inc esi ;|
- mov dl,byte ptr [esi] ;|
- mov byte ptr [[ecx].dip.byte3],dl ;|
- inc esi ;|
- mov dl,byte ptr [esi] ;|
- mov byte ptr [[ecx].dip.byte4],dl ;|-
-
- assume ecx:nothing
- xor eax,eax
-
- ret
-
- GetArpHeader endp
-
-
- ;==========================================================================
- ; GetIpHeader
- ;==========================================================================
-
- align 4
-
- GetIpHeader proc uses esi edx lpBuffPacket:DWORD,lpiphead:DWORD
-
- mov esi,DWORD ptr [lpBuffPacket]
-
- add esi,14 ;|- debut de l'entête IP (Byte : 14)
- assume ecx:ptr ip_header
- mov ecx,lpiphead
- ;|- Bytes: 14
- mov dl,byte ptr [esi] ;| Version (4 bits) + Internet header length (4 bits)
- mov byte ptr [[ecx].ver_ihl],dl ;|-
-
- inc esi ;|- Bytes: 15
- mov dl,byte ptr [esi] ;| Type de service
- mov byte ptr [[ecx].tos],dl ;|-
-
- inc esi ;|-
- movzx edx,byte ptr [esi] ;| Bytes: 16 - 17
- shl edx,8 ;|
- inc esi ;| Total length
- mov dl,byte ptr [esi] ;|
- mov word ptr [[ecx].tlen],dx ;|-
-
- inc esi ;|-
- movzx edx,byte ptr [esi] ;| Bytes: 18 - 19
- shl edx,8 ;|
- inc esi ;| Identification
- mov dl,byte ptr [esi] ;|
- mov word ptr [[ecx].identification],dx ;|-
-
- inc esi ;|-
- movzx edx,byte ptr [esi] ;| Bytes: 20 - 21
- shl edx,8 ;|
- inc esi ;| flags info
- mov dl,byte ptr [esi] ;|
- mov word ptr [[ecx].flags_fo],dx ;|-
-
- inc esi ;|- Bytes: 22
- mov dl,byte ptr [esi] ;| ttl
- mov byte ptr [[ecx].ttl],dl ;|-
-
- inc esi ;|- Bytes: 23
- mov dl,byte ptr [esi] ;| protocole
- mov byte ptr [[ecx].protocole],dl ;|-
-
- inc esi ;|-
- movzx edx,byte ptr [esi] ;| Bytes: 24 - 25
- shl edx,8 ;|
- inc esi ;| Header checksum
- mov dl,byte ptr [esi] ;|
- mov word ptr [[ecx].crc],dx ;|-
-
- inc esi ;|-
- mov dl,byte ptr [esi] ;| Bytes: 26 - 27
- mov byte ptr [[ecx].sip.byte1],dl ;|
- inc esi ;|
- mov dl,byte ptr [esi] ;|
- mov byte ptr [[ecx].sip.byte2],dl ;| Destination Address
- inc esi ;|
- mov dl,byte ptr [esi] ;|
- mov byte ptr [[ecx].sip.byte3],dl ;|
- inc esi ;|
- mov dl,byte ptr [esi] ;|
- mov byte ptr [[ecx].sip.byte4],dl ;|-
-
- inc esi ;|-
- mov dl,byte ptr [esi] ;| Bytes: 28 - 29
- mov byte ptr [[ecx].dip.byte1],dl ;|
- inc esi ;|
- mov dl,byte ptr [esi] ;|
- mov byte ptr [[ecx].dip.byte2],dl ;| Destination Address
- inc esi ;|
- mov dl,byte ptr [esi] ;|
- mov byte ptr [[ecx].dip.byte3],dl ;|
- inc esi ;|
- mov dl,byte ptr [esi] ;|
- mov byte ptr [[ecx].dip.byte4],dl ;|-
-
- inc esi ;|-
- movzx edx,byte ptr [esi] ;| Bytes: 24 - 25
- shl edx,8 ;|
- inc esi ;| Option + Padding
- mov dl,byte ptr [esi] ;|
- shl edx,8 ;|
- inc esi ;|
- mov dl,byte ptr [esi] ;|
- shl edx,8 ;|
- inc esi ;|
- mov dl,byte ptr [esi] ;|
- mov DWORD ptr [[ecx].op_pad],edx ;|-
-
- assume ecx:nothing
- xor eax,eax
-
- ret
-
- GetIpHeader endp
-
-
- ;==========================================================================
- ; GetEthHeader
- ;==========================================================================
-
- align 4
-
- GetEthHeader proc uses esi edx lpBuffPacket:DWORD,lpiphead:DWORD
-
- mov esi,DWORD ptr [lpBuffPacket]
-
- assume ecx:ptr ip_header
- mov ecx,lpiphead
- mov dl,byte ptr [esi] ;|-
- mov byte ptr [[ecx].dmac.byte1],dl ;| Bytes: 0 - 5
- inc esi ;|
- mov dl,byte ptr [esi] ;|
- mov byte ptr [[ecx].dmac.byte2],dl ;| Destination Address
- inc esi ;|
- mov dl,byte ptr [esi] ;|
- mov byte ptr [[ecx].dmac.byte3],dl ;|
- inc esi ;|
- mov dl,byte ptr [esi] ;|
- mov byte ptr [[ecx].dmac.byte4],dl ;|
- inc esi ;|
- mov dl,byte ptr [esi] ;|
- mov byte ptr [[ecx].dmac.byte5],dl ;|
- inc esi ;|
- mov dl,byte ptr [esi] ;|
- mov byte ptr [[ecx].dmac.byte6],dl ;|-
-
- inc esi ;|-
- mov dl,byte ptr [esi] ;| Bytes: 6 - 11
- mov byte ptr [[ecx].smac.byte1],dl ;|
- inc esi ;|
- mov dl,byte ptr [esi] ;|
- mov byte ptr [[ecx].smac.byte2],dl ;|
- inc esi ;|
- mov dl,byte ptr [esi] ;|
- mov byte ptr [[ecx].smac.byte3],dl ;|
- inc esi ;| Source Address
- mov dl,byte ptr [esi] ;|
- mov byte ptr [[ecx].smac.byte4],dl ;|
- inc esi ;|
- mov dl,byte ptr [esi] ;|
- mov byte ptr [[ecx].smac.byte5],dl ;|
- inc esi ;|
- mov dl,byte ptr [esi] ;|
- mov byte ptr [[ecx].smac.byte6],dl ;|-
-
- inc esi ;|-
- movzx edx,byte ptr [esi] ;| Bytes: 12 - 13
- shl edx,8 ;|
- inc esi ;| Ethernet Type
- mov dl,byte ptr [esi] ;|
- mov word ptr [[ecx].eth_type],dx ;|-
-
- assume ecx:nothing
- xor eax,eax
-
- ret
-
- GetEthHeader endp
-
- end start
; Liens
; http://www.frameip.com/
; http://www.winpcap.org/
; http://www.wireshark.org/
; installer WinPcap_4_0_2.exe
.386
.model flat, stdcall
include C:\masm32\include\windows.inc
include C:\masm32\include\user32.inc
include C:\masm32\include\kernel32.inc
include C:\masm32\include\wsock32.inc
include C:\masm32\include\masm32.inc
include C:\masm32\macros\macros.asm
include ..\packet\Packet.inc
include ..\wpcap\wpcap.inc
includelib C:\masm32\lib\kernel32.lib
includelib C:\masm32\lib\user32.lib
includelib C:\masm32\lib\wsock32.lib
includelib C:\masm32\lib\masm32.lib
includelib ..\packet\Packet.lib
includelib ..\wpcap\wpcap.lib
include SNIFFERMASM.Inc
.code
start:
; =====================
; capture de packet !!!
; =====================
invoke GetStdHandle,STD_OUTPUT_HANDLE ;|- handle de la fenetre dos
mov Hconsole,eax
invoke SetConsoleTitle,addr szTitle ;|- change le titre
invoke pcap_findalldevs,addr alldevs,addr errbuf ;|- cherche les cartes réseaux
.if (eax == -1) ;|- erreur
print offset szErrpcap_findalldevs
.endif
assume ecx:ptr pcap_if
mov ecx,alldevs
inc compteur
@@:
push ecx
invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_INTENSITY ;|- déco super tendance "gris"
print offset szSpace
print offset ParOpen
invoke SetConsoleTextAttribute,Hconsole,compteur ;|- déco super tendance couleur du chiffre devant la carte
invoke wsprintf,addr buffsz, addr szformatNb,compteur
print offset buffsz
invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_INTENSITY ;|- déco super tendance "gris"
print offset ParClose
;|-
print offset szSpace ;|
;|
pop ecx ;|
push ecx ;|
invoke wsprintf,addr buffsz, addr szformat,[ecx]._name ;|
print offset buffsz ;| afficchage des "devices"
print offset szRet ;|
pop ecx ;| avec leurs descripitions
push ecx ;|
invoke wsprintf,addr buffsz, addr szformat,[ecx].description ;|
print offset buffsz ;|
print offset szRet ;|
pop ecx ;|
push ecx ;|-
.if ([ecx].next) ;|-
print offset szRet ;| on test si y en a une autre sinon
pop ecx ;| on sort
mov ecx,[ecx].next ;|
inc compteur ;|
jmp @B ;|
.else ;|
pop ecx ;|
.endif ;|
@@: ;|-
assume ecx:nothing
.if(!compteur) ;|-
print offset szNoInterfa ;| si y a pas de "dev" on exitprocess
invoke pcap_freealldevs,alldevs ;|-
jmp EXIT
.else
@@:
print offset szQuset1
invoke SetConsoleTextAttribute,Hconsole,1
print offset szQuset11
invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_INTENSITY
print offset szAffHsep
invoke SetConsoleTextAttribute,Hconsole,compteur
invoke wsprintf,addr buffsz, addr szformatNb,compteur
print offset buffsz
invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_INTENSITY
print offset szQuset111
mov lpstring,input()
mov eax,lpstring
mov al,byte ptr[eax]
.if (al >= "1") && (al <= "9") ;|-
invoke DecToBin,lpstring ;| là on teste les conneries que l'utilisteurs va saisir
mov DevSelection,eax ;| dailleur on remarque le bug suivant !
.else ;|- si il a 10 cartes reseaux !!!! beh !!!
jmp EXIT
.endif
mov ecx,compteur
.if((eax > ecx) || (eax < 1))
print offset szOutRange
invoke pcap_freealldevs,alldevs
jmp EXIT
.endif
.endif
mov eax,1
assume ecx:ptr pcap_if
mov ecx,alldevs
assume edx:ptr pcap_if
mov edx,alldevs
.while (eax != DevSelection)
assume edx:ptr pcap_if
mov edx,[ecx].next
mov ecx,edx
inc eax
.endw
invoke wsprintf,addr buffsz, addr szformat,[edx]._name
print offset buffsz
print offset szRet
invoke pcap_open_live,addr buffsz,\ ;|- name of the device
65536,\ ;| portion of the packet to capture.
;| 65536 grants that the whole packet will be captured on all the MACs.
1,\ ;| promiscuous mode (nonzero means promiscuous)
1000,\ ;| read timeout
addr errbuf ;|- error buffer
mov adhandle,eax
.if !eax
print offset szErrOpenDev
invoke pcap_freealldevs,alldevs
jmp EXIT
.endif
invoke pcap_datalink,adhandle ;|- Check the link layer. We support only Ethernet for simplicity. bon je traduis pas !!
.if( eax != 1)
print offset szIndic ;|- en fait la je ne savais pas si j' devais sortir ou continuer l'execution !!
.endif
invoke pcap_freealldevs,alldevs ;|- la on a plus besoin de ça, on le quik !
xor ecx,ecx
.while TRUE
invoke pcap_next_ex,adhandle,addr ph,addr packet
.if (eax > 0)
assume eax: ptr pcap_pkthdr
mov eax,ph
invoke wsprintf,addr buffsz, addr szformatNb,[eax].caplen
assume eax:nothing
print offset buffsz
print offset szBytesCapture
print offset szRet
push offset iphead
push packet
call GetEthHeader
invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_GREEN
movzx edx,byte ptr [iphead.smac.byte1] ;|-
invoke wsprintf,addr buffsz, addr szformatHex,edx ;|
print offset buffsz ;|
print offset szPoiMac ;|
movzx edx,byte ptr [iphead.smac.byte2] ;|
invoke wsprintf,addr buffsz, addr szformatHex,edx ;|
print offset buffsz ;|
print offset szPoiMac ;|
movzx edx,byte ptr [iphead.smac.byte3] ;|
invoke wsprintf,addr buffsz, addr szformatHex,edx ;|
print offset buffsz ;|
print offset szPoiMac ;| Affichage
movzx edx,byte ptr [iphead.smac.byte4] ;|
invoke wsprintf,addr buffsz, addr szformatHex,edx ;| addr
print offset buffsz ;|
print offset szPoiMac ;| - MAC -
movzx edx,byte ptr [iphead.smac.byte5] ;|
invoke wsprintf,addr buffsz, addr szformatHex,edx ;| - ETH -
print offset buffsz ;|
print offset szPoiMac ;|
movzx edx,byte ptr [iphead.smac.byte6] ;|
invoke wsprintf,addr buffsz, addr szformatHex,edx ;|
print offset buffsz ;|-
invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_INTENSITY
print offset szAffHsep ;|-
invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_RED
movzx edx,byte ptr [iphead.dmac.byte1] ;|
invoke wsprintf,addr buffsz, addr szformatHex,edx ;|
print offset buffsz ;|
print offset szPoiMac ;|
movzx edx,byte ptr [iphead.dmac.byte2] ;|
invoke wsprintf,addr buffsz, addr szformatHex,edx ;|
print offset buffsz ;|
print offset szPoiMac ;|
movzx edx,byte ptr [iphead.dmac.byte3] ;|
invoke wsprintf,addr buffsz, addr szformatHex,edx ;|
print offset buffsz ;|
print offset szPoiMac ;| Affichage
movzx edx,byte ptr [iphead.dmac.byte4] ;|
invoke wsprintf,addr buffsz, addr szformatHex,edx ;| adresse
print offset buffsz ;|
print offset szPoiMac ;| Mac
movzx edx,byte ptr [iphead.dmac.byte5] ;|
invoke wsprintf,addr buffsz, addr szformatHex,edx ;|
print offset buffsz ;|
print offset szPoiMac ;|
movzx edx,byte ptr [iphead.dmac.byte6] ;|
invoke wsprintf,addr buffsz, addr szformatHex,edx ;|
print offset buffsz ;|-
print offset szRet
invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_INTENSITY
mov dx,WORD ptr [iphead.eth_type]
;============================================================
; IPv4
;============================================================
.if (dx == 00800h)
print offset zz0800
push offset iphead
push packet
call GetIpHeader
xor edx, edx ;|-
mov dl,byte ptr [iphead.protocole] ;|
.if (dl > 1) ;|
mov eax,TAILLE_SZPROTOCOL ;| taille d'une ligne
mul dl ;|
mov edx,offset szProtocol1 ;|
add eax,edx ;|
sub eax,45 ;| -45 pour pointer sur
print eax ;| le debut de la ligne
.else ;|
mov eax,offset szProtocol1 ;|
print eax ;|-
.endif
invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_GREEN
movzx edx,byte ptr [iphead.sip.byte1] ;|-
invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
print offset buffsz ;|
print offset szPoi ;|
movzx edx,byte ptr [iphead.sip.byte2] ;|
invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
print offset buffsz ;|
print offset szPoi ;|
movzx edx,byte ptr [iphead.sip.byte3] ;|
invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
print offset buffsz ;|
print offset szPoi ;| Affichage d'adresse
movzx edx,byte ptr [iphead.sip.byte4] ;|
invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
print offset buffsz ;| IP source et
;|
invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_INTENSITY
print offset szAffHsep ;| destination
invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_RED ;|
;|
movzx edx,byte ptr [iphead.dip.byte1] ;|
invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
print offset buffsz ;|
print offset szPoi ;|
movzx edx,byte ptr [iphead.dip.byte2] ;|
invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
print offset buffsz ;|
print offset szPoi ;|
movzx edx,byte ptr [iphead.dip.byte3] ;|
invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
print offset buffsz ;|
print offset szPoi ;|
movzx edx,byte ptr [iphead.dip.byte4] ;|
invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
print offset buffsz ;|
print offset szRet ;|-
invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_INTENSITY
print offset szRet
assume eax: ptr pcap_pkthdr ;|-
mov eax,ph ;| affiche la
push TCP_PRINT_COLOR ;|
push [eax].caplen ;|
push packet ;| trame en hexa
call PrintPacket ;|
assume eax:nothing ;| et en ascii.
;============================================================
; ARP
;============================================================
.elseif (dx == 00806h)
print offset sz0806
push offset iphead
push packet
call GetArpHeader
invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_GREEN
movzx edx,byte ptr [iphead.sip.byte1] ;|-
invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
print offset buffsz ;|
print offset szPoi ;|
movzx edx,byte ptr [iphead.sip.byte2] ;|
invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
print offset buffsz ;|
print offset szPoi ;|
movzx edx,byte ptr [iphead.sip.byte3] ;|
invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
print offset buffsz ;|
print offset szPoi ;| Affichage d'adresse
movzx edx,byte ptr [iphead.sip.byte4] ;|
invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
print offset buffsz ;| IP source et
;|
invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_INTENSITY
print offset szAffHsep ;| destination
invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_RED ;|
;|
movzx edx,byte ptr [iphead.dip.byte1] ;|
invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
print offset buffsz ;|
print offset szPoi ;|
movzx edx,byte ptr [iphead.dip.byte2] ;|
invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
print offset buffsz ;|
print offset szPoi ;|
movzx edx,byte ptr [iphead.dip.byte3] ;|
invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
print offset buffsz ;|
print offset szPoi ;|
movzx edx,byte ptr [iphead.dip.byte4] ;|
invoke wsprintf,addr buffsz, addr szformatNb,edx ;|
print offset buffsz ;|
print offset szRet ;|-
invoke SetConsoleTextAttribute,Hconsole,FOREGROUND_INTENSITY
print offset szRet
assume eax: ptr pcap_pkthdr ;|-
mov eax,ph ;| affiche la
push ARP_PRINT_COLOR ;|
push [eax].caplen ;|
push packet ;| trame en hexa
call PrintPacket ;|
assume eax:nothing ;| et en ascii.
.elseif (dx == 08035h) ;|-
print offset sz8035 ;|
.elseif (dx == 0809Bh) ;|
print offset sz809B ;|
.elseif (dx == 080F3h) ;|
print offset sz80F3 ;|
.elseif (dx == 08100h) ;|
print offset sz8100 ;|
.elseif (dx == 08137h) ;|
print offset sz8137 ;| les autres tu complaiteras
.elseif (dx == 08138h) ;|
print offset sz8138 ;|
.elseif (dx == 086DDh) ;|
print offset sz86DD ;|
.elseif (dx == 08847h) ;|
print offset sz8847 ;|
.elseif (dx == 08848h) ;|
print offset sz8848 ;|
.elseif (dx == 08863h) ;|
print offset sz8863 ;|
.elseif (dx == 08864h) ;|
print offset sz8864 ;|
.elseif (dx == 088A2h) ;|
print offset sz88A2 ;|-
.else
print offset szUnknowPk
.endif
print offset szRet
print offset szRet
.endif
.endw
invoke pcap_close,adhandle
mov lpstring,input()
mov eax,lpstring
EXIT:
invoke Sleep,500
xor eax,eax
invoke ExitProcess,eax
;==========================================================================
; DecToBin (decimal -> binaire)
;==========================================================================
align 4
DecToBin proc uses ecx edx esi edi lpstr:DWORD
mov esi,lpstr
xor eax,eax
@@:
xor edx,edx
mov dl,byte ptr[esi]
test edx,edx
jz @F
inc esi
sub edx,'0'
shl eax,1 ; eax = 10*eax + edx;
mov ecx,eax
shl eax,2
add eax,ecx
add eax,edx
jmp @B
@@:
ret
DecToBin endp
;==========================================================================
; PrintPacket
;==========================================================================
align 4
PrintPacket proc uses esi edx lpBuffPacket:DWORD,lengthPacket:DWORD,Opt:DWORD
;|-
LOCAL comp :DWORD ;| variable local
LOCAL comp16 :DWORD ;|
LOCAL BuffAffichage [MAX_PATH]:BYTE ;|
;|-
; =====================
; Affichage du Packet
; =====================
lea edi,BuffAffichage ;|-
mov esi,DWORD ptr [lpBuffPacket] ;|-
mov PosPointeur,esi ;|
mov comp,0 ;|
mov comp16,0 ;|- On initialise
L1: ;|
assume eax: ptr pcap_pkthdr ;|
mov eax,ph ;|
mov ecx,lengthPacket ;|
cmp comp,ecx ;|
assume eax:nothing ;|
;|
je E1 ;|
mov eax,comp ;| Si oui, on sort de la boucle
mov dl,byte ptr [esi+eax] ;|-
;|- ASCII compris entre :
.if ((dl >= 00020h) && (dl <= 0007eh) || \ ;|
(dl >= 'A') && (dl <= 'Z') || \ ;| ('A' et 'Z') ou
(dl >= 'a') && (dl <= 'z') || \ ;| ('a' et 'z') ou
(dl >= '0') && (dl <= '9')) ;| ('0' et '9')
mov eax,comp16 ;| on copy le char
mov byte ptr [edi+eax],dl ;|-
.elseif (dl == 0000Dh)
mov eax,comp16 ;| on copy le char
mov byte ptr [edi+eax],"." ;|-
;add FlagDoublRet
.elseif (dl == 0000Ah)
mov eax,comp16 ;| on copy le char
mov byte ptr [edi+eax],"." ;|-
.else ;|-
mov eax,comp16 ;| sinon
mov byte ptr [edi+eax],'.' ;| on copy
.endif ;| un point '.'
;|-
mov eax,comp ;|-
mov dl,byte ptr [esi+eax] ;|
movzx edx,byte ptr [esi+eax] ;|
pusha ;| Afichage en couleur !! WOUAHH
pusha ;|
.if (Opt == TCP_PRINT_COLOR)
.if ((comp >= 6) && (comp < 12)) || ((comp >= 26) && (comp < 30))
invoke SetConsoleTextAttribute, Hconsole,FOREGROUND_GREEN
.elseif ((comp >= 0) && (comp < 6)) || ((comp >= 30) && (comp < 34))
invoke SetConsoleTextAttribute, Hconsole,FOREGROUND_RED;|
.else
invoke SetConsoleTextAttribute, Hconsole,FOREGROUND_INTENSITY
.endif
.elseif (Opt == ARP_PRINT_COLOR)
.if ((comp >= 6) && (comp < 12)) || ((comp >= 28) && (comp < 32))
invoke SetConsoleTextAttribute, Hconsole,FOREGROUND_GREEN;|
.elseif ((comp >= 0) && (comp < 6)) || ((comp >= 38) && (comp < 42))
invoke SetConsoleTextAttribute, Hconsole,FOREGROUND_RED;|
.else
invoke SetConsoleTextAttribute, Hconsole,FOREGROUND_INTENSITY
.endif
.endif
popa
invoke wsprintf,addr buffsz, addr szformatHex,edx ;| caractères, un par un !
print offset buffsz ;|
print offset szSpace ;|
popa ;|
inc comp ;| comp+1
inc comp16 ;|
xor edx,edx ;|
mov eax,comp ;|
mov ecx,16 ;|
div ecx ;|
.if (!edx) ;|
invoke SetConsoleTextAttribute, Hconsole,\ ;|
FOREGROUND_INTENSITY;|
;|
print offset szSpace ;|
mov comp16,0 ;|
lea eax,BuffAffichage ;|
;|
mov byte ptr [eax+16],0 ;|
;|
print eax ;|
print offset szRet ;|
.endif ;|
;|
jmp L1 ;| Retour au debut de la boucle
E1: ;|-
mov edx,16 ;|-
mov ecx,comp16 ;|
sub edx,ecx ;|
.if (edx > 0) ;|
.while (edx > 0) ;| calcul des espaces nécessaires
pusha ;| pour afficher la dernière ligne.
print offset szSpace ;|
print offset szSpace ;|
print offset szSpace ;|
popa ;|
dec edx ;|
.endw ;|
.endif ;|-
invoke SetConsoleTextAttribute, Hconsole,\ ;|
FOREGROUND_INTENSITY ;|
print offset szSpace ;|-
lea eax,BuffAffichage ;|
mov ecx,comp16 ;|
mov byte ptr [eax+ecx],0 ;| affiche la dernière ligne.
print eax ;|
print offset szRet ;|-
ret
PrintPacket endp
;==========================================================================
; GetIpHeader
;==========================================================================
align 4
GetArpHeader proc uses esi edx lpBuffPacket:DWORD,lpiphead:DWORD
mov esi,DWORD ptr [lpBuffPacket]
;add esi,14 ;|- debut de l'entête IP (Byte : 14)
assume ecx:ptr ip_header
mov ecx,lpiphead
; Modifie esi et pointe ou tu veux dans le buffer. au 28ième caractère, par exemple
; il y a l'adresse IP de destination !! pour pour d'info va sur le site frameip.com
add esi,28 ;|-
mov dl,byte ptr [esi] ;| Bytes: 28 - 32
mov byte ptr [[ecx].sip.byte1],dl ;|
inc esi ;|
mov dl,byte ptr [esi] ;|
mov byte ptr [[ecx].sip.byte2],dl ;| Destination Address
inc esi ;|
mov dl,byte ptr [esi] ;|
mov byte ptr [[ecx].sip.byte3],dl ;|
inc esi ;|
mov dl,byte ptr [esi] ;|
mov byte ptr [[ecx].sip.byte4],dl ;|-
add esi,7 ;|-
mov dl,byte ptr [esi] ;| Bytes: 33 - 37
mov byte ptr [[ecx].dip.byte1],dl ;|
inc esi ;|
mov dl,byte ptr [esi] ;|
mov byte ptr [[ecx].dip.byte2],dl ;| Destination Address
inc esi ;|
mov dl,byte ptr [esi] ;|
mov byte ptr [[ecx].dip.byte3],dl ;|
inc esi ;|
mov dl,byte ptr [esi] ;|
mov byte ptr [[ecx].dip.byte4],dl ;|-
assume ecx:nothing
xor eax,eax
ret
GetArpHeader endp
;==========================================================================
; GetIpHeader
;==========================================================================
align 4
GetIpHeader proc uses esi edx lpBuffPacket:DWORD,lpiphead:DWORD
mov esi,DWORD ptr [lpBuffPacket]
add esi,14 ;|- debut de l'entête IP (Byte : 14)
assume ecx:ptr ip_header
mov ecx,lpiphead
;|- Bytes: 14
mov dl,byte ptr [esi] ;| Version (4 bits) + Internet header length (4 bits)
mov byte ptr [[ecx].ver_ihl],dl ;|-
inc esi ;|- Bytes: 15
mov dl,byte ptr [esi] ;| Type de service
mov byte ptr [[ecx].tos],dl ;|-
inc esi ;|-
movzx edx,byte ptr [esi] ;| Bytes: 16 - 17
shl edx,8 ;|
inc esi ;| Total length
mov dl,byte ptr [esi] ;|
mov word ptr [[ecx].tlen],dx ;|-
inc esi ;|-
movzx edx,byte ptr [esi] ;| Bytes: 18 - 19
shl edx,8 ;|
inc esi ;| Identification
mov dl,byte ptr [esi] ;|
mov word ptr [[ecx].identification],dx ;|-
inc esi ;|-
movzx edx,byte ptr [esi] ;| Bytes: 20 - 21
shl edx,8 ;|
inc esi ;| flags info
mov dl,byte ptr [esi] ;|
mov word ptr [[ecx].flags_fo],dx ;|-
inc esi ;|- Bytes: 22
mov dl,byte ptr [esi] ;| ttl
mov byte ptr [[ecx].ttl],dl ;|-
inc esi ;|- Bytes: 23
mov dl,byte ptr [esi] ;| protocole
mov byte ptr [[ecx].protocole],dl ;|-
inc esi ;|-
movzx edx,byte ptr [esi] ;| Bytes: 24 - 25
shl edx,8 ;|
inc esi ;| Header checksum
mov dl,byte ptr [esi] ;|
mov word ptr [[ecx].crc],dx ;|-
inc esi ;|-
mov dl,byte ptr [esi] ;| Bytes: 26 - 27
mov byte ptr [[ecx].sip.byte1],dl ;|
inc esi ;|
mov dl,byte ptr [esi] ;|
mov byte ptr [[ecx].sip.byte2],dl ;| Destination Address
inc esi ;|
mov dl,byte ptr [esi] ;|
mov byte ptr [[ecx].sip.byte3],dl ;|
inc esi ;|
mov dl,byte ptr [esi] ;|
mov byte ptr [[ecx].sip.byte4],dl ;|-
inc esi ;|-
mov dl,byte ptr [esi] ;| Bytes: 28 - 29
mov byte ptr [[ecx].dip.byte1],dl ;|
inc esi ;|
mov dl,byte ptr [esi] ;|
mov byte ptr [[ecx].dip.byte2],dl ;| Destination Address
inc esi ;|
mov dl,byte ptr [esi] ;|
mov byte ptr [[ecx].dip.byte3],dl ;|
inc esi ;|
mov dl,byte ptr [esi] ;|
mov byte ptr [[ecx].dip.byte4],dl ;|-
inc esi ;|-
movzx edx,byte ptr [esi] ;| Bytes: 24 - 25
shl edx,8 ;|
inc esi ;| Option + Padding
mov dl,byte ptr [esi] ;|
shl edx,8 ;|
inc esi ;|
mov dl,byte ptr [esi] ;|
shl edx,8 ;|
inc esi ;|
mov dl,byte ptr [esi] ;|
mov DWORD ptr [[ecx].op_pad],edx ;|-
assume ecx:nothing
xor eax,eax
ret
GetIpHeader endp
;==========================================================================
; GetEthHeader
;==========================================================================
align 4
GetEthHeader proc uses esi edx lpBuffPacket:DWORD,lpiphead:DWORD
mov esi,DWORD ptr [lpBuffPacket]
assume ecx:ptr ip_header
mov ecx,lpiphead
mov dl,byte ptr [esi] ;|-
mov byte ptr [[ecx].dmac.byte1],dl ;| Bytes: 0 - 5
inc esi ;|
mov dl,byte ptr [esi] ;|
mov byte ptr [[ecx].dmac.byte2],dl ;| Destination Address
inc esi ;|
mov dl,byte ptr [esi] ;|
mov byte ptr [[ecx].dmac.byte3],dl ;|
inc esi ;|
mov dl,byte ptr [esi] ;|
mov byte ptr [[ecx].dmac.byte4],dl ;|
inc esi ;|
mov dl,byte ptr [esi] ;|
mov byte ptr [[ecx].dmac.byte5],dl ;|
inc esi ;|
mov dl,byte ptr [esi] ;|
mov byte ptr [[ecx].dmac.byte6],dl ;|-
inc esi ;|-
mov dl,byte ptr [esi] ;| Bytes: 6 - 11
mov byte ptr [[ecx].smac.byte1],dl ;|
inc esi ;|
mov dl,byte ptr [esi] ;|
mov byte ptr [[ecx].smac.byte2],dl ;|
inc esi ;|
mov dl,byte ptr [esi] ;|
mov byte ptr [[ecx].smac.byte3],dl ;|
inc esi ;| Source Address
mov dl,byte ptr [esi] ;|
mov byte ptr [[ecx].smac.byte4],dl ;|
inc esi ;|
mov dl,byte ptr [esi] ;|
mov byte ptr [[ecx].smac.byte5],dl ;|
inc esi ;|
mov dl,byte ptr [esi] ;|
mov byte ptr [[ecx].smac.byte6],dl ;|-
inc esi ;|-
movzx edx,byte ptr [esi] ;| Bytes: 12 - 13
shl edx,8 ;|
inc esi ;| Ethernet Type
mov dl,byte ptr [esi] ;|
mov word ptr [[ecx].eth_type],dx ;|-
assume ecx:nothing
xor eax,eax
ret
GetEthHeader endp
end start
Conclusion
ZIP
Historique
- 10 octobre 2008 16:43:29 :
- aucune modif c est toujours aussi nul !
- 10 octobre 2008 22:58:36 :
- .
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
IMAGINE CUP 2012, MAKE A SIGN EN FINALEIMAGINE CUP 2012, MAKE A SIGN EN FINALE par junarnoalg
Voilà qui est fait, la nouvelle est officielle ! L'équipe belge "Make a Sign" va au pays des kangourous défendre son projet dans la catégorie Software Design. http://www.imaginecup.com/CompetitionsContent/Competition/WorldwideFinalists.aspx V...
Cliquez pour lire la suite de l'article par junarnoalg KINECT 1.5 IS OUT !KINECT 1.5 IS OUT ! par Vko
La version 1.5 du Kinect For Microsoft vient tout juste de sortir ! Plein de nouveautés: Tracking de squelette en Near Mode Détection en position assise Détection faciale avec un SDK dédié Documentation et des guideline (enfin) Un out...
Cliquez pour lire la suite de l'article par Vko LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) par richardc
Mise à jour des Web API du 14 Mai
Réservez dès maintenant votre journée du 20 juin pour le Windows Azure Dev Camp 2012 à Paris
Mise à jour de Team Foundation Service
MechCommander 2 sur Windows 8
Entity Framework 5 Release Candidate e...
Cliquez pour lire la suite de l'article par richardc REACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITERREACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITER par Groc
Une mauvaise utilisation de rx lors de l'écriture d'une couche d'accès à des services peut conduire à des cas embarassants avec des erreurs mal gérées, des appels qui ne partent lorsqu'ils le devraient, et même des résultats incorrects . le tout nuis...
Cliquez pour lire la suite de l'article par Groc SHAREPOINT BLOG SITE, PROBLèME D'ARCHIVESSHAREPOINT BLOG SITE, PROBLèME D'ARCHIVES par junarnoalg
Dernièrement, nous avons migré le site
myTIC
vers un nouveau serveur SharePoint 2010. Dans les contenus que nous vouloins récupérer, nous avions un certain nombre de blogs.
Nous avons utilisé les commandes Power...
Cliquez pour lire la suite de l'article par junarnoalg
Logiciels
974 Application Server (12.2.4.0)974 APPLICATION SERVER (12.2.4.0)Développez de puissantes applications dans un environnement de 'cloud computing', clusterisé, séc... Cliquez pour télécharger 974 Application Server vPicture (1.4.2.1)VPICTURE (1.4.2.1)Avec vPicture, hébergez vos images facilement et rapidement.
vPicture est un utilitaire simple, ... Cliquez pour télécharger vPicture Easy-Planning (2.2.1.6)EASY-PLANNING (2.2.1.6)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté au... Cliquez pour télécharger Easy-Planning COM-BACKUP (2.0)COM-BACKUP (2.0)
COM-BACKUP est un logiciel de sauvegarde qui permet de planifier les sauvegardes de vos dossiers ...
Cliquez pour télécharger COM-BACKUP mySongBook Player (1.0.0)MYSONGBOOK PLAYER (1.0.0)mySongBook Player est un logiciel gratuit permettant l'accès à une archive de tablatures/partitio... Cliquez pour télécharger mySongBook Player
|