Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft Lightfuzz PR #1817

Draft
wants to merge 280 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
280 commits
Select commit Hold shift + click to select a range
1487f25
add libpcap to masscan deps
TheTechromancer Jul 2, 2024
c0e3074
fix package name
TheTechromancer Jul 2, 2024
2b319b2
switch to -dev
TheTechromancer Jul 2, 2024
022ec53
fix masscan top ports issue
TheTechromancer Jul 2, 2024
4c3561d
add top ports
TheTechromancer Jul 2, 2024
66d125f
fixing handling of redirects/location headers
liquidsec Jul 3, 2024
048fcb5
validator docstring
TheTechromancer Jul 3, 2024
f5c6dc9
detaching discovery_context from rule object
liquidsec Jul 4, 2024
1aab3dc
removing debugging
liquidsec Jul 4, 2024
8ea1910
rework event dudupe initial
liquidsec Jul 3, 2024
fb796f0
fixing test
liquidsec Jul 4, 2024
75e9566
spacing
liquidsec Jul 4, 2024
582a55c
fixing querystring_collapse dedupe, adding tests
liquidsec Jul 4, 2024
6d0b87d
black
liquidsec Jul 4, 2024
667501f
fixing bug with URL dedupe
liquidsec Jul 4, 2024
b4d929e
more fixes for URL dedupe
liquidsec Jul 4, 2024
a32bea3
revising test
liquidsec Jul 4, 2024
e6a0019
black
liquidsec Jul 4, 2024
956d491
small tweaks
TheTechromancer Jul 4, 2024
7ad0dcf
blacked
TheTechromancer Jul 4, 2024
894915b
remove parse_list_string
liquidsec Jun 24, 2024
354a3c8
replacing line
liquidsec Jun 24, 2024
9993086
removing unnecessary imports
liquidsec Jun 24, 2024
297a6c0
doc string typo
liquidsec Jun 24, 2024
63368e3
speed up fingerprintx
TheTechromancer Jun 27, 2024
67f373e
Refresh module docs
blsaccess Jun 27, 2024
1a2f121
merge killing multiple modules
TheTechromancer Jul 2, 2024
b0d2f73
missing word
liquidsec Jul 5, 2024
4818b18
removing excavate on RAW_TEXT (raw now)
liquidsec Jul 5, 2024
01d7650
removing remaining parse_list_string call
liquidsec Jul 5, 2024
8467b6f
black
liquidsec Jul 5, 2024
dd96e4c
adding doc strings for new excavate functionality
liquidsec Jul 5, 2024
bf1599c
more docstring details
liquidsec Jul 5, 2024
419d1bb
adding excavate IP url test
liquidsec Jul 5, 2024
0c965bd
adding excavate IP url test (cleanup)
liquidsec Jul 5, 2024
c012129
black
liquidsec Jul 5, 2024
7af7ebf
merge from 2.0
liquidsec Jul 5, 2024
e0dfa15
yara-excavate merge
liquidsec Jul 5, 2024
f963491
more merge nonsense
liquidsec Jul 5, 2024
3c09bb6
adding lightfuzz tests, moving tests to excavate
liquidsec Jul 5, 2024
e0f4738
adding target direct URL parameter processing, tests, black, cookie b…
liquidsec Jul 6, 2024
ed3956a
Merge branch 'bbot-2.0' into lightfuzz
liquidsec Jul 6, 2024
8581b40
various bug fixes / test fixes
liquidsec Jul 7, 2024
1c14da6
adjusting path traversal payloads to reduce false postives
liquidsec Jul 7, 2024
2ca0b18
additional path module signatures
liquidsec Jul 7, 2024
28f81ef
removing original value defaults
liquidsec Jul 7, 2024
cefa78e
black
liquidsec Jul 7, 2024
3442e3e
sqli module improvements
liquidsec Jul 7, 2024
4fefef1
changing additional_parameter behavior
liquidsec Jul 7, 2024
7e973e4
sqli to use new additional_params logic
liquidsec Jul 7, 2024
9e97933
fixing multuple same header extraction
liquidsec Jul 7, 2024
0e44ae6
remove debug
liquidsec Jul 7, 2024
8a837c7
merge from cherry pick
liquidsec Jul 7, 2024
613d512
blind sqli tweaks
liquidsec Jul 7, 2024
e25e198
black
liquidsec Jul 7, 2024
b8da0a8
merge from 2.0
liquidsec Jul 8, 2024
eed27de
fix path test
liquidsec Jul 8, 2024
1323041
cleanup
liquidsec Jul 8, 2024
672ecfb
little bug fixes
liquidsec Jul 8, 2024
4d4ce7d
Merge branch 'bbot-2.0' into lightfuzz
liquidsec Jul 8, 2024
7b8a06f
enhancing xss module
liquidsec Jul 8, 2024
0cfe17a
xss message fix
liquidsec Jul 8, 2024
7ee9f75
fixing lightfuzz presets
liquidsec Jul 8, 2024
c7c40ab
Merge branch 'bbot-2.0' into lightfuzz
liquidsec Jul 9, 2024
0cf868a
exit after success for xss between tags
liquidsec Jul 9, 2024
fdb5fc0
Merge branch 'excavate-utf8-fix' into lightfuzz
liquidsec Jul 9, 2024
adba1bb
Merge branch 'dev' into lightfuzz
liquidsec Jul 9, 2024
4c6e834
better error handling / black
liquidsec Jul 10, 2024
ef9d9f6
hopefully less false postives
liquidsec Jul 11, 2024
0304400
remove debug
liquidsec Jul 11, 2024
676eeee
changing confirmations logic
liquidsec Jul 11, 2024
253b2b3
fixing missing import
liquidsec Jul 13, 2024
ed9cea1
looks like excavate missed the rename
liquidsec Jul 13, 2024
896ae85
using correct threads parameter
liquidsec Jul 13, 2024
79a9b7e
fixing endless loop
liquidsec Jul 14, 2024
328d8e5
removing excessive debug messages
liquidsec Jul 14, 2024
3f69c85
adjusting confirmations for path modules
liquidsec Jul 14, 2024
f4cf8a5
handle speculative parameters properly
liquidsec Jul 14, 2024
a35789e
more bugs with speculative parameters, tests
liquidsec Jul 14, 2024
def263e
oops
liquidsec Jul 14, 2024
a262413
custom cookies / new crypto tests / lots of bug fixes
liquidsec Jul 20, 2024
b372166
little bug fixes
liquidsec Jul 20, 2024
c7568d2
minor bug fix
liquidsec Jul 20, 2024
7f496c8
debug msg remove
liquidsec Jul 21, 2024
c73bf9b
small bug fix
liquidsec Jul 21, 2024
1a90154
fixing add_get_params, allowing malicious querystrings through
liquidsec Jul 21, 2024
d940f9c
bug fixes
liquidsec Jul 21, 2024
bdf8683
sometimes no additional params
liquidsec Jul 21, 2024
a82e7fc
bug fix.
liquidsec Jul 21, 2024
2d59463
another lil bug
liquidsec Jul 22, 2024
84b9967
better fix
liquidsec Jul 22, 2024
6cb5c19
3rd try :|
liquidsec Jul 22, 2024
c8329c7
original value fix
liquidsec Jul 22, 2024
bf4b5be
one more
liquidsec Jul 22, 2024
54b2fcb
handle non-str strings
liquidsec Jul 22, 2024
23c414f
tweaks to form extraction
liquidsec Jul 24, 2024
197b579
fixing unreachable host issues
liquidsec Aug 9, 2024
8a6a4ca
reworking parameter extraction rules, bug fixes
liquidsec Aug 10, 2024
67b69d1
removing debug
liquidsec Aug 10, 2024
d4d07e5
Merge branch 'stable' into lightfuzz
liquidsec Aug 10, 2024
1b00b06
adding lightfuzz serialization submodule
liquidsec Aug 12, 2024
bd4b760
ruby serialization signature
liquidsec Aug 12, 2024
658f0e0
unnecessary strip
liquidsec Aug 14, 2024
52937bb
tweaking padding oracle detection
liquidsec Aug 14, 2024
39ca3d5
moderate refactor and test fix
liquidsec Aug 15, 2024
85c3c73
small crypto bug fix
liquidsec Aug 15, 2024
6875f56
better error handling
liquidsec Aug 15, 2024
10c11b3
updating hunt to show more detail in finding
liquidsec Aug 15, 2024
0926773
little hunt bug fix
liquidsec Aug 15, 2024
f1d0096
missing import
liquidsec Aug 15, 2024
0ae5ad8
adding no-post safety option
liquidsec Aug 16, 2024
89b0212
false positive reduction for path module
liquidsec Aug 18, 2024
e819c5d
enforcing prefix blacklist
liquidsec Aug 18, 2024
4e5789e
lightfuzz presets rework
liquidsec Aug 18, 2024
95323a0
ugh
liquidsec Aug 18, 2024
1128ab7
bug fix/test
liquidsec Aug 18, 2024
16cdea3
fixing issues with serializtion regexes
liquidsec Aug 23, 2024
bfa22d5
Update lightfuzz.yml
liquidsec Aug 23, 2024
6df6163
adding cookie test
liquidsec Sep 5, 2024
ec6bb0c
fixing tests and bugs from excavate merge
liquidsec Sep 5, 2024
bcbfe23
removing extranious blacklist
liquidsec Sep 5, 2024
0473a51
removing unnecessary blacklist, fixing tests
liquidsec Sep 5, 2024
c30fb87
fixing excavate conflict
liquidsec Oct 2, 2024
4836f1c
original value display bug fix
liquidsec Oct 3, 2024
aedb391
black
liquidsec Oct 3, 2024
a3cf592
flake8 nightmare
liquidsec Oct 3, 2024
2ad2177
dependency update
liquidsec Oct 3, 2024
ecee809
fixing module pre-loading logic
liquidsec Oct 3, 2024
01e7a26
flag compliance
liquidsec Oct 3, 2024
a0081f0
adding author
liquidsec Oct 3, 2024
cda0bd7
add cookies cli bug fix
liquidsec Oct 3, 2024
8ff836b
fixing bug with rand_string helper
liquidsec Oct 3, 2024
c0f9e43
always add original value
liquidsec Oct 4, 2024
c70db9b
handling failure to get all test responses sqli
liquidsec Oct 4, 2024
68c934b
handling failure to get all test responses sqli (again)
liquidsec Oct 4, 2024
0416fea
fixing preset web spider settings
liquidsec Oct 4, 2024
5ab40eb
add escapable slash javascript xss detection
liquidsec Oct 4, 2024
25991ac
Merge branch 'dev' into lightfuzz
liquidsec Oct 4, 2024
ceaa658
Merge branch 'parent-url-bug' into lightfuzz
liquidsec Oct 4, 2024
5d8e0d3
lightfuzz envelope system
liquidsec Oct 8, 2024
5f126f9
flake8
liquidsec Oct 8, 2024
b1fabdd
black
liquidsec Oct 8, 2024
2f60624
clean up debug
liquidsec Oct 8, 2024
07eccb5
remove debug
liquidsec Oct 8, 2024
9f2b949
Merge branch 'dev' into lightfuzz
liquidsec Oct 8, 2024
4ca9b79
update poetry.lock
liquidsec Oct 8, 2024
cfddbb8
Merge branch 'lightfuzz' of https://github.com/blacklanternsecurity/b…
liquidsec Oct 8, 2024
68f9b9d
poetry lock update
liquidsec Oct 8, 2024
9da63bb
replacing dummy
liquidsec Oct 9, 2024
0d395f9
black
liquidsec Oct 9, 2024
d66badd
tweak debug msg
liquidsec Oct 9, 2024
8ec46cb
fixing path reconstruction bug
liquidsec Oct 9, 2024
45c6c1b
adding additional test
liquidsec Oct 9, 2024
069fdc6
3.9 compatibility hack
liquidsec Oct 9, 2024
d7aa126
Merge branch 'lightfuzz' into lightfuzz-envelopes
liquidsec Oct 9, 2024
9cd281a
removing unnecessary threading lock handling
liquidsec Oct 9, 2024
91199dd
Merge pull request #1832 from blacklanternsecurity/lightfuzz-envelopes
liquidsec Oct 9, 2024
03c06ca
various bug fixes with parameter extraction, and in crypto submodule
liquidsec Oct 10, 2024
0650d92
the worst test i've ever had to make
liquidsec Oct 11, 2024
25f6960
Merge pull request #1838 from blacklanternsecurity/lightfuzz-paddingo…
liquidsec Oct 11, 2024
590ce58
adding json body parameter support
liquidsec Oct 15, 2024
75d7715
sqli error-based detection
liquidsec Oct 15, 2024
a1a3679
Merge branch 'lightfuzz' into lightfuzz-bodyparams
liquidsec Oct 15, 2024
f425b40
flake8
liquidsec Oct 15, 2024
eef8adf
irrelevent comment
liquidsec Oct 15, 2024
f1f8a66
additional sqli error strings
liquidsec Oct 15, 2024
0dd6ab6
black
liquidsec Oct 15, 2024
60b7c30
fixing probe type bug
liquidsec Oct 15, 2024
8b9717a
fixing probe type bug again
liquidsec Oct 15, 2024
2f51dce
hunt change description text
liquidsec Oct 15, 2024
f7a290f
fix cookies
invalid-email-address Oct 16, 2024
dd466bb
small bug fix parsing cookies
liquidsec Oct 16, 2024
518be6b
adding custom cookie support to httpx
liquidsec Oct 16, 2024
e1ea6d9
httpx tests for custom headers and cookies
liquidsec Oct 16, 2024
6c2a06a
oopsie
liquidsec Oct 16, 2024
e58967a
Merge pull request #1853 from blacklanternsecurity/lightfuzz-bodyparams
liquidsec Oct 16, 2024
0af6947
Merge branch 'dev' into lightfuzz
liquidsec Oct 16, 2024
a92d085
fixing bug with # in form action
liquidsec Oct 17, 2024
36b9832
handle dangerous redirects gracefully
liquidsec Oct 17, 2024
b4fda15
expanding path techniques for path submodule
liquidsec Oct 17, 2024
10c5741
fixing excavate relative paths, adding tests
liquidsec Oct 17, 2024
21ab06a
fixing test
liquidsec Oct 17, 2024
e431348
Merge branch 'dev' into lightfuzz
liquidsec Oct 17, 2024
cedb4e6
hunt consolidate categories
liquidsec Oct 17, 2024
61ca3ce
better error handling
liquidsec Oct 17, 2024
0f6b6f6
prevent false JSON tag
liquidsec Oct 18, 2024
45201f0
black
liquidsec Oct 18, 2024
be0dc4a
poetry lock update
liquidsec Oct 18, 2024
7020b48
poetry lock w/dev merge
liquidsec Oct 18, 2024
e02e91e
Merge branch 'dev' into lightfuzz
liquidsec Oct 18, 2024
e8a83c9
poetry.lock
liquidsec Oct 18, 2024
b59f41b
fixing but with html tag parameter extraction
liquidsec Oct 22, 2024
ab4fef4
truncate long error
liquidsec Oct 24, 2024
027210b
fixing bug with cloning web_parameters
liquidsec Oct 29, 2024
617add6
adding reflected_parameters module
liquidsec Oct 29, 2024
09f4b46
dev->lightfuzz merge
liquidsec Oct 29, 2024
aae28bc
Merge branch 'dev' into lightfuzz
liquidsec Oct 29, 2024
5520951
oops
liquidsec Oct 29, 2024
bc0b8b9
Merge branch 'lightfuzz' of https://github.com/blacklanternsecurity/b…
liquidsec Oct 29, 2024
14bc07f
Merge branch 'dev' into lightfuzz
liquidsec Oct 30, 2024
1695681
sync with dev
liquidsec Nov 5, 2024
8ab5222
Merge branch 'dev' into lightfuzz
liquidsec Nov 20, 2024
8ef31d5
black
liquidsec Nov 20, 2024
e4e99e6
poetry.lock update
liquidsec Nov 20, 2024
4d29a4a
fix tests
liquidsec Nov 21, 2024
0819db4
Merge branch 'dev' into lightfuzz
liquidsec Nov 21, 2024
a3a6ca0
Merge branch 'dev' into lightfuzz
liquidsec Nov 21, 2024
b9c39d6
dev to lightfuzz sync
liquidsec Nov 25, 2024
c94ba8f
making lightfuzz presets more explicit
liquidsec Nov 26, 2024
a50f771
initial lightfuzz docs
liquidsec Nov 26, 2024
164a091
readme adjust
liquidsec Nov 26, 2024
856ebc9
merge from dev
liquidsec Nov 26, 2024
5dd2318
exception for assert not in tests
liquidsec Nov 26, 2024
35c3918
ruff
liquidsec Nov 26, 2024
6264022
Merge branch 'dev' into lightfuzz
liquidsec Nov 26, 2024
0898c31
preset whitespace
liquidsec Nov 27, 2024
e0e6756
regex tweaks
liquidsec Nov 27, 2024
2763487
adding test for select tags
liquidsec Nov 27, 2024
0fef49c
tests passing
invalid-email-address Nov 27, 2024
c47fd7f
fix conflict
invalid-email-address Nov 27, 2024
81260a3
lint
invalid-email-address Nov 27, 2024
89effec
remove dead code
invalid-email-address Nov 27, 2024
93a9eb2
comment
invalid-email-address Nov 27, 2024
2203230
fix tests
invalid-email-address Nov 28, 2024
989d082
regex and other tweaks
liquidsec Nov 28, 2024
d4fbb73
i literally spent FOUR HOURS ON THIS BUG :( :( :(
liquidsec Nov 28, 2024
2971eb6
adding default blacklist to lightfuzz presets
liquidsec Nov 28, 2024
0510ee0
ssti submodule tweak
liquidsec Nov 28, 2024
060babf
may this bug be vanquished for all of eternity
liquidsec Nov 28, 2024
65ee9b0
Merge branch 'lightfuzz' into classify-envelopes
liquidsec Nov 28, 2024
5243089
additional ssti signature
liquidsec Nov 29, 2024
0ff947a
Merge branch 'lightfuzz' into classify-envelopes
liquidsec Nov 29, 2024
aa1bbcc
adding new envelope multiple test
liquidsec Nov 29, 2024
737999b
envelope bug fixes / enhancements
liquidsec Nov 29, 2024
c3ec029
remove debug
liquidsec Nov 29, 2024
cbfae57
variable name
liquidsec Nov 30, 2024
ab7e43d
Merge pull request #2045 from blacklanternsecurity/lightfuzz-crypto-r…
liquidsec Nov 30, 2024
c8888c0
stringifying all original values
liquidsec Nov 30, 2024
063a34d
Revert "stringifying all original values"
liquidsec Nov 30, 2024
64c6943
ensuring original_value is str
liquidsec Dec 3, 2024
a885451
fix?
invalid-email-address Dec 5, 2024
1f58cf4
Merge pull request #2043 from blacklanternsecurity/classify-envelopes
liquidsec Dec 18, 2024
4f4c2d7
Merge branch 'dev' into lightfuzz
liquidsec Dec 18, 2024
1f0f6c1
Merge branch 'dev' into lightfuzz
liquidsec Dec 18, 2024
4a72eda
adding form actions XSS detect, fixing parameter extraction bugs, dep…
liquidsec Dec 18, 2024
0efca3a
deps conflict resolution
liquidsec Dec 18, 2024
e98d2e8
remove debug msg
liquidsec Dec 18, 2024
8808fd3
better handling of malformed url errors during parameter extraction
liquidsec Dec 19, 2024
7487d7b
Merge branch 'dev' into lightfuzz
liquidsec Dec 20, 2024
85bd5ec
update poetry.lock
liquidsec Dec 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ For details, see [Configuration](https://www.blacklanternsecurity.com/bbot/Stabl
- [List of Modules](https://www.blacklanternsecurity.com/bbot/Stable/modules/list_of_modules)
- [Nuclei](https://www.blacklanternsecurity.com/bbot/Stable/modules/nuclei)
- [Custom YARA Rules](https://www.blacklanternsecurity.com/bbot/Stable/modules/custom_yara_rules)
- [Lightfuzz](https://www.blacklanternsecurity.com/bbot/Stable/modules/lightfuzz)
- **Misc**
- [Contribution](https://www.blacklanternsecurity.com/bbot/Stable/contribution)
- [Release History](https://www.blacklanternsecurity.com/bbot/Stable/release_history)
Expand Down
68 changes: 64 additions & 4 deletions bbot/core/event/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import ipaddress
import traceback

from copy import copy
from pathlib import Path
from typing import Optional
from copy import copy, deepcopy
from contextlib import suppress
from radixtarget import RadixTarget
from pydantic import BaseModel, field_validator
Expand Down Expand Up @@ -40,6 +40,7 @@
validators,
get_file_extension,
)
from bbot.core.helpers.web.envelopes import BaseEnvelope


log = logging.getLogger("bbot.core.event")
Expand Down Expand Up @@ -589,6 +590,10 @@ def parent(self, parent):
elif not self._dummy:
log.warning(f"Tried to set invalid parent on {self}: (got: {parent})")

@property
def children(self):
return []

@property
def parent_id(self):
parent_id = getattr(self.get_parent(), "id", None)
Expand Down Expand Up @@ -643,6 +648,13 @@ def get_parents(self, omit=False, include_self=False):
e = parent
return parents

def clone(self):
# Create a shallow copy of the event first
cloned_event = copy(self)
# Re-assign a new UUID
cloned_event._uuid = uuid.uuid4()
return cloned_event

def _host(self):
return ""

Expand Down Expand Up @@ -824,7 +836,13 @@ def json(self, mode="json", siem_friendly=False):
j["discovery_path"] = self.discovery_path
j["parent_chain"] = self.parent_chain

# parameter envelopes
parameter_envelopes = getattr(self, "envelopes", None)
if parameter_envelopes is not None:
j["envelopes"] = parameter_envelopes.to_dict()

# normalize non-primitive python objects

for k, v in list(j.items()):
if k == "data":
continue
Expand Down Expand Up @@ -1307,12 +1325,56 @@ class URL_HINT(URL_UNVERIFIED):


class WEB_PARAMETER(DictHostEvent):
@property
def children(self):
# if we have any subparams, raise a new WEB_PARAMETER for each one
children = []
envelopes = getattr(self, "envelopes", None)
if envelopes is not None:
subparams = sorted(list(self.envelopes.get_subparams()))

if envelopes.selected_subparam is None:
current_subparam = subparams[0]
envelopes.selected_subparam = current_subparam[0]
if len(subparams) > 1:
for subparam, _ in subparams[1:]:
clone = self.clone()
clone.envelopes = deepcopy(envelopes)
clone.envelopes.selected_subparam = subparam
clone.parent = self
children.append(clone)
return children

def sanitize_data(self, data):
original_value = data.get("original_value", None)
if original_value is not None:
try:
envelopes = BaseEnvelope.detect(original_value)
setattr(self, "envelopes", envelopes)
except ValueError as e:
log.verbose(f"Error detecting envelopes for {self}: {e}")
return data

def _data_id(self):
# dedupe by url:name:param_type
url = self.data.get("url", "")
name = self.data.get("name", "")
param_type = self.data.get("type", "")
return f"{url}:{name}:{param_type}"
envelopes = getattr(self, "envelopes", "")
subparam = getattr(envelopes, "selected_subparam", "")

return f"{url}:{name}:{param_type}:{subparam}"

def _outgoing_dedup_hash(self, event):
return hash(
(
str(event.host),
event.data["url"],
event.data.get("name", ""),
event.data.get("type", ""),
event.data.get("envelopes", ""),
)
)

def _url(self):
return self.data["url"]
Expand Down Expand Up @@ -1730,7 +1792,6 @@ def make_event(
data = net.network_address

event_class = globals().get(event_type, DefaultEvent)

return event_class(
data,
event_type=event_type,
Expand Down Expand Up @@ -1790,7 +1851,6 @@ def event_from_json(j, siem_friendly=False):

resolved_hosts = j.get("resolved_hosts", [])
event._resolved_hosts = set(resolved_hosts)

event.timestamp = datetime.datetime.fromisoformat(j["timestamp"])
event.scope_distance = j["scope_distance"]
parent_id = j.get("parent", None)
Expand Down
13 changes: 8 additions & 5 deletions bbot/core/helpers/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,24 @@ def __init__(
parent_helper,
method="GET",
data=None,
json=None,
allow_redirects=False,
include_cache_buster=True,
headers=None,
cookies=None,
timeout=15,
timeout=10,
):
self.parent_helper = parent_helper
self.baseline_url = baseline_url
self.include_cache_buster = include_cache_buster
self.method = method
self.data = data
self.json = json
self.allow_redirects = allow_redirects
self._baselined = False
self.headers = headers
self.cookies = cookies
self.timeout = 15
self.timeout = 10

@staticmethod
def merge_dictionaries(headers1, headers2):
Expand All @@ -53,6 +55,7 @@ async def _baseline(self):
follow_redirects=self.allow_redirects,
method=self.method,
data=self.data,
json=self.json,
headers=self.headers,
cookies=self.cookies,
retries=2,
Expand All @@ -76,6 +79,7 @@ async def _baseline(self):
follow_redirects=self.allow_redirects,
method=self.method,
data=self.data,
json=self.json,
retries=2,
timeout=self.timeout,
)
Expand Down Expand Up @@ -103,11 +107,9 @@ async def _baseline(self):

for k in ddiff.keys():
for x in list(ddiff[k]):
log.debug(f"Added {k} filter for path: {x.path()}")
self.ddiff_filters.append(x.path())

self.baseline_json = baseline_1_json

self.baseline_ignore_headers = [
h.lower()
for h in [
Expand Down Expand Up @@ -158,7 +160,6 @@ def compare_body(self, content_1, content_2):
if len(ddiff.keys()) == 0:
return True
else:
log.debug(ddiff)
return False

async def compare(
Expand All @@ -169,6 +170,7 @@ async def compare(
check_reflection=False,
method="GET",
data=None,
json=None,
allow_redirects=False,
timeout=None,
):
Expand Down Expand Up @@ -199,6 +201,7 @@ async def compare(
follow_redirects=allow_redirects,
method=method,
data=data,
json=json,
timeout=timeout,
)

Expand Down
4 changes: 3 additions & 1 deletion bbot/core/helpers/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ def http_compare(
cookies=None,
method="GET",
data=None,
timeout=15,
json=None,
timeout=10,
):
return HttpCompare(
url,
Expand All @@ -141,6 +142,7 @@ def http_compare(
timeout=timeout,
method=method,
data=data,
json=json,
)

def temp_filename(self, extension=None):
Expand Down
66 changes: 57 additions & 9 deletions bbot/core/helpers/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
import sys
import copy
import json
import math
import random
import string
import asyncio
import logging
import ipaddress
import ahocorasick
import regex as re
import subprocess as sp

from pathlib import Path
from contextlib import suppress
from unidecode import unidecode # noqa F401
Expand Down Expand Up @@ -797,17 +800,14 @@ def recursive_decode(data, max_depth=5):
return data


rand_pool = string.ascii_lowercase
rand_pool_digits = rand_pool + string.digits


def rand_string(length=10, digits=True):
def rand_string(length=10, digits=True, numeric_only=False):
"""
Generates a random string of specified length.

Args:
length (int, optional): The length of the random string. Defaults to 10.
digits (bool, optional): Whether to include digits in the string. Defaults to True.
numeric_only (bool, optional): Whether to generate a numeric-only string. Defaults to False.

Returns:
str: A random string of the specified length.
Expand All @@ -819,11 +819,17 @@ def rand_string(length=10, digits=True):
'ap4rsdtg5iw7ey7y3oa5'
>>> rand_string(30, digits=False)
'xdmyxtglqfzqktngkesyulwbfrihva'
>>> rand_string(15, numeric_only=True)
'934857349857395'
"""
pool = rand_pool
if digits:
pool = rand_pool_digits
return "".join([random.choice(pool) for _ in range(int(length))])
if numeric_only:
pool = string.digits
elif digits:
pool = string.ascii_lowercase + string.digits
else:
pool = string.ascii_lowercase

return "".join(random.choice(pool) for _ in range(length))


def truncate_string(s, n):
Expand Down Expand Up @@ -921,6 +927,7 @@ def extract_params_xml(xml_data, compare_mode="getparam"):
"getparam": {chr(c) for c in range(33, 127) if chr(c) not in ":/?#[]@!$&'()*+,;="},
"postparam": {chr(c) for c in range(33, 127) if chr(c) not in ":/?#[]@!$&'()*+,;="},
"cookie": {chr(c) for c in range(33, 127) if chr(c) not in '()<>@,;:"/[]?={} \t'},
"bodyjson": set(chr(c) for c in range(33, 127) if chr(c) not in ":/?#[]@!$&'()*+,;="),
}


Expand Down Expand Up @@ -2772,6 +2779,35 @@ def clean_dict(d, *key_names, fuzzy=False, exclude_keys=None, _prev_key=None):
return d


def string_scan(substrings, text, case_insensitive=True):
automaton = ahocorasick.Automaton()
if case_insensitive:
substrings = [s.lower() for s in substrings]
text = text.lower()
for idx, substring in enumerate(substrings):
automaton.add_word(substring, (idx, substring))
automaton.make_automaton()
found_substrings = []
for end_index, (insert_order, original_value) in automaton.iter(text):
found_substrings.append(original_value)
return found_substrings


def calculate_entropy(data):
"""Calculate the Shannon entropy of a byte sequence"""
if not data:
return 0
frequency = {}
for byte in data:
if byte in frequency:
frequency[byte] += 1
else:
frequency[byte] = 1
data_len = len(data)
entropy = -sum((count / data_len) * math.log2(count / data_len) for count in frequency.values())
return entropy


top_ports_cache = None


Expand Down Expand Up @@ -2825,3 +2861,15 @@ def clean_requirement(req_string):

dist = distribution("bbot")
return [clean_requirement(r) for r in dist.requires]


def is_printable(s):
"""
Check if a string is printable
"""
if not isinstance(s, str):
raise ValueError(f"Expected a string, got {type(s)}")

# Exclude control characters that break display/printing
s = set(s)
return all(ord(c) >= 32 or c in "\t\n\r" for c in s)
Loading
Loading