Getting an ACK for RAW SYN packet


 
Thread Tools Search this Thread
Top Forums Programming Getting an ACK for RAW SYN packet
# 15  
Old 05-21-2004
Computer sample syn

Here is a sample code that may help u!
Most kernel support syn-cookies to prevent synflood attack...
# 16  
Old 05-21-2004
Wow could not attach the file, leave an email for delivery
# 17  
Old 05-24-2004
Quote:
Originally posted by zampya

Can you please tell me what's wrong with the packet header I have created? I can't accept it using a STREAM socket. I think there is a problem with the header format, can you tell me what's that?

Thanks
Which compiler are you using, BTW? Sorry, I've been away. Did you mention the compiler? GCC?

Neo
# 18  
Old 05-24-2004
Yes. I'm using gcc.

Btw, I'm getting a very strange error with sendto. Here's my code. I have compiled it with gcc and I get error :

sendto:invalid argument.

int main(int argc, char *argv[])
{
struct pseudohdr {
unsigned long saddr; /* source address */
unsigned long daddr; /* dest address */
char zer0; /* zero */
unsigned char protocol; /* protocol to use */
unsigned short length; /* length of packet */
};

int one = 1, sent;
int packSize=sizeof(struct tcphdr)+sizeof(struct iphdr)
+sizeof(struct pseudohdr);
char packet[packSize]; /* Packet. */
struct sockaddr_in sin; /* Our address info structures. */
struct iphdr *ip = (struct iphdr *) packet;
struct tcphdr *tcp = (struct tcphdr *) packet + sizeof(struct iphdr);
struct pseudohdr *pseudo;
pseudo = (struct pseudohdr *) (packet + sizeof(struct iphdr) -
sizeof(struct pseudohdr));
char *remote_ip_str="128.112.139.72";

/* create the socket. */
if((sock = socket (AF_INET, SOCK_RAW, IPPROTO_TCP)) == -1) {
perror("socket"); /* Error creating socket. */
exit(-1);
}

bzero((char *) &sin, sizeof(sin));
sin.sin_port = htons(MYPORT);

if ((bind(sock, (struct sockaddr *)& sin, sizeof(sin))) < 0) {
perror("bind");
exit(1);
}

/* Tell the kernel we'll fill in the IP headers
* outselves. */
if((setsockopt(sock, IPPROTO_IP, IP_HDRINCL, &one, sizeof(one))) < 0 )
{
perror("setsockopt");
exit(1);
}

/* Fill in the destination info. */
bzero((char *)& sin, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_port = htons(MYPORT);
sin.sin_addr.s_addr = inet_addr(remote_ip_str);

bzero(packet, sizeof(packet));

/* fill in the pseudo header - this is needed to help calculate
* the checksum for the tcp segment of the packet. */
pseudo->saddr = 0;
pseudo->daddr = (u_long)inet_ntoa(sin.sin_addr);
pseudo->zer0 = 0;
pseudo->protocol = IPPROTO_TCP;
pseudo->length = htons(sizeof(struct tcphdr));

/* Fill in IP headers. */
ip->ihl = 5;
ip->version = 4;
ip->tot_len = sizeof(struct iphdr) + sizeof(struct tcphdr);
ip->id = htons(0);
ip->saddr = 0;
ip->daddr = (u_long)inet_ntoa(sin.sin_addr);
ip->ttl = 64;
ip->protocol = IPPROTO_TCP;
ip->check = 0; /* calculate checksum later, below. */
ip->tos = 0;
ip->frag_off = 0;
/* set the checksum. */
ip->check = in_cksum((unsigned short *)ip, sizeof(struct iphdr));

/* Fill in the TCP headers. */
tcp->source = htons(MYPORT);
tcp->dest = htons(MYPORT);

tcp->seq = htons(random()); /* "random" sequence number. */
tcp->ack = 0; /* ACKnowledgement */
tcp->syn = 1;
tcp->window = htons(65535);
tcp->doff = 5;
tcp->rst = 0;
tcp->check = 0; /* calculate checksum later, below. */
tcp->psh = 0;
tcp->fin = 0;
tcp->urg = 0;
tcp->ack_seq = htons(0);
/* set the checksum. */
tcp->check = (unsigned short)in_cksum((unsigned short *)pseudo,
sizeof(struct tcphdr)+sizeof(struct pseudohdr));

//if((sent=sendto(sock, packet, ip->tot_len, 0, This didn't work either.
if((sent=sendto(sock, packet, sizeof(packet), 0,
(struct sockaddr *)&sin, sizeof(sin))) < 0 ) {
printf("sent is %d\n", sent);
perror("sendto");
exit(1);
}
printf("sent is %d\n", sent);
return(0);
}

unsigned short in_cksum(unsigned short *addr, int len) {
register int sum = 0;
u_short answer = 0;
register u_short *w = addr;
register int nleft = len;

while (nleft > 1) {
sum += *w++;
nleft -= 2;
}

if (nleft == 1) {
*(u_char *)(&answer) = *(u_char *)w ;
sum += answer;
}

sum = (sum >> 16) + (sum & 0xffff);
sum += (sum >> 16);
answer = ~sum;
return(answer); /* return the checksum value. */
}
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. AIX

Packet loss coming with big packet size ping

(5 Replies)
Discussion started by: Vishal_dba
5 Replies

2. Programming

Raw Socket Programming - Efficient Packet Sniffer

Hi, I have the requirement to sniff packets from the Ethernet card on my Linux machine and process it and feed it to a RANAP protocol stack. So far I have written the raw packet sniffer and successfully sniffing packets and do little processing. However, for huge number of packets ... (9 Replies)
Discussion started by: rstnsrr
9 Replies

3. IP Networking

TCP Same Ack Sequencing for Two Packets

I was analyzing a TCP snoop. And found following scenario From Server to Client ---> SEQ 2993 ACK 1744 WIN 8192 LEN 13 From Server to Client ---> SEQ 3006 ACK 1744 WIN 8192 LEN 13 From Client to server --> SEQ 1744 ACK 3019 WIN 3304 I just want to know Why Packet 1 and 2... (3 Replies)
Discussion started by: mr_deb
3 Replies

4. UNIX for Dummies Questions & Answers

plug in for syn on

I am using vim version 7.1.314.It don't have syn on.Is there any plug in available for syn on or I have to update the version. (2 Replies)
Discussion started by: karthigayan
2 Replies

5. UNIX for Advanced & Expert Users

What is FIN/ACK/SYN

Please tell me details about terms FIN, ACK, SYN, RST; used in TCP based communication. Also tell me any RFC or other document which tell me details about these terms. (1 Reply)
Discussion started by: mansoorulhaq
1 Replies

6. Shell Programming and Scripting

syn

suppose I have data in a log file in the below format date|time|name|email|address|SSN date|time|name|email|address|SSN date|time|name|email|address|SSN is it possible to create a search engine which takes input as three filters out of which two filters should be optional? say i give... (4 Replies)
Discussion started by: wannalearn
4 Replies

7. UNIX for Dummies Questions & Answers

ACK! Help! What do I do?

Hiya folks, I am a windows xp home user and for awhile I have been thinking about changing my OS, the only problem is that I don't know where to start. Is it called Unix or Linux? Are they the same thing? It's really confusing. I would really appreaciate some help on this. I have looked all... (1 Reply)
Discussion started by: Mr_Pinky
1 Replies
Login or Register to Ask a Question