forked from wireghoul/graudit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
graudit
executable file
·99 lines (88 loc) · 2.07 KB
/
graudit
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
#!/bin/bash
# Graudit - Rough code review tool using grep
# Written by Wireghoul - http://www.justanotherhacker.com
# Released under the GPL licence
set -e
set -o pipefail
VERSION='1.3'
grdir=`dirname $0`
# Default values
context=1
color='always'
database="$grdir/signatures/default.db"
separator='##############################################'
if [ ! -x /bin/grep ]; then
echo "/bin/grep not found"
exit 2
fi
version () {
echo "Graudit version: $VERSION"
}
usage () {
cat <<EOU
Usage: graudit [opts] /path/to/scan
OPTIONS
-h show this message
-v show version number
-d database to use
-c number of lines of context to display
-z supress colors
Database is one of php, perl, rough or default, not providing a database will use default
/path is the path to the file or directory to audit
EOU
}
while getopts "hvzd:c:" opt; do
case $opt in
h)
usage
exit 1
;;
v)
version
exit 0
;;
z)
color='none'
;;
c)
context="$OPTARG"
;;
d)
sigdb="$OPTARG"
if [ "$sigdb" == '-' ]; then
database='-'
elif [ "$sigdb" == '*' ]; then
database="$grdir/signatures/*"
elif [ -f "$sigdb" ]; then
database="$sigdb"
else
database="$grdir/signatures/$sigdb.db"
fi
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
exit 2
;;
esac
done
#Remove arguments from $@
shift $((OPTIND-1))
if [ -z "$1" ]; then
usage
exit 2
fi
# -R is recursive
# -H prints the name of the file
# -C prints # lines of context before and after the match
# -E uses extended regexp
# -f specifies the rule file (signature database)
# -n prints the line number
grep --color=$color \
--exclude-dir=.svn \
--exclude-dir=.cvs \
--exclude-dir=.git \
-n -R -H -C $context -E \
-f "$database" "$@" \
| sed -e"s/--/$separator/"
exit $?