LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 03-02-2012, 08:21 PM   #1
haggismn
LQ Newbie
 
Registered: Dec 2011
Posts: 6

Rep: Reputation: Disabled
Adding gzip compression to a netcat proxy


Hello all,
I am trying to add gzip compression to a netcat proxy connection. I have the connection working without compression with the following on both sides.

Code:
mkfifo /tmp/rev
while true ; do cat /tmp/rev | nc -l 8080 | nc localhost 80 > /tmp/rev ; done
The idea is that the data entering the connection will be gzipped, then passed onto httptunnel, which forwards it to the remote host. The remote host will then pass the result to the opposing nc/gzip -d , and forward it from there to a test application.

I have made an educated attempt at the following, but it doenst work;

Code:
while true ; do cat /tmp/rev | gzip | nc -l 8008 | nc localhost 80 | gzip -d > /tmp/rev ; done
I am aware that I can use an array of other protocols like ssh and ssl, however I need to have a gzipped tunnel to test out suricata's ability to decompress gzip on the fly.

Can anyone advise on how to alter the statement to implement compression on input and decompression on output? Or, if anyone understands what I am trying to do and believes it not to be possible, this advice would be welcome too so I do not keep wasting my time!

Thanks in advance for any help.

Last edited by haggismn; 03-02-2012 at 08:30 PM.
 
Old 03-03-2012, 02:21 AM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
It looks like you're trying to do it all in one command pipeline, try doing it in 2 - 1 sending and 1 receiving. From memory, having the same file as a source and destination in the same command will truncate the file to zero bytes.
 
Old 03-03-2012, 11:22 AM   #3
haggismn
LQ Newbie
 
Registered: Dec 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Thanks for your response!
How would I go about putting this into 2 commands? I am trying this first without using gzip. Please bear with me as I am not well versed on how piping works.

I believe the following command shows the points that gzip should occur;
Code:
while true ; do cat /tmp/fifo | nc -l -p 8008 | gzip | nc localhost 80 | gzip -d > /tmp/fifo ; done
I get the following error, which indicates you may be right
Code:
gzip: stdin: unexpected end of file

Code:
while true ; do nc -l 8080 (| gzip )| nc localhost 80 ; done
This would send from from client to the server, wouldn't it?

This is the part I get stuck at. How can I read back data only in one command? The following is an educated guess, however I can't use it because port 8080 is already in use.

Code:
while true ; do nc localhost 80 (| gzip -d )> /tmp/rev | nc -l 8080 ; done
How can I adjust this to make it work?

Another possible problem I was thinking of might be that gzip will not know when to stop compressing, then at the end send everything in one big gz file. Optimally, I would like only one packet compressed, then sent on. Will this happen, or is there something I can add to make sure that compression only occurs for x bytes (eg the MTU size). Of course, I don't think I am limited to using gzip, if there is another program which can act in this way, I will use it instead.

Thanks again for any help.

Edit: I now have 2 separate commands working although I am not sure where to go next. It seems as though reading and writing are still occurring in both commands so it might not be useful;
Code:
cat fifo2 | nc -l 8080 > fifo1
Code:
cat fifo1 | nc localhost 80 > fifo2
Can gzip be added to these commands, or do I need to make different changes? The following does not seem to work.

Code:
cat fifo2 | nc -l 8080 | gzip > fifo1
Code:
cat fifo1 | nc localhost 80 | gzip -d fifo2

Last edited by haggismn; 03-03-2012 at 01:15 PM.
 
Old 03-04-2012, 04:31 AM   #4
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Netcat should be the end/start of each command:

Example:
Quote:
nc -l -p 2000 -q 0 | gzip -d | destcmd
srccmd | gzip | nc -q 0 otherhost 2000
Ref: http://www.debian-administration.org/articles/58
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] What are the differences between the Gzip, Lzma, Xz and Lzop compression smag Linux - Kernel 4 08-29-2011 10:07 AM
Determining the compression ratio when using -9 with gzip kaplan71 Linux - Software 2 04-08-2010 03:45 PM
Problem with installpkg - external compression utility gzip missing samkz Slackware 5 04-20-2009 12:48 AM
Is gzip -c9 giving the highest compression? Thaidog Linux - General 2 04-23-2007 05:15 AM
gzip , general compression question ?? glenn69 Linux - Newbie 5 10-12-2004 12:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 05:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration