-
Notifications
You must be signed in to change notification settings - Fork 0
/
_disk_rand
74 lines (62 loc) · 3.41 KB
/
_disk_rand
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
#!/bin/bash
last=0;
start=$(date +%s)
fail=1;
test -e "$1" && fail=0;
if [ $fail -eq 1 ] ;then echo "FILE DOES NOT EXIST , ABORT" ;exit 235;fi
megabyte=$(dd if=/dev/zero bs=1M count=1 2>/dev/null|wc -c)
blockdev --getsize64 $1 &>/dev/null && size=$(sudo blockdev --getsize64 "$1" ) || size=$(wc -c < "$1")
if [ $size -eq 0 ];then echo "SIZE 0 after detection , maybe sparse file or something worse , ABORT";exit 235;fi
lowest=$size
highest=0
mbsize=$(expr $size / 1024 / 1024)
echo "I WILL DESTROY $1 ( "$(expr $size / 1024 / 1024 / 1024 )" Gbytes == $mbsize Mbytes ), ARE YOU SURE ? (y/n)"
read yesno
if [ "$yesno" == "y" ];then
echo "WIPING INITIAL 8 MB (openssl)"
openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -iter 3 -nosalt < /dev/zero 2>/dev/null | head -c 8388608| pv -pr -s 8388608 -S > $1
echo "STARTING WIPE"
bytes=0;
smallmodulo=8589934592 # 8Gbytes
if [ $size -lt $smallmodulo ];then smallmodulo=$(expr $size / 5 );fi # if disk is smaller than 8G we take the first 20% , e.g. 800MB for 4Gbytes , usually enough for MBR/GPT
lastmb=$((${size}-${megabyte}))
ciphercount=$(echo $size|wc -c);
let ciphercount++;
while (true); do
# which openssl >/dev/zero && randnum=$(openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -iter 3 -nosalt < /dev/zero 2>/dev/null | tr -cd '0-9' |head -c 13) || randnum=${RANDOM}${RANDOM}${RANDOM}
# smallrand=$randnum
smallrand=$(cat /dev/urandom |tr -cd '0-9'|head -c11)
#smallrand=$((10#${smallrandtmp}"%" $smallmodulo));
#overwrite lower area more intense
number=$((10#$smallrand%10#$smallmodulo))
end=$(($number+$megabyte))
if [ $number -lt $lowest ];then lowest=$number;fi;if [ $end -gt $highest ];then highest=$end;fi
cat /dev/urandom |head -c1|dd of=$1 skip=$number bs=1M count=1 &>/dev/null &
smallrand=$number
let bytes++;
# which openssl >/dev/zero && randnum=$(openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -iter 3 -nosalt < /dev/zero 2>/dev/null | tr -cd '0-9' |head -c $((${RANDOM}%13)) ) || randnum=$(echo ${RANDOM}${RANDOM}${RANDOM} |head -c $((${RANDOM}%13)) )
# number=$((10#$randnum%10#$size))
##openssl is cool but costy, also the %size is not so random it seems
randnum=$(cat /dev/urandom |tr -cd '0-9' |head -c $((10#${RANDOM}%$ciphercount)) )
#number="${randnum:-$(cat /dev/urandom |tr -cd 0-9 |head -c $ciphercount)" ;
number=$((10#$randnum%10#$size))
# echo $number $lastmb
if [ $number -gt $lastmb ] ;then number=$lastmb ;fi
dd if=/dev/urandom of=$1 skip=$number bs=1M count=1 &>/dev/null &
let bytes++;
end=$(($number+$megabyte))
if [ $number -lt $lowest ];then lowest=$number;fi;if [ $end -gt $highest ];then highest=$end;fi
#let number=number+megabyte;
now=$(date +%s)
runtime=$((${now}-${start}))
if [ "$runtime" -eq 0 ] ;then runtime=1 ;fi
if [ $now -ne $last ];then
( echo -en "\r\t ↓↓ low: "$(($lowest/1024))" KBytes ↓↓ | lowmem: "$(printf %x $smallrand)"_|_ wholedisk: "$(printf %x $number)" _||↑↑ high: "$(($highest/1024/1024))" of $mbsize bytes ↑↑|| wiped : $bytes Mbytes in $runtime sec → Ø "$(($bytes/$runtime ))" MBy/s \r ";sleep 0.01; ) &
fi
last=$now;
done
echo -e "\nWIPE PASS 1 (RAND) finished in $runtime ..\n PASS2: ZEROING DEVICE"
pv -s $size -S /dev/zero > $1
else
echo WRONG ANSWER...USER ABORT
fi