0

I can't seem to get a response through the proxy when I pipe something to nc through it (note there are two different commands issued below):

 $ echo "GET / HTTP/1.1
 > Host: torproject.org
 >
 > " | sudo nc -n -X 5 -x 127.0.0.1:9050 38.229.72.16 80 -v -D
 Connection to 38.229.72.16 80 port [tcp/*] succeeded!
 $ echo "GET / HTTP/1.1
 Host: torproject.org

 " | sudo nc -n 38.229.72.16 80 -v -D
 Connection to 38.229.72.16 80 port [tcp/*] succeeded!
 HTTP/1.1 302 Found
 Date: XXXXXXXXXXXXXXXXXXXXXXX
 Server: Apache
 X-Content-Type-Options: nosniff
 X-Frame-Options: sameorigin
 X-Xss-Protection: 1
 Location: https://www.torproject.org/
 Content-Length: 275
 Content-Type: text/html; charset=iso-8859-1

 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
 <html><head>
 <title>302 Found</title>
 </head><body>
 <h1>Found</h1>
 <p>The document has moved <a href="https://www.torproject.org/">here</a>.</p>
 <hr>
 <address>Apache Server at torproject.org Port 80</address>
 </body></html>

I've also tried with

 $ echo "hey" | torsocks nc ...

If I send interactively, I DO receive a response.

 $ nc -x 127.0.0.1:9050 torproject.org 80
 GET / HTTP/1.1
 Host: torproject.org

 HTTP/1.1 302 Found
 Date: XXXXXXXXXXXXXXXXXXXXXXXXX
 Server: Apache
 X-Content-Type-Options: nosniff
 X-Frame-Options: sameorigin
 X-Xss-Protection: 1
 Location: https://www.torproject.org/
 Content-Length: 275
 Content-Type: text/html; charset=iso-8859-1
 [...]

Is this behavior to be expected? Can I invoke / "turn on" output somehow?

  • "If I send interactively, I DO receive a response." clearly a netcat bug then? – cacahuatl Dec 8 '16 at 8:59
  • Not necessarily because as you see there are two pipe commands in the first segment, one with and one without tor, and without tor nc returns the server response. – lash Dec 8 '16 at 9:18
  • That is "not necessarily" instead of "no," of course :) – lash Dec 8 '16 at 9:25
  • But the problem only happens when you pipe into netcat, it's likely related to the pipe closing resulting in netcat terminating? This is a well known issue under certain circumstances. – cacahuatl Dec 8 '16 at 11:11
  • 1
    So the problem is netcat takes the input from stdin, sends it over the network but then stdin closes (when echo is finished writing into the pipe) so netcat is like "welp, the user is done" and dies, it likely works without Tor because of the reduced latency, it gets the response before it closes. Tor adds extra latency so it closes before the response gets back and thus never prints it. – cacahuatl Dec 8 '16 at 11:28
1

As described in the commments by canonizing ironize, the problem is that nc exits before the response is received:

So the problem is netcat takes the input from stdin, sends it over the network but then stdin closes (when echo is finished writing into the pipe) so netcat is like "welp, the user is done" and dies, it likely works without Tor because of the reduced latency, it gets the response before it closes. Tor adds extra latency so it closes before the response gets back and thus never prints it.

Suggested workaround is adding option -q -1, meaning "wait for response forever" to nc, which worked for me.

If anyone has further insight into this, feel free to contribute.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.