[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [ooni-probe/master] Add test that generates a random invalid HTTP request



commit ebf39da6ee59e2fb55226e5c256553ce1093006c
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Thu Nov 22 11:22:16 2012 +0100

    Add test that generates a random invalid HTTP request
---
 nettests/core/http_invalid_requests.py |   63 ++++++++++++++++++++++++++++++++
 1 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/nettests/core/http_invalid_requests.py b/nettests/core/http_invalid_requests.py
new file mode 100644
index 0000000..7e6f47f
--- /dev/null
+++ b/nettests/core/http_invalid_requests.py
@@ -0,0 +1,63 @@
+# -*- encoding: utf-8 -*-
+from twisted.python import usage
+
+from ooni.utils import randomStr
+from ooni.templates import tcpt
+
+class UsageOptions(usage.Options):
+    optParameters = [['backend', 'b', '127.0.0.1:57002',
+                        'The OONI backend that runs a TCP echo server (must be on port 80)']]
+
+    optFlags = [['nopayloadmatch', 'n',
+        "Don't match the payload of the response. This option is used when you don't have a TCP echo server running"]]
+
+class HTTPInvalidRequests(tcpt.TCPTest):
+    name = "HTTP Invalid Requests"
+    version = "0.1.1"
+    authors = "Arturo Filastò"
+
+    inputFile = ['file', 'f', None,
+                 'Input file of list of hostnames to attempt to resolve']
+
+    usageOptions = UsageOptions
+    requiredOptions = ['backend']
+
+    def setUp(self):
+        try:
+            self.address, self.port = self.localOptions['backend'].split(":")
+            self.port = int(self.port)
+        except:
+            raise usage.UsageError("Invalid backend address specified (must be address:port)")
+
+    def test_random_invalid_request(self):
+        """
+        We test sending data to a TCP echo server, if what we get back is not
+        what we have sent then there is tampering going on.
+        This is for example what squid will return when performing such
+        request:
+
+            HTTP/1.0 400 Bad Request
+            Server: squid/2.6.STABLE21
+            Date: Sat, 23 Jul 2011 02:22:44 GMT
+            Content-Type: text/html
+            Content-Length: 1178
+            Expires: Sat, 23 Jul 2011 02:22:44 GMT
+            X-Squid-Error: ERR_INVALID_REQ 0
+            X-Cache: MISS from cache_server
+            X-Cache-Lookup: NONE from cache_server:3128
+            Via: 1.0 cache_server:3128 (squid/2.6.STABLE21)
+            Proxy-Connection: close
+
+        """
+        payload = randomStr(10) + "\n\r"
+        def got_all_data(received_array):
+            if not self.localOptions['nopayloadmatch']:
+                first = received_array[0]
+                if first != payload:
+                    self.report['tampering'] = True
+            else:
+                self.report['tampering'] = 'unknown'
+
+        d = self.sendPayload(payload)
+        d.addCallback(got_all_data)
+        return d



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits