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

Fixed filedownload file counter #832

Merged
merged 1 commit into from
Nov 9, 2023
Merged
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
13 changes: 7 additions & 6 deletions bbot/modules/filedownload.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ async def setup(self):
self.max_filesize = self.options.get("max_filesize", "10MB")
self.download_dir = self.scan.home / "filedownload"
self.helpers.mkdir(self.download_dir)
self.files_downloaded = set()
self.urls_downloaded = set()
self.files_downloaded = 0
self.mime_db_file = await self.helpers.wordlist(
"https://raw.githubusercontent.com/jshttp/mime-db/master/db.json"
)
Expand All @@ -100,8 +101,7 @@ async def filter_event(self, event):
# accept file download requests from other modules
if "filedownload" in event.tags:
return True
h = self.hash_event(event)
if h in self.files_downloaded:
if self.hash_event(event) in self.urls_downloaded:
return False, f"Already processed {event}"
return True

Expand All @@ -128,7 +128,8 @@ async def download_file(self, url, content_type=None):
result = await self.helpers.download(url, warn=False, filename=file_destination, max_size=self.max_filesize)
if result:
self.info(f'Found "{orig_filename}" at "{base_url}", downloaded to {file_destination}')
self.files_downloaded.add(hash(url))
self.files_downloaded += 1
self.urls_downloaded.add(hash(url))

def make_filename(self, url, content_type=None):
# first, try to determine original filename
Expand Down Expand Up @@ -161,5 +162,5 @@ def make_filename(self, url, content_type=None):
return orig_filename, self.download_dir / filename, base_url

async def report(self):
if self.files_downloaded:
self.success(f"Downloaded {len(self.files_downloaded):,} file(s) to {self.download_dir}")
if self.files_downloaded > 0:
self.success(f"Downloaded {self.files_downloaded:,} file(s) to {self.download_dir}")