-
Notifications
You must be signed in to change notification settings - Fork 0
Improve noexec robustness and security #4
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,13 +1,43 @@ | ||||||||||||||||||||||||||||||||||||||
| curl "https://raw.githubusercontent.com/ByteJoseph/noexec/refs/heads/main/src/noexec" -o noexec | ||||||||||||||||||||||||||||||||||||||
| set -e | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| # Check for required commands | ||||||||||||||||||||||||||||||||||||||
| for cmd in curl dirname command cp chmod rm; do | ||||||||||||||||||||||||||||||||||||||
| if ! command -v "$cmd" >/dev/null 2>&1; then | ||||||||||||||||||||||||||||||||||||||
| echo "Error: Required command '$cmd' not found. Please install it and try again." | ||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| echo "Downloading noexec..." | ||||||||||||||||||||||||||||||||||||||
| if ! curl -s "https://raw.githubusercontent.com/ByteJoseph/noexec/refs/heads/main/src/noexec" -o noexec; then | ||||||||||||||||||||||||||||||||||||||
| echo "Error: Failed to download noexec." | ||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| file="noexec" | ||||||||||||||||||||||||||||||||||||||
| dir_name=$(dirname "$(command -v bash)") | ||||||||||||||||||||||||||||||||||||||
| bash_path=$(command -v bash) | ||||||||||||||||||||||||||||||||||||||
| if [ -z "$bash_path" ]; then | ||||||||||||||||||||||||||||||||||||||
| echo "Error: Could not find bash in PATH." | ||||||||||||||||||||||||||||||||||||||
| rm -f "$file" | ||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| dir_name=$(dirname "$bash_path") | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if [ ! -w "$dir_name" ]; then | ||||||||||||||||||||||||||||||||||||||
| echo "Error: No write permission to $dir_name. Please run with appropriate permissions." | ||||||||||||||||||||||||||||||||||||||
| rm -f "$file" | ||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if [ -f "$file" ]; then | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| cp "$file" "$dir_name/$file" | ||||||||||||||||||||||||||||||||||||||
| chmod +x "$dir_name/$file" | ||||||||||||||||||||||||||||||||||||||
| echo "noexec Installed Successfully" | ||||||||||||||||||||||||||||||||||||||
| rm "noexec" | ||||||||||||||||||||||||||||||||||||||
| echo "noexec Installed Successfully to $dir_name/$file" | ||||||||||||||||||||||||||||||||||||||
| rm "$file" | ||||||||||||||||||||||||||||||||||||||
| echo "" | ||||||||||||||||||||||||||||||||||||||
| echo "Start using now" | ||||||||||||||||||||||||||||||||||||||
| noexec | ||||||||||||||||||||||||||||||||||||||
| echo "Start using now by typing: noexec" | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
33
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Use Because the file is only needed in its final location, you can replace the
Suggested change
|
||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||
| echo "Error: Downloaded file not found." | ||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Setup a fake bin directory and add it to PATH | ||
| FAKE_BIN="$(pwd)/fake_bin_test" | ||
| mkdir -p "$FAKE_BIN" | ||
| cp "$(command -v bash)" "$FAKE_BIN/bash" | ||
| export PATH="$FAKE_BIN:$PATH" | ||
|
|
||
| NOEXEC="$(pwd)/src/noexec" | ||
|
|
||
| # Helper for testing | ||
| assert_contains() { | ||
| local output="$1" | ||
| local expected="$2" | ||
| local name="$3" | ||
| if echo "$output" | grep -q "$expected"; then | ||
| echo "PASS: $name" | ||
| else | ||
| echo "FAIL: $name" | ||
| echo " Expected to contain: $expected" | ||
| echo " Actual output: $output" | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| # Test Case 1: Verify successful execution of a simple script passing arguments | ||
| echo 'echo "Test Output: $1 $2"' > test_script.sh | ||
| chmod +x test_script.sh | ||
| OUTPUT=$(bash "$NOEXEC" ./test_script.sh "Arg1" "Arg2") | ||
| assert_contains "$OUTPUT" "Test Output: Arg1 Arg2" "Successful execution with arguments" | ||
|
|
||
| # Test Case 2: Verify correct output for the --help flag | ||
| OUTPUT=$(bash "$NOEXEC" --help) | ||
| assert_contains "$OUTPUT" "Usage : noexec" "Help flag output" | ||
|
|
||
| # Test Case 3: Verify error message when the input file does not exist | ||
| OUTPUT=$(bash "$NOEXEC" non_existent_file 2>&1) | ||
| assert_contains "$OUTPUT" "Error: File 'non_existent_file' doesn't exist." "Missing file error" | ||
|
|
||
| # Test Case 4: Verify error message when the input is a directory instead of a file | ||
| mkdir -p test_dir | ||
| OUTPUT=$(bash "$NOEXEC" test_dir 2>&1) | ||
| assert_contains "$OUTPUT" "Error: 'test_dir' is a directory, not a file." "Directory input error" | ||
|
|
||
| # Cleanup | ||
| rm test_script.sh | ||
| rm -rf test_dir | ||
| rm -rf "$FAKE_BIN" | ||
|
|
||
| echo "All tests passed!" |
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.
suggestion: Consider using curl’s failure flags (e.g.,
-fS) instead of fully suppressing output with-s.-shides curl’s error output, which makes debugging failures harder. A pattern likecurl -fSLo noexec "…"keeps normal output quiet while still failing on HTTP errors and showing a clear error message on stderr.