Skip to content

Commit 3c367da

Browse files
Merge pull request #2339 from blacklanternsecurity/dev
Dev -> Stable 2.4.1
2 parents dc25f53 + e5a0455 commit 3c367da

53 files changed

Lines changed: 2649 additions & 1898 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/codeql.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL Advanced"
13+
14+
on:
15+
push:
16+
branches: [ "stable", "dev" ]
17+
pull_request:
18+
branches: [ "stable", "dev" ]
19+
schedule:
20+
- cron: '32 3 * * 5'
21+
22+
jobs:
23+
analyze:
24+
name: Analyze (${{ matrix.language }})
25+
# Runner size impacts CodeQL analysis time. To learn more, please see:
26+
# - https://gh.io/recommended-hardware-resources-for-running-codeql
27+
# - https://gh.io/supported-runners-and-hardware-resources
28+
# - https://gh.io/using-larger-runners (GitHub.com only)
29+
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
30+
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
31+
permissions:
32+
# required for all workflows
33+
security-events: write
34+
35+
# required to fetch internal or private CodeQL packs
36+
packages: read
37+
38+
# only required for workflows in private repositories
39+
actions: read
40+
contents: read
41+
42+
strategy:
43+
fail-fast: false
44+
matrix:
45+
include:
46+
- language: python
47+
build-mode: none
48+
# CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
49+
# Use `c-cpp` to analyze code written in C, C++ or both
50+
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
51+
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
52+
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
53+
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
54+
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
55+
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
56+
steps:
57+
- name: Checkout repository
58+
uses: actions/checkout@v4
59+
60+
# Add any setup steps before running the `github/codeql-action/init` action.
61+
# This includes steps like installing compilers or runtimes (`actions/setup-node`
62+
# or others). This is typically only required for manual builds.
63+
# - name: Setup runtime (example)
64+
# uses: actions/setup-example@v1
65+
66+
# Initializes the CodeQL tools for scanning.
67+
- name: Initialize CodeQL
68+
uses: github/codeql-action/init@v3
69+
with:
70+
languages: ${{ matrix.language }}
71+
build-mode: ${{ matrix.build-mode }}
72+
# If you wish to specify custom queries, you can do so here or in a config file.
73+
# By default, queries listed here will override any specified in a config file.
74+
# Prefix the list here with "+" to use these queries and those in the config file.
75+
76+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
77+
# queries: security-extended,security-and-quality
78+
79+
# If the analyze step fails for one of the languages you are analyzing with
80+
# "We were unable to automatically build your code", modify the matrix above
81+
# to set the build mode to "manual" for that language. Then modify this step
82+
# to build your code.
83+
# ℹ️ Command-line programs to run using the OS shell.
84+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
85+
- if: matrix.build-mode == 'manual'
86+
shell: bash
87+
run: |
88+
echo 'If you are using a "manual" build mode for one or more of the' \
89+
'languages you are analyzing, replace this with the commands to build' \
90+
'your code, for example:'
91+
echo ' make bootstrap'
92+
echo ' make release'
93+
exit 1
94+
95+
- name: Perform CodeQL Analysis
96+
uses: github/codeql-action/analyze@v3
97+
with:
98+
category: "/language:${{matrix.language}}"

.github/workflows/distro_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
export BBOT_DISTRO_TESTS=true
6464
poetry env use python3.11
6565
poetry install
66-
poetry run pytest --reruns 2 -o timeout_func_only=true --timeout 1200 --disable-warnings --log-cli-level=INFO .
66+
poetry run pytest --reruns 2 --exitfirst -o timeout_func_only=true --timeout 1200 --disable-warnings --log-cli-level=INFO .
6767
- name: Upload Debug Logs
6868
if: always()
6969
uses: actions/upload-artifact@v4

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
poetry run ruff format --check
3737
- name: Run tests
3838
run: |
39-
poetry run pytest -vv --exitfirst --reruns 2 -o timeout_func_only=true --timeout 1200 --disable-warnings --log-cli-level=INFO --cov-config=bbot/test/coverage.cfg --cov-report xml:cov.xml --cov=bbot .
39+
poetry run pytest -vv --reruns 2 -o timeout_func_only=true --timeout 1200 --disable-warnings --log-cli-level=INFO --cov-config=bbot/test/coverage.cfg --cov-report xml:cov.xml --cov=bbot .
4040
- name: Upload Debug Logs
4141
if: always()
4242
uses: actions/upload-artifact@v4

bbot/cli.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python3
22

3+
import io
34
import sys
45
import logging
56
import multiprocessing
@@ -78,7 +79,7 @@ async def _main():
7879
return
7980

8081
# if we're listing modules or their options
81-
if options.list_modules or options.list_output_modules or options.list_module_options:
82+
if options.list_modules or options.list_output_modules or options.list_module_options or options.module_help:
8283
# if no modules or flags are specified, enable everything
8384
if not (options.modules or options.output_modules or options.flags):
8485
for module, preloaded in preset.module_loader.preloaded().items():
@@ -119,6 +120,20 @@ async def _main():
119120
print(row)
120121
return
121122

