Skip to content

Commit

Permalink
Merge pull request #832 from blacklanternsecurity/filedownload-fix
Browse files Browse the repository at this point in the history
Fixed filedownload file counter
  • Loading branch information
TheTechromancer authored Nov 9, 2023
2 parents 6cf5c47 + f0e389d commit 8a325be
Showing 1 changed file with 7 additions and 6 deletions.
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}")

0 comments on commit 8a325be

Please sign in to comment.