forked from wireghoul/graudit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graudit
executable file
·198 lines (183 loc) · 4.76 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
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
#!/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='2.3'
basedir=$(dirname "$0")
BINFILE=$(which grep)
# Default values
hidebanner=0
context=1
zimlines="#"
vimlines="#"
color='always'
sigdb='default'
separator='##############################################'
excludefiles='--exclude=*.bz2 --exclude=*.gz --exclude=*.zip --exclude=*.rar --exclude=*.gif --exclude=*.jpg --exclude=*.png'
#Save custom colors
OLD_COLORS=$GREP_COLORS
OLD_COLOR=$GREP_COLOR
if [ ! -x "$BINFILE" ]; then
echo "grep not found!"
exit 2
fi
$BINFILE --exclude-dir=. test "$0" >/dev/null 2>&1
if [ $? -eq 2 ]; then
echo $?
echo "graudit requires a newer version of grep (>=2.5.3)"
exit 2
fi
banner() {
if [ $hidebanner == 0 ]; then
echo \
'===========================================================
.___ __ __
_________________ __ __ __| _/|__|/ |_
/ ___\_` __ \__ \ | | \/ __ | | \\_ __\
/ /_/ > | \// __ \| | / /_/ | | || |
\___ /|__| (____ /____/\____ | |__||__|
/_____/ \/ \/
grep rough audit - static analysis tool
v2.3 written by @Wireghoul
=================================[justanotherhacker.com]==='
fi
}
version () {
echo "graudit version: $VERSION"
}
usage () {
banner
cat <<EOU
Usage: graudit [opts] /path/to/scan
OPTIONS
-d <dbname> database to use or /path/to/file.db (uses default if not specified)
-A scan ALL files
-x exclude these files (comma separated list: -x *.js,*.sql)
-i case in-sensitive scan
-c <num> number of lines of context to display, default is 2
-B supress banner
-L vim friendly lines
-b colour blind friendly template
-z supress colors
-Z high contrast colors
-l lists databases available
-v prints version number
-h prints this help screen
EOU
}
listdb () {
banner
if [ -n "$GRDIR" ] && [ -d "$GRDIR" ]; then
ls -1 "$GRDIR/*.db"
fi
if [ -d /usr/share/graudit/ ]; then
ls -1 /usr/share/graudit/*.db
fi
if [ -d ~/.graudit/ ]; then
ls -1 ~/.graudit/*.db
fi
if [ -d "$basedir"/signatures/ ]; then
ls -1 "$basedir"/signatures/*.db
fi
}
while getopts "AbBhvilLzZd:c:x:" opt; do
case $opt in
B)
hidebanner=1
;;
h)
usage
exit 1
;;
v)
version
exit 0
;;
l)
listdb
exit 0
;;
b)
export GREP_COLORS='ms=93:sl=:cx=:fn=94:ln=92:bn=92:se=32'
export GREP_COLOR='1;35'
;;
z)
color='none'
;;
Z)
export GREP_COLORS='ms=41;01;37:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36'
export GREP_COLOR='1;37;41;'
;;
c)
context="$OPTARG"
;;
d)
sigdb="$OPTARG"
;;
i)
icase="-i"
;;
x)
OIFS=$IFS
IFS=','
for ign in $OPTARG; do
ignorepattern="$ignorepattern --exclude=$ign"
done
IFS=$OIFS
;;
L)
zimlines="s/\([:-]\)\([0-9][0-9]*\)\([:-]\)/ \+\2\3/"
#\(\x1b\[.*m\x1b\[K\)
vimlines="s/\(\x1b.*\)\([:-]\)\(\x1b\[.*\)\([0-9][0-9]*\)\(\x1b.*\)\([:-]\)/\1 +\3\4\5\6/"
;;
A)
excludefiles=""
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
exit 2
;;
esac
done
#Remove arguments from $@
shift $((OPTIND-1))
#Database location can vary based on installation
if [ "$sigdb" == '-' ]; then
database='-'
elif [ -f "$GRDIR/$sigdb.db" ]; then
database="$GRDIR/$sigdb.db"
elif [ -f "/usr/share/graudit/$sigdb.db" ]; then
database="/usr/share/graudit/$sigdb.db"
elif [ -f "$HOME/.graudit/$sigdb.db" ]; then
database="$HOME/.graudit/$sigdb.db"
elif [ -f "$basedir/signatures/$sigdb.db" ]; then
database="$basedir/signatures/$sigdb.db"
else
database="$sigdb"
fi
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
banner
$BINFILE --color=$color \
--exclude-dir=.svn \
--exclude-dir=CVS \
--exclude-dir=.git \
$excludefiles \
$icase $ignorepattern \
-n -R -H -C "$context" -E \
-f "$database" "$@" \
| sed -e"s/^\(\x1b\[.*m\x1b\[K\)--\(\x1b\[.*\x1b\[K\)$/\1##############################################\2/" -e"s/^--$/$separator/" | sed -e"$vimlines" -e"$zimlines"
SUCCESS=$?
export GREP_COLORS="$OLD_COLORS"
exit $SUCCESS