forked from OpenSC/OpenSC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-fuzzing.sh
executable file
·51 lines (42 loc) · 1.09 KB
/
test-fuzzing.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
#!/bin/bash
set -ex
case "$1" in
"pkcs11-tool")
CMD="src/tools/pkcs11-tool --test --login --pin 123456"
;;
"pkcs15-tool")
CMD="src/tools/pkcs15-tool --dump"
;;
"eidenv")
CMD="src/tools/eidenv"
;;
*)
echo "Unknown fuzzing target"
exit 1
;;
esac
IN=tests/fuzzing-testcases
if [ ! -d "$IN" ]
then
mkdir -p "$IN"
echo -ne "$(printf '\\x90\\x00')" > "$IN"/9000
fi
# reuse output directory if possible
OUT="out-$1"
if [ -d "$OUT" ]
then
IN=-
fi
if [ ! -d x41-smartcard-fuzzing ];
then
git clone https://github.com/x41sec/x41-smartcard-fuzzing
fi
gcc -shared -fPIC -o x41-smartcard-fuzzing/scard_override/libsccard_override.so x41-smartcard-fuzzing/scard_override/scard_override.c -ldl -I/usr/include/PCSC/
if [ ! -f configure ];
then
autoreconf -vis
fi
#export AFL_USE_ASAN=1
./configure CC=afl-gcc CFLAGS="-O0" --disable-shared --disable-notify --with-pcsc-provider=$PWD/x41-smartcard-fuzzing/scard_override/libsccard_override.so
make
FUZZ_FILE=input.apdu afl-fuzz -i "$IN" -o "$OUT" -f input.apdu $CMD