Skip to content

Commit

Permalink
handle timeouts from urllib (headers/source) (#668)
Browse files Browse the repository at this point in the history
* timeout handling on urllib (headers & source)

* report: include screenshot from selenium when it exists even if urllib timed-out
  • Loading branch information
Relkci authored Jun 14, 2024
1 parent 90fb5e8 commit a9558ec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
10 changes: 8 additions & 2 deletions Python/modules/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,14 @@ def create_table_html(self):
</tr>
""")
elif self.error_state == 'Timeout':
html += ("""</td><td>Hit timeout limit while attempting to
screenshot</td></tr>""")
html += ("</td><td>Hit timeout limit")
if os.path.isfile(self.screenshot_path):
html += ("""<br>
<div id=\"screenshot\"><a href=\"{1}\"
target=\"_blank\"><img style=\"max-height:400px;height: expression(this.height > 400 ? 400: true);\"
src=\"{1}\"></a></div></td></tr>""").format(src_path, scr_path)
else:
html += ("</td></tr>")
elif self.error_state == 'BadStatus':
html += ("""</td><td>Unknown error while attempting to
screenshot</td></tr>""")
Expand Down
9 changes: 7 additions & 2 deletions Python/modules/selenium_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ def capture_host(cli_parsed, http_object, driver, ua=None):
req.set_proxy(str(cli_parsed.proxy_ip) + ':' + str(cli_parsed.proxy_port), 'http')
req.set_proxy(str(cli_parsed.proxy_ip) + ':' + str(cli_parsed.proxy_port), 'https')
if context is None:
opened = urllib.request.urlopen(req)
opened = urllib.request.urlopen(req, timeout=cli_parsed.timeout)
else:
opened = urllib.request.urlopen(req, context=context)
opened = urllib.request.urlopen(req,timeout=cli_parsed.timeout, context=context)
headers = dict(opened.info())
headers['Response Code'] = str(opened.getcode())
except urllib.error.HTTPError as e:
Expand Down Expand Up @@ -266,6 +266,11 @@ def capture_host(cli_parsed, http_object, driver, ua=None):
headers = {'Error': 'Connection Reset'}
http_object.error_state = 'ConnReset'
return http_object, driver
elif 'timed out' in str(e):
headers = {'Error': 'Timed Out'}
http_object.error_state = 'Timeout'
print('[*] Socket Timeout when connecting to {0}'.format(http_object.remote_system))
return http_object, driver
else:
http_object.error_state = 'BadStatus'
return http_object, driver
Expand Down

0 comments on commit a9558ec

Please sign in to comment.