Shred a box
Certainly! To prevent the script from potentially affecting system components, you can add a safety check to ensure that the generated command doesn’t start with a critical system command (e.g., rm
, mv
, etc.). Here’s the modified script with this safety check:#!/bin/bash # Fetch command names from the /bin folder commands=($(ls /bin)) # File to store executed combinations executed_file="executed_combinations.txt" # Function to generate combinations and check execution generate_and_check_combinations() { local combination="$1" # Safety check to prevent affecting system components if [[ $combination =~ (^|\|)\s*(rm|mv|cp|chmod|chown|dd)\s* ]]; then echo "Unsafe combination detected: $combination" return fi local result=$(eval "$combination" 2>/dev/null) if [ $? -eq 0 ]; then # Check for duplicate before saving if ! grep -Fxq "$combination" "$executed_file"; then echo "Executing: $combination" echo "$combination" >> "$executed_file" echo "Combination executed and saved." else echo "Combination already executed: $combination" fi else echo "Combination failed: $combination" fi } # Infinite loop for continuous checking while true; do # Generate a random combination (replace this with your logic) random_combination="" for ((i=0; i<3; i++)); do if [ $((RANDOM % 2)) -eq 0 ]; then random_combination+=" /bin/${commands[$((RANDOM % ${#commands[@]}))]}" fi if [ $((RANDOM % 2)) -eq 0 ]; then random_combination+=" | " fi done # Check and save the combination generate_and_check_combinations "$random_combination" # Display the size of the executed_combinations.txt file file_size=$(du -h "$executed_file" | cut -f1) echo "Size of $executed_file: $file_size" # Adjust sleep duration based on your needs sleep 1 done
This safety check ensures that the generated command doesn’t contain certain critical system commands before attempting to execute it. Adjustments can be made based on your specific safety requirements.
#!/bin/bash
# Fetch command names from the /bin folder
commands=($(ls /bin))
# File to store executed combinations
executed_file=”executed_combinations.txt”
# Function to generate combinations and check execution
generate_and_check_combinations() {
local combination=”$1″
# Safety check to prevent affecting system components
if [[ $combination =~ (^|\|)\s*(rm|mv|cp|chmod|chown|dd)\s* ]]; then
echo “Unsafe combination detected: $combination”
return
fi
local result=$(eval “$combination” 2>/dev/null)
if [ $? -eq 0 ]; then
# Check for duplicate before saving
if ! grep -Fxq “$combination” “$executed_file”; then
echo “Executing: $combination”
echo “$combination” >> “$executed_file”
echo “Combination executed and saved.”
else
echo “Combination already executed: $combination”
fi
else
echo “Combination failed: $combination”
fi
}
# Infinite loop for continuous checking
while true; do
# Generate a random combination (replace this with your logic)
random_combination=””
for ((i=0; i<3; i++)); do
if [ $((RANDOM % 2)) -eq 0 ]; then
random_combination+=” /bin/${commands[$((RANDOM % ${#commands[@]}))]}”
fi
if [ $((RANDOM % 2)) -eq 0 ]; then
random_combination+=” | “
fi
done
# Check and save the combination
generate_and_check_combinations “$random_combination”
# Display the size of the executed_combinations.txt file
file_size=$(du -h “$executed_file” | cut -f1)
echo “Size of $executed_file: $file_size”
# Adjust sleep duration based on your needs
sleep 1
done
Leave a Reply