Getting an ACK for RAW SYN packet


 
Thread Tools Search this Thread
Top Forums Programming Getting an ACK for RAW SYN packet
# 1  
Old 05-02-2004
Getting an ACK for RAW SYN packet

Hi,

I'm trying to create a RAW TCP SYN packet and send it from one Linux machine to another. I know the packet I have created is well formed and is received by the peer.

Now what I want is to get an ACK for my SYN. I want the peer's Network protocol stack to send me an ACK for that. I know RAW socket is not stream oriented, but is instead datagram-oriented. But can you tell me if there is any hack that I can use to get the network protocol stack to send back an ACK.

Thanks.
# 2  
Old 05-03-2004
>How do you know this?
I know this, since when I do a revcfrom on the peer, I receive the exact no. of bytes I sent.. If my packet was malformed, I should have got an ICMP error message, which I don't.

>If your TCP segment was well-formed, then the peer should do this automatically. It >wouldn't be able to tell the difference between the raw socket you used and a >``normal'' socket anyway, so the same behavior can be expected. It is transparent ...
>Maybe you could post the code you're using if it isn't too long. [/B][/QUOTE]
RAW sockets difer from stream sockets in the sense that the network protocol stack does not bother about packets coming from RAW sockets. Therefore, for the SYN on a RAW socket, it doen't return an SYN|ACK.

I will post my code once the remote machine is up.
# 3  
Old 05-04-2004
>I can't see how this guarantees that your packet is ``well-formed''. Maybe we have differing definitions of ``well-formed'' on this issue, but I mean a packet with valid TCP >content too, not just the same number of bytes you sent out ...


On this issue, can you tell me if the packet is mal formed, will I receive an ICMP error? And if I do, how can I catch it ?

>It's not my fault if you do not mention that the server side uses a raw socket too. Why don't you run a normal server and see whether an ACK is generated? Running both sides with raw >sockets where you could use a stream socket on either side to >ease debugging is asking for trouble ...

Thanks I will try this and let you know what happens.

>Edit: May I ask what's the purpose of your applications?

The research we are doing involves mesuring the MTU from each hop to other. We are using an approach in which the Maximum Segment Size in TCP header can be used.
# 4  
Old 05-05-2004
What you're attempting is so far "out there" that I hesitate to reply. I have never used raw sockets at all. And you seem to be trying to bypass TCP entirely. I'm not sure what to expect when raw sockets are used like that. Like Driver, I think it would help if you posted your code.

I do know the TCP protocol though. Your SYN packet seems to be step one of the 3-way handshake. If it's addressed to port that is listening, You should get a packet that ACK's your SYN and contains a SYN of it's own. Otherwise you should get a RST packet. These days, some systems run in stealth mode and just ignore SYN's to unused ports.

You should not get an ICMP message. But if you fumble a bit, and set the protocol to UDP instead on TCP, then a ICMP port unreachable would be in order.

But you're using raw sockets, right? So isn't all of this your job? You seem to be expecting the kernel's TCP code to help you out. I don't know if it should or not. Like I said, I've never used raw sockets like this. But my expectation would be that the kernel's TCP code would not be in use. After all, to the kernel, there is no TCP connection.
# 5  
Old 05-13-2004
To answer your original question, you can use a raw socket on the client who sends the SYN, and a regular listening stream socket on the server to automatically reply with ACK.
# 6  
Old 05-17-2004
typedef struct ip_header_t {
unsigned char ihl:4,
version:4;
unsigned char tos;
unsigned short tot_len;
unsigned short id;
unsigned short frag_off;
unsigned char ttl;
unsigned char protocol;
unsigned short check;
unsigned int saddr;
unsigned int daddr;
} * ip_header_t;

typedef struct tcp_header_t {
unsigned short source;
unsigned short dest;
unsigned int seq;
unsigned int ack_seq;
unsigned short res1:4,
doff:4,
fin:1,
syn:1,
rst:1,
psh:1,
ack:1,
urg:1,
ece:1,
cwr:1;
unsigned short window;
unsigned short check;
unsigned short urg_ptr;
} * tcp_header_t;

int readn(int, void *, int);

int main(int argc, char * argv[])
{
int sock,sent, temp, rcvd;
struct sockaddr_in sin;
unsigned short local_port;
unsigned short remote_port;
unsigned char protocol;
char * buffer;
//char data[1452];
ip_header_t ip_header;
tcp_header_t tcp_header;
char *remote_ip_str;
int semantics = 0;
unsigned short buffer_size = 0;
int tmp;

protocol = IPPROTO_TCP;
semantics = SOCK_RAW;

remote_ip_str=DEST_IP_ADDR;
remote_port = 6666;

if((sock = socket(PF_INET, semantics, protocol)) < 0) {
perror("socket");
exit(1);
}

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

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

tmp = 1;
setsockopt(sock, 0, IP_HDRINCL, &tmp, sizeof(tmp));

bzero((char *)& sin, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_port = htons(remote_port);
sin.sin_addr.s_addr = inet_addr(remote_ip_str);

buffer_size = sizeof(struct ip_header_t) + sizeof(struct tcp_header_t);

srand(getpid());

buffer = (char *) malloc(buffer_size);

ip_header = (ip_header_t) buffer;
ip_header->ihl = 5;
ip_header->version = 4;
ip_header->tos = 0;
ip_header->tot_len = htons(buffer_size);
ip_header->id = 0;
ip_header->ttl = 64;
ip_header->frag_off = 0x40;
ip_header->protocol = protocol;
ip_header->check = 0;
ip_header->daddr = inet_addr(remote_ip_str);
ip_header->saddr = 0;

tcp_header = (tcp_header_t) (ip_header + 1);

tcp_header->source = htons(local_port);
tcp_header->dest = htons(remote_port);
tcp_header->seq = rand()%time(NULL);
tcp_header->ack_seq = rand()%time(NULL);
tcp_header->res1 = 0;
tcp_header->doff = 4;
tcp_header->syn = 1;
tcp_header->check = 0;

printf("SEQ is %u\n", tcp_header->seq);
if((sent=sendto(sock, buffer, buffer_size, 0, (struct sockaddr *) &sin,
sizeof(sin))) < buffer_size) {
perror("sendto");
exit(1);
}
printf("Came here sent %d bytes \n",sent);
if((rcvd = readn(sock, buffer, buffer_size)) < 0 ) {
fprintf(stderr, "nread error\n");
}
else
printf("Received %d bytes\n", rcvd);

close(sock);

return 0;
}

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
# 7  
Old 05-18-2004
Question

Maybe the checksum field is incorrect and your packet gets discarded...
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