Skip to content

Commit 2af7b4d

Browse files
author
Offensive Security
committed
Merge branch 'g0tmi1k-searchsploit'
2 parents 49a8e7d + 8610384 commit 2af7b4d

2 files changed

Lines changed: 145 additions & 89 deletions

File tree

README.md

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
The Exploit-Database Git Repository
22
===================================
33

4-
This is the official repository of [The Exploit Database](http://www.exploit-db.com/), a project sponsored by [Offensive Security](https://www.offensive-security.com/).
4+
This is the official repository of [The Exploit Database](https://www.exploit-db.com/), a project sponsored by [Offensive Security](https://www.offensive-security.com/).
55

66
The Exploit Database is an archive of public exploits and corresponding vulnerable software, developed for use by penetration testers and vulnerability researchers. Its aim is to serve as the most comprehensive collection of exploits gathered through direct submissions, mailing lists, and other public sources, and present them in a freely-available and easy-to-navigate database. The Exploit Database is a repository for exploits and proof-of-concepts rather than advisories, making it a valuable resource for those who need actionable data right away.
77

@@ -11,42 +11,46 @@ Included with this repository is the **searchsploit** utility, which will allow
1111

1212
```
1313
root@kali:~# searchsploit -h
14-
Usage: searchsploit [OPTIONS] term1 [term2] ... [termN]
14+
Usage: searchsploit [options] term1 [term2] ... [termN]
1515
Example:
1616
searchsploit afd windows local
1717
searchsploit -t oracle windows
1818
1919
=========
2020
Options
2121
=========
22-
-c, --case Perform a case-sensitive search (Default is insensitive).
23-
-h, --help Show this help screen.
24-
-t, --title Search just the exploit title (Default is title AND the file's path).
25-
-u, --update Update exploit database from git.
26-
-v, --verbose Verbose output. Title lines are allowed to overflow their columns.
27-
-w, --www Show URLs to Exploit-DB.com rather than local path.
28-
--colour Disable colour highlighting.
29-
--id Display EDB-ID value rather than local path.
22+
-c, --case Perform a case-sensitive search (Default is inSEnsITiVe).
23+
-e, --exact Perform an EXACT match on exploit title (Default is AND) [Implies "-t"].
24+
-h, --help Show this help screen.
25+
-o, --overflow Exploit title's are allowed to overflow their columns.
26+
-t, --title Search just the exploit title (Default is title AND the file's path).
27+
-u, --update Update exploit database from git.
28+
-w, --www Show URLs to Exploit-DB.com rather than local path.
29+
--id Display EDB-ID value rather than local path.
30+
--colour Disable colour highlighting.
3031
3132
=======
3233
Notes
3334
=======
34-
* Use any number of search terms, in any order.
35+
* Use any number of search terms.
3536
* Search terms are not case sensitive, and order is irrelevant.
3637
* Use '-c' if you wish to reduce results by case-sensitive searching.
37-
* Use '-t' to exclude the file's path to filter the search results.
38-
* Could possibly remove false positives (especially when searching numbers).
38+
* And/Or '-e' if you wish to filter results by using an exact match.
39+
* Use '-t' to exclude the file's path to filter the search results.
40+
* Remove false positives (especially when searching numbers/versions).
3941
* When updating from git or displaying help, search terms will be ignored.
4042
4143
root@kali:~# searchsploit afd windows local
42-
------------------------------------------------------------ ----------------------------------
43-
Exploit Title | Path
44-
| (/usr/share/exploitdb/platforms)
45-
------------------------------------------------------------ ----------------------------------
46-
MS Windows XP/2003 - AFD.sys Privilege Escalation Exploit (K| /windows/local/6757.txt
47-
Microsoft Windows XP - AFD.sys Local Kernel DoS Exploit | /windows/dos/17133.c
48-
Windows XP/2003 Afd.sys - Local Privilege Escalation Exploit| /windows/local/18176.py
49-
Windows - AfdJoinLeaf Privilege Escalation (MS11-080) | /windows/local/21844.rb
50-
------------------------------------------------------------ ----------------------------------
44+
--------------------------------------------------------------------------------- ----------------------------------
45+
Exploit Title | Path
46+
| (/usr/share/exploitdb/platforms)
47+
--------------------------------------------------------------------------------- ----------------------------------
48+
Microsoft Windows 2003/XP - AFD.sys Privilege Escalation Exploit (K-plugin) | ./windows/local/6757.txt
49+
Microsoft Windows XP - AFD.sys Local Kernel DoS Exploit | ./windows/dos/17133.c
50+
Microsoft Windows XP/2003 Afd.sys - Local Privilege Escalation Exploit (MS11-080)| ./windows/local/18176.py
51+
Microsoft Windows - AfdJoinLeaf Privilege Escalation (MS11-080) | ./windows/local/21844.rb
52+
Microsoft Windows - AFD.SYS Dangling Pointer Privilege Escalation (MS14-040) | ./win32/local/39446.py
53+
Microsoft Windows 7 x64 - AFD.SYS Privilege Escalation (MS14-040) | ./win64/local/39525.py
54+
--------------------------------------------------------------------------------- ----------------------------------
5155
root@kali:~#
5256
```

searchsploit

Lines changed: 119 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/bin/bash
2-
# Name: searchsploit - Exploit-DB's CLI search tool
3-
# Version: 3.1 (Release date: 2015-07-08)
2+
# Name: SearchSploit - Exploit-DB's CLI search tool
3+
# Version: 3.2 (Release date: 2016-03-18)
44
# Written by: Offensive Security, Unix-Ninja & g0tmi1k
55
# Homepage: https://github.com/offensive-security/exploit-database
6-
6+
#
77
## NOTE:
88
# Exit code '0' means finished normally
99
# Exit code '1' means finished help screen
@@ -14,18 +14,29 @@
1414
gitpath="/usr/share/exploitdb"
1515
csvpath="${gitpath}/files.csv"
1616

17+
1718
## Program settings
1819
gitremote="https://github.com/offensive-security/exploit-database.git"
1920
progname="$( basename "$0" )"
2021

22+
2123
## Default options
22-
TAGS=""
23-
SCASE="tolower"
24-
VERBOSE=0
25-
WEBLINK=0
24+
COLOUR=1
2625
EDBID=0
27-
COLOUR='true'
26+
EXACT=0
2827
FILEPATH=1
28+
OVERFLOW=0
29+
WEBLINK=0
30+
SCASE=0
31+
TAGS=""
32+
CASE_TAG_GREP="-i"
33+
CASE_TAG_FGREP="tolower"
34+
COLOUR_TAG=""
35+
SEARCH=""
36+
37+
38+
## Set LANG variable to avoid illegal byte sequence errors
39+
LANG=C
2940

3041

3142
## If files.csv is in the searchsploit path, use that instead
@@ -45,23 +56,25 @@ function usage()
4556
echo "========="
4657
echo " Options "
4758
echo "========="
48-
echo " -c, --case Perform a case-sensitive search (Default is insensitive)."
49-
echo " -h, --help Show this help screen."
50-
echo " -t, --title Search just the exploit title (Default is title AND the file's path)."
51-
echo " -u, --update Update exploit database from git."
52-
echo " -v, --verbose Verbose output. Title lines are allowed to overflow their columns."
53-
echo " -w, --www Show URLs to Exploit-DB.com rather than local path."
54-
echo " --colour Disable colour highlighting."
55-
echo " --id Display EDB-ID value rather than local path."
59+
echo " -c, --case Perform a case-sensitive search (Default is inSEnsITiVe)."
60+
echo " -e, --exact Perform an EXACT match on exploit title (Default is AND) [Implies \"-t\"]."
61+
echo " -h, --help Show this help screen."
62+
echo " -o, --overflow Exploit title's are allowed to overflow their columns."
63+
echo " -t, --title Search just the exploit title (Default is title AND the file's path)."
64+
echo " -u, --update Update exploit database from git."
65+
echo " -w, --www Show URLs to Exploit-DB.com rather than local path."
66+
echo " --id Display EDB-ID value rather than local path."
67+
echo " --colour Disable colour highlighting."
5668
echo
5769
echo "======="
5870
echo " Notes "
5971
echo "======="
60-
echo " * Use any number of search terms, in any order."
72+
echo " * Use any number of search terms."
6173
echo " * Search terms are not case sensitive, and order is irrelevant."
6274
echo " * Use '-c' if you wish to reduce results by case-sensitive searching."
75+
echo " * And/Or '-e' if you wish to filter results by using an exact match."
6376
echo " * Use '-t' to exclude the file's path to filter the search results."
64-
echo " * Could possibly remove false positives (especially when searching numbers)."
77+
echo " * Remove false positives (especially when searching numbers/versions)."
6578
echo " * When updating from git or displaying help, search terms will be ignored."
6679
echo ""
6780
exit 1
@@ -70,10 +83,11 @@ function usage()
7083
## Update database (via GIT)
7184
function update()
7285
{
86+
## Make sure we are in the correct folder
7387
mkdir -p "${gitpath}/"
7488
cd "${gitpath}/"
7589

76-
# Make sure a git repo is init before updating
90+
## Make sure a git repo is init before updating
7791
if [[ "$( git rev-parse --is-inside-work-tree )" != "true" ]]; then
7892
if [[ "$( ls )" = "" ]]; then
7993
# If directory is empty, just clone
@@ -122,19 +136,21 @@ fi
122136
ARGS="-"
123137
for param in "$@"; do
124138
if [[ "${param}" == "--case" ]]; then
125-
SCASE=''
139+
SCASE=1
140+
elif [[ "${param}" == "--exact" ]]; then
141+
EXACT=1
126142
elif [[ "${param}" == "--help" ]]; then
127143
usage >&2
144+
elif [[ "${param}" == "--overflow" ]]; then
145+
OVERFLOW=1
128146
elif [[ "${param}" == "--title" ]]; then
129147
FILEPATH=0
130148
elif [[ "${param}" == "--update" ]]; then
131149
update
132150
elif [[ "${param}" == "--www" ]]; then
133151
WEBLINK=1
134-
elif [[ "${param}" == "--verbose" ]]; then
135-
VERBOSE=1
136152
elif [[ "${param}" == "--colour" ]] || [[ "${param}" == "--color" ]]; then
137-
COLOUR=''
153+
COLOUR=""
138154
elif [[ "${param}" == "--id" ]]; then
139155
EDBID=1
140156
else
@@ -149,24 +165,39 @@ done
149165

150166

151167
## Parse short arguments
152-
while getopts "chtuvw" arg "${ARGS}"; do
168+
while getopts "cehotuw" arg "${ARGS}"; do
153169
if [[ "${arg}" = "?" ]]; then
154170
usage >&2;
155171
fi
156172
case ${arg} in
157-
c) SCASE='';;
173+
c) SCASE=1;;
174+
e) EXACT=1;;
158175
h) usage >&2;;
176+
o) OVERFLOW=1;;
159177
t) FILEPATH=0;;
160178
u) update;;
161-
v) VERBOSE=1;;
162179
w) WEBLINK=1;;
163180
esac
164181
shift $(( OPTIND - 1 ))
165182
done
166183

