Add update support to searchsploit
This commit is contained in:
parent
c263b4d439
commit
ac19b0c0b3
1 changed files with 65 additions and 29 deletions
94
searchsploit
94
searchsploit
|
@ -1,44 +1,49 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# exploitdb CLI search tool
|
# exploitdb CLI search tool
|
||||||
# Version 2
|
# Version 3
|
||||||
# Written by Unix-Ninja
|
# Written by Unix-Ninja
|
||||||
|
|
||||||
csvpath=/usr/share/exploitdb/files.csv
|
gitremote=https://github.com/offensive-security/exploit-database.git
|
||||||
|
gitpath=/usr/share/exploitdb
|
||||||
|
csvpath=${gitpath}/files.csv
|
||||||
progname=`basename $0`
|
progname=`basename $0`
|
||||||
TAGS=
|
TAGS=
|
||||||
SCASE='-i'
|
SCASE='-i'
|
||||||
|
UPDATE=0
|
||||||
VERBOSE=0
|
VERBOSE=0
|
||||||
|
|
||||||
# if files.csv is in the searchsploit source path, use that
|
# NOTE:
|
||||||
scriptsrc=$0
|
# Exit code 0 means finished normally
|
||||||
while [ -h $scriptsrc ]; do
|
# Exit code 6 means updated from github
|
||||||
scriptsrc=$(readlink $scriptsrc)
|
|
||||||
[[ $scriptsrc != /* ]] && scriptsrc="$( cd -P $( dirname $scriptsrc ) && pwd )/$scriptsrc"
|
# if files.csv is in the searchsploit path, use that
|
||||||
done
|
if [ -f "$( dirname $0 )/files.csv" ]; then
|
||||||
progdir="$( cd -P "$( dirname "$scriptsrc" )" && pwd )"
|
csvpath="$( dirname $0 )/files.csv"
|
||||||
if [ -f "$progdir/files.csv" ]; then
|
|
||||||
csvpath="$progdir/files.csv"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# usage info
|
# usage info
|
||||||
function usage()
|
function usage()
|
||||||
{
|
{
|
||||||
echo "Usage : $progname [OPTIONS] term1 [term2] ... [termN]"
|
echo "Usage: $progname [options] term1 [term2] ... [termN]"
|
||||||
echo "Example: $progname oracle windows local"
|
echo "Example: $progname oracle windows local"
|
||||||
echo
|
echo
|
||||||
echo "========="
|
echo "========="
|
||||||
echo " OPTIONS "
|
echo " Options "
|
||||||
echo "========="
|
echo "========="
|
||||||
echo " -c - Perform case-sensitive searches; by default,"
|
echo " -c Perform case-sensitive searches; by default, searches will"
|
||||||
echo " searches will try to be greedy"
|
echo " try to be greedy"
|
||||||
echo " -v - By setting verbose output, description lines"
|
echo " -h, --help Show help screen"
|
||||||
echo " are allowed to overflow their columns"
|
echo " -u Update db from git"
|
||||||
echo " -h, --help - Show help screen"
|
echo " -v By setting verbose output, description lines are allowed to"
|
||||||
|
echo " overflow their columns"
|
||||||
echo
|
echo
|
||||||
echo "NOTES:"
|
echo "======="
|
||||||
echo " - Use any number of search terms you would like (minimum: 1)"
|
echo " NOTES "
|
||||||
echo " - Search terms are not case sensitive, and order is irrelevant"
|
echo "======="
|
||||||
exit 0
|
echo " * Use any number of search terms you would like (minimum: 1)"
|
||||||
|
echo " * Search terms are not case sensitive, and order is irrelevant"
|
||||||
|
echo " * When updating from git, searches will be ignored"
|
||||||
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# dynamically set column widths
|
# dynamically set column widths
|
||||||
|
@ -66,26 +71,57 @@ for param in $@; do
|
||||||
done
|
done
|
||||||
|
|
||||||
# parse short arguments
|
# parse short arguments
|
||||||
while getopts "chv" arg $ARGS; do
|
while getopts "chuv" arg $ARGS; do
|
||||||
if [ "$arg" = "?" ]; then
|
if [ "$arg" = "?" ]; then
|
||||||
usage >&2;
|
usage >&2;
|
||||||
fi
|
fi
|
||||||
case $arg in
|
case $arg in
|
||||||
c) SCASE='';;
|
c) SCASE='';;
|
||||||
h) usage >&2;;
|
h) usage >&2;;
|
||||||
|
u) UPDATE=1;;
|
||||||
v) VERBOSE=1;;
|
v) VERBOSE=1;;
|
||||||
esac
|
esac
|
||||||
shift $((OPTIND-1))
|
shift $((OPTIND-1))
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# was an update requested?
|
||||||
|
if [ "$UPDATE" -eq 1 ]; then
|
||||||
|
cd $gitpath
|
||||||
|
# make sure a git repo is init before updating
|
||||||
|
if [ "$(git rev-parse --is-inside-work-tree)" != "true" ]; then
|
||||||
|
if [ "$(ls)" = "" ]; then
|
||||||
|
#if directory is empty, just clone
|
||||||
|
git clone $gitremote .
|
||||||
|
else
|
||||||
|
# if not empty, init and add remote
|
||||||
|
git init > /dev/null
|
||||||
|
git remote add origin $gitremote
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
# make sure to prep checkout first
|
||||||
|
git checkout -- .
|
||||||
|
# update from github
|
||||||
|
git pull origin master
|
||||||
|
# if conflicts, clean and try again
|
||||||
|
if [ "$?" -ne 0 ]; then
|
||||||
|
git clean -d -fx ""
|
||||||
|
git pull origin master
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Update finished."
|
||||||
|
exit 6
|
||||||
|
fi
|
||||||
|
|
||||||
# print header
|
# print header
|
||||||
printf "%0.s-" `eval echo {1..$(( $COL1 + 1 ))}`
|
printf "%0.s-" `eval echo {1..$(( $COL1 + 1 ))}`
|
||||||
echo -n "|"
|
echo -n " "
|
||||||
printf "%0.s-" `eval echo {1..$(( $COL2 - 1 ))}`
|
printf "%0.s-" `eval echo {1..$(( $COL2 - 1 ))}`
|
||||||
printf "%-${COL1}s |%s" " Description"
|
|
||||||
echo " Path"
|
printf "%-${COL1}s %s" " Description"
|
||||||
|
echo "| Path"
|
||||||
|
|
||||||
printf "%0.s-" `eval echo {1..$(( $COL1 + 1 ))}`
|
printf "%0.s-" `eval echo {1..$(( $COL1 + 1 ))}`
|
||||||
echo -n "|"
|
echo -n " "
|
||||||
printf "%0.s-" `eval echo {1..$(( $COL2 - 1 ))}`
|
printf "%0.s-" `eval echo {1..$(( $COL2 - 1 ))}`
|
||||||
echo
|
echo
|
||||||
|
|
||||||
|
@ -114,7 +150,7 @@ fi
|
||||||
| eval $SEARCH
|
| eval $SEARCH
|
||||||
|
|
||||||
printf "%0.s-" `eval echo {1..$(( $COL1 + 1 ))}`
|
printf "%0.s-" `eval echo {1..$(( $COL1 + 1 ))}`
|
||||||
echo -n "|"
|
echo -n " "
|
||||||
printf "%0.s-" `eval echo {1..$(( $COL2 - 1 ))}`
|
printf "%0.s-" `eval echo {1..$(( $COL2 - 1 ))}`
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Add table
Reference in a new issue