[or-cvs] r19731: {check} Patch from Marcus Griep to allow bulk exit list generation f (check/trunk/cgi-bin)

ioerror at seul.org ioerror at seul.org
Wed Jun 17 01:54:45 UTC 2009


Author: ioerror
Date: 2009-06-16 21:54:45 -0400 (Tue, 16 Jun 2009)
New Revision: 19731

Modified:
   check/trunk/cgi-bin/TorBulkExitList.py
Log:
Patch from Marcus Griep to allow bulk exit list generation for custom port numbers as well as any arbitraty IP address.


Modified: check/trunk/cgi-bin/TorBulkExitList.py
===================================================================
--- check/trunk/cgi-bin/TorBulkExitList.py	2009-06-16 16:48:40 UTC (rev 19730)
+++ check/trunk/cgi-bin/TorBulkExitList.py	2009-06-17 01:54:45 UTC (rev 19731)
@@ -8,9 +8,10 @@
 from mod_python import util
 
 DNS.ParseResolvConf()
-def bulkCheck(RemoteServerIP):
+def bulkCheck(RemoteServerIP, RemotePort):
     parsedExitList = "/tmp/TorBulkCheck/parsed-exit-list"
-    cacheFile = parsedExitList + "-" + RemoteServerIP + ".cache"
+    cacheFile = parsedExitList + "-" + RemoteServerIP +\
+        "_" + RemotePort + ".cache"
     confirmedExits = []
 
     # Do we have a fresh exit cache?
@@ -34,7 +35,7 @@
         # the list
         for possibleExit in possibleExits:
             try:
-                if (isUsingTor(possibleExit, RemoteServerIP) == 0 ):
+                if (isUsingTor(possibleExit, RemoteServerIP, RemotePort) == 0 ):
                     confirmedExits.append(possibleExit)
             except:
                 return None
@@ -52,7 +53,7 @@
 
     else:
         # Lets return the cache
-        cachedExits = open(parsedExitList, 'r')
+        cachedExits = open(cacheFile, 'r')
         cachedExitList = cachedExits.readlines()
         return cachedExitList
 
@@ -170,10 +171,13 @@
             # We're getting unexpected data - fail closed
             return 2
         for a in answer.answers:
-            if a['data'] != "127.0.0.2":
-                return 2
-        # If we're here, we've had a positive exit answer
-        return 0
+            # if 127.0.0.2 is in the answer section,
+            # then exits are allowed from "clientIp" to "ELTarget:ELPort"
+            if a['data'] == "127.0.0.2":
+                return 0
+        # If we're here, the DNS exit list gave us a non-exit answer
+        # that we don't understand. Return a failure code.
+        return 2
 
 def parseAddress(req):
     # Get the ip from apache
@@ -192,6 +196,24 @@
         return None
 
     return parsed_ip 
+
+def parsePort(req):
+    # Get the port from apache
+    user_supplied_port = None
+    formSubmission = util.FieldStorage(req)
+    user_supplied_port = formSubmission.getfirst("port", "80")
+
+    # Verify that the port is a number between 1 and 65535
+    # Otherwise return a sane default of 80
+    search = re.compile("^(?:[1-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|"+\
+                            "65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$")
+
+    if search.match(user_supplied_port):
+        parsed_port = user_supplied_port
+    else:
+        parsed_port = "80"
+
+    return parsed_port
     
 def handler(req):
     
@@ -199,16 +221,21 @@
     req.content_type = 'text/plain; charset=utf-8'
 
     RemoteServerIP = parseAddress(req)
-    RemotePort = "80"
+    RemotePort = parsePort(req)
     
     if RemoteServerIP is not None:
 
         updateCache()
-        TestedExits = bulkCheck(RemoteServerIP)
+        TestedExits = bulkCheck(RemoteServerIP, RemotePort)
         req.write("# This is a list of all Tor exit nodes that can contact " + RemoteServerIP + 
         " on Port " + RemotePort + " #\n")
+
+        querystring = "ip=%s" % RemoteServerIP
+	if RemotePort != "80":
+		querystring += "&port=%s" % RemotePort
+
         req.write("# You can update this list by visiting " + \
-        "https://check.torproject.org/cgi-bin/TorBulkExitList.py?ip=%s #\n" % RemoteServerIP)
+        "https://check.torproject.org/cgi-bin/TorBulkExitList.py?%s #\n" % querystring)
 
         dateOfAccess = time.asctime(time.gmtime())
         req.write("# This file was generated on %s UTC #\n" % dateOfAccess)



More information about the tor-commits mailing list