Fuzzing, and fixes for errors found with fuzzing.

This commit is contained in:
Aldo Cortesi 2013-03-03 22:03:27 +13:00
parent 8216801728
commit cde66cd584
5 changed files with 33 additions and 10 deletions

View File

@ -237,6 +237,8 @@ class ProxyHandler(tcp.BaseHandler):
continue continue
else: else:
raise raise
except http.HttpError, v:
raise ProxyError(502, "Invalid server response.")
else: else:
break break
@ -278,7 +280,6 @@ class ProxyHandler(tcp.BaseHandler):
) )
else: else:
self.log(cc, cc.error) self.log(cc, cc.error)
if isinstance(e, ProxyError): if isinstance(e, ProxyError):
self.send_error(e.code, e.msg, e.headers) self.send_error(e.code, e.msg, e.headers)
else: else:

View File

@ -3,7 +3,18 @@
# mitmproxy/mitmdump is running on port 8080 in straight proxy mode. # mitmproxy/mitmdump is running on port 8080 in straight proxy mode.
# pathod is running on port 9999 # pathod is running on port 9999
BASE="/Users/aldo/git/public/pathod/venv/bin/pathoc -eo -I 200,400,405,502 -p 8080 localhost " BASE_HTTP="/Users/aldo/git/public/pathod/pathoc -Tt 1 -eo -I 200,400,405,502 -p 8080 localhost "
$BASE -n 10000 "get:'http://localhost:9999':ir,@1" #$BASE_HTTP -n 10000 "get:'http://localhost:9999':ir,@1"
#$BASE_HTTP -n 100 "get:'http://localhost:9999':dr"
#$BASE_HTTP -n 10000 "get:'http://localhost:9999/p/200:ir,@300.0
# Assuming:
# mitmproxy/mitmdump is running on port 8080 in straight proxy mode.
# pathod with SSL enabled is running on port 9999
BASE_HTTPS="/Users/aldo/git/public/pathod/pathoc -sc localhost:9999 -Tt 1 -eo -I 200,400,404,405,502,800 -p 8080 localhost "
$BASE_HTTPS -en 10000 "get:/p/200:ir,@1"
#$BASE_HTTP -n 100 "get:/p/'200:dr'"
#$BASE_HTTPS -n 10000 "get:'/p/200:ir,@3000'"
#$BASE_HTTPS -n 10000 "get:'/p/200:ir,\"\ \n \"'"

View File

@ -1,6 +1,5 @@
import os import os
from cStringIO import StringIO from cStringIO import StringIO
import libpry
from libmproxy import dump, flow, proxy from libmproxy import dump, flow, proxy
import tutils import tutils
import mock import mock
@ -65,7 +64,7 @@ class TestDumpMaster:
cs = StringIO() cs = StringIO()
o = dump.Options(server_replay="nonexistent", kill=True) o = dump.Options(server_replay="nonexistent", kill=True)
libpry.raises(dump.DumpError, dump.DumpMaster, None, o, None, outfile=cs) tutils.raises(dump.DumpError, dump.DumpMaster, None, o, None, outfile=cs)
with tutils.tmpdir() as t: with tutils.tmpdir() as t:
p = os.path.join(t, "rep") p = os.path.join(t, "rep")
@ -90,7 +89,7 @@ class TestDumpMaster:
self._flowfile(p) self._flowfile(p)
assert "GET" in self._dummy_cycle(0, None, "", verbosity=1, rfile=p) assert "GET" in self._dummy_cycle(0, None, "", verbosity=1, rfile=p)
libpry.raises( tutils.raises(
dump.DumpError, self._dummy_cycle, dump.DumpError, self._dummy_cycle,
0, None, "", verbosity=1, rfile="/nonexistent" 0, None, "", verbosity=1, rfile="/nonexistent"
) )
@ -130,7 +129,7 @@ class TestDumpMaster:
assert len(list(flow.FlowReader(open(p)).stream())) == 1 assert len(list(flow.FlowReader(open(p)).stream())) == 1
def test_write_err(self): def test_write_err(self):
libpry.raises( tutils.raises(
dump.DumpError, dump.DumpError,
self._dummy_cycle, self._dummy_cycle,
1, 1,
@ -148,11 +147,11 @@ class TestDumpMaster:
assert "XREQUEST" in ret assert "XREQUEST" in ret
assert "XRESPONSE" in ret assert "XRESPONSE" in ret
assert "XCLIENTDISCONNECT" in ret assert "XCLIENTDISCONNECT" in ret
libpry.raises( tutils.raises(
dump.DumpError, dump.DumpError,
self._dummy_cycle, 1, None, "", script="nonexistent" self._dummy_cycle, 1, None, "", script="nonexistent"
) )
libpry.raises( tutils.raises(
dump.DumpError, dump.DumpError,
self._dummy_cycle, 1, None, "", script="starterr.py" self._dummy_cycle, 1, None, "", script="starterr.py"
) )

View File

@ -25,3 +25,15 @@ class TestFuzzy(tservers.HTTPProxTest):
req = 'get:"http://localhost:%s":i13,"["' req = 'get:"http://localhost:%s":i13,"["'
p = self.pathoc() p = self.pathoc()
assert p.request(req%self.server.port).status_code == 400 assert p.request(req%self.server.port).status_code == 400
def test_invalid_upstream(self):
req = r"get:'http://localhost:%s/p/200:i10,\'+\''"
p = self.pathoc()
assert p.request(req%self.server.port).status_code == 502
def test_upstream_disconnect(self):
req = r'200:d0:h"Date"="Sun, 03 Mar 2013 04:00:00 GMT"'
p = self.pathod(req)
assert p.status_code == 400

View File

@ -185,7 +185,7 @@ class TestHTTPSNoUpstream(tservers.HTTPProxTest, CommonMixin):
no_upstream_cert = True no_upstream_cert = True
def test_cert_gen_error(self): def test_cert_gen_error(self):
f = self.pathoc_raw() f = self.pathoc_raw()
f.connect((u"\u2102\u0001".encode("utf8"), 0)) f.connect((u"foo..bar".encode("utf8"), 0))
f.request("get:/") f.request("get:/")
assert "dummy cert" in "".join(self.proxy.log) assert "dummy cert" in "".join(self.proxy.log)