Skip to content

Commit 7d2bc43

Browse files
committed
Quick fix #5 - TorDNSEL service changes
Patch TorDNSEL::IpPort to function with newer Tor DNS exit list service that uses the format <reverse client ip>.dnsel.torproject.org. See https://lists.torproject.org/pipermail/tor-project/2020-March/002759.html for more details
1 parent b2ebcbc commit 7d2bc43

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

examples/TorDNSEL.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,27 @@
2424
// Third is the server port
2525
// Fourth is the DNS server to query
2626
$lookups = array(
27-
array('208.111.35.21', '1.2.3.4', 80, 'exitlist.torproject.org'),
28-
array('208.111.35.21', '1.2.3.4', 80, '8.8.8.8'),
29-
array('208.113.166.5', '1.2.3.4', 80, 'exitlist.torproject.org'),
30-
array('208.113.166.5', '1.2.3.4', 80, 'exitlist.torproject.org'),
31-
array('197.231.221.211', '1.2.3.4', 80, 'exitlist.torproject.org'),
32-
array('208.111.35.21', '1.2.3.4', 80, '10.11.12.13'), // should time out
27+
array('195.176.3.20', 'check-01.torproject.org'), /* DigiGesTor4e3 */
28+
array('185.220.103.4', '1.1.1.1'), /* CalyxInstitute16 */
29+
array('185.220.103.4', '9.9.9.9'), /* CalyxInstitute16 */
30+
array('185.220.101.220', 'check-01.torproject.org'), /* niftyguard */
31+
array('89.34.27.59', 'check-01.torproject.org'), /* Hydra2 */
32+
array('104.215.148.63', 'check-01.torproject.org'), /* not a relay */
33+
array('208.111.35.21', '10.11.12.13'), // should time out
3334
);
3435

3536
foreach($lookups as $lookup) {
36-
list($remoteIP, $myIp, $myPort, $server) = $lookup;
37+
list($remoteIP, $server) = $lookup;
3738

3839
try {
3940
// send DNS request to Tor DNS exit list service
40-
// returns true if $remoteIP is a Tor exit node that permits connections to $myIp:$myPort
41-
$isTor = TorDNSEL::IpPort($myIp, $myPort, $remoteIP, $server);
41+
// returns true if $remoteIP is a Tor exit relay
42+
$isTor = TorDNSEL::IpPort(null, null, $remoteIP, $server);
4243

43-
echo sprintf("Connection to %s:%d from %s *%s* coming from a Tor exit node.\n",
44-
$myIp, $myPort, $remoteIP, ($isTor ? 'is' : 'is NOT'));
44+
echo sprintf("Connection from %s *%s* a Tor exit relay.\n",
45+
$remoteIP, ($isTor ? 'is' : 'is NOT'));
4546
} catch (\Exception $ex) {
46-
echo sprintf("Lookup of %s:%s for %s failed with error '%s'\n",
47-
$myIp, $myPort, $remoteIP, $ex->getMessage());
47+
echo sprintf("Query for %s failed. Error: %s\n",
48+
$remoteIP, $ex->getMessage());
4849
}
4950
}

src/TorDNSEL.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,27 @@ class TorDNSEL
4949
* This function determines if the remote IP address is a Tor exit node
5050
* that permits connections to the specified IP:Port combination.
5151
*
52-
* @param string $ip IP address (dotted quad) of the local server
53-
* @param string $port Numeric port the remote client is connecting to (e.g. 80, 443, 53)
54-
* @param string $remoteIp IP address of the client (potential Tor exit) to look up
55-
* @param string $dnsServer The DNS server to query (by default queries exitlist.torproject.org)
56-
* @return boolean true if the $remoteIp is a Tor exit node that allows connections to $ip:$port
52+
* @deprecated 1.1.14 Will be removed in future releases and replaced by a simpler interface
53+
*
54+
* @param string $ip No longer used. IP address (dotted quad) of the local server
55+
* @param string $port No longer used. Numeric port the remote client is connecting to (e.g. 80, 443, 53)
56+
* @param string $remoteIp IP address of the client (potential Tor exit relay) to check
57+
* @param string $dnsServer The DNS server to query (by default queries check-01.torproject.org)
58+
* @return boolean true if the $remoteIp is a Tor exit relay
5759
*/
58-
public static function IpPort($ip, $port, $remoteIp, $dnsServer = 'exitlist.torproject.org')
60+
public static function IpPort($ip, $port, $remoteIp, $dnsServer = 'check-01.torproject.org')
5961
{
6062
$dnsel = new self();
6163

6264
// construct a hostname in the format of {rip}.{port}.{ip}.ip-port.exitlist.torproject.org
6365
// where {ip} is the destination IP address and {port} is the destination port
6466
// and {rip} is the remote (user) IP address which may or may not be a Tor router exit address
6567

66-
$host = implode('.', array_reverse(explode('.', $remoteIp))) .
67-
'.' . $port . '.' .
68-
implode('.', array_reverse(explode('.', $ip))) .
69-
'.ip-port' .
70-
'.exitlist.torproject.org';
68+
$host = sprintf(
69+
'%s.%s',
70+
implode('.', array_reverse(explode('.', $remoteIp))),
71+
'dnsel.torproject.org'
72+
);
7173

7274
return $dnsel->_dnsLookup($host, $dnsServer);
7375
}

0 commit comments

Comments
 (0)