TCP proxy with netcat
From Noah.org
Jump to navigationJump to search
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 web server will return an error like this.
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 HTTP proxy will rewrite the Host: field in the HTTP request header to support virtual web sites. This version also add logging of the server response.
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