Skip to content

Commit

Permalink
codesmell fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
KissPeter committed Feb 9, 2020
1 parent 08a2d02 commit 5bf12e1
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions apifuzzer/fuzzer_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,22 @@ def format_pycurl_header(self, headers):
_return.append('{}: {}'.format(k, v).encode())
return _return

@staticmethod
def init_pycurl():
"""
Provides an instances of pycurl with basic configuration
:return: pycurl instance
"""
_curl = pycurl.Curl()
_curl.setopt(pycurl.SSL_OPTIONS, pycurl.SSLVERSION_TLSv1_2)
_curl.setopt(pycurl.SSL_VERIFYPEER, False)
_curl.setopt(pycurl.SSL_VERIFYHOST, False)
_curl.setopt(pycurl.VERBOSE, True)
_curl.setopt(pycurl.TIMEOUT, 10)
_curl.setopt(pycurl.COOKIEFILE, "")
_curl.setopt(pycurl.USERAGENT, 'APIFuzzer')
return _curl

def transmit(self, **kwargs):
"""
Prepares fuzz HTTP request, sends and processes the response
Expand Down Expand Up @@ -272,19 +288,11 @@ def transmit(self, **kwargs):
try:
resp_buff_hdrs = BytesIO()
resp_buff_body = BytesIO()
_curl = pycurl.Curl()
b = BytesIO()
if request_url.startswith('https'):
_curl.setopt(pycurl.SSL_OPTIONS, pycurl.SSLVERSION_TLSv1_2)
_curl.setopt(pycurl.SSL_VERIFYPEER, False)
_curl.setopt(pycurl.SSL_VERIFYHOST, False)
_curl.setopt(pycurl.VERBOSE, True)
_curl.setopt(pycurl.TIMEOUT, 10)
_curl = self.init_pycurl()
_curl.setopt(pycurl.URL, self.format_pycurl_url(request_url))
_curl.setopt(pycurl.HEADERFUNCTION, self.header_function)
_curl.setopt(pycurl.HTTPHEADER, self.format_pycurl_header(kwargs.get('headers', {})))
_curl.setopt(pycurl.COOKIEFILE, "")
_curl.setopt(pycurl.USERAGENT, 'APIFuzzer')
_curl.setopt(pycurl.POST, len(kwargs.get('data', {}).items()))
_curl.setopt(pycurl.CUSTOMREQUEST, method)
_curl.setopt(pycurl.POSTFIELDS, urllib.parse.urlencode(kwargs.get('data', {})))
Expand Down

0 comments on commit 5bf12e1

Please sign in to comment.