Skip to content

Commit

Permalink
burplog test and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xmendez committed Nov 2, 2020
1 parent 7ee1aa0 commit d2e0d8b
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/wfuzz/plugins/payloads/burplog.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def parse_burp_log(self, burp_log):
if rl == CRLF:
fr = FuzzRequest()
fr.update_from_raw_http(
raw_request, host[: host.find("://")], raw_response
raw_request, host[: host.find("://")], raw_response.rstrip()
)
frr = FuzzResult(history=fr)

Expand Down
132 changes: 132 additions & 0 deletions tests/plugins/test_burplog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import pytest
import sys
from io import BytesIO

import wfuzz
from wfuzz.facade import Facade

try:
# Python >= 3.3
from unittest import mock
except ImportError:
# Python < 3.3
import mock


@pytest.fixture
def burp_log_raw():
return """======================================================
22:35:55 https://aus5.mozilla.org:443 [35.244.181.201]
======================================================
GET /update/3/SystemAddons/81.0/20200917005511/Linux_x86_64-gcc3/null/release-cck-ubuntu/Linux%205.4.0-48-generic%20(GTK%203.24.20%2Clibpulse%2013.99.0)/canonical/1.0/update.xml HTTP/1.1
Host: aus5.mozilla.org
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0
Accept: */*
Accept-Language: en-GB,en;q=0.5
Accept-Encoding: gzip, deflate
Cache-Control: no-cache
Pragma: no-cache
Connection: close
======================================================
HTTP/1.1 200 OK
Server: nginx/1.17.9
Date: Sun, 01 Nov 2020 21:35:08 GMT
Content-Type: text/xml; charset=utf-8
Content-Length: 42
Strict-Transport-Security: max-age=31536000;
X-Content-Type-Options: nosniff
Content-Security-Policy: default-src 'none'; frame-ancestors 'none'
X-Proxy-Cache-Status: EXPIRED
Via: 1.1 google
Age: 47
Cache-Control: public, max-age=90
Alt-Svc: clear
Connection: close
<?xml version="1.0"?>
<updates>
</updates>
======================================================
"""


class mock_saved_session(object):
def __init__(self, infile):
self.outfile = BytesIO(bytes(infile, "ascii"))
self.outfile.seek(0)
self.outfile.name = "mockfile"

def close(self):
pass

def read(self, *args, **kwargs):
return self.outfile.read(*args, **kwargs)

def seek(self, *args, **kwargs):
return self.outfile.seek(*args, **kwargs)

def tell(self):
return self.outfile.tell()

def readline(self, *args, **kwargs):
line = self.outfile.readline()
if line:
return line.decode("utf-8")
return ""


def test_burplog(burp_log_raw):
# load plugins before mocking file object
Facade().payloads

m = mock.MagicMock(name="open", spec=open)
m.return_value = mock_saved_session(burp_log_raw)

mocked_fun = "builtins.open" if sys.version_info >= (3, 0) else "__builtin__.open"
with mock.patch(mocked_fun, m, create=True):
payload_list = list(
wfuzz.payload(
**{
"payloads": [
("burplog", {"default": "mockedfile", "encoder": None}, None)
],
}
)
)

fres = payload_list[0][0]

assert fres.history.headers.response["Server"] == "nginx/1.17.9"
assert fres.history.headers.response["server"] == "nginx/1.17.9"
assert fres.history.content == '<?xml version="1.0"?>\n<updates>\n</updates>'
assert fres.history.headers.request == {
"Host": "aus5.mozilla.org",
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0",
"Accept": "*/*",
"Accept-Language": "en-GB,en;q=0.5",
"Accept-Encoding": "gzip, deflate",
"Cache-Control": "no-cache",
"Pragma": "no-cache",
"Connection": "close",
}

assert fres.history.headers.response == {
'Server': 'nginx/1.17.9',
'Date': 'Sun, 01 Nov 2020 21:35:08 GMT',
'Content-Type': 'text/xml; charset=utf-8',
'Content-Length': '42',
'Strict-Transport-Security': 'max-age=31536000;',
'X-Content-Type-Options': 'nosniff',
'Content-Security-Policy': "default-src 'none'; frame-ancestors 'none'",
'X-Proxy-Cache-Status': 'EXPIRED',
'Via': '1.1 google',
'Age': '47',
'Cache-Control': 'public, max-age=90',
'Alt-Svc': 'clear',
'Connection': 'close',
}

0 comments on commit d2e0d8b

Please sign in to comment.