I'm trying for security purpose to write my own packet (currently i'm tsting the strenght of an encrypted chat server).
I have the following code :
The IP header that i write is written by the OS after his own IP header :Structure in_addr
s_addr.l
EndStructure
Structure sockaddr_in2
sin_family.w
sin_port.w
sin_addr.in_addr
sin_zero.b[8]
EndStructure
Structure ip_hdr2
ip_hl.b
ip_v.b
ip_tos.b
ip_len.w
ip_id.w
ip_off.w
ip_ttl.b
ip_p.b
ip_cksum.w
ip_src.l
ip_dest.l
EndStructure
Structure Packet
headerIP.ip_hdr2
EndStructure
Procedure toto()
; Variables
IPdst.s
sock.sockaddr_in2
pckt.packet
; Initialise la pile TCP/IP
Resultat = InitWinsock() ; (Steve Bigras piece of code)
If Resultat = 0
MessageBox_(0, "Aucune Pile TCP/IP disponible sur le système.", "Error", #MB_ICONERROR)
ProcedureReturn 1
EndIf
; remplissage variables
IPdst = GetGadgetText(#String_0)
*pckt = @VirtualAlloc_(#NULL, SizeOf(ip_hdr2), #MEM_COMMIT, #PAGE_READWRITE)
rtlzeromemory_(pckt, SizeOf(ip_hdr2))
; IP header
pckt\headerIP\ip_src = inet_addr_("192.168.0.4")
pckt\headerIP\ip_dest = inet_addr_("192.168.0.2")
pckt\headerIP\ip_v = 4
pckt\headerIP\ip_hl = 5
pckt\headerIP\ip_tos = 0
pckt\headerIP\ip_len = htons_(SizeOf(ip_hdr2))
pckt\headerIP\ip_id = htons_(1111)
pckt\headerIP\ip_off = htons_(0)
pckt\headerIP\ip_ttl = 255
pckt\headerIP\ip_p = #IPPROTO_IP
;pckt\headerIP\ip_cksum = 0
; création du socket
fd = socket_(#AF_INET, #SOCK_RAW, #IPPROTO_RAW)
If fd < 0
MessageBox_(0, "Erreur lors de la création du socket", "Socket Error", #MB_ICONERROR)
ProcedureReturn 1
EndIf
; envoi du paquet
sock\sin_family = #AF_INET
sock\sin_addr\s_addr = inet_addr_(IPdst)
res = sendto_(fd, @pckt, SizeOf(ip_hdr2), 0, @sock.sockaddr_in2, SizeOf(sock))
If res < 0
MessageBox_(0, "Erreur lors de l'envois du paquet", "Erreur", #MB_ICONERROR)
EndIf
CloseSocket_(fd)
TerminateWinsock()
MessageBox_(0, "Envoyés", "ok", #MB_ICONINFORMATION)
EndProcedure
80 : TTL => 128 (OS defined)20:56:23.826775 192.168.0.1 > 192.168.0.2: ip-proto-255 21 (ttl 128, id 2672, len 41)
0x0000 4500 0029 0a70 0000 80ff ae12 c0a8 0001 E..).p..........
0x0010 c0a8 0002 0504 0000 1504 5700 00ff 0000 ..........W.....
0x0020 00c0 a800 04c0 a800 0200 0000 0000 ..............
FF : TTL => 255 : that i chose, but it is not written (like all the other stuff) where it should be written, so it isn't a TTL from the OS point of view.
Why my IP header is not write in first ?
The fact to define a socket as RAW should force the OS to _not_ write the header and to let us do it, what's wrong ?

