-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
} |