-
Notifications
You must be signed in to change notification settings - Fork 0
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
Squashed public commit of v0.2 #7
Conversation
- Refactor the codebase to use it as a submodule in other projects. - Remove support for `-ee` argument. - Remove `experiments` folder. - Support `--auto-recharge` argument to automatically recharge the battery of the device during experiments. - Remove unused libs and scripts, not relevant to core BLaDE infrastructure. - Convert wait times into constants. - Support latest Raspberry Pi 5 and Raspberry Pi OS 12 (Bookworm). - `pid` files are now saved into a global `.pid_files` folder - Add support for memory monitoring per app. - Support local proxy for dynamically injecting custom JavaScript. - Updated documentation and list of optional but recommended OS configuration settings. - Add a logger that by default logs to the stdout, and with flag `--log-output` it adds a log.txt file to the output directory. - Replace parameter `-d` to be a positional parameter which is required, except when running `-h`, `-ld` or `--list-devices`. - Add support for remote control for the device. Only available for Android devices. Co-Authored-By: Ralph Ankele <117092743+ankeleralph@users.noreply.github.com> Co-Authored-By: Artem Chaikin <10810135+stoletheminerals@users.noreply.github.com>
DescriptionThis PR represents a significant refactoring and enhancement of the BLaDE (BatteryLab and Device Evaluations) infrastructure. The changes focus on improving code organization, adding new features, and enhancing reliability. Major changes include:
Security Hotspots
ChangesChangesBy filename:
sequenceDiagram
participant User
participant BLaDE
participant Device
participant Monsoon
participant Proxy
User->>BLaDE: Initialize Device Control
BLaDE->>Monsoon: Configure Power Monitor
BLaDE->>Device: Setup Connection
alt Remote Control Enabled
BLaDE->>Device: Enable Remote Access
Device-->>User: Provide Remote Interface
end
alt Auto-recharge Enabled
loop Battery Monitoring
BLaDE->>Device: Check Battery Level
Device-->>BLaDE: Battery Status
alt Battery Low
BLaDE->>Device: Enable Charging
BLaDE->>Device: Wait for Target Level
end
end
end
opt Proxy Enabled
BLaDE->>Proxy: Start Local Proxy
Proxy->>Device: Inject Monitoring Code
Device-->>Proxy: Send Performance Data
end
BLaDE->>Device: Start Measurements
Device-->>BLaDE: Stream Performance Data
|
return subprocess.check_output(command, shell=True).rstrip().decode() | ||
# run the command | ||
start_time = time.time() | ||
output = subprocess.check_output(command, shell=True).rstrip().decode() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reported by reviewdog 🐶
[semgrep] Found 'subprocess' function 'check_output' with 'shell=True'. This is dangerous because this call will spawn the command using a shell process. Doing so propagates current shell settings and variables, which makes it much easier for a malicious actor to execute commands. Use 'shell=False' instead.
Source: https://semgrep.dev/r/python.lang.security.audit.subprocess-shell-true.subprocess-shell-true
Cc @thypon @kdenhartog
return subprocess.check_output(command, shell=True).rstrip().decode() | ||
# run the command | ||
start_time = time.time() | ||
output = subprocess.check_output(command, shell=True).rstrip().decode() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reported by reviewdog 🐶
[semgrep] Found subprocess
function check_output
with shell=True
. This is dangerous because this call will
spawn the command using a shell process. Doing so propagates current shell settings and
variables,
which makes it much easier for a malicious actor to execute commands. Use shell=False
instead.
Source: https://semgrep.dev/r/gitlab.bandit.B602
Cc @thypon @kdenhartog
|
||
# Get all process IDs for the package | ||
ps_cmd = f'adb -s {adb_identifier} shell "ps -A | grep {package_name}"' | ||
ps_output = os.popen(ps_cmd).read().strip() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reported by reviewdog 🐶
[semgrep] Starting a process with a shell; seems safe, but may be changed in the future, consider
rewriting without shell
Source: https://semgrep.dev/r/gitlab.bandit.B605
Cc @thypon @kdenhartog
|
||
# Run dumpsys meminfo for this PID | ||
meminfo_cmd = f'adb -s {adb_identifier} shell dumpsys meminfo {pid}' | ||
meminfo_output = os.popen(meminfo_cmd).read() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reported by reviewdog 🐶
[semgrep] Starting a process with a shell; seems safe, but may be changed in the future, consider
rewriting without shell
Source: https://semgrep.dev/r/gitlab.bandit.B605
Cc @thypon @kdenhartog
def disable_remote_control(): | ||
|
||
script = os.path.join(__location__, "../disable_remote_control.sh") | ||
os.system(script) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reported by reviewdog 🐶
[semgrep] Starting a process with a shell; seems safe, but may be changed in the future, consider
rewriting without shell
Source: https://semgrep.dev/r/gitlab.bandit.B605
Cc @thypon @kdenhartog
] | ||
if not verbose: | ||
command.append("-q") | ||
process = subprocess.Popen(command) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reported by reviewdog 🐶
[semgrep] Python possesses many mechanisms to invoke an external executable. However,
doing so may present a security issue if appropriate care is not taken to
sanitize any user provided or variable input. This plugin test is part of a
family of tests built to check for process spawning and warn appropriately.
Specifically, this test looks for the spawning of a subprocess without the
use of a command shell. This type of subprocess invocation is not
vulnerable to shell injection attacks, but care should still be taken to
ensure validity of input.
Source: https://semgrep.dev/r/gitlab.bandit.B603
Cc @thypon @kdenhartog
"--cert", "cert.pem", | ||
"--key", "key.pem", | ||
"--output", output_dir, | ||
]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reported by reviewdog 🐶
[semgrep] Python possesses many mechanisms to invoke an external executable. However,
doing so may present a security issue if appropriate care is not taken to
sanitize any user provided or variable input. This plugin test is part of a
family of tests built to check for process spawning and warn appropriately.
Specifically, this test looks for the spawning of a subprocess without the
use of a command shell. This type of subprocess invocation is not
vulnerable to shell injection attacks, but care should still be taken to
ensure validity of input.
Source: https://semgrep.dev/r/gitlab.bandit.B603
Cc @thypon @kdenhartog
output_file, | ||
f"--interval={interval_ms}", | ||
] | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reported by reviewdog 🐶
[semgrep] Python possesses many mechanisms to invoke an external executable. However,
doing so may present a security issue if appropriate care is not taken to
sanitize any user provided or variable input. This plugin test is part of a
family of tests built to check for process spawning and warn appropriately.
Specifically, this test looks for the spawning of a subprocess without the
use of a command shell. This type of subprocess invocation is not
vulnerable to shell injection attacks, but care should still be taken to
ensure validity of input.
Source: https://semgrep.dev/r/gitlab.bandit.B603
Cc @thypon @kdenhartog
|
||
import json | ||
import os | ||
import subprocess |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reported by reviewdog 🐶
[semgrep] Consider possible security implications associated with subprocess module.
Source: https://semgrep.dev/r/gitlab.bandit.B404
Cc @thypon @kdenhartog
|
||
|
||
if __name__ == "__main__": | ||
# To create certificates: openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reported by reviewdog 🐶
[semgrep] Found openssl
command using insecure flags
Source: https://semgrep.dev/r/trailofbits.generic.openssl-insecure-flags.openssl-insecure-flags
Cc @thypon @kdenhartog
This PR is a squashed public version of BLaDE v0.2, with the following changes:
-ee
argument.experiments
folder.--auto-recharge
argument to automatically recharge the battery of the device during experiments.pid
files are now saved into a global.pid_files
folder--log-output
it adds a log.txt file to the output directory.-d
to be a positional parameter which is required, except when running-h
,-ld
or--list-devices
.