RedSiege / EyeWitness

EyeWitness is designed to take screenshots of websites, provide some server header info, and identify default credentials if possible.
https://www.christophertruncer.com/eyewitness-usage-guide/
GNU General Public License v3.0
5.01k stars 849 forks source link

Cleanly Exit Single Mode Upon Ctrl+C #641

Closed 0x6d6f7468 closed 10 months ago

0x6d6f7468 commented 10 months ago

Closes #632.

Adds similar signal handler as multi_mode function into single_mode function. Does not remove created directory, though I can look at adding that if desirable.

Tested on Parrot Security.

0x6d6f7468 commented 10 months ago

Hey @digininja, hate to bug you on something else but since you requested this change I would love to hear your thoughts whenever you have a chance to look at it. No rush though. Thanks!

digininja commented 10 months ago

Looks like you've missed wrapping a bit as I can still get a stack trace from it.

$ ./EyeWitness.py --single https://digi.ninja

################################################################################
#                                  EyeWitness                                  #
################################################################################
#           Red Siege Information Security - https://www.redsiege.com          #
################################################################################

^CTraceback (most recent call last):
  File "/home/robin/tools/web/EyeWitness/Python/./EyeWitness.py", line 425, in <module>
    single_mode(cli_parsed)
  File "/home/robin/tools/web/EyeWitness/Python/./EyeWitness.py", line 245, in single_mode
    driver = create_driver(cli_parsed)
  File "/home/robin/tools/web/EyeWitness/Python/modules/selenium_module.py", line 79, in create_driver
    driver = webdriver.Firefox(profile, capabilities=capabilities, options=options, service_log_path=cli_parsed.selenium_log_path)
  File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/firefox/webdriver.py", line 201, in __init__
    super().__init__(command_executor=executor, options=options, keep_alive=True)
  File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py", line 286, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py", line 378, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py", line 438, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/remote_connection.py", line 290, in execute
    return self._request(command_info[0], url, body=data)
  File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/remote_connection.py", line 311, in _request
    response = self._conn.request(method, url, body=body, headers=headers)
  File "/usr/lib/python3/dist-packages/urllib3/request.py", line 78, in request
    return self.request_encode_body(
  File "/usr/lib/python3/dist-packages/urllib3/request.py", line 170, in request_encode_body
    return self.urlopen(method, url, **extra_kw)
  File "/usr/lib/python3/dist-packages/urllib3/poolmanager.py", line 375, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 700, in urlopen
    httplib_response = self._make_request(
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 446, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 441, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.10/http/client.py", line 1375, in getresponse
    response.begin()
  File "/usr/lib/python3.10/http/client.py", line 318, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.10/http/client.py", line 279, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/lib/python3.10/socket.py", line 705, in readinto
    return self._sock.recv_into(b)
KeyboardInterrupt
digininja commented 10 months ago

Make that multiple stack traces, this is a single run!

################################################################################
#                                  EyeWitness                                  #
################################################################################
#           Red Siege Information Security - https://www.redsiege.com          #
################################################################################

^C[*] Skipping: https://digi.ninja
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 169, in _new_conn
    conn = connection.create_connection(
  File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 96, in create_connection
    raise err
  File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 86, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 700, in urlopen
    httplib_response = self._make_request(
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 395, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 234, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "/usr/lib/python3.10/http/client.py", line 1283, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.10/http/client.py", line 1329, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.10/http/client.py", line 1278, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.10/http/client.py", line 1038, in _send_output
    self.send(msg)
  File "/usr/lib/python3.10/http/client.py", line 976, in send
    self.connect()
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 200, in connect
    conn = self._new_conn()
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 181, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fa80ff9d120>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/robin/tools/web/EyeWitness/Python/./EyeWitness.py", line 425, in <module>
    single_mode(cli_parsed)
  File "/home/robin/tools/web/EyeWitness/Python/./EyeWitness.py", line 246, in single_mode
    result, driver = capture_host(cli_parsed, http_object, driver)
  File "/home/robin/tools/web/EyeWitness/Python/modules/selenium_module.py", line 193, in capture_host
    driver.save_screenshot(http_object.screenshot_path)
  File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py", line 917, in save_screenshot
    return self.get_screenshot_as_file(filename)
  File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py", line 893, in get_screenshot_as_file
    png = self.get_screenshot_as_png()
  File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py", line 927, in get_screenshot_as_png
    return b64decode(self.get_screenshot_as_base64().encode("ascii"))
  File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py", line 938, in get_screenshot_as_base64
    return self.execute(Command.SCREENSHOT)["value"]
  File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py", line 438, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/remote_connection.py", line 290, in execute
    return self._request(command_info[0], url, body=data)
  File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/remote_connection.py", line 311, in _request
    response = self._conn.request(method, url, body=body, headers=headers)
  File "/usr/lib/python3/dist-packages/urllib3/request.py", line 74, in request
    return self.request_encode_url(
  File "/usr/lib/python3/dist-packages/urllib3/request.py", line 96, in request_encode_url
    return self.urlopen(method, url, **extra_kw)
  File "/usr/lib/python3/dist-packages/urllib3/poolmanager.py", line 375, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 784, in urlopen
    return self.urlopen(
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 784, in urlopen
    return self.urlopen(
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 784, in urlopen
    return self.urlopen(
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 756, in urlopen
    retries = retries.increment(
  File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 574, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=50471): Max retries exceeded with url: /session/fd08d319-d71f-405e-be6f-55a1db4cff84/screenshot (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fa80ff9d120>: Failed to establish a new connection: [Errno 111] Connection refused'))
digininja commented 10 months ago

It runs fine and fairly quickly if I let it go, so there is no problem with it connecting to my site and getting the screenshot.

0x6d6f7468 commented 10 months ago

Hey Robin, I'm unable to replicate that behavior on the PR branch. Sorry for the potentially silly question, but did you pull/checkout the PR (or the relevant branch from my fork) before testing? The behavior you sent looks identical to the original behavior, the modified behavior should appear like this:

################################################################################
#                                  EyeWitness                                  #
################################################################################
#           Red Siege Information Security - https://www.redsiege.com          #
################################################################################

^C
Quitting...

Thanks.

digininja commented 10 months ago

Sorry, I thought it was on main branch. I'll grab yours and try again

On Tue, 23 Jan 2024, 17:24 moth, @.***> wrote:

Hey Robin, I'm unable to replicate that behavior on the PR branch. Sorry for the potentially silly question, but did you pull/checkout the PR (or the relevant branch from my fork) for testing? The behavior you sent looks identical to the original behavior, the modified behavior should appear like this:

################################################################################

EyeWitness

################################################################################

Red Siege Information Security - https://www.redsiege.com

################################################################################

^C Quitting...

Thanks.

— Reply to this email directly, view it on GitHub https://github.com/RedSiege/EyeWitness/pull/641#issuecomment-1906560499, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA4SWJMYWIUGBAYCAQIJ3DYP7W3XAVCNFSM6AAAAABCCOR3Q6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMBWGU3DANBZHE . You are receiving this because you were mentioned.Message ID: @.***>

0x6d6f7468 commented 10 months ago

No worries, I'm avoiding pushing straight to master for most things.

digininja commented 10 months ago

After reminding myself how to git to add a new remote, I've just tested it and it seems to work fine.

On Tue, 23 Jan 2024 at 17:39, moth @.***> wrote:

No worries, I'm avoiding pushing straight to master for most things.

— Reply to this email directly, view it on GitHub https://github.com/RedSiege/EyeWitness/pull/641#issuecomment-1906589987, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA4SWKFEPESOD36XRZ6L2LYP7YV5AVCNFSM6AAAAABCCOR3Q6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMBWGU4DSOJYG4 . You are receiving this because you were mentioned.Message ID: @.***>

0x6d6f7468 commented 10 months ago

Awesome, thanks so much for testing it. Sorry to make you go through all the git trouble.

digininja commented 10 months ago

I've got it all documented so it isn't too bad as long as it all works, it's when it goes wrong that the problems start!

On Tue, 23 Jan 2024, 18:11 moth, @.***> wrote:

Awesome, thanks so much for testing it. Sorry to make you go through all the git trouble.

— Reply to this email directly, view it on GitHub https://github.com/RedSiege/EyeWitness/pull/641#issuecomment-1906639966, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA4SWOO3EZYNC42LTV5WBLYP74MVAVCNFSM6AAAAABCCOR3Q6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMBWGYZTSOJWGY . You are receiving this because you were mentioned.Message ID: @.***>