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

Email addresses output #929

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 25 additions & 0 deletions bbot/modules/output/emails.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from bbot.modules.base import BaseModule
from bbot.modules.output.human import Human


class Emails(Human):
watched_events = ["EMAIL_ADDRESS"]
flags = ["email-enum"]
meta = {"description": "Output any email addresses found belonging to the target domain"}
options = {"output_file": ""}
options_desc = {"output_file": "Output to file"}
in_scope_only = True

output_filename = "emails.txt"

def _scope_distance_check(self, event):
return BaseModule._scope_distance_check(self, event)

async def handle_event(self, event):
if self.file is not None:
self.file.write(f"{event.data}\n")
self.file.flush()

async def report(self):
if getattr(self, "_file", None) is not None:
self.info(f"Saved email addresses to {self.output_file}")
7 changes: 0 additions & 7 deletions bbot/modules/output/subdomains.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from contextlib import suppress

from bbot.modules.base import BaseModule
from bbot.modules.output.human import Human

Expand Down Expand Up @@ -32,11 +30,6 @@ async def handle_event(self, event):
self.file.write(f"{event.data}\n")
self.file.flush()

async def cleanup(self):
if getattr(self, "_file", None) is not None:
with suppress(Exception):
self.file.close()

async def report(self):
if getattr(self, "_file", None) is not None:
self.info(f"Saved subdomains to {self.output_file}")
23 changes: 23 additions & 0 deletions bbot/test/test_step_2/module_tests/test_module_emails.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from .base import ModuleTestBase


class TestEmais(ModuleTestBase):
modules_overrides = ["emails", "emailformat", "skymem"]

async def setup_before_prep(self, module_test):
module_test.httpx_mock.add_response(
url="https://www.email-format.com/d/blacklanternsecurity.com/",
text="<p>[email protected]</p>",
)
module_test.httpx_mock.add_response(
url="https://www.skymem.info/srch?q=blacklanternsecurity.com",
text="<p>[email protected]</p>",
)

def check(self, module_test, events):
assert 2 == len([e for e in events if e.data == "[email protected]"])
email_file = module_test.scan.home / "emails.txt"
emails = open(email_file).read().splitlines()
# make sure deduping works as intended
assert len(emails) == 1
assert set(emails) == {"[email protected]"}