def _create_fuzzable_request(self): ''' Based on the attributes, return a fuzzable request object. Important variables used here: - self.headers : Stores the headers for the request - self.rfile : A file like object that stores the post_data - self.path : Stores the URL that was requested by the browser ''' # See HTTPWrapperClass if hasattr(self.server, 'chainedHandler'): base_path = "https://" + self.server.chainedHandler.path path = base_path + self.path else: path = self.path fuzzable_request = FuzzableRequest( URL(path), self.command, Headers(self.headers.dict.items()) ) post_data = self._get_post_data() if post_data: fuzzable_request.set_data(post_data) return fuzzable_request
def _urllibReq2fr(self, request): ''' Convert a urllib2 request object to a FuzzableRequest. Used in http_request. :param request: A urllib2 request obj. :return: A FuzzableRequest. ''' headers = request.headers headers.update(request.unredirected_hdrs) fr = FuzzableRequest(request.url_object, request.get_method(), headers) fr.set_data(request.get_data() or '') return fr
def test_dump_mangle(self): fr = FuzzableRequest(URL("http://www.w3af.com/"),\ headers=Headers([('Host','www.w3af.com'),])) expected = u'\r\n'.join([u'GET http://www.w3af.com/ HTTP/1.1', u'Host: www.w3af.com', u'', u'']) self.assertEqual(fr.dump(), expected) fr.set_method('POST') fr.set_data('data=23') expected = u'\r\n'.join([u'POST http://www.w3af.com/ HTTP/1.1', u'Host: www.w3af.com', u'', u'data=23']) self.assertEqual(fr.dump(), expected)
def test_dump_mangle(self): fr = FuzzableRequest(URL("http://www.w3af.com/"),\ headers=Headers([('Host','www.w3af.com'),])) expected = u'\r\n'.join([ u'GET http://www.w3af.com/ HTTP/1.1', u'Host: www.w3af.com', u'', u'' ]) self.assertEqual(fr.dump(), expected) fr.set_method('POST') fr.set_data('data=23') expected = u'\r\n'.join([ u'POST http://www.w3af.com/ HTTP/1.1', u'Host: www.w3af.com', u'', u'data=23' ]) self.assertEqual(fr.dump(), expected)