1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
|
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 burplog_file(request):
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 ""
return mock_saved_session(request.param)
@pytest.mark.parametrize(
"burplog_file, expected_content",
[
# (
# (
# "======================================================\n"
# "22:35:55 https://aus5.mozilla.org:443 [35.244.181.201]\n"
# "======================================================\n"
# "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\n"
# "Host: aus5.mozilla.org\n"
# "\n"
# "\n"
# "======================================================\n"
# "HTTP/1.1 200 OK\n"
# "Server: nginx/1.17.9\n"
# "\n"
# "<?xml version=\"1.0\"?>\n"
# "<updates>\n"
# "</updates>\r\n"
# "======================================================\n"
# "\n"
# "\n"
# "\n"
# ),
# '<?xml version="1.0"?>\n<updates>\n</updates>',
# ),
(
(
"======================================================\n"
"22:35:55 https://aus5.mozilla.org:443 [35.244.181.201]\n"
"======================================================\n"
"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\n"
"Host: aus5.mozilla.org\n"
"\n"
"\n"
"======================================================\n"
"HTTP/1.1 200 OK\n"
"Server: nginx/1.17.9\n"
"\n"
'<?xml version="1.0"?>\n'
"<updates>\n"
"</updates> \n"
"======================================================\n"
"\n"
"\n"
"\n"
),
'<?xml version="1.0"?>\n<updates>\n</updates> ',
),
(
(
"======================================================\n"
"22:35:55 https://aus5.mozilla.org:443 [35.244.181.201]\n"
"======================================================\n"
"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\n"
"Host: aus5.mozilla.org\n"
"\n"
"\n"
"======================================================\n"
"HTTP/1.1 200 OK\n"
"Server: nginx/1.17.9\n"
"\n"
'<?xml version="1.0"?>\n'
"<updates>\n"
"</updates>\n"
"\n"
"======================================================\n"
"\n"
"\n"
"\n"
),
'<?xml version="1.0"?>\n<updates>\n</updates>\n',
),
(
(
"======================================================\n"
"22:35:55 https://aus5.mozilla.org:443 [35.244.181.201]\n"
"======================================================\n"
"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\n"
"Host: aus5.mozilla.org\n"
"\n"
"\n"
"======================================================\n"
"HTTP/1.1 200 OK\n"
"Server: nginx/1.17.9\n"
"\n"
'<?xml version="1.0"?>\n'
"<updates>\n"
"</updates>\n"
"======================================================\n"
"\n"
"\n"
"\n"
),
'<?xml version="1.0"?>\n<updates>\n</updates>',
),
(
(
"======================================================\n"
"2:17:05 PM https://www.xxx.es:443 [2.2.2.1]\n"
"======================================================\n"
"GET /sttc/dbook-fp/ctrip-prod-2.4.0.min.js HTTP/1.1\n"
"Host: www.xxx.es\n"
"\n"
"\n"
"======================================================\n"
"HTTP/1.1 200 OK\n"
"\n"
'HTTP"," 333D Visionplugin\n'
"======================================================\n"
"\n"
"\n"
"\n"
),
'HTTP"," 333D Visionplugin',
),
(
(
"======================================================\n"
"22:26:48 http://testphp.vulnweb.com:80 [176.28.50.165]\n"
"======================================================\n"
"GET /style.css HTTP/1.1\n"
"Host: testphp.vulnweb.com\n"
"\n"
"\n"
"======================================================\n"
"HTTP/1.1 304 Not Modified\n"
"Server: nginx/1.4.1\n"
"Date: Mon, 19 Jan 1970 15:36:40 GMT\n"
"Last-Modified: Wed, 11 May 2011 10:27:48 GMT\n"
"Connection: close\n"
'ETag: "4dca64a4-156a"\n'
"\n"
"\n"
"======================================================\n"
"\n"
"\n"
"\n"
),
"",
),
],
indirect=["burplog_file"],
)
def test_burplog_content(burplog_file, expected_content):
# load plugins before mocking file object
Facade().payloads
m = mock.MagicMock(name="open", spec=open)
m.return_value = burplog_file
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.content == expected_content
@pytest.mark.parametrize(
"burplog_file, expected_req_headers, expected_resp_headers",
[
(
(
"======================================================\n"
"22:35:55 https://aus5.mozilla.org:443 [35.244.181.201]\n"
"======================================================\n"
"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\n"
"Host: aus5.mozilla.org\n"
"User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0\n"
"Accept: */*\n"
"Accept-Language: en-GB,en;q=0.5\n"
"Accept-Encoding: gzip, deflate\n"
"Cache-Control: no-cache\n"
"Pragma: no-cache\n"
"Connection: close\n"
"\n"
"\n"
"======================================================\n"
"HTTP/1.1 200 OK\n"
"Server: nginx/1.17.9\n"
"Date: Sun, 01 Nov 2020 21:35:08 GMT\n"
"Content-Type: text/xml; charset=utf-8\n"
"Content-Length: 42\n"
"Strict-Transport-Security: max-age=31536000;\n"
"X-Content-Type-Options: nosniff\n"
"Content-Security-Policy: default-src 'none'; frame-ancestors 'none'\n"
"X-Proxy-Cache-Status: EXPIRED\n"
"Via: 1.1 google\n"
"Age: 47\n"
"Cache-Control: public, max-age=90\n"
"Alt-Svc: clear\n"
"Connection: close\n"
"\n"
'<?xml version="1.0"?>\n'
"<updates>\n"
"</updates>\n"
"======================================================\n"
"\n"
"\n"
"\n"
),
{
"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",
},
{
"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",
},
),
],
indirect=["burplog_file"],
)
def test_burplog_headers(burplog_file, expected_req_headers, expected_resp_headers):
# load plugins before mocking file object
Facade().payloads
m = mock.MagicMock(name="open", spec=open)
m.return_value = burplog_file
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.request == expected_req_headers
assert fres.history.headers.response == expected_resp_headers
|