Главная страница


ru.nethack

 
 - RU.NETHACK -------------------------------------------------------------------
 From : Tolik Pozdeev                        2:5005/76.100  15 May 2002  21:54:00
 To : All
 Subject : tcp connect
 -------------------------------------------------------------------------------- 
 
 
 // spoof.cpp 
 //
 
 #include "stdafx.h"
 #include "windows.h"
 #include "stdlib.h"
 #include "winsock2.h"
 #include "packet32.h"
 
 #define ICMP_ECHO 8
 
 struct mach
 {
 char src[6],dst[6];
 USHORT type;
 };
 
 struct ip {
 char  vl;              /* header length */ /* version */
 char  ip_tos;               /* type of service */
 USHORT ip_len;               /* total length */
 USHORT ip_id;                /* identification */
 USHORT ip_off;               /* fragment offset field */
 char  ip_ttl;               /* time to live */
 char  ip_p;                 /* protocol */
 USHORT ip_sum;               /* checksum */
 struct in_addr ip_src, ip_dst;
 };
 
 struct tcphdr {
 USHORT th_sport;             /* source port */
 USHORT th_dport;             /* destination port */
 int th_seq;               /* sequence number */
 int th_ack;               /* acknowledgement number */
 char th_off;              /* (unused) *//* data offset */
 char  th_flags;             /* flags */
 USHORT th_win;               /* window */
 USHORT th_sum;               /* checksum */
 USHORT th_urp;               /* urgent pointer */
 //char opt[8];
 };
 
 struct pseudo {
        u_long saddr;
        u_long daddr;
        u_char zero;
        u_char protocol;
        u_short length;
 };
 #define        TH_FIN        0x01
 #define        TH_SYN        0x02
 #define        TH_RST        0x04
 #define        TH_PUSH       0x08
 #define        TH_ACK        0x10
 #define        TH_URG        0x20
 
 USHORT checksum(USHORT *, int);
 int main(int argc, char* argv[])
 {
   unsigned char packet[sizeof(struct mach) + sizeof(struct ip) + 
 sizeof(struct pseudo) + sizeof(struct tcphdr)];
               
         struct mach *mac = (struct mach *) packet;
         struct ip *ip = (struct ip *) (packet + sizeof(struct mach));
         struct pseudo *pseudo = (struct pseudo *) (packet + sizeof(struct 
 mach) + sizeof(struct ip));
       struct tcphdr *tcp = (struct tcphdr *) (packet + sizeof(struct mach) + 
 sizeof(struct ip) + sizeof(struct pseudo));
 
         struct in_addr srcinaddr,dstinaddr;
         USHORT dstport,srcport;
         int srcaddr,dstaddr;
         dstport=htons(80);
         srcport=htons(1049);
         srcaddr=inet_addr("213.210.71.126");
         dstaddr=inet_addr("217.106.127.233");
 
         memset(packet,0,sizeof(packet));
 
         memcpy(&mac->src,"\x20\x53\x52\x43\x00\x00",6);
         memcpy(&mac->dst,"\x44\x45\x53\x54\x00\x00",6);
         mac->type=8;
         
     srcinaddr.s_addr = srcaddr;
     dstinaddr.s_addr = dstaddr;
 
     pseudo->saddr = srcaddr;
     pseudo->daddr = dstaddr;
     pseudo->zero = 0;
     pseudo->protocol=IPPROTO_TCP;
     pseudo->length = htons(sizeof (struct tcphdr));
 
                 /*ip->ip_v = 4;
                 ip->ip_hl = 5;*/
                 ip->vl=69;
                 ip->ip_id = 1234;
                 ip->ip_src = srcinaddr;
                 ip->ip_dst = dstinaddr;
                 ip->ip_p = IPPROTO_TCP;
                 ip->ip_ttl = 128;
                 ip->ip_off = 64;
                 ip->ip_len = ntohs( sizeof(struct ip) + sizeof(struct
 tcphdr) );
                 ip->ip_sum = checksum((u_short *) ip,sizeof(struct ip));
                 tcp->th_sport = srcport;
                 tcp->th_dport = dstport;
                 tcp->th_seq = htonl(rand());
                 tcp->th_ack = htonl(0);
                 tcp->th_off=(sizeof(struct tcphdr)/4) << 4;
                 tcp->th_flags = TH_SYN;
                 tcp->th_urp = 0;
                 tcp->th_win = htons(512);
                 tcp->th_sum = checksum((u_short *) pseudo,
                 sizeof(struct pseudo) + sizeof(struct tcphdr));
                 memcpy(pseudo,tcp,sizeof(struct tcphdr));
 
         
 
         LPADAPTER  lpAdapter = 0;
         LPPACKET   lpPacket;
         char                 AdapterNamea[512];
         ULONG                                   AdapterLength=1024;
         PacketGetAdapterNames(AdapterNamea,&AdapterLength);
         lpAdapter =   PacketOpenAdapter(AdapterNamea);
         int k=PacketSetHwFilter(lpAdapter,NDIS_PACKET_TYPE_PROMISCUOUS);
         lpPacket = PacketAllocatePacket();
         
         PacketInitPacket(lpPacket,packet,sizeof(packet)-sizeof(struct 
 pseudo));
           PacketSendPacket(lpAdapter,lpPacket,TRUE);
 
         printf("%d\n",sizeof(USHORT));
 
         PacketFreePacket(lpPacket);
         PacketCloseAdapter(lpAdapter);
         return 0;
 }
 
 USHORT checksum(USHORT *buffer, int size) {
 
   unsigned long cksum=0;
 
   while(size >1) {
   cksum+=*buffer++;
   size -=sizeof(USHORT);
   }
   
   if(size ) {
   cksum += *(UCHAR*)buffer;
   }
 
   cksum = (cksum >> 16) + (cksum & 0xffff);
   cksum += (cksum >>16);
   return (USHORT)(~cksum);
 }
 
 Кто знаком с сабжем,подскажите плиз в чём проблема.
 Пакет вроде уходит нормальный,а ответа не приходит?
 Tolik aka KiLLeR
 
 --- Fregate 1.27
  * Origin: all for nothing (2:5005/76.100)
 
 

Вернуться к списку тем, сортированных по: возрастание даты  уменьшение даты  тема  автор 

 Тема:    Автор:    Дата:  
 tcp connect   Tolik Pozdeev   15 May 2002 21:54:00 
Архивное /ru.nethack/38722cafaf40.html, оценка 2 из 5, голосов 10
Яндекс.Метрика
Valid HTML 4.01 Transitional