Skip to content

Commit 05b3932

Browse files
Add files via upload
1 parent 75f296c commit 05b3932

11 files changed

+200
-27
lines changed

src/delay.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
3+
# give a chance to network configuration and DHCP, then continue
4+
# but don't rely on them, since it could stop the whole solution
5+
# (eg. on Wifi-only computers, where we don't know the password)
6+
sleep 15
7+
8+
# additional time on Fit-PC2 and possibly other boards,
9+
# due to slower Wi-fi autoconfiguration on them
10+
if [ -d /sys/class/dmi/id ] && grep -q CompuLab /sys/class/dmi/id/board_vendor; then
11+
sleep 10
12+
fi
13+
14+
# additional time to allow smooth start of X environment
15+
if [ "`ps aux |grep Xorg |grep -v grep`" != "" ]; then
16+
sleep 20
17+
fi

src/functions

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
lock() {
3+
local lock="/run/`basename $1`.lock"
4+
exec 9>$lock
5+
if ! flock -n 9; then exit 1; fi
6+
}
7+
8+
show() {
9+
if [ ! -d /opt/drivebadger/external/ext-mobile-drivers ]; then
10+
logger -p user.info -t "badger-event[$$]" -- "$1 [$2]"
11+
else
12+
/opt/drivebadger/external/ext-mobile-drivers/event.sh "$1" "$2"
13+
fi
14+
}

src/get-first-persistent-partition.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
3+
# FIXME: this can work improperly, if:
4+
# - user connects 2 Kali Linux Live USB drives
5+
# - the first one is NVMe
6+
# - the second is not NVMe
7+
# - Kali Linux will be booted from the second one
8+
# - first persistent partition after boot will be mounted from the first one
9+
#
10+
# sample output from get-persistent-partitions.sh:
11+
#
12+
# /dev/mapper/sdb3
13+
# /dev/mapper/sdc3
14+
#
15+
# and medium should be eg. "sdb" (this allows choosing the proper partition)
16+
# or empty (first persistent partition is most usually the correct one)
17+
#
18+
medium=`mount |grep live/medium |grep iso9660 |grep ^/dev/sd |cut -d' ' -f1 |sed -e 's/\/dev\///g' -e 's/[0-9]//g'`
19+
20+
21+
if [ "$medium" != "" ]; then
22+
/opt/drivebadger/internal/kali/get-persistent-partitions.sh |grep "$medium"
23+
else
24+
/opt/drivebadger/internal/kali/get-persistent-partitions.sh |head -n 1
25+
fi

src/get-keys-directory.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
3+
# In Drive Badger mode, keys_directory is created if not exists. This is ok, because
4+
# Drive Badger is meant to be used mostly with encrypted storage - so keys are also
5+
# encrypted.
6+
#
7+
# On the other hand, Mobile Badger can only use unencrypted storage, so administrator
8+
# has to choose, if/where to create this directory - and create it manually.
9+
#
10+
# If keys_directory is not present (not created manually) on target drive, then the
11+
# one from internal SD storage will be used.
12+
13+
BASE="/media/target"
14+
FALLBACK="/etc/drivebadger/keys"
15+
16+
if [ -d $BASE/.support/.keys ]; then
17+
echo $BASE/.support/.keys
18+
elif [ -d $BASE/.files/.keys ]; then
19+
echo $BASE/.files/.keys
20+
elif [ -d $BASE/files/keys ]; then
21+
echo $BASE/files/keys
22+
else
23+
echo $FALLBACK
24+
fi

src/get-metadata-directory.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
echo /var/cache/drivebadger/metadata

src/get-persistent-partitions.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
3+
partitions=`mount |grep live/persistence |grep -v 'type overlay' |grep -v 'type iso9660' |grep rw |cut -d' ' -f1`
4+
5+
for part in $partitions; do
6+
if [ -f /run/live/persistence/`basename $part`/persistence.conf ]; then
7+
echo $part
8+
fi
9+
done

