infobyte / faraday_agent_dispatcher

Faraday Agent Dispatcher launches any security tools and send results to Faradaysec Platform.
https://www.faradaysec.com/
GNU General Public License v3.0
39 stars 12 forks source link

Failing to reach port 9000 and issue with websockets version being used by faraday_agent_dispatcher #11

Closed csk closed 1 year ago

csk commented 1 year ago

Hi!

I wanted to let you know a problem I found and how did I fix it in case someone stumbles upon the same issue.

Working on a Kali Linux I downloaded few weeks ago I wanted to try out what is new in Faraday. So far so good until I wanted to try the agent feature.

Because I was running faraday using docker-compose the agent initially not reach port 9000

2022-10-25 12:55:01,883 - faraday_agent_dispatcher - INFO {MainThread} [dispatcher.py:160 - register()]  token_registration_url: http://localhost:5985/_api/v3/agents
2022-10-25 12:55:01,934 - faraday_agent_dispatcher - INFO {MainThread} [dispatcher.py:200 - register()]  Registered successfully
Traceback (most recent call last):
  File "/home/kali/.local/bin/faraday-dispatcher", line 8, in <module>
    sys.exit(cli())
  File "/usr/lib/python3/dist-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3/dist-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/kali/.local/lib/python3.10/site-packages/faraday_agent_dispatcher/cli/main.py", line 98, in run
    exit_code = asyncio.run(main(config_file, logger, token))
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "/home/kali/.local/lib/python3.10/site-packages/faraday_agent_dispatcher/cli/main.py", line 75, in main
    await dispatcher.connect()
  File "/home/kali/.local/lib/python3.10/site-packages/faraday_agent_dispatcher/dispatcher.py", line 231, in connect
    async with websockets.connect(
  File "/usr/lib/python3/dist-packages/websockets/legacy/client.py", line 604, in __aenter__
    return await self
  File "/usr/lib/python3/dist-packages/websockets/legacy/client.py", line 622, in __await_impl__
    transport, protocol = await self._create_connection()
  File "/usr/lib/python3.10/asyncio/base_events.py", line 1072, in create_connection
    raise OSError('Multiple exceptions: {}'.format(
OSError: Multiple exceptions: [Errno 111] Connect call failed ('::1', 9000, 0, 0), [Errno 111] Connect call failed ('127.0.0.1', 9000)

To fix this I just added the port 9000 to the port mapping in the downloaded docker-compose.yamlfile.

*** docker-compose.yaml.old     2022-10-25 13:35:20.996391742 -0400
--- docker-compose.yaml 2022-10-25 13:35:26.308391961 -0400
***************
*** 34,39 ****
--- 34,40 ----
       - redis
      ports:
       - "5985:5985"
+      - "9000:9000"
  volumes:
    db:
      driver: local

After fixing the port problem I got another error.

2022-10-25 13:10:22,876 - faraday_agent_dispatcher - INFO {MainThread} [dispatcher.py:200 - register()]  Registered successfully
Traceback (most recent call last):
  File "/home/kali/.local/bin/faraday-dispatcher", line 8, in <module>
    sys.exit(cli())
  File "/usr/lib/python3/dist-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3/dist-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/kali/.local/lib/python3.10/site-packages/faraday_agent_dispatcher/cli/main.py", line 98, in run
    exit_code = asyncio.run(main(config_file, logger, token))
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "/home/kali/.local/lib/python3.10/site-packages/faraday_agent_dispatcher/cli/main.py", line 75, in main
    await dispatcher.connect()
  File "/home/kali/.local/lib/python3.10/site-packages/faraday_agent_dispatcher/dispatcher.py", line 231, in connect
    async with websockets.connect(
  File "/usr/lib/python3/dist-packages/websockets/legacy/client.py", line 604, in __aenter__
    return await self
  File "/usr/lib/python3/dist-packages/websockets/legacy/client.py", line 622, in __await_impl__
    transport, protocol = await self._create_connection()
  File "/usr/lib/python3.10/asyncio/base_events.py", line 1089, in create_connection
    transport, protocol = await self._create_connection_transport(
  File "/usr/lib/python3.10/asyncio/base_events.py", line 1107, in _create_connection_transport
    protocol = protocol_factory()
  File "/usr/lib/python3/dist-packages/websockets/legacy/client.py", line 160, in __init__
    super().__init__(**kwargs)
  File "/usr/lib/python3/dist-packages/websockets/legacy/protocol.py", line 154, in __init__
    self._drain_lock = asyncio.Lock(
  File "/usr/lib/python3.10/asyncio/locks.py", line 78, in __init__
    super().__init__(loop=loop)
  File "/usr/lib/python3.10/asyncio/mixins.py", line 17, in __init__
    raise TypeError(
TypeError: As of 3.10, the *loop* parameter was removed from Lock() since it is no longer necessary

After googling a bit I discovered there was an issue with the websocket dependency which I solved forcing the version to be > 9.1.

diff --git a/setup.py b/setup.py
index ffa5c5a..a00d0fc 100644
--- a/setup.py
+++ b/setup.py
@@ -33,7 +33,7 @@ with open("RELEASE.md") as history_file:

 requirements = [
     "Click>=7",
-    "websockets",
+    "websockets > 9.1",
     "aiohttp",
     "syslog_rfc5424_formatter",
     "requests",             

After patching the file you will have to run pip install -e . again.

Hope this will help the faradaysec team or someone else there.

aenima-x commented 1 year ago

@csk you are totally right, I forgot the websocket port.

Also thanks for the dependency tip