Skip to content

Commit

Permalink
Merge pull request #788 from blacklanternsecurity/fix-console-hang
Browse files Browse the repository at this point in the history
Fix Console Hang
  • Loading branch information
TheTechromancer authored Oct 17, 2023
2 parents 0bad648 + 84c2dc4 commit c2ed0a6
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 22 deletions.
48 changes: 27 additions & 21 deletions bbot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import sys
import asyncio
import logging
import threading
import traceback
from aioconsole import ainput
from omegaconf import OmegaConf
from contextlib import suppress

Expand Down Expand Up @@ -306,36 +306,42 @@ async def _main():
log.hugesuccess(f"Scan ready. Press enter to execute {scanner.name}")
input()

def keyboard_listen():
allowed_errors = 10
def handle_keyboard_input(keyboard_input):
kill_regex = re.compile(r"kill (?P<module>[a-z0-9_]+)")
if keyboard_input:
log.verbose(f'Got keyboard input: "{keyboard_input}"')
kill_match = kill_regex.match(keyboard_input)
if kill_match:
module = kill_match.group("module")
if module in scanner.modules:
log.hugewarning(f'Killing module: "{module}"')
scanner.manager.kill_module(module, message="killed by user")
else:
log.warning(f'Invalid module: "{module}"')
else:
toggle_log_level(logger=log)
scanner.manager.modules_status(_log=True)

async def akeyboard_listen():
allowed_errors = 10
while 1:
keyboard_input = "a"
try:
keyboard_input = input()
allowed_errors = 10
keyboard_input = await ainput()
except Exception:
allowed_errors -= 1
if keyboard_input:
log.verbose(f'Got keyboard input: "{keyboard_input}"')
kill_match = kill_regex.match(keyboard_input)
if kill_match:
module = kill_match.group("module")
if module in scanner.modules:
log.hugewarning(f'Killing module: "{module}"')
scanner.manager.kill_module(module, message="killed by user")
else:
log.warning(f'Invalid module: "{module}"')
else:
toggle_log_level(logger=log)
scanner.manager.modules_status(_log=True)
handle_keyboard_input(keyboard_input)
if allowed_errors <= 0:
break

keyboard_listen_thread = threading.Thread(target=keyboard_listen, daemon=True)
keyboard_listen_thread.start()
try:
keyboard_listen_task = asyncio.create_task(akeyboard_listen())

await scanner.async_start_without_generator()
await scanner.async_start_without_generator()
finally:
keyboard_listen_task.cancel()
with suppress(asyncio.CancelledError):
await keyboard_listen_task

except bbot.core.errors.ScanError as e:
log_to_stderr(str(e), level="ERROR")
Expand Down
13 changes: 13 additions & 0 deletions docs/dev/helpers/command.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Command Helpers

These are helpers related to executing shell commands. They are used throughout BBOT and its modules for executing various binaries such as `nmap`, `nuclei`, etc.

Note that these helpers can be invoked directly from `self.helpers`, e.g.:

```python
self.helpers.run("ls", "-l")
```

::: bbot.core.helpers.command
options:
show_root_heading: false
19 changes: 19 additions & 0 deletions docs/dev/helpers/dns.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# DNS

These are helpers related to DNS resolution. They are used throughout BBOT and its modules for performing DNS lookups and detecting DNS wildcards, etc.

Note that these helpers can be invoked directly from `self.helpers`, e.g.:

```python
self.helpers.resolve("evilcorp.com")
```

::: bbot.core.helpers.dns.DNSHelper
handler: python
options:
members:
- resolve
- resolve_batch
- resolve_raw
- is_wildcard
- is_wildcard_domain
5 changes: 5 additions & 0 deletions docs/dev/helpers/interactsh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Interact.sh

::: bbot.core.helpers.interactsh.Interactsh
options:
show_root_heading: false
15 changes: 15 additions & 0 deletions docs/dev/helpers/web.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Web

These are helpers for making various web requests.

Note that these helpers can be invoked directly from `self.helpers`, e.g.:

```python
self.helpers.request("https://www.evilcorp.com")
```

::: bbot.core.helpers.web
options:
show_root_heading: false
members:
- WebHelper
13 changes: 13 additions & 0 deletions docs/dev/helpers/wordcloud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Word Cloud

These are helpers related to BBOT's Word Cloud, a mechanism for storing target-specific keywords that are useful for custom wordlists, etc.

Note that these helpers can be invoked directly from `self.helpers`, e.g.:

```python
self.helpers.word_cloud
```

::: bbot.core.helpers.wordcloud
options:
show_root_heading: false
13 changes: 12 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ httpx = {extras = ["http2"], version = "^0.24.1"}
dnspython = "^2.4.2"
anyio = "4.0.0rc1"
httpcore = "^0.17.3"
aioconsole = "^0.6.2"

[tool.poetry.group.dev.dependencies]
flake8 = "^6.0.0"
Expand Down

0 comments on commit c2ed0a6

Please sign in to comment.