src/get-target-directory.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/sh
2+
3+
# Discover subdirectory inside target drive (all copied data is stored inside
4+
# hidden subdirectory to prevent accidental showing such data to 3rd party in
5+
# case of forced inspection etc. - it's definitely not enough to call it
6+
# "secure", however it's often enough in real life).
7+
8+
BASE="/media/target"
9+
FALLBACK="/media/fallback"
10+
11+
if [ -d $BASE/.support/.files ]; then
12+
SUBDIR=$BASE/.support/.files
13+
elif [ -d $BASE/.files/.data ]; then
14+
SUBDIR=$BASE/.files/.data
15+
elif [ -d $BASE/files/data ]; then
16+
SUBDIR=$BASE/files/data
17+
else
18+
SUBDIR=$FALLBACK
19+
fi
20+
21+
TARGET="$SUBDIR/`date +%Y%m%d`"
22+
mkdir -p $TARGET
23+
echo $TARGET

src/main.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/sh
2+
3+
perdev=`/opt/drivebadger/internal/kali/get-first-persistent-partition.sh`
4+
5+
if [ "$perdev" != "" ]; then
6+
target_partition=`basename $perdev`
7+
target_drive=`/opt/drivebadger/internal/generic/get-partition-drive.sh $target_partition`
8+
9+
target_raw_device=`/opt/drivebadger/internal/generic/get-raw-device.sh $perdev` # sdb3 or dm-0
10+
logger "persistent partition $perdev on device $target_raw_device"
11+
12+
id=`/opt/drivebadger/internal/generic/get-computer-id.sh`
13+
target_root_directory=`/opt/drivebadger/internal/kali/get-target-directory.sh $target_partition`
14+
target_directory=$target_root_directory/$id
15+
keys_directory=`/opt/drivebadger/internal/kali/get-keys-directory.sh $target_partition`
16+
17+
mkdir -p $target_directory $keys_directory
18+
/opt/drivebadger/internal/generic/dump-debug-files.sh $target_directory
19+
20+
for uuid in `ls /dev/disk/by-uuid`; do
21+
tmp=`readlink /dev/disk/by-uuid/$uuid`
22+
current_partition=`basename $tmp` # dm-0 is handled properly below, but dm-1 etc. not - fix before reusing this code in different context
23+
current_drive=`/opt/drivebadger/internal/generic/get-partition-drive.sh $current_partition`
24+
25+
if [ "$current_partition" = "$target_raw_device" ] || [ "$current_partition" = "$target_partition" ]; then
26+
logger "skipping UUID=$uuid (partition $current_partition matches target $target_partition)"
27+
elif [ "$current_drive" = "$target_drive" ]; then
28+
logger "skipping UUID=$uuid (partition $current_partition lays on the same target drive $target_drive as target partition $target_partition)"
29+
else
30+
fs=`/opt/drivebadger/internal/generic/get-partition-fs-type.sh $current_partition $target_directory`
31+
drive_serial=`/opt/drivebadger/internal/generic/get-drive-serial.sh $current_drive $target_directory`
32+
33+
if [ "$fs" = "swap" ]; then
34+
logger "skipping UUID=$uuid (swap partition $current_partition)"
35+
elif [ "$fs" = "apfs" ]; then
36+
nohup /opt/drivebadger/internal/generic/mount/apfs.sh $target_root_directory $target_directory $keys_directory "$drive_serial" $current_partition $uuid 2>/dev/null
37+
elif [ "$fs" = "crypto_LUKS" ]; then
38+
nohup /opt/drivebadger/internal/generic/mount/luks.sh $target_root_directory $target_directory $keys_directory "$drive_serial" $current_partition $uuid 2>/dev/null
39+
else
40+
nohup /opt/drivebadger/internal/generic/mount/plain.sh $target_root_directory $target_directory $keys_directory "$drive_serial" $current_partition $uuid $fs 2>/dev/null
41+
fi
42+
fi
43+
done
44+
45+
# now process encrypted drives
46+
47+
for current_partition in `/opt/drivebadger/internal/generic/get-udev-unrecognized-devices.sh`; do
48+
current_drive=`/opt/drivebadger/internal/generic/get-partition-drive.sh $current_partition`
49+
drive_serial=`/opt/drivebadger/internal/generic/get-drive-serial.sh $current_drive $target_directory`
50+
fs=`/opt/drivebadger/internal/generic/get-partition-fs-type.sh $current_partition $target_directory`
51+
52+
if [ "$fs" = "VMFS_volume_member" ]; then
53+
nohup /opt/drivebadger/internal/generic/mount/vmfs.sh $target_root_directory $target_directory $keys_directory "$drive_serial" $current_partition 2>/dev/null
54+
else
55+
nohup /opt/drivebadger/internal/generic/mount/unrecognized.sh $target_root_directory $target_directory $keys_directory "$drive_serial" $current_partition 2>/dev/null
56+
fi
57+
58+
done
59+
60+
logger "finished processing drives and partitions"
61+
fi

src/rebuild-uuid-lists.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
TYPES="target ignore"
4+
5+
for TYPE in $TYPES; do
6+
FILE=/var/cache/drivebadger/$TYPE.uuid.generated
7+
echo "# generated at `date`" >$FILE.new
8+
cat /opt/drivebadger/config/*/$TYPE.uuid |grep -v ^$ |grep -v "^#" >>$FILE.new
9+
mv -f $FILE.new $FILE
10+
done

src/show-key-stats.sh

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,5 @@
11
#!/bin/sh
22

3-
if [ "$1" = "" ]; then
4-
echo "usage: $0 [keys-directory]"
5-
exit 0
6-
elif [ ! -d $1 ]; then
7-
echo "error: invalid keys directory $1"
8-
exit 1
9-
fi
3+
keys_directory=`/opt/drivebadger/internal/mobile/get-keys-directory.sh`
104

11-
keys_directory=$1
12-
tmpfile=`mktemp -p /run`
13-
14-
echo "encryption mode | keys assigned to drives | repo keys unassigned | common | total repo keys | unique repo keys"
15-
echo "--------------------------------------------------------------------------------------------------------------"
16-
17-
for encryption_mode in apfs bitlocker luks veracrypt; do
18-
19-
keys_assigned=`cat $keys_directory/*.$encryption_mode 2>/dev/null |wc -l`
20-
cat $keys_directory/*.$encryption_mode 2>/dev/null >$tmpfile
21-
22-
keys_unassigned=`cat /opt/drivebadger/config/*/$encryption_mode.keys 2>/dev/null |grep -v "^#" |grep -v ^$ |grep -vxFf $tmpfile |wc -l`
23-
keys_common=`cat /opt/drivebadger/config/*/$encryption_mode.keys 2>/dev/null |grep -v "^#" |grep -v ^$ |grep -xFf $tmpfile |wc -l`
24-
keys_total_repos=`cat /opt/drivebadger/config/*/$encryption_mode.keys 2>/dev/null |grep -v "^#" |grep -v ^$ |wc -l`
25-
keys_total_unique=`cat /opt/drivebadger/config/*/$encryption_mode.keys 2>/dev/null |grep -v "^#" |grep -v ^$ |sort |uniq |wc -l`
26-
27-
printf "%-15s | %-23d | %-20d | %-6d | %-15d | %d \n" $encryption_mode $keys_assigned $keys_unassigned $keys_common $keys_total_repos $keys_total_unique |sed 's/ 0 / /g'
28-
done
29-
30-
rm -f $tmpfile
5+
/opt/drivebadger/internal/generic/keys/show-key-stats.sh $keys_directory

src/show-spooler-tasks.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
perdev=`/opt/drivebadger/internal/kali/get-first-persistent-partition.sh`
4+
5+
if [ "$perdev" != "" ]; then
6+
target_partition=`basename $perdev`
7+
target_root_directory=`/opt/drivebadger/internal/kali/get-target-directory.sh $target_partition`
8+
target_base=`dirname $target_root_directory`
9+
tsp |sed -r -e "s#/opt/drivebadger/hooks/hook-virtual/handle-image.sh ##g" -e "s#/media/(.*)/mnt/#\1 #g" -e "s#/media/(.*)/mnt##g" -e "s#$target_base/##g"
10+
else
11+
tsp |sed -r -e "s#/opt/drivebadger/hooks/hook-virtual/handle-image.sh ##g" -e "s#/media/(.*)/mnt/#\1 #g" -e "s#/media/(.*)/mnt##g"
12+
fi

0 commit comments

Comments
 (0)