diff options
author | Nick Mathewson <nickm@torproject.org> | 2011-01-25 20:39:44 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2011-01-25 20:39:44 -0500 |
commit | 411ec3c0f8cd4786233a3bc274cb2b766d4bfe7c (patch) | |
tree | f48f77c8f33b73f9d386c87026c87b0d1a2055d1 /src/or/connection_edge.c | |
parent | 85da676108f0de765301f961bc58aebd139a5564 (diff) | |
download | tor-411ec3c0f8cd4786233a3bc274cb2b766d4bfe7c.tar.gz tor-411ec3c0f8cd4786233a3bc274cb2b766d4bfe7c.zip |
Add client code to detect attempts to connect to 127.0.0.1 etc
We detect and reject said attempts if there is no chosen exit node or
circuit: connecting to a private addr via a randomly chosen exit node
will usually fail (if all exits reject private addresses), is always
ill-defined (you're not asking for any particular host or service),
and usually an error (you've configured all requests to go over Tor
when you really wanted to configure all _remote_ requests to go over
Tor).
This can also help detect forwarding loop requests.
Found as part of bug2279.
Diffstat (limited to 'src/or/connection_edge.c')
-rw-r--r-- | src/or/connection_edge.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index 73ed9fb5c3..a85943f69f 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -1659,6 +1659,27 @@ connection_ap_handshake_rewrite_and_attach(edge_connection_t *conn, connection_mark_unattached_ap(conn, END_STREAM_REASON_TORPROTOCOL); return -1; } + if (!conn->use_begindir && !conn->chosen_exit_name && !circ) { + tor_addr_t addr; + if (tor_addr_from_str(&addr, socks->address) >= 0 && + tor_addr_is_internal(&addr, 0)) { + /* If this is an explicit private address with no chosen exit node, + * then we really don't want to try to connect to it. That's + * probably an error. */ + if (conn->is_transparent_ap) { + log_warn(LD_NET, + "Rejecting request for anonymous connection to private " + "address %s on a TransPort or NatdPort. Possible loop " + "in your NAT rules?", safe_str_client(socks->address)); + } else { + log_warn(LD_NET, + "Rejecting SOCKS request for anonymous connection to " + "private address %s", safe_str_client(socks->address)); + } + connection_mark_unattached_ap(conn, END_STREAM_REASON_PRIVATE_ADDR); + return -1; + } + } if (!conn->use_begindir && !conn->chosen_exit_name && !circ) { /* see if we can find a suitable enclave exit */ |