Can't capture my Spoofed SYN packet by ethereal...

Several days ago I wrote a spoofing SYN c++ program, I execute it on one PC, sending the spoofed syn to my own computer. But I can't see any SYN packets by running ethereal on my own computer. I captured only one IP(but protocol I set in the spoofed syn is TCP) packet, the info is: IPv6 hop-by-hop option(0x00) , and this IP packet used the real source ip, not the spoofed source ip I set in the program... I want to know if there is anything wrong with my program? Can anyone help me? Thanks in advance. Both computers' system are XP, and the program is the following:

int _tmain(int argc, _TCHAR* argv[])
                class SpoofSocket spoof_socket;

      WSADATA WSAData;
      int ret=WSAStartup(MAKEWORD(2,2),&WSAData);

      //Create Raw_Socket
      bool ip_hdrincl=true;
      int SendTimeOver=1000;

      SOCKET raw_sock=WSASocket(AF_INET,SOCK_RAW,IPPROTO_IP,NULL,0,WSA_FLAG_OVERLAPPED);                  
      setsockopt(raw_sock,IPPROTO_IP,IP_HDRINCL,(char *)&ip_hdrincl,sizeof(ip_hdrincl));      
      setsockopt(raw_sock,SOL_SOCKET,SO_SNDTIMEO,(char *)&SendTimeOver,sizeof(SendTimeOver));
      unsigned int s_ipAddress=inet_addr("");
      unsigned int d_ipAddress=inet_addr("");
      unsigned short s_port=2006;
      unsigned short d_port=8000;
      unsigned int seq=0x00000000;
      unsigned int ack=0x00000001;

      //Spoof buffer for sending
      int len=spoof_socket.tcp_head_len+spoof_socket.ip_head_len;
      SOCKADDR_IN addr_client1_in;
      int send_bytes=sendto(raw_sock,spoof_socket.SendBuffer,len,0,(struct sockaddr*)&addr_client1_in,sizeof(addr_client1_in));
      Console::WriteLine(S"Send one SYN+ACK success!!!");


      char i;
      return 0;

unsigned short SpoofSocket::checksum(unsigned short *buffer,int size){

      unsigned short cksum=0;
            size-=sizeof(unsigned short);
            cksum+=*(unsigned char*)buffer;
      cksum=(cksum>>16) + (cksum&0xffff);

      return cksum;


void SpoofSocket::SetIP_Head_Buffer(unsigned long SourceAddress,unsigned long DestAddress){

      //Set ip_header
      ip_header.h_lenver=(4<<4|sizeof(ip_header)/sizeof(unsigned int));
      ip_header.ttl=(unsigned char)GetTickCount()%87+123;

void SpoofSocket::SetTCP_Head_Buffer(unsigned short SourcePort,unsigned short DestPort,unsigned char flag,unsigned long seqNumber,unsigned long ackNumber){

      //Set tcp_Header
      tcp_header.th_flags=flag;//flag=2 is SYN; flag=16 is ACK; flag=12 is SYN_ACK

      //Set TCP psudHeader

      //Get header length

      send_buffer=new BYTE[psd_head_len+tcp_head_len];

      //Compute the Checksum value
      tcp_header.th_sum=checksum((unsigned short *)send_buffer,psd_head_len+tcp_head_len);

      send_buffer=new BYTE[tcp_head_len+ip_head_len];

      //put spoofed IP and TCP header into the SendBuffer
      ip_header.checksum=checksum((unsigned short *)send_buffer,ip_head_len+tcp_head_len);

      char SendBuffer[60]={0};

typedef struct ip_head{

      unsigned char h_lenver; //four bits for header length;four bits for IP version
      unsigned char tos;     //eight bits for Type of Service
      unsigned short total_len;// 16bits for total length
      unsigned short ident;
      unsigned short flags; //3flags
      unsigned char ttl;
      unsigned char proto;
      unsigned short checksum;
      unsigned int sourceIP; //32bits source IP
      unsigned int destIP;//32bits destination IP


typedef struct tcp_head{

      unsigned short th_sport;//16bits source port
      unsigned short th_dport;//16bits destination port
      unsigned int th_seq;//32bits sequence number
      unsigned int th_ack;//32bits confirmation number
      unsigned char th_lenres;//four bits for header length;four bits for restoring key words
      unsigned char th_flags;//6flags
      unsigned short th_win;//16bits windows size
      unsigned short th_sum;//16bits checksum
      unsigned short th_urp;//16bits urgent data offsets


//define TCP pseudHeader
typedef struct ts_head{

      unsigned long saddr;
      unsigned long daddr;
      char mbz;
      char ptcl;//protocol type
      unsigned short tcpl;//TCP length


class SpoofSocket {

      unsigned short checksum(unsigned short *,int);
      void SetIP_Head_Buffer(unsigned long SourceAddress,unsigned long DestAddress);
      void SetTCP_Head_Buffer(unsigned short SourcePort,unsigned short DestPort,unsigned char flag,unsigned long seqNumber,unsigned long ackNumber);
      unsigned short psd_sport;
      bool result;
      char SendBuffer[60];
      BYTE * send_buffer;
      int psd_head_len;
      int tcp_head_len;
      int ip_head_len;

      TCPHEADER tcp_header;
      PSDHEADER psd_header;
      IPHEADER ip_header;      
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Did you check WSAGetLastError() after sendto has failed?

send_bytes has a value of -1 if sendto failed.

Regards, Alex
This usually means the packet has a bad checksum so everybody ignores it.

Can you set etherreal to accept "bad" packets too?

another possibility--  if your PC's are hooked together by something other than a really dumb hub, that little box may be tossing out packets that are obviously faked.  have you been able to make a good unspoofed packet and receive it on the other PC?  I'd try that first.

gotdoughAuthor Commented:
1, the send_bytes returns correct, 40 bytes.
2, I have made the test with the unspoofed packets between the two computers, they all are captured correctly.
This problem have confused me serveral days. . .
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

So what is connecting your PC's?

Any firewall software anywhere?

gotdoughAuthor Commented:
no firewall , just a router , and the router connects to ISP, maybe there is a firewall at the ISP end.
>>>> Any firewall software anywhere?

With XP SP 2 you got a firewall that would prevent packages from passing. You would need to switch off the firewall (you can do that if your internet connection does *not* use the same LAN and C-Net 192.168.0) or configure the firewall to open ports 2006 and 8000.

Regards, Alex
>>>>  no firewall , just a router

There is no modern router without a firewall ...

Try to configure the router.

Did you use XP SP2 ?

Regards, Alex
>>>> and the router connects to ISP, maybe there is a firewall at the ISP end.

No, if you connect to local IP addresses like your ISP isn't involved. The router acts like a local hub/switch. But the default configuration wouldn't open port 2006 or port 8000.

Regards, Alex

gotdoughAuthor Commented:
then, you mean it didn't send out the spoofed packet at all, but why I captured a packet from the sending-spoofed-packet machine?
>>>> but why I captured a packet from the sending-spoofed-packet machine?

Maybe you should explain your configuration a little more in detail. Actually, I don't know what a sending-spoofed-packet machine is and what might be different to the machine where it doesn't work. What's about your XP firewalls? Are they on or off?

Your router or XP's routers and firewalls may be blocking spoofed packets.

Routers and firewalls are smart enough to notice that a particular hardware address that has been saying it's for the last 343,432 packets, is now claiming to be   Of course that is impossible.  So the packet gets dropped.

You need a dumb HUB, one that doesnt inspect each packet.  They're available on eBay for $0.99 to $4.99 usually.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.