123+
# --module-help
124+
if options.module_help:
125+
module_name = options.module_help
126+
all_modules = list(preset.module_loader.preloaded())
127+
if module_name not in all_modules:
128+
log.hugewarning(f'Module "{module_name}" not found')
129+
return
130+
131+
# Load the module class
132+
loaded_modules = preset.module_loader.load_modules([module_name])
133+
module_name, module_class = next(iter(loaded_modules.items()))
134+
print(module_class.help_text())
135+
return
136+
122137
# --list-flags
123138
if options.list_flags:
124139
flags = preset.flags if preset.flags else None
@@ -184,7 +199,7 @@ async def _main():
184199
if sys.stdin.isatty():
185200
# warn if any targets belong directly to a cloud provider
186201
if not scan.preset.strict_scope:
187-
for event in scan.target.seeds.events:
202+
for event in scan.target.seeds.event_seeds:
188203
if event.type == "DNS_NAME":
189204
cloudcheck_result = scan.helpers.cloudcheck(event.host)
190205
if cloudcheck_result:
@@ -226,7 +241,12 @@ def handle_keyboard_input(keyboard_input):
226241

227242
# set stdout and stderr to blocking mode
228243
# this is needed to prevent BlockingIOErrors in logging etc.
229-
fds = [sys.stdout.fileno(), sys.stderr.fileno()]
244+
fds = []
245+
for stream in [sys.stdout, sys.stderr]:
246+
try:
247+
fds.append(stream.fileno())
248+
except io.UnsupportedOperation:
249+
log.debug(f"Can't get fileno for {stream}")
230250
for fd in fds:
231251
flags = fcntl.fcntl(fd, fcntl.F_GETFL)
232252
fcntl.fcntl(fd, fcntl.F_SETFL, flags & ~os.O_NONBLOCK)

bbot/core/config/logger.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
from contextlib import suppress
1010

1111
from ..helpers.misc import mkdir, error_and_exit
12-
from ...logger import colorize, loglevel_mapping
1312
from ..multiprocess import SHARED_INTERPRETER_STATE
14-
13+
from ...logger import colorize, loglevel_mapping, GzipRotatingFileHandler
1514

1615
debug_format = logging.Formatter("%(asctime)s [%(levelname)s] %(name)s %(filename)s:%(lineno)s %(message)s")
1716

@@ -61,7 +60,6 @@ def __init__(self, core):
6160
self._loggers = None
6261
self._log_handlers = None
6362
self._log_level = None
64-
self.root_logger = logging.getLogger()
6563
self.core_logger = logging.getLogger("bbot")
6664
self.core = core
6765

@@ -84,14 +82,6 @@ def cleanup_logging(self):
8482
with suppress(Exception):
8583
self.queue_handler.close()
8684

87-
# Clean root logger
88-
root_logger = logging.getLogger()
89-
for handler in list(root_logger.handlers):
90-
with suppress(Exception):
91-
root_logger.removeHandler(handler)
92-
with suppress(Exception):
93-
handler.close()
94-
9585
# Clean all other loggers
9686
for logger in logging.Logger.manager.loggerDict.values():
9787
if hasattr(logger, "handlers"): # Logger, not PlaceHolder
@@ -112,8 +102,7 @@ def setup_queue_handler(self, logging_queue=None, log_level=logging.DEBUG):
112102
self.queue = logging_queue
113103
self.queue_handler = logging.handlers.QueueHandler(logging_queue)
114104

115-
self.root_logger.addHandler(self.queue_handler)
116-
105+
self.core_logger.addHandler(self.queue_handler)
117106
self.core_logger.setLevel(log_level)
118107
# disable asyncio logging for child processes
119108
if not SHARED_INTERPRETER_STATE.is_main_process:
@@ -217,13 +206,11 @@ def log_handlers(self):
217206
error_and_exit(f"Failure creating or error writing to BBOT logs directory ({log_dir})")
218207

219208
# Main log file
220-
main_handler = logging.handlers.TimedRotatingFileHandler(
221-
f"{log_dir}/bbot.log", when="d", interval=1, backupCount=14
222-
)
209+
main_handler = GzipRotatingFileHandler(f"{log_dir}/bbot.log", maxBytes=1024 * 1024 * 100, backupCount=100)
223210

224211
# Separate log file for debugging
225-
debug_handler = logging.handlers.TimedRotatingFileHandler(
226-
f"{log_dir}/bbot.debug.log", when="d", interval=1, backupCount=14
212+
debug_handler = GzipRotatingFileHandler(
213+
f"{log_dir}/bbot.debug.log", maxBytes=1024 * 1024 * 100, backupCount=100
227214
)
228215

229216
# Log to stderr

0 commit comments

Comments
 (0)