Difference between revisions of "TCP proxy with netcat"

From Noah.org
Jump to navigationJump to search
m
m
Line 1: Line 1:
 
[[Category:Engineering]]
 
[[Category:Engineering]]
  
 +
This is the simplest proxy for HTTP.
 
<pre>
 
<pre>
 
mkfifo /tmp/fifo
 
mkfifo /tmp/fifo
 
nc -lk -p 8080 </tmp/fifo | nc www.noah.org 80 >/tmp/fifo
 
nc -lk -p 8080 </tmp/fifo | nc www.noah.org 80 >/tmp/fifo
 +
</pre>
 +
Note that this will not work on virtual web sites. Web servers use the '''Host''' request header field to determine which virtual web site to serve. If '''Host''' is not set correctly then the brower
 +
<pre>
 +
Site Temporarily Unavailable
 +
We apologize for the inconvenience. Please contact the webmaster/ tech support immediately to have them rectify this.
 +
error id: "bad_httpd_conf"
 
</pre>
 
</pre>
  

Revision as of 12:36, 28 May 2014


This is the simplest proxy for HTTP.

mkfifo /tmp/fifo
nc -lk -p 8080 </tmp/fifo | nc www.noah.org 80 >/tmp/fifo

Note that this will not work on virtual web sites. Web servers use the Host request header field to determine which virtual web site to serve. If Host is not set correctly then the brower

Site Temporarily Unavailable
We apologize for the inconvenience. Please contact the webmaster/ tech support immediately to have them rectify this.
error id: "bad_httpd_conf"

This creates a primitive HTTP proxy with logging. It rewrites the Host: field in the HTTP request header to satisfy HTTP servers that use the Host: header to decide which virtual web site to serve.

mkfifo /tmp/fifo
nc -lk -p 8080 </tmp/fifo | sed -u -e 's/^Host.*/Host: www.noah.org/' | tee -a http_request.log | nc www.noah.org 80 | tee -a http_response.log >/tmp/fifo
mkfifo /tmp/fifo
nc -lk -p 8080 </tmp/fifo | sed -u -e 's/^Host.*/Host: www.noah.org/' | tee -a http_request.log | nc www.noah.org 80 | tee -a http_response.log >/tmp/fifo
mkfifo /tmp/fifo
nc -q -1 -l -p 8080 </tmp/fifo | sed -u -e 's/^Host:.*/Host: www.noah.org/' -e '/^If-None-Match:.*/d' -e '/^If-Modified-Since:.*/d' -e '/^Connection:.*/d' -e '/^Accept-Encoding:.*/d' | tee -i -a http_request.log | nc -q -1 www.noah.org 80 | sed -u -e 's/noah.org/localhost/i' | tee -i -a http_response.log >/tmp/fifo