167184

168-
## Dynamically set column widths
169-
if [[ "${WEBLINK}" -eq '1' ]]; then
185+
## If we are doing an exact match, do not check folder path.
186+
if [[ "${EXACT}" -eq 1 ]]; then
187+
FILEPATH=0
188+
fi
189+
190+
191+
## Case sensitive?
192+
if [[ "${SCASE}" -eq 1 ]]; then
193+
## Remove the default flags
194+
CASE_TAG_GREP=""
195+
CASE_TAG_FGREP=""
196+
fi
197+
198+
199+
## Dynamically set column widths to the current screen size
200+
if [[ "${WEBLINK}" -eq 1 ]]; then
170201
COL2=45
171202
else
172203
COL2=35
@@ -177,9 +208,9 @@ COL1=$(( $( tput cols ) - COL2 - 1 ))
177208
## Print header
178209
drawline
179210
printf "%-${COL1}s %s" " Exploit Title"
180-
if [[ "${WEBLINK}" -eq '1' ]]; then
211+
if [[ "${WEBLINK}" -eq 1 ]]; then
181212
echo "| URL"
182-
elif [[ "${EDBID}" -eq '1' ]]; then
213+
elif [[ "${EDBID}" -eq 1 ]]; then
183214
echo "| EDB-ID"
184215
else
185216
echo "| Path"
@@ -188,69 +219,90 @@ else
188219
fi
189220
drawline
190221

