forked from IntelLabs/kAFL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·310 lines (268 loc) · 7.45 KB
/
install.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#!/bin/bash
#LINUX_VERSION="5.4.55"
LINUX_VERSION="5.7.12"
LINUX_VERSION="5.8.12"
LINUX_URL="https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-${LINUX_VERSION}.tar.xz"
#QEMU_VERSION="4.2.0"
QEMU_VERSION="5.0.0"
QEMU_URL="https://download.qemu.org/qemu-${QEMU_VERSION}.tar.xz"
echo "================================================="
echo " kAFL auto-magic installer "
echo "================================================="
checked_download()
{
filename="$1"
url="$2"
if [ ! -f "$filename" ]; then
echo "[*] Downloading $filename ..."
wget -O "$filename" "$url"
fi
grep $filename sha256sums.lst | sha256sum -c || exit
}
check_gitconfig()
{
if [ ! "`git config --get user.name`" ] || [ ! "`git config --get user.email`" ]; then
echo "[-] Error: The installer uses git in order to manage local patches against qemu and linux sources."
echo " Please setup a valid git config in order for this to work:"
echo
echo " $ git config --global user.name Joe User"
echo " $ git config --global user.email [email protected]"
echo
exit 1
fi
}
system_check()
{
echo
echo "[*] Performing basic sanity checks..."
if [ ! "`uname -s`" = "Linux" ]; then
echo "[-] Error: KVM-PT is supported only on Linux ..."
exit 1
fi
grep -q ^flags.*intel_pt /proc/cpuinfo
if [ $? -ne 0 ]; then
echo "According to /proc/cpuinfo this system has no intel_pt."
exit 1
fi
dist_id="$(lsb_release -si)"
if [ "$dist_id" != "Debian" -a "$dist_id" != "Ubuntu" ]; then
echo "[-] Error: This installer was tested using recent Debian and Ubuntu."
echo
echo "Other recent Linux distributions will generally work as well but"
echo "the installer will not be able to resolve the required dependencies."
echo
echo "It is recommended to abort the installer and instead follow this"
echo "script by hand, resolving any build/runtime errors as they come up."
echo
echo "Press [Ctrl-c] to abort or [Return] to continue.."
read
fi
for i in dpkg apt-get sudo; do
T=`which "$i" 2>/dev/null`
if [ "$T" = "" ]; then
echo "[-] Error: '$i' not found, please install first."
exit 1
fi
done
check_gitconfig
}
system_deps()
{
echo
echo "[*] Installing essentials tools ..."
sudo apt-get install git make gcc bc libssl-dev pax-utils libelf-dev \
libgraphviz-dev gnuplot ruby libgtk-3-dev libc6-dev flex bison \
python3 python3-pip python3-all-dev python3-setuptools python3-wheel -y
echo "[*] Installing build dependencies for QEMU ..."
sudo apt-get build-dep qemu-system-x86 -y
# libcapstone is an optional qemu feature but a hard requirement for kAFL
sudo apt-get install libcapstone-dev libcapstone3
echo "[*] Installing kAFL python dependencies ..."
pip3 install --user mmh3 lz4 psutil fastrand ipdb inotify msgpack toposort pygraphviz pgrep tqdm six python-dateutil
}
build_qemu()
{
echo
echo "[*] Building Qemu ${QEMU_VERSION} ..."
check_gitconfig
if [ -d "qemu-${QEMU_VERSION}" ]; then
echo "[*] Folder exists, skipping download + patching..."
pushd "qemu-${QEMU_VERSION}"
else
checked_download "qemu-${QEMU_VERSION}.tar.xz" "$QEMU_URL"
tar xf "qemu-${QEMU_VERSION}.tar.xz" || exit
pushd "qemu-${QEMU_VERSION}"
git init
git add .
git commit -m "vanilla qemu-${QEMU_VERSION}"
echo "[*] Applying QEMU patches ..."
git am ../patches/qemu/v${QEMU_VERSION}/00*.patch
fi
echo "[*] Building ..."
echo "-------------------------------------------------"
./configure --target-list=i386-softmmu,x86_64-softmmu --enable-vnc --enable-gtk --enable-pt --enable-redqueen --disable-werror
make -j $jobs
echo
echo "-------------------------------------------------"
echo "Qemu build should be done now. Note that you do not have to install this Qemu build into the system."
echo "Just update kAFL-Fuzzer/kafl.ini to point it in the proper direction:"
echo
echo QEMU_KAFL_LOCATION = qemu-${QEMU_VERSION}/x86_64-softmmu/qemu-system-x86_64
echo
popd
}
build_linux()
{
echo
echo "[*] Building Linux $LINUX_VERSION ..."
check_gitconfig
if [ -d linux-${LINUX_VERSION} ]; then
echo "[*] Folder exists, assume it is already patched.."
pushd "linux-${LINUX_VERSION}"
else
checked_download "linux-${LINUX_VERSION}.tar.xz" "$LINUX_URL"
tar xf "linux-${LINUX_VERSION}.tar.xz" || exit
pushd "linux-${LINUX_VERSION}" || exit
git init
git add .
git commit -m "vanilla linux-${LINUX_VERSION}"
echo "[*] Applying Linux patches ..."
BASE_VERSION=$(echo $LINUX_VERSION|sed "s/\.[0-9]*$//")
git am ../patches/kvm/v${BASE_VERSION}/*.patch
fi
echo "[*] Building ..."
echo "-------------------------------------------------"
# use current/system config as base, but limit modules to actual used..
yes ""|make oldconfig
#make localmodconfig
./scripts/config --set-str CONFIG_LOCALVERSION "-kAFL" --set-val CONFIG_KVM_VMX_PT y
./scripts/config --set-str CONFIG_SYSTEM_TRUSTED_KEYS ""
make -j $jobs
echo "-------------------------------------------------"
popd
}
build_radamsa()
{
echo
echo "[*] Building radamsa..."
check_gitconfig
if [ -d radamsa ]; then
echo "[*] Folder exists, skipping download..."
else
git clone https://gitlab.com/akihe/radamsa.git radamsa
fi
echo "[*] Building ..."
make -j $jobs -C radamsa
}
build_targets()
{
echo
echo "[*] Building Target components ..."
pushd targets
bash compile.sh
popd
}
system_perms()
{
echo
echo "[*] Fix permissions for user access to /dev/kvm..."
echo
sudo groupmod kvm
if [ $? -ne 0 ]; then
echo "Creating group kvm for user $USER to access /dev/kvm.."
echo "KERNEL==\"kvm\", GROUP=\"kvm\"" | sudo -Eu root tee /etc/udev/rules.d/40-permissions.rules > /dev/null
sudo groupadd kvm
sudo usermod -a -G kvm $USER
sudo root service udev restart
else
id|grep -q '(kvm)'
if [ $? -eq 0 ]; then
echo "KVM already seems to be setup for user $USER, skipping.."
else
echo "Group KVM already exists, adding this user $USER.."
sudo usermod -a -G kvm $USER
fi
fi
}
print_help()
{
echo
echo "Usage: ./install <action>"
echo
echo "Perform complete installation or limit to individual action:"
echo
echo " check - check for basic requirements"
echo " deps - install dependencies"
echo " qemu - download and build modified qemu"
echo " linux - download and build modified linux kernel"
echo " perms - create kvm group and add user <$USER> for /dev/kvm access"
echo " radamsa - download and build radamsa plugin"
echo
echo " all - perform all of the above."
echo
}
install_note()
{
echo "To install the patched kernel, try something like this:"
echo
echo " $ cd linux-${LINUX_VERSION}"
echo " $ # optionally set 'MODULES=dep' in /etc/initramfs-tools/initramfs.conf"
echo " $ sudo make INSTALL_MOD_STRIP=1 modules_install"
echo " $ sudo make install"
echo
}
####################################
# main()
####################################
# Auto-scale building with number of CPUs. Override with ./install -j N <action>
jobs=$(nproc)
[ "$1" = "-j" ] && [ -n $2 ] && [ $2 -gt 0 ] && jobs=$2 && shift 2
#echo "Detected $(nproc) cores, building with -j $jobs..."
case $1 in
"check")
system_check
;;
"deps")
system_check
system_deps
;;
"radamsa")
build_radamsa
;;
"qemu")
build_qemu
;;
"linux")
build_linux
;;
"targets")
build_targets
;;
"perms")
system_perms
;;
"all")
system_deps
build_qemu
build_linux
build_radamsa
system_perms
build_targets
;;
"note")
install_note
;;
*)
print_help
exit
;;
esac
echo
echo "[*] All done."
echo
case $1 in
"linux"|"all")
install_note
;;
esac
exit