[Click] tcp spoofing

Sofia Rodriguez blink_sgirl_182 at hotmail.com
Fri Jun 10 09:23:36 EDT 2011


Hello:
I'm trying to implement a tcp spoofer. I tried to create an element that takes the incoming packet from sender and just creates an ACK and sends it back. (taking everything step by step) When I intercept the packets from sender (using wireshark) the generated packets are wrong in length. I was wondering if you could give me any clues on what is wrong in my code and I donno if its possible any clues on how to develop the rest if spoofer (meaning an element that keeps track on received acks to remove from a queue the sent packets and to manage lost packets properly)

I am new to writing C++ so please be patience if I have stupid errors. 

this is the c of spoofer:

#include <click/config.h>
#include "spoofer.hh"
#include <clicknet/tcp.h>
#include <click/confparse.hh>
#include <click/error.hh>
#include <click/packet.hh>
#include <clicknet/ip.h>
#include <click/glue.hh>
#include <click/string.hh>
#include <click/vector.hh>

CLICK_DECLS

Spoofer::Spoofer(){} //constructor

Spoofer::~Spoofer(){} // destructor



int Spoofer::configure(Vector<String> &conf, ErrorHandler *errh){ 

click_ip iph;

if (cp_va_kparse(conf, this, errh, 
        "SourceAdd",cpkP+cpkM,cpIPAddress,&iph.ip_src,
        "DstAdd",cpkP+cpkM,cpIPAddress,&iph.ip_dst,
cpEnd) < 0)
    return -1;
_iph=iph;
}

Packet *Spoofer::simple_action(Packet *p){

  const click_tcp *tcph = p->tcp_header();
unsigned short sport;
unsigned short dport;

 struct click_ip *ip;
  struct click_tcp *tcp;
  WritablePacket *q = Packet::make(sizeof(*ip) + sizeof(*tcp));
  if (q == 0) {
    click_chatter("in spoofer: cannot make packet!");
    assert(0);
  } 
  memset(q->data(), '\0', q->length());
  ip = (struct click_ip *) q->data();
  tcp = (struct click_tcp *) (ip + 1);
  q->set_ip_header(ip, sizeof(click_ip));
  
  // IP fields
  ip->ip_v = 4;
  ip->ip_hl = 5;
  ip->ip_tos = 0;
  ip->ip_len = htons(q->length());
  ip->ip_id = htons(0);
  ip->ip_off = htons(IP_DF);
  ip->ip_ttl = 255;
  ip->ip_p = IP_PROTO_TCP;
  ip->ip_sum = 0;

  memcpy((void *) &(ip->ip_src), (void *) &_iph.ip_dst, sizeof(ip->ip_src));
  memcpy((void *) &(ip->ip_dst), (void *) &_iph.ip_src, sizeof(ip->ip_dst));
  //memcpy((void *) &(ip->ip_src), (void *) &saddr, sizeof(saddr));
  //memcpy((void *) &(ip->ip_dst), (void *) &daddr, sizeof(daddr));
  ip->ip_sum = click_in_cksum((unsigned char *)ip, sizeof(click_ip));

  // TCP fields
  sport = tcph->th_dport;
  dport = tcph->th_sport;
  memcpy((void *) &(tcp->th_sport), (void *) &sport, sizeof(sport));
  memcpy((void *) &(tcp->th_dport), (void *) &dport, sizeof(dport));
  tcp->th_seq = tcph->th_ack;
  tcp->th_ack = tcph->th_seq +1;
  tcp->th_off = 5;
  tcp->th_flags = 0|1|0|0|0|0;
  tcp->th_win = htons(32120);
  tcp->th_sum = htons(0);
  tcp->th_urp = htons(0);

  // now calculate tcp header cksum
  unsigned csum = click_in_cksum((unsigned char *)tcp, sizeof(click_tcp));
  tcp->th_sum = click_in_cksum_pseudohdr(csum, ip, sizeof(click_tcp));

  return q;



}

void Spoofer::push(int, Packet *p){
output(0).push(p);

}
Packet* Spoofer::pull(int){
    Packet *p = input(0).pull();
    return p;
}

CLICK_ENDDECLS
EXPORT_ELEMENT(Spoofer)
ELEMENT_MT_SAFE(Spoofer)



this is the header:

#ifndef CLICK_SPOOFER_HH
#define CLICK_SPOOFER_HH
#include <click/atomic.hh>
#include <click/packet.hh>    
#include <click/element.hh>
#include <click/glue.hh>
#include <clicknet/tcp.h>

CLICK_DECLS

class Spoofer : public Element { public:

    Spoofer();
    ~Spoofer();

    const char *class_name() const        { return "Spoofer"; }
    const char *port_count() const        { return PORTS_1_1; }
    const char *processing() const        { return AGNOSTIC; }





int configure(Vector<String> &, ErrorHandler *);

    Packet *simple_action(Packet *);

//unsigned int saddr, daddr;

 click_ip _iph;



void push(int, Packet *);
Packet* pull(int);

};

CLICK_ENDDECLS
#endif


 		 	   		  


More information about the click mailing list