191-
## Create (AND) search command
192-
SEARCH=
193-
for tag in ${TAGS}; do
194222

195-
if [[ "${COLOUR}" ]]; then
196-
COLOUR="${COLOUR}\|${tag}"
223+
## EXACT search command?
224+
if [[ "${EXACT}" -eq 1 ]]; then
225+
## Case sensitive?
226+
if [[ "${SCASE}" -eq 1 ]]; then
227+
SEARCH="${TAGS}"
228+
else
229+
SEARCH="$( echo ${TAGS} | tr '[:upper:]' '[:lower:]' )"
197230
fi
198231

199-
if [[ "${FILEPATH}" -eq 1 ]]; then
200-
if [[ "${SCASE}" ]]; then
201-
SCASE='-i'
202-
fi
232+
## Remove leading space
233+
SEARCH="$(echo ${SEARCH} | sed -e 's/^[[:space:]]//')"
203234

204-
if [[ "${SEARCH}" ]]; then
205-
SEARCH="${SEARCH} |"
235+
## If we are to use colour, add the values to search for
236+
if [[ "${COLOUR}" -eq 1 ]]; then
237+
COLOUR_TAG="${SEARCH}"
238+
fi
239+
## or AND search command?
240+
else
241+
## For each term
242+
for tag in ${TAGS}; do
243+
## If we are to use colour, add the values to search for between "or"
244+
if [[ "${COLOUR}" -eq 1 ]]; then
245+
COLOUR_TAG="${COLOUR_TAG}\|${tag}"
206246
fi
207247

