Opened 7 years ago

Closed 4 years ago

#6542 closed defect (not a bug)

curl 7.27.0 doesn't work with torsocks

Reported by: cypherpunks Owned by: dgoulet
Priority: High Milestone:
Component: Core Tor/Torsocks Version:
Severity: Keywords:
Cc: Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description

After upgrading curl to version 7.27.0, various programs that depend on libcurl (including curl itself) no longer work with torsocks.

All requests are replied to with the "501 Tor is not an HTTP proxy" message. Curiously, the first two bytes of the response are 0x05 0x00 as you would expect from a valid SOCKS5 reply.

Perhaps there's some poor buffer management lurking around.

Thanks.

Software versions:
Linux 3.4.7-1-ARCH i686
curl 7.27.0
torsocks 1.2
tor 0.2.2.37

Child Tickets

Change History (9)

comment:1 Changed 7 years ago by arma

Component: - Select a componentTorify
    case 'G': /* get */
    case 'H': /* head */
    case 'P': /* put/post */
    case 'C': /* connect */
      strlcpy((char*)req->reply,
"HTTP/1.0 501 Tor is not an HTTP Proxy\r\n"

The first byte that goes to Tor's socks port is a G, H, P, or C. You are trying to talk http to the socks port. Perhaps you have an http proxy set in your curl as well?

comment:2 in reply to:  1 Changed 7 years ago by cypherpunks

Replying to arma:

    case 'G': /* get */
    case 'H': /* head */
    case 'P': /* put/post */
    case 'C': /* connect */
      strlcpy((char*)req->reply,
"HTTP/1.0 501 Tor is not an HTTP Proxy\r\n"

The first byte that goes to Tor's socks port is a G, H, P, or C. You are trying to talk http to the socks port. Perhaps you have an http proxy set in your curl as well?

Nope. That was the first thing I checked. I'll try to get some traces tomorrow. I had a quick glance at the changes from 7.26.0 and 7.27.0 in curl's git repo but nothing jumped out at me.

comment:3 Changed 7 years ago by arma

Turn off your Tor and run nc -l -p 9050 and see what it's receiving.

comment:4 in reply to:  3 Changed 7 years ago by cypherpunks

Replying to arma:

Turn off your Tor and run nc -l -p 9050 and see what it's receiving.

That only shows the SOCKS4 hostname lookup request that torsocks does before initiating the V5 handshake.

Here's a dump of what I'm seeing. Note the first two bytes and the final byte.

$ usewithtor curl -iI http://en.wikipedia.org/ | hexdump -C
00000000  05 00 48 54 54 50 2f 31  2e 30 20 35 30 31 20 54  |..HTTP/1.0 501 T|
00000010  6f 72 20 69 73 20 6e 6f  74 20 61 6e 20 48 54 54  |or is not an HTT|
00000020  50 20 50 72 6f 78 79 0d  0a 43 6f 6e 74 65 6e 74  |P Proxy..Content|
00000030  2d 54 79 70 65 3a 20 74  65 78 74 2f 68 74 6d 6c  |-Type: text/html|
00000040  3b 20 63 68 61 72 73 65  74 3d 69 73 6f 2d 38 38  |; charset=iso-88|
00000050  35 39 2d 31 0d 0a 0d 0a  3c 68 74 6d 6c 3e 0a 3c  |59-1....<html>.<|
00000060  68 65 61 64 3e 0a 3c 74  69 74 6c 65 3e 54 6f 72  |head>.<title>Tor|
00000070  20 69 73 20 6e 6f 74 20  61 6e 20 48 54 54 50 20  | is not an HTTP |
00000080  50 72 6f 78 79 3c 2f 74  69 74 6c 65 3e 0a 3c 2f  |Proxy</title>.</|
00000090  68 65 61 64 3e 0a 3c 62  6f 64 79 3e 0a 3c 68 31  |head>.<body>.<h1|
000000a0  3e 54 6f 72 20 69 73 20  6e 6f 74 20 61 6e 20 48  |>Tor is not an H|
000000b0  54 54 50 20 50 72 6f 78  79 3c 2f 68 31 3e 0a 3c  |TTP Proxy</h1>.<|
000000c0  70 3e 0a 49 74 20 61 70  70 65 61 72 73 20 79 6f  |p>.It appears yo|
000000d0  75 20 68 61 76 65 20 63  6f 6e 66 69 67 75 72 65  |u have configure|
000000e0  64 20 79 6f 75 72 20 77  65 62 20 62 72 6f 77 73  |d your web brows|
000000f0  65 72 20 74 6f 20 75 73  65 20 54 6f 72 20 61 73  |er to use Tor as|
00000100  20 61 6e 20 48 54 54 50  20 70 72 6f 78 79 2e 0a  | an HTTP proxy..|
00000110  54 68 69 73 20 69 73 20  6e 6f 74 20 63 6f 72 72  |This is not corr|
00000120  65 63 74 3a 20 54 6f 72  20 69 73 20 61 20 53 4f  |ect: Tor is a SO|
00000130  43 4b 53 20 70 72 6f 78  79 2c 20 6e 6f 74 20 61  |CKS proxy, not a|
00000140  6e 20 48 54 54 50 20 70  72 6f 78 79 2e 0a 50 6c  |n HTTP proxy..Pl|
00000150  65 61 73 65 20 63 6f 6e  66 69 67 75 72 65 20 79  |ease configure y|
00000160  6f 75 72 20 63 6c 69 65  6e 74 20 61 63 63 6f 72  |our client accor|
00000170  64 69 6e 67 6c 79 2e 0a  3c 2f 70 3e 0a 3c 70 3e  |dingly..</p>.<p>|
00000180  0a 53 65 65 20 3c 61 20  68 72 65 66 3d 22 68 74  |.See <a href="ht|
00000190  74 70 73 3a 2f 2f 77 77  77 2e 74 6f 72 70 72 6f  |tps://www.torpro|
000001a0  6a 65 63 74 2e 6f 72 67  2f 64 6f 63 75 6d 65 6e  |ject.org/documen|
000001b0  74 61 74 69 6f 6e 2e 68  74 6d 6c 22 3e 68 74 74  |tation.html">htt|
000001c0  70 73 3a 2f 2f 77 77 77  2e 74 6f 72 70 72 6f 6a  |ps://www.torproj|
000001d0  65 63 74 2e 6f 72 67 2f  64 6f 63 75 6d 65 6e 74  |ect.org/document|
000001e0  61 74 69 6f 6e 2e 68 74  6d 6c 3c 2f 61 3e 20 66  |ation.html</a> f|
000001f0  6f 72 20 6d 6f 72 65 20  69 6e 66 6f 72 6d 61 74  |or more informat|
00000200  69 6f 6e 2e 0a 3c 21 2d  2d 20 50 6c 75 73 20 74  |ion..<!-- Plus t|
00000210  68 69 73 20 63 6f 6d 6d  65 6e 74 2c 20 74 6f 20  |his comment, to |
00000220  6d 61 6b 65 20 74 68 65  20 62 6f 64 79 20 72 65  |make the body re|
00000230  73 70 6f 6e 73 65 20 6d  6f 72 65 20 74 68 61 6e  |sponse more than|
00000240  20 35 31 32 20 62 79 74  65 73 2c 20 73 6f 20 20  | 512 bytes, so  |
00000250  20 20 20 20 49 45 20 77  69 6c 6c 20 62 65 20 77  |    IE will be w|
00000260  69 6c 6c 69 6e 67 20 74  6f 20 64 69 73 70 6c 61  |illing to displa|
00000270  79 20 69 74 2e 20 43 6f  6d 6d 65 6e 74 20 63 6f  |y it. Comment co|
00000280  6d 6d 65 6e 74 20 63 6f  6d 6d 65 6e 74 20 63 6f  |mment comment co|
00000290  6d 6d 65 6e 74 20 20 20  20 20 20 63 6f 6d 6d 65  |mment      comme|
000002a0  6e 74 20 63 6f 6d 6d 65  6e 74 20 63 6f 6d 6d 65  |nt comment comme|
*
000002d0  6e 74 20 63 6f 6d 6d 65  6e 74 2e 2d 2d 3e 0a 3c  |nt comment.-->.<|
000002e0  2f 70 3e 0a 3c 2f 62 6f  64 79 3e 0a 3c 2f 68 74  |/p>.</body>.</ht|
000002f0  6d 6c 3e 0a 00                                    |ml>..|
000002f5

Now if I pass the debugging environment variables to torsocks (which slows down its execution), I get the following result. Note that curl seems to be handing us the entire buffer with the SOCKS header before the HTTP reply from the remote server.

$ TORSOCKS_DEBUG=3 TORSOCKS_DEBUG_FILE=trace usewithtor curl -iI http://en.wikipedia.org/ | hexdump -C
00000000  05 00 00 01 00 00 00 00  00 00 48 54 54 50 2f 31  |..........HTTP/1|
00000010  2e 30 20 33 30 31 20 4d  6f 76 65 64 20 50 65 72  |.0 301 Moved Per|
00000020  6d 61 6e 65 6e 74 6c 79  0d 0a 44 61 74 65 3a 20  |manently..Date: |
00000030  53 61 74 2c 20 30 34 20  41 75 67 20 32 30 31 32  |Sat, 04 Aug 2012|
00000040  20 30 36 3a 30 33 3a 35  38 20 47 4d 54 0d 0a 53  | 06:03:58 GMT..S|
00000050  65 72 76 65 72 3a 20 41  70 61 63 68 65 0d 0a 58  |erver: Apache..X|
00000060  2d 43 6f 6e 74 65 6e 74  2d 54 79 70 65 2d 4f 70  |-Content-Type-Op|
00000070  74 69 6f 6e 73 3a 20 6e  6f 73 6e 69 66 66 0d 0a  |tions: nosniff..|
00000080  43 61 63 68 65 2d 43 6f  6e 74 72 6f 6c 3a 20 73  |Cache-Control: s|
00000090  2d 6d 61 78 61 67 65 3d  31 32 30 30 2c 20 6d 75  |-maxage=1200, mu|
000000a0  73 74 2d 72 65 76 61 6c  69 64 61 74 65 2c 20 6d  |st-revalidate, m|
000000b0  61 78 2d 61 67 65 3d 30  0d 0a 56 61 72 79 3a 20  |ax-age=0..Vary: |
000000c0  41 63 63 65 70 74 2d 45  6e 63 6f 64 69 6e 67 2c  |Accept-Encoding,|
000000d0  58 2d 46 6f 72 77 61 72  64 65 64 2d 50 72 6f 74  |X-Forwarded-Prot|
000000e0  6f 2c 43 6f 6f 6b 69 65  0d 0a 4c 61 73 74 2d 4d  |o,Cookie..Last-M|
000000f0  6f 64 69 66 69 65 64 3a  20 53 61 74 2c 20 30 34  |odified: Sat, 04|
00000100  20 41 75 67 20 32 30 31  32 20 30 36 3a 30 33 3a  | Aug 2012 06:03:|
00000110  35 38 20 47 4d 54 0d 0a  4c 6f 63 61 74 69 6f 6e  |58 GMT..Location|
00000120  3a 20 68 74 74 70 3a 2f  2f 65 6e 2e 77 69 6b 69  |: http://en.wiki|
00000130  70 65 64 69 61 2e 6f 72  67 2f 77 69 6b 69 2f 4d  |pedia.org/wiki/M|
00000140  61 69 6e 5f 50 61 67 65  0d 0a 43 6f 6e 74 65 6e  |ain_Page..Conten|
00000150  74 2d 4c 65 6e 67 74 68  3a 20 30 0d 0a 43 6f 6e  |t-Length: 0..Con|
00000160  74 65 6e 74 2d 54 79 70  65 3a 20 74 65 78 74 2f  |tent-Type: text/|
00000170  68 74 6d 6c 3b 20 63 68  61 72 73 65 74 3d 75 74  |html; charset=ut|
00000180  66 2d 38 0d 0a 41 67 65  3a 20 32 0d 0a 58 2d 43  |f-8..Age: 2..X-C|
00000190  61 63 68 65 3a 20 48 49  54 20 66 72 6f 6d 20 63  |ache: HIT from c|
000001a0  70 31 30 31 37 2e 65 71  69 61 64 2e 77 6d 6e 65  |p1017.eqiad.wmne|
000001b0  74 0d 0a 58 2d 43 61 63  68 65 2d 4c 6f 6f 6b 75  |t..X-Cache-Looku|
000001c0  70 3a 20 48 49 54 20 66  72 6f 6d 20 63 70 31 30  |p: HIT from cp10|
000001d0  31 37 2e 65 71 69 61 64  2e 77 6d 6e 65 74 3a 33  |17.eqiad.wmnet:3|
000001e0  31 32 38 0d 0a 58 2d 43  61 63 68 65 3a 20 4d 49  |128..X-Cache: MI|
000001f0  53 53 20 66 72 6f 6d 20  63 70 31 30 31 30 2e 65  |SS from cp1010.e|
00000200  71 69 61 64 2e 77 6d 6e  65 74 0d 0a 58 2d 43 61  |qiad.wmnet..X-Ca|
00000210  63 68 65 2d 4c 6f 6f 6b  75 70 3a 20 4d 49 53 53  |che-Lookup: MISS|
00000220  20 66 72 6f 6d 20 63 70  31 30 31 30 2e 65 71 69  | from cp1010.eqi|
00000230  61 64 2e 77 6d 6e 65 74  3a 38 30 0d 0a 43 6f 6e  |ad.wmnet:80..Con|
00000240  6e 65 63 74 69 6f 6e 3a  20 63 6c 6f 73 65 0d 0a  |nection: close..|
00000250  0d 0a                                             |..|
00000252

Weird, huh? I'm not sure if this is a curl bug or a torsocks bug.

comment:5 Changed 7 years ago by cypherpunks

Yes, curl 7.27.0 doesn`t work with torsocks. --socks4a option does work though

7.26.0 does work well

comment:6 Changed 7 years ago by rransom

This is a more general problem with torsocks, probably with non-blocking sockets. It has also been reported with irssi.

comment:7 in reply to:  6 Changed 7 years ago by cypherpunks

Replying to rransom:

This is a more general problem with torsocks, probably with non-blocking sockets. It has also been reported with irssi.

This appears to be the same issue. I rebuilt curl from source, passing "--disable-nonblocking" to configure and now it works just fine with torsocks.

Thanks rransom.

comment:8 Changed 5 years ago by nickm

Component: TorifyTorsocks
Owner: set to dgoulet

comment:9 Changed 4 years ago by dgoulet

Resolution: not a bug
Status: newclosed

Works with the current supported version of torsocks 2.x.

Note: See TracTickets for help on using tickets.