Networking Forums  

Go Back   Networking Forums > Networking Newsgroups > Linux Networking

TCP/IP packet modifications

Reply
 
Thread Tools Display Modes
  #1  
Old 03-21-2005, 10:51 PM
Default TCP/IP packet modifications



Hello, All!

I want to cut off some data from existing already established connection.
In other words I want to make something like a transparent pxoxy, so both
client and server do not know about it.

I successfully can modify data of TCP packets, without changing packet
length.
But TCP data gets corrupted and connection is broken when I try to change
packet length.

Please tell me what I am doing wrong here:

1) cut off N bytes of TCP packet
2) IP.Length = IP.Length - N
3) update IP header checksum
4) TCP.sequenceNum = TCP.sequenceNum - N
5) update TCP checksum

All actions above are made on the same packet. Do I need to modify
previous/next packets as well? How?

TCP and IP checksum is calculated correctly, I know it for sure.

Any help would be greatly appreciated.

Best regards,
Serge.




serge
Reply With Quote
  #2  
Old 03-22-2005, 12:18 AM
Barry Margolin
Guest
 
Posts: n/a
Default Re: TCP/IP packet modifications

In article <d1nj9d$8kg$(E-Mail Removed)>, "serge" <(E-Mail Removed)>
wrote:

> Hello, All!
>
> I want to cut off some data from existing already established connection.
> In other words I want to make something like a transparent pxoxy, so both
> client and server do not know about it.
>
> I successfully can modify data of TCP packets, without changing packet
> length.
> But TCP data gets corrupted and connection is broken when I try to change
> packet length.
>
> Please tell me what I am doing wrong here:
>
> 1) cut off N bytes of TCP packet
> 2) IP.Length = IP.Length - N
> 3) update IP header checksum
> 4) TCP.sequenceNum = TCP.sequenceNum - N
> 5) update TCP checksum
>
> All actions above are made on the same packet. Do I need to modify
> previous/next packets as well? How?


Yes, you need to modify all the TCP packets after this. All their
sequence numbers have to be reduced by N. Otherwise, there will be a
gap in the sequence numbers -- the receiver will think that a packet was
lost and wait for it.

--
Barry Margolin, (E-Mail Removed)
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
Reply With Quote
  #3  
Old 03-22-2005, 02:03 AM
Raghu Uppalli
Guest
 
Posts: n/a
Default Re: TCP/IP packet modifications


serge wrote:
> Hello, All!
>
> I want to cut off some data from existing already established

connection.
> In other words I want to make something like a transparent pxoxy, so

both
> client and server do not know about it.
>
> I successfully can modify data of TCP packets, without changing

packet
> length.
> But TCP data gets corrupted and connection is broken when I try to

change
> packet length.
>
> Please tell me what I am doing wrong here:
>
> 1) cut off N bytes of TCP packet
> 2) IP.Length = IP.Length - N
> 3) update IP header checksum
> 4) TCP.sequenceNum = TCP.sequenceNum - N
> 5) update TCP checksum
>
> All actions above are made on the same packet. Do I need to modify
> previous/next packets as well? How?
>
> TCP and IP checksum is calculated correctly, I know it for sure.
>
> Any help would be greatly appreciated.
>
> Best regards,
> Serge.



Have you looked into Divert Sockets? That might be the way to go if you
don't want to go from scratch.

Reply With Quote
  #4  
Old 03-22-2005, 01:30 PM
Keith Wansbrough
Guest
 
Posts: n/a
Default Re: TCP/IP packet modifications

Barry Margolin <(E-Mail Removed)> writes:

> In article <d1nj9d$8kg$(E-Mail Removed)>, "serge" <(E-Mail Removed)>
> wrote:
> > Please tell me what I am doing wrong here:
> >
> > 1) cut off N bytes of TCP packet
> > 2) IP.Length = IP.Length - N
> > 3) update IP header checksum
> > 4) TCP.sequenceNum = TCP.sequenceNum - N
> > 5) update TCP checksum
> >
> > All actions above are made on the same packet. Do I need to modify
> > previous/next packets as well? How?

>
> Yes, you need to modify all the TCP packets after this. All their
> sequence numbers have to be reduced by N. Otherwise, there will be a
> gap in the sequence numbers -- the receiver will think that a packet was
> lost and wait for it.


....and _don't_ decrease the sequence number for the truncated segment
- the sequence number applies to the _first_ byte in the segment, not
the last.

BTW, there's no such thing as a TCP packet, there is only a TCP
_segment_. Do you handle IP fragmentation/reassembly correctly?
(Although this case is unlikely to arise, you should handle it
somehow.)

--KW 8-)
--
Keith Wansbrough <(E-Mail Removed)>
http://www.cl.cam.ac.uk/users/kw217/
University of Cambridge Computer Laboratory.
Reply With Quote
Reply

Tags
modifications, packet, tcp or ip

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT. The time now is 07:12 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.