-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathfind-it.sh
executable file
·304 lines (259 loc) · 15.3 KB
/
find-it.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
#!/bin/bash
#
# A simple file identifier for code, loot, IT-tech-stuff-the-customer-throws-at-you.
# Tries to find IT security and privacy related stuff.
# For pentesters.
#
# ----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# <floyd at floyd dot ch> wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return
# floyd http://floyd.ch @floyd_ch <floyd at floyd dot ch>
# July 2013
# ----------------------------------------------------------------------------
#
# Requirements:
# - find command. Reason: Get all files and exec file with them
# - file command. Reason: To identify file types
# - grep command. Reason: We need to filter certain results
# - sort command. Reason: Uniquely sorted (if you don't have sort -u you can use uniq as well)
# - mkdir command. Reason: we need to make the $TARGET directory
#
# Howto:
# - Customize the "OPTIONS" section below to your needs
# - Copy this file to the parent directory which you want to find
# - run it like this: ./find-it.sh ./directory-to-find-through/
#
# Output:
# You can check the output with any text viewer, "less -R ./find-output/*" works fine
# Output files have the following naming conventions (separated by underscore):
# - priority: 1-5, where 1 is more interesting (low false positive rate, certainty of "vulnerability") and 5 is only "you might want to have a look"
# - section: eg. by file extension, or using the "file" command
# - name of what we looked for
###
#OPTIONS - please customize
###
FIND_COMMAND="find"
FILE_COMMAND="file"
GREP_COMMAND="grep"
SORT_COMMAND="sort"
CUT_COMMAND="cut"
ADDITIONAL_FIND_ARGUMENTS=""
#Where to put the output (if not otherwise specified on command line)
TARGET="./find-output"
#Write the comment to each file at the beginning
WRITE_COMMENT="true"
#In my opinion I would always leave all the options below here on true,
#I would only change it if the script needs very long, you are looking through a lot of stuff
#or if you have any other performance issues with this script.
#try to find file types according to the "file" command
DO_FILE_COMMAND="true"
#try to find file types according to their file extension
DO_FILEEXTENSION="true"
#try to find files according to known interesting file names
DO_FILE_NAME="true"
###
#END OPTIONS
#Normally you don't have to change anything below here...
###
###
#CODE SECTION
#As a user of this script you shouldn't need to care about the stuff that is coming down here...
###
# Conventions if you add new searches:
# - First think about which sections you want to put a new rule
# - Most of the time we use find not with regex but with the simple pattern of -iname (from the find man):
# -name pattern
# True if the last component of the pathname being examined matches
# pattern. Special shell pattern matching characters (``['',
# ``]'', ``*'', and ``?'') may be used as part of pattern. These
# characters may be matched explicitly by escaping them with a
# backslash (``\'').
# - If in doubt, prefer to make two searches and output files rather then joining with wildcards. If one produces false positives it is really annoying to search for the true positives of the other.
# - Take care with single/double quoted strings. From the bash manual:
# 3.1.2.2 Single Quotes
# Enclosing characters in single quotes (‘'’) preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.
# 3.1.2.3 Double Quotes
# Enclosing characters in double quotes (‘"’) preserves the literal value of all characters within the quotes, with the exception of ‘$’, ‘`’, ‘\’, and, when history expansion is enabled, ‘!’. The characters ‘$’ and ‘`’ retain their special meaning within double quotes (see Shell Expansions). The backslash retains its special meaning only when followed by one of the following characters: ‘$’, ‘`’, ‘"’, ‘\’, or newline. Within double quotes, backslashes that are followed by one of these characters are removed. Backslashes preceding characters without a special meaning are left unmodified. A double quote may be quoted within double quotes by preceding it with a backslash. If enabled, history expansion will be performed unless an ‘!’ appearing in double quotes is escaped using a backslash. The backslash preceding the ‘!’ is not removed. The special parameters ‘*’ and ‘@’ have special meaning when in double quotes (see Shell Parameter Expansion).
#
# TODO:
# - Delete files when find doesn't have a result. Find's exit code can't be used for that :(
# - Find PKCS#12 files and their encryption: find code-from-bitbucket-modified -iname "*.jks" -exec echo % openssl pkcs12 -info -noout -nomacver -passin pass:unknown -in {} \; -exec openssl pkcs12 -info -noout -nomacver -passin pass:unknown -in {} \; 2>&1 |ggrep -v 'PKCS7 Data'|ggrep -v 'Error outputting keys and certificates'| grep -v 'error'
if [ $# -lt 1 ]
then
echo "Usage: `basename $0` directory-to-grep-through [output-dir]"
exit 0
fi
if [ "$1" = "." ]
then
echo "You are shooting yourself in the foot. Do not find through . but rather cd into parent directory and mv `basename $0` there."
echo "READ THE HOWTO (3 lines)"
exit 0
fi
if [ $# -eq 2 ]
then
#argument without last /
TARGET=${2%/}
fi
#argument without last /
SEARCH_FOLDER=${1%/}
mkdir "$TARGET"
echo "Output will be put into this folder: $TARGET"
echo "You are currently finding through folder: $SEARCH_FOLDER"
if [ "$DO_FILE_COMMAND" = "true" ]; then
# Attention: This can take a very very long time...
MAIN_OUTFILE="3_file_all_files_listed.txt"
echo "# Info: All files and their type according to the file command" >> $TARGET/$MAIN_OUTFILE
echo "# Filename: $MAIN_OUTFILE" >> "$TARGET/$MAIN_OUTFILE"
echo "# Search: file {}" >> "$TARGET/$MAIN_OUTFILE"
echo "Searching for results for $MAIN_OUTFILE"
$FIND_COMMAND "$SEARCH_FOLDER" -exec $FILE_COMMAND '{}' \; >> $TARGET/$MAIN_OUTFILE
# ... therefore, at least don't do it again and just work on the above output
OUTFILE="2_file_all_types.txt"
echo "# Info: All types uniquely listed (according to the file command)" >> $TARGET/$OUTFILE
echo "# Filename: $OUTFILE" >> "$TARGET/$OUTFILE"
#echo "# Search: file -b {} | sort -u" >> "$TARGET/$OUTFILE"
echo "# Search: grep -v '^#' $TARGET/$MAIN_OUTFILE | cut -d ':' -f 2- | sort -u" >> "$TARGET/$OUTFILE"
echo "Searching for results for $OUTFILE"
$GREP_COMMAND -v '^#' "$TARGET/$MAIN_OUTFILE" | $CUT_COMMAND -d ":" -f 2- | $SORT_COMMAND -u >> $TARGET/$OUTFILE
OUTFILE="1_file_dot_net_decompilable_files.txt"
echo "# Info: .NET executable files (and therefore decompilable) according to file command" >> $TARGET/$OUTFILE
echo "# Filename: $OUTFILE" >> "$TARGET/$OUTFILE"
#echo "# Search: file {}|grep -i executable|grep -i '.net'" >> "$TARGET/$OUTFILE"
echo "# Search: grep -v '^#' $TARGET/$MAIN_OUTFILE |grep -i executable|grep -i '.net'" >> "$TARGET/$OUTFILE"
echo "Searching for results for $OUTFILE"
#$FIND_COMMAND "$SEARCH_FOLDER" -exec $FILE_COMMAND '{}' \; | $GREP_COMMAND -i executable | $GREP_COMMAND -i '.net' >> $TARGET/$OUTFILE
$GREP_COMMAND -v '^#' "$TARGET/$MAIN_OUTFILE" | $GREP_COMMAND -i executable | $GREP_COMMAND -i '.net' >> $TARGET/$OUTFILE
#jars are just zips according to file: Zip archive data, at least v1.0 to extract
#class: compiled Java class data, version 50.0 (Java 1.6)
OUTFILE="1_file_java_decompilable_files.txt"
echo "# Info: Java class files (and therefore decompilable) according to file command, but attention: file detects jar files as zips, so jars are not listed." >> $TARGET/$OUTFILE
echo "# Filename: $OUTFILE" >> "$TARGET/$OUTFILE"
#echo "# Search: file {}|grep -i \"Java class\"" >> "$TARGET/$OUTFILE"
echo "# Search: grep -v '^#' $TARGET/$MAIN_OUTFILE |grep -i \"Java class\"" >> "$TARGET/$OUTFILE"
echo "Searching for results for $OUTFILE"
$GREP_COMMAND -v '^#' "$TARGET/$MAIN_OUTFILE" | $GREP_COMMAND -i "Java class" >> $TARGET/$OUTFILE
fi
if [ "$DO_FILEEXTENSION" = "true" ]; then
OUTFILE="2_find_pfx.txt"
echo "# Info: All pfx files (certificates and private key) according to their file extension" >> $TARGET/$OUTFILE
echo "# Filename: $OUTFILE" >> "$TARGET/$OUTFILE"
echo "# Search: find -iname '*.pfx'" >> "$TARGET/$OUTFILE"
echo "Searching for results for $OUTFILE"
$FIND_COMMAND "$SEARCH_FOLDER" -iname '*.pfx' >> $TARGET/$OUTFILE
OUTFILE="2_find_p12.txt"
echo "# Info: All p12 files (certificates and private key) according to their file extension" >> $TARGET/$OUTFILE
echo "# Filename: $OUTFILE" >> "$TARGET/$OUTFILE"
echo "# Search: find -iname '*.p12'" >> "$TARGET/$OUTFILE"
echo "Searching for results for $OUTFILE"
$FIND_COMMAND "$SEARCH_FOLDER" -iname '*.p12' >> $TARGET/$OUTFILE
OUTFILE="2_find_pem.txt"
echo "# Info: All pem files (certificates and private key) according to their file extension" >> $TARGET/$OUTFILE
echo "# Filename: $OUTFILE" >> "$TARGET/$OUTFILE"
echo "# Search: find -iname '*.pem'" >> "$TARGET/$OUTFILE"
echo "Searching for results for $OUTFILE"
$FIND_COMMAND "$SEARCH_FOLDER" -iname '*.pem' >> $TARGET/$OUTFILE
OUTFILE="2_find_key.txt"
echo "# Info: All key files (private key) according to their file extension" >> $TARGET/$OUTFILE
echo "# Filename: $OUTFILE" >> "$TARGET/$OUTFILE"
echo "# Search: find -iname '*.key'" >> "$TARGET/$OUTFILE"
echo "Searching for results for $OUTFILE"
$FIND_COMMAND "$SEARCH_FOLDER" -iname '*.key' >> $TARGET/$OUTFILE
OUTFILE="2_find_htpasswd.txt"
echo "# Info: All htpasswd files (web authorization passwords) according to their file name" >> $TARGET/$OUTFILE
echo "# Filename: $OUTFILE" >> "$TARGET/$OUTFILE"
echo "# Search: find -iname '*htpasswd*'" >> "$TARGET/$OUTFILE"
echo "Searching for results for $OUTFILE"
$FIND_COMMAND "$SEARCH_FOLDER" -iname '*htpasswd*' >> $TARGET/$OUTFILE
OUTFILE="1_find_azure_publishsettings.txt"
echo "# Info: All publishsettings files (Azure settings file) according to their file extension" >> $TARGET/$OUTFILE
echo "# Filename: $OUTFILE" >> "$TARGET/$OUTFILE"
echo "# Search: find -iname '*.publishsettings'" >> "$TARGET/$OUTFILE"
echo "Searching for results for $OUTFILE"
$FIND_COMMAND "$SEARCH_FOLDER" -iname '*.publishsettings' >> $TARGET/$OUTFILE
OUTFILE="4_find_class.txt"
echo "# Info: All class files (decompilable!) according to their file extension" >> $TARGET/$OUTFILE
echo "# Filename: $OUTFILE" >> "$TARGET/$OUTFILE"
echo "# Search: find -iname '*.class'" >> "$TARGET/$OUTFILE"
echo "Searching for results for $OUTFILE"
$FIND_COMMAND "$SEARCH_FOLDER" -iname '*.class' >> $TARGET/$OUTFILE
OUTFILE="4_find_jar.txt"
echo "# Info: All class files (decompilable!) according to their file extension" >> $TARGET/$OUTFILE
echo "# Filename: $OUTFILE" >> "$TARGET/$OUTFILE"
echo "# Search: find -iname '*.jar'" >> "$TARGET/$OUTFILE"
echo "Searching for results for $OUTFILE"
$FIND_COMMAND "$SEARCH_FOLDER" -iname '*.jar' >> $TARGET/$OUTFILE
OUTFILE="4_find_php.txt"
echo "# Info: All php files (cleartext!) according to their file extension (.php .php5 etc.)" >> $TARGET/$OUTFILE
echo "# Filename: $OUTFILE" >> "$TARGET/$OUTFILE"
echo "# Search: find -iname '*.php?'" >> "$TARGET/$OUTFILE"
echo "Searching for results for $OUTFILE"
$FIND_COMMAND "$SEARCH_FOLDER" -iname '*.php?' >> $TARGET/$OUTFILE
OUTFILE="3_find_db.txt"
echo "# Info: All sqlite or other database files (cleartext?) according to their file extension (.db)" >> $TARGET/$OUTFILE
echo "# Filename: $OUTFILE" >> "$TARGET/$OUTFILE"
echo "# Search: find -iname '*.db'" >> "$TARGET/$OUTFILE"
echo "Searching for results for $OUTFILE"
$FIND_COMMAND "$SEARCH_FOLDER" -iname '*.db' >> $TARGET/$OUTFILE
OUTFILE="3_find_c.txt"
echo "# Info: All c files (cleartext?) according to their file extension (.c)" >> $TARGET/$OUTFILE
echo "# Filename: $OUTFILE" >> "$TARGET/$OUTFILE"
echo "# Search: find -iname '*.c'" >> "$TARGET/$OUTFILE"
echo "Searching for results for $OUTFILE"
$FIND_COMMAND "$SEARCH_FOLDER" -iname '*.c' >> $TARGET/$OUTFILE
OUTFILE="5_find_html.txt"
echo "# Info: All html files according to their file extension (.html .htm)" >> $TARGET/$OUTFILE
echo "# Filename: $OUTFILE" >> "$TARGET/$OUTFILE"
echo "# Search: find -iname '*.htm?'" >> "$TARGET/$OUTFILE"
echo "Searching for results for $OUTFILE"
$FIND_COMMAND "$SEARCH_FOLDER" -iname '*.htm?' >> $TARGET/$OUTFILE
OUTFILE="5_find_javascript.txt"
echo "# Info: All javascript files according to their file extension (.js)" >> $TARGET/$OUTFILE
echo "# Filename: $OUTFILE" >> "$TARGET/$OUTFILE"
echo "# Search: find -iname '*.js?'" >> "$TARGET/$OUTFILE"
echo "Searching for results for $OUTFILE"
$FIND_COMMAND "$SEARCH_FOLDER" -iname '*.js?' >> $TARGET/$OUTFILE
OUTFILE="5_find_log.txt"
echo "# Info: All log files according to their file extension (.log .log1 .log2)" >> $TARGET/$OUTFILE
echo "# Filename: $OUTFILE" >> "$TARGET/$OUTFILE"
echo "# Search: find -iname '*.log?'" >> "$TARGET/$OUTFILE"
echo "Searching for results for $OUTFILE"
$FIND_COMMAND "$SEARCH_FOLDER" -iname '*.log?' >> $TARGET/$OUTFILE
OUTFILE="5_find_all_others.txt"
echo "# Info: All files with file extensions we didn't looked for yet" >> $TARGET/$OUTFILE
echo "# Filename: $OUTFILE" >> "$TARGET/$OUTFILE"
echo "# Search: find | grep -v '.class|.jar|.php|.db|.htm|.js'" >> "$TARGET/$OUTFILE"
echo "Searching for results for $OUTFILE"
$FIND_COMMAND "$SEARCH_FOLDER" | $GREP_COMMAND -v '.pfx|.publishsettings|.class|.jar|.php|.db|.c|.htm|.log|.js' >> $TARGET/$OUTFILE
fi
if [ "$DO_FILE_NAME" = "true" ]; then
OUTFILE="1_filename_web-xml.txt"
echo "# Info: web.xml is the Spring frameworks main mapping XML and important to understand which URLs are mapped to where" >> $TARGET/$OUTFILE
echo "# Filename: $OUTFILE" >> "$TARGET/$OUTFILE"
echo "# Search: find -iname 'web.xml'" >> "$TARGET/$OUTFILE"
echo "Searching for results for $OUTFILE"
$FIND_COMMAND "$SEARCH_FOLDER" -iname 'web.xml' >> $TARGET/$OUTFILE
OUTFILE="1_filename_commons-collection.txt"
echo "# Info: commons-collection can be used to exploit deserialization issues. Deserialization is something that can result in remote command execution, there are various exploits for such things, see http://foxglovesecurity.com/2015/11/06/what-do-weblogic-websphere-jboss-jenkins-opennms-and-your-application-have-in-common-this-vulnerability/ for example" >> $TARGET/$OUTFILE
echo "# Filename: $OUTFILE" >> "$TARGET/$OUTFILE"
echo "# Search: find -iname '*commons*collection*'" >> "$TARGET/$OUTFILE"
echo "Searching for results for $OUTFILE"
$FIND_COMMAND "$SEARCH_FOLDER" -iname '*commons*collection*' >> $TARGET/$OUTFILE
#TODO filenames:
#wsadmin.properties configuration file of Websphere
#TODO:
#random
#sql
#database
#keychain
#shadow
#passwd
#key
#salt
#pass
#secret
#pin
#authorization
#authentication
fi