improved wording for not finding file
[feisty_meow.git] / scripts / security / shellshock_test.sh
1 #!/bin/bash
2 EXITCODE=0
3
4 # this file was downloaded with this command:
5 # curl https://shellshocker.net/shellshock_test.sh >shellshock_test.sh
6
7 # CVE-2014-6271
8 CVE20146271=$(env 'x=() { :;}; echo vulnerable' 'BASH_FUNC_x()=() { :;}; echo vulnerable' bash -c "echo test" 2>&1 | grep 'vulnerable' | wc -l)
9
10 echo -n "CVE-2014-6271 (original shellshock): "
11 if [ $CVE20146271 -gt 0 ]; then
12         echo -e "\033[91mVULNERABLE\033[39m"
13         EXITCODE=$((EXITCODE+1))
14 else
15         echo -e "\033[92mnot vulnerable\033[39m"
16 fi
17
18 # CVE-2014-6277
19 # it is fully mitigated by the environment function prefix passing avoidance
20 CVE20146277=$((shellshocker="() { x() { _;}; x() { _;} <<a; }" bash -c date 2>/dev/null || echo vulnerable) | grep 'vulnerable' | wc -l)
21
22 echo -n "CVE-2014-6277 (segfault): "
23 if [ $CVE20146277 -gt 0 ]; then
24         echo -e "\033[91mVULNERABLE\033[39m"
25         EXITCODE=$((EXITCODE+2))
26 else
27         echo -e "\033[92mnot vulnerable\033[39m"
28 fi
29
30 # CVE-2014-6278
31 CVE20146278=$(shellshocker='() { echo vulnerable; }' bash -c shellshocker 2>/dev/null | grep 'vulnerable' | wc -l)
32
33 echo -n "CVE-2014-6278 (Florian's patch): "
34 if [ $CVE20146278 -gt 0 ]; then
35         echo -e "\033[91mVULNERABLE\033[39m"
36         EXITCODE=$((EXITCODE+4))
37 else
38         echo -e "\033[92mnot vulnerable\033[39m"
39 fi
40
41 # CVE-2014-7169
42 CVE20147169=$((cd /tmp; rm -f /tmp/echo; env X='() { (a)=>\' bash -c "echo echo nonvuln" 2>/dev/null; [[ "$(cat echo 2> /dev/null)" == "nonvuln" ]] && echo "vulnerable" 2> /dev/null) | grep 'vulnerable' | wc -l)
43
44 echo -n "CVE-2014-7169 (taviso bug): "
45 if [ $CVE20147169 -gt 0 ]; then
46         echo -e "\033[91mVULNERABLE\033[39m"
47         EXITCODE=$((EXITCODE+8))
48 else
49         echo -e "\033[92mnot vulnerable\033[39m"
50 fi
51
52 # CVE-2014-7186
53 CVE20147186=$((bash -c 'true <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF' 2>/dev/null || echo "vulnerable") | grep 'vulnerable' | wc -l)
54
55 echo -n "CVE-2014-7186 (redir_stack bug): "
56 if [ $CVE20147186 -gt 0 ]; then
57         echo -e "\033[91mVULNERABLE\033[39m"
58         EXITCODE=$((EXITCODE+16))
59 else
60         echo -e "\033[92mnot vulnerable\033[39m"
61 fi
62
63 # CVE-2014-7187
64 CVE20147187=$(((for x in {1..200}; do echo "for x$x in ; do :"; done; for x in {1..200}; do echo done; done) | bash || echo "vulnerable") | grep 'vulnerable' | wc -l)
65
66 echo -n "CVE-2014-7187 (nested loops off by one): "
67 if [ $CVE20147187 -gt 0 ]; then
68         echo -e "\033[91mVULNERABLE\033[39m"
69         EXITCODE=$((EXITCODE+32))
70 else
71         echo -e "\033[92mnot vulnerable\033[39m"
72 fi
73
74 # CVE-2014-////
75 CVE2014=$(env X=' () { }; echo vulnerable' bash -c 'date' | grep 'vulnerable' | wc -l)
76
77 echo -n "CVE-2014-//// (exploit 3 on http://shellshocker.net/): "
78 if [ $CVE2014 -gt 0 ]; then
79         echo -e "\033[91mVULNERABLE\033[39m"
80         EXITCODE=$((EXITCODE+64))
81 else
82         echo -e "\033[92mnot vulnerable\033[39m"
83 fi
84
85 exit $EXITCODE