208-
SEARCH="${SEARCH} fgrep ${SCASE} \"${tag}\""
209-
else
210-
if [[ "${SEARCH}" ]]; then
211-
SEARCH="${SEARCH}/ && ${SCASE}(\$1) ~ /"
212-
fi
248+
## Search both title and path?
249+
if [[ "${FILEPATH}" -eq 1 ]]; then
250+
## Is there a value already?
251+
if [[ "${SEARCH}" ]]; then
252+
SEARCH="${SEARCH} |"
253+
fi
213254

214-
if [[ "${SCASE}" ]]; then
215-
tag="$( echo ${tag} | tr '[:upper:]' '[:lower:]' )"
255+
## Search command for each term
256+
SEARCH="${SEARCH} fgrep ${CASE_TAG_GREP} \"${tag}\""
257+
## Search just the title, not the path
258+
else
259+
## If there is already a value, prepend text to get ready
260+
if [[ "${SEARCH}" ]]; then
261+
SEARCH="${SEARCH}/ && ${CASE_TAG_FGREP}(\$1) ~ /"
262+
fi
263+
264+
## Case sensitive?
265+
if [[ "${SCASE}" -eq 1 ]]; then
266+
EARCH="${SEARCH}${tag}"
267+
else
268+
SEARCH="${SEARCH}$( echo ${tag} | tr '[:upper:]' '[:lower:]' )"
269+
fi
216270
fi
217-
218-
SEARCH="${SEARCH}${tag}"
219-
fi
220-
done
221-
222-
if [[ "${FILEPATH}" -ne 1 ]]; then
223-
SEARCH="awk -F '[|]' '${SCASE}(\$1) ~ /${SEARCH}/ {print}'"
271+
done
224272
fi
225273

226-
if [[ "${COLOUR}" ]]; then
227-
SEARCH="${SEARCH} | grep --color=always -ie \"\${COLOUR}\""
274+
275+
## If we are not to use the path name
276+
if [[ "${FILEPATH}" -eq 0 ]]; then
277+
SEARCH="awk -F '[|]' '${CASE_TAG_FGREP}(\$1) ~ /${SEARCH}/ {print}'"
228278
fi
229279

230280

231-
## Set LANG variable to avoid illegal byte sequence errors
232-
LANG=C
281+
## If we are to use colour, add the value here
282+
if [[ "${COLOUR_TAG}" ]]; then
283+
SEARCH="${SEARCH} | grep --color=always -ie \"\${COLOUR_TAG}\""
284+
fi
233285

234286

235287
## Search, format, and print results
236-
if [[ "${VERBOSE}" -eq 0 ]]; then
237-
FORMAT=${COL1}'.'${COL1}
238-
else
288+
if [[ "${OVERFLOW}" -eq 1 ]]; then
239289
FORMAT=${COL1}
290+
else
291+
FORMAT=${COL1}'.'${COL1}
240292
fi
241293

242294

295+
## Magic search Fu
243296
## Web link format?
244-
if [[ "${WEBLINK}" -eq '1' ]]; then
245-
## Magic search Fu
297+
if [[ "${WEBLINK}" -eq 1 ]]; then
246298
awk -F "\"*,\"*" '{ printf "%-'${FORMAT}'s | %s\n", $3, "https://www.exploit-db.com/exploits/"$1"/"}' "${csvpath}" \
247299
| eval "${SEARCH}"
248-
elif [[ "${EDBID}" -eq '1' ]]; then
249-
## Magic search Fu
300+
## Just the EDB-ID?
301+
elif [[ "${EDBID}" -eq 1 ]]; then
250302
awk -F "\"*,\"*" '{ printf "%-'${FORMAT}'s | %s\n", $3, $1}' "${csvpath}" \
251303
| eval "${SEARCH}"
304+
## Default view
252305
else
253-
## Magic search Fu
254306
awk -F "\"*,\"*" '{ printf "%-'${FORMAT}'s | %s\n", $3, $2}' "${csvpath}" \
255307
| eval "${SEARCH}" \
256308
| sed "s/| platforms/| ./"

0 commit comments

Comments
 (0)