-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
3,189 additions
and
2,548 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Copyright (C) 2024 [email protected] | ||
# This file is part of Cuckoo Sandbox - http://www.cuckoosandbox.org | ||
# See the file 'docs/LICENSE' for copying permission. | ||
import logging | ||
import os | ||
import subprocess | ||
import tempfile | ||
import time | ||
from threading import Thread | ||
|
||
from lib.common.abstracts import Auxiliary | ||
from lib.common.results import upload_to_host | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class Browsermonitor(Auxiliary, Thread): | ||
"""Monitors Browser Extension request logs.""" | ||
|
||
def __init__(self, options=None, config=None): | ||
if options is None: | ||
options = {} | ||
Auxiliary.__init__(self, options, config) | ||
Thread.__init__(self) | ||
self.do_run = False | ||
self.enabled = config.browsermonitor | ||
self.startupinfo = subprocess.STARTUPINFO() | ||
self.startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW | ||
self.browser_logfile = "" | ||
self.last_modification = 0.0 | ||
self._is_first_save = True | ||
|
||
def _find_browser_extension(self): | ||
temp_dir = tempfile.gettempdir() | ||
while not self.browser_logfile and self.do_run: | ||
temp_dir_list = os.listdir(temp_dir) | ||
for directory in temp_dir_list: | ||
tmp_directory_path = os.path.join(temp_dir, directory) | ||
if not os.path.isdir(tmp_directory_path): | ||
continue | ||
if not directory.startswith("tmp"): | ||
continue | ||
tmp_dir_files = os.listdir(tmp_directory_path) | ||
for file in tmp_dir_files: | ||
if file.startswith("bext_") and file.endswith(".json"): | ||
self.browser_logfile = os.path.join(temp_dir, directory, file) | ||
log.debug(f"Found extension logs: {self.browser_logfile}") | ||
break | ||
time.sleep(1) | ||
|
||
def _collect_browser_logs(self): | ||
if not self._is_first_save and self.last_modification != os.path.getmtime(self.browser_logfile): | ||
return | ||
self.last_modification = os.path.getmtime(self.browser_logfile) | ||
upload_to_host(self.browser_logfile, "browser/requests.log") | ||
self._is_first_save = False | ||
|
||
def run(self): | ||
self.do_run = True | ||
if self.enabled: | ||
self._find_browser_extension() | ||
self.last_modification = os.path.getmtime(self.browser_logfile) | ||
while self.do_run: | ||
self._collect_browser_logs() | ||
time.sleep(1) | ||
return True | ||
return False | ||
|
||
def stop(self): | ||
if self.enabled: | ||
self.do_run = False | ||
if self.browser_logfile: | ||
self._collect_browser_logs() | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright (C) 2024 [email protected] | ||
# This file is part of Cuckoo Sandbox - http://www.cuckoosandbox.org | ||
# See the file 'docs/LICENSE' for copying permission. | ||
|
||
import time | ||
import webbrowser | ||
|
||
from lib.common.abstracts import Package | ||
|
||
|
||
class ChromiumExt(Package): | ||
"""Chromium extension analysis package.""" | ||
|
||
PATHS = [ | ||
("LOCALAPPDATA", "Chromium", "chrome.exe"), | ||
] | ||
summary = "Opens the URL in Chromium with loaded extension." | ||
description = """Runs Chromium preloaded with a custom extensios.""" | ||
|
||
def start(self, url): | ||
webbrowser.register("chromium", None, webbrowser.BackgroundBrowser(self.get_path("chrome.exe"))) | ||
chromium = webbrowser.get("chromium") | ||
chromium.open("about:blank") | ||
time.sleep(10) | ||
return chromium.open(url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Copyright (C) 2024 [email protected] | ||
# This file is part of Cuckoo Sandbox - http://www.cuckoosandbox.org | ||
# See the file 'docs/LICENSE' for copying permission. | ||
import time | ||
import webbrowser | ||
|
||
from lib.common.abstracts import Package | ||
|
||
|
||
class Firefox_Ext(Package): | ||
"""Firefox analysis package (with extension).""" | ||
|
||
PATHS = [ | ||
("ProgramFiles", "Mozilla Firefox", "firefox.exe"), | ||
] | ||
summary = "Opens the URL in firefox." | ||
description = """Spawns firefox.exe and opens the supplied URL.""" | ||
|
||
def start(self, url): | ||
webbrowser.register("firefox", None, webbrowser.BackgroundBrowser(self.get_path("firefox.exe"))) | ||
firefox = webbrowser.get("firefox") | ||
firefox.open("about:blank") | ||
time.sleep(7) # Rough estimate, change based on your setup times. | ||
return firefox.open(url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -221,3 +221,6 @@ enabled = no | |
# Community | ||
[malheur] | ||
enabled = no | ||
|
||
[browserext] | ||
enabled = no |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
This browser extension intercepts requests done within a browser and sends them | ||
back to agent.py. | ||
|
||
Extension setup differs on a browser basis: | ||
|
||
|
||
==== Firefox ==== | ||
|
||
Firefox requires having a signed extension. Head to | ||
https://addons.mozilla.org/en-US/developers/addons and sign your extension | ||
(adjust details on manifest.json) and install it in your browser. | ||
|
||
Alternatively it's possible to install an unsigned extension temporarily by | ||
heading to about:debugging and pointing to your compressed (.zip) extension but | ||
this is not supported. | ||
|
||
|
||
==== Chromium ==== | ||
|
||
Download latest build from https://download-chromium.appspot.com/ -- Enable | ||
developer mode and load unpacked extension. Then, close the browser. Once you | ||
open chromium again, it will complain about the extension being unsafe and | ||
Chromium auto-disables it. Head back to the extensions page and give it | ||
permissions back. Then, the extension is permantently loaded. Tested on version | ||
131.0.X | ||
|
||
The default path for the `chromium_ext` package is %LOCALAPPDATA%/Chromium/chrome.exe, | ||
change the path in .py if needed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
let networkData = []; | ||
|
||
|
||
function onRequestEvent(details) { | ||
if (details.url.includes("/browser_extension")) { | ||
return; | ||
} | ||
const requestEvent = networkData.find(entry => entry.url === details.url); | ||
if (requestEvent) { | ||
return | ||
} | ||
const info = { | ||
url: details.url, | ||
method: details.method, | ||
timeStamp: details.timeStamp, | ||
requestHeaders: details.requestHeaders, | ||
}; | ||
networkData.push(info); | ||
} | ||
|
||
function onResponseEvent(details) { | ||
const requestEvent = networkData.find(entry => entry.url === details.url); | ||
if (requestEvent) { | ||
if (requestEvent.ip) { | ||
return; | ||
} | ||
requestEvent.responseHeaders = details.responseHeaders; | ||
requestEvent.type = details.type; | ||
requestEvent.ip = details.ip; | ||
requestEvent.originUrl = details.originUrl; | ||
sendEvents(); | ||
} | ||
} | ||
|
||
function sendEvents() { | ||
const form = new FormData(); | ||
form.append('networkData', JSON.stringify(networkData)); | ||
|
||
fetch('http://localhost:8000/browser_extension', { | ||
method: 'POST', | ||
body: form | ||
}) | ||
.then(response => response.json()) | ||
.catch(error => { | ||
console.error('Error posting data to endpoint:', error); | ||
}); | ||
} | ||
|
||
|
||
browser.webRequest.onBeforeSendHeaders.addListener( | ||
onRequestEvent, | ||
{urls: ["<all_urls>"]}, | ||
["requestHeaders"] | ||
); | ||
|
||
browser.webRequest.onCompleted.addListener( | ||
onResponseEvent, | ||
{urls: ["<all_urls>"]}, | ||
["responseHeaders"] | ||
); | ||
|
||
browser.downloads.onCreated.addListener(function(downloadItem) { | ||
const downloadId = downloadItem.id; | ||
browser.downloads.onChanged.addListener(function(delta) { | ||
if (delta.id === downloadId && delta.state && delta.state.current === "complete") { | ||
const requestEvent = networkData.find(entry => entry.url === downloadItem.url); | ||
if (requestEvent) { | ||
requestEvent.filePath = downloadItem.filename; | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
browser.runtime.onStartup.addListener(function () { | ||
networkData = []; | ||
}); |
Oops, something went wrong.