-
Notifications
You must be signed in to change notification settings - Fork 0
/
disk_neuralizer.sh
129 lines (109 loc) · 3.69 KB
/
disk_neuralizer.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
#
# Disk Neuralyzer Script
#
# This script securely destroys all data on the specified disk by overwriting it with
# multiple patterns (ones, random data, and zeroes) to comply with NIST Special Publication 800-88
# guidelines for data sanitization.
#
# Important Notes:
#
# - Use this script with caution; all data on the specified disk will be permanently lost.
# - Ensure that the disk is unmounted before running the script.
# - This script requires root privileges to execute.
# - It will install the 'pv' utility if it is not already present on the system.
#
# Usage:
#
# Run the script as root:
# sudo ./disk_neuralyzer.sh
# Follow the onscreen instructions to select the disk to wipe.
#
# Version: 2.3
#
# Author: Daniel Sol
# Date: 2024
# Git: https://github.com/szolll/disk_neuralizer/
#
# License:
#
# This script is provided "as is" without any warranty. Redistribution or modification
# of this script is not permitted without explicit permission from the author.
# The author is not liable for any damages resulting from the use of this script.
# HELP message
usage() {
cat << EOF
Usage: Run the script as root and follow the onscreen instructions!
Options:
-h, --help Show this help message
EOF
}
# Check for flags
case "$1" in
-h|--help)
usage
exit
;;
esac
# Set output colors
ALERT_YELLOW="\033[0;33m%s\033[0m"
ALERT_RED="\033[0;31m%s\033[0m"
ALERT_GREEN="\033[0;32m%s\033[0m"
# Clear screen
clear
# Welcome message
printf "${ALERT_GREEN}Running the Disk Neuralyzer!\n"
# Warning about data destruction
printf "${ALERT_YELLOW}This program will destroy data on selected disks! Once data is lost, it cannot be recovered. Proceed with caution!\n\n"
# Check if script is run as root
if [ "$EUID" -ne 0 ]; then
printf "${ALERT_RED}Please run this script as root!\n"
exit 1
fi
# Check if pv is installed; install if not
if ! dpkg -s pv &> /dev/null; then
printf "\nPV not found. Installing...\n"
apt update && apt install -y pv
fi
# List available disks, ignoring loop devices
printf "\nAvailable disks:\n"
lsblk | grep -v '^loop'
# Prompt user for the disk to wipe
printf "${ALERT_YELLOW}\nSelect the drive to wipe (no full path needed): "
read -r DISK2KILL
# Validate user input
if [[ -z "$DISK2KILL" ]]; then
printf "${ALERT_RED}Error! Please provide the disk you want to wipe.\n"
exit 1
fi
printf "\nPreparing to wipe disk: $DISK2KILL\n"
# Check if the disk is mounted
if grep -q "$DISK2KILL " /proc/mounts; then
printf "${ALERT_RED}This disk is mounted. Please unmount it before running this script.\n"
exit 1
fi
# Run badblocks check
if ! badblocks -e 1 -wsv /dev/"$DISK2KILL"; then
printf "${ALERT_RED}Badblocks failed. Sensitive data may remain in badblocks!\n"
exit 1
fi
# Wipe the disk with zeroes
printf "${ALERT_YELLOW}Wiping data...\n"
wipe -qrfc -F -Q 1 /dev/"$DISK2KILL"
# Data types to write
declare -a DATA_TYPES=("ones" "random data" "zeroes")
declare -A WRITE_COMMANDS=(
["ones"]="tr '\0' '\377' < /dev/zero | pv -prtb | dd of=/dev/$DISK2KILL status=progress bs=1M conv=noerror"
["random data"]="pv -tpreb /dev/urandom | dd of=/dev/$DISK2KILL status=progress bs=1M conv=noerror"
["zeroes"]="pv -tpreb /dev/zero | dd of=/dev/$DISK2KILL status=progress bs=1M conv=noerror"
)
# Loop through each data type and write to disk
for DATA_TYPE in "${DATA_TYPES[@]}"; do
printf "${ALERT_YELLOW}Filling the disk with $DATA_TYPE until it's full...\n"
if eval "${WRITE_COMMANDS[$DATA_TYPE]}"; then
printf "${ALERT_GREEN}Successfully filled the disk with $DATA_TYPE.\n"
else
printf "${ALERT_RED}Failed to fill the disk with $DATA_TYPE. Please wipe it manually.\n"
fi
done
printf "${ALERT_YELLOW}\nPlease verify the output of this script for any errors.\n"