-
Notifications
You must be signed in to change notification settings - Fork 4
/
initialize-target.sh
executable file
·120 lines (99 loc) · 2.85 KB
/
initialize-target.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
#!/usr/bin/env bash
set -e
SGXFUZZ_ROOT=$(dirname "$(realpath "$0")")
FEATURES=(
"-struct_size_havoc"
"-no_struct_ptr_loc_havoc -no_struct_recovery -no_struct_size_detection"
"-no_struct_ptr_loc_havoc -no_struct_size_detection"
"-no_struct_ptr_loc_havoc"
"-no_struct_ptr_loc_havoc -struct_size_havoc"
)
if [[ " $*" == *" -h"* ]]; then
echo "$(basename "$0") <run-name> <enclave.mem> [ablation id]"
for (( i = 0; i < ${#FEATURES[@]}; i++ )); do
echo " $i: ${FEATURES[$i]}"
done
exit 0
fi
# eval name
NAME=$1
# enclave memory dump
ENCLAVE=$(realpath "$2")
BASE=$(realpath ./)
for t in "$ENCLAVE.tcs.txt" \
"$(dirname "$ENCLAVE")/$(basename -s .mem "$ENCLAVE").tcs.txt" \
"$(dirname "$ENCLAVE")/tcs.txt"; do
if [[ -r "$t" ]]; then
tcs=$(realpath "$t")
break
fi
done
if [[ ! -r "$tcs" ]]; then
echo "TCS not found"
exit 1
fi
echo "Using TCS: $tcs"
TYPE=${3:-0}
FEATURE=${FEATURES[$TYPE]}
if [[ -z $FEATURE ]]; then
echo "Invalid Type: $TYPE"
exit 1
fi
echo "Using Type $TYPE ($FEATURE)"
count=0
evaldir="$BASE/$NAME-T$TYPE-$(date +%F)"
while [[ -e $evaldir ]]; do
count=$((count+1))
evaldir="$BASE/$NAME-T$TYPE-$(date +%F)_$count"
done
mkdir -p "$evaldir/sgx_workdir"
cp -r seeds/ "$evaldir/"
cd "$evaldir"
"$SGXFUZZ_ROOT/native-sgx-runner/make-enclave-fuzz-target.sh" "$ENCLAVE" "$tcs" --no-reload
mv "$(basename "$ENCLAVE").fuzz" "$(basename "$ENCLAVE").fuzz-noreload"
ln -rs "$(basename "$ENCLAVE").fuzz-noreload" fuzz-generic
"$SGXFUZZ_ROOT/native-sgx-runner/make-enclave-fuzz-target.sh" "$ENCLAVE" "$tcs"
fuzz_target=$(basename "$ENCLAVE").fuzz
cp "$SGXFUZZ_ROOT/native-sgx-runner/build/liblibnyx_dummy.so" ./
args=""
if [[ -r "$(dirname "$ENCLAVE")/init.raw" ]]; then
cp "$(dirname "$ENCLAVE")/init.raw" ./
args="-args init.raw"
fi
share_dir=/tmp/$(basename $evaldir)_fuzz_folder
PY2=$(realpath "$SGXFUZZ_ROOT/venv-python2/bin/python2")
PY3=$(realpath "$SGXFUZZ_ROOT/venv-python3/bin/python3")
cat > pack.sh <<EOF
#!/usr/bin/env bash
mkdir -p "$share_dir"
LD_LIBRARY_PATH=. \\
"$PY2" "$(realpath "$SGXFUZZ_ROOT/packer/packer/nyx_packer.py")" \\
"$fuzz_target" \\
"$share_dir" \\
m64 --legacy --purge --no_pt_auto_conf_b --fast_reload_mode \\
--delayed_init \\
$args
EOF
cat > fuzz.sh <<EOF
#!/usr/bin/env bash
# -struct_size_havoc
# -no_struct_recovery
# -no_struct_ptr_loc_havoc
# -no_struct_size_detection
"$PY3" "$(realpath "$SGXFUZZ_ROOT/kafl/kAFL-Fuzzer/kafl_fuzz.py")" \\
-sharedir "$share_dir" \\
-work_dir "$evaldir/sgx_workdir" \\
-initrd "$(realpath "$SGXFUZZ_ROOT/packer/linux_initramfs/init.cpio.gz")" \\
-kernel "$(realpath "$SGXFUZZ_ROOT/packer/linux_initramfs/bzImage-linux-4.15-rc7")" \\
-seed_dir "$evaldir/seeds/" \\
--purge \\
-R \\
-mem 512 \\
-funky \\
-p 40 \\
-redqueen -redq_do_simple \\
$FEATURE \\
-abort_time 24 \\
|& tee fuzzer.log
EOF
chmod +x pack.sh fuzz.sh