Code clean up

This commit is contained in:
g0tmi1k 2017-06-14 15:58:12 +01:00
parent 2170122160
commit 62241c3543

View file

@ -9,7 +9,7 @@
# Exit code '0' means finished normally # Exit code '0' means finished normally
# Exit code '1' means something went wrong # Exit code '1' means something went wrong
# Exit code '2' means help screen # Exit code '2' means help screen
# Exit code '6' means updated exploitdb package (deb or git) # Exit code '6' means updated exploitdb package (APT or Git)
## OS settings (get the path of where the script is stored + database file) ## OS settings (get the path of where the script is stored + database file)
@ -60,16 +60,16 @@ LANG=C
function usage() function usage()
{ {
echo " Usage: ${progname} [options] term1 [term2] ... [termN]" echo " Usage: ${progname} [options] term1 [term2] ... [termN]"
echo echo ""
echo "==========" echo "=========="
echo " Examples " echo " Examples "
echo "==========" echo "=========="
echo " ${progname} afd windows local" echo " ${progname} afd windows local"
echo " ${progname} -t oracle windows" echo " ${progname} -t oracle windows"
echo " ${progname} -p 39446" echo " ${progname} -p 39446"
echo echo ""
echo " For more examples, see the manual: https://www.exploit-db.com/searchsploit/" echo " For more examples, see the manual: https://www.exploit-db.com/searchsploit/"
echo echo ""
echo "=========" echo "========="
echo " Options " echo " Options "
echo "=========" echo "========="
@ -88,6 +88,7 @@ function usage()
echo " --id Display the EDB-ID value rather than local path." echo " --id Display the EDB-ID value rather than local path."
echo " --nmap [file.xml] Checks all results in Nmap's XML output with service version (e.g.: nmap -sV -oX file.xml)." echo " --nmap [file.xml] Checks all results in Nmap's XML output with service version (e.g.: nmap -sV -oX file.xml)."
echo " Use \"-v\" (verbose) to try even more combinations" echo " Use \"-v\" (verbose) to try even more combinations"
echo ""
echo "=======" echo "======="
echo " Notes " echo " Notes "
echo "=======" echo "======="
@ -97,7 +98,7 @@ function usage()
echo " * And/Or '-e' if you wish to filter results by using an exact match." echo " * And/Or '-e' if you wish to filter results by using an exact match."
echo " * Use '-t' to exclude the file's path to filter the search results." echo " * Use '-t' to exclude the file's path to filter the search results."
echo " * Remove false positives (especially when searching using numbers - i.e. versions)." echo " * Remove false positives (especially when searching using numbers - i.e. versions)."
echo " * When updating from git or displaying help, search terms will be ignored." echo " * When updating or displaying help, search terms will be ignored."
echo "" echo ""
exit 2 exit 2
} }
@ -120,7 +121,7 @@ function update()
updatedbrew updatedbrew
fi fi
# Update via git # Update via Git
updategit updategit
# Done # Done
@ -131,7 +132,7 @@ function update()
## Update database (via .deb/apt) ## Update database (via .deb/apt)
function updatedeb() function updatedeb()
{ {
echo -e '[i] Updating via APT package management. Expect weekly-ish updates.\n' echo -e '[i] Updating via APT package management (Expect weekly-ish updates).\n'
sudo apt update \ sudo apt update \
|| echo -e '\n[-] Issue with apt update (Please check network connectivity & APT SourcesList values).' 1>&2 || echo -e '\n[-] Issue with apt update (Please check network connectivity & APT SourcesList values).' 1>&2
@ -153,17 +154,17 @@ function updatedbrew()
echo -e "\n[*] Brew update finished." echo -e "\n[*] Brew update finished."
} }
## Update database (via GIT) ## Update database (via Git)
function updategit() function updategit()
{ {
echo -e '[i] Updating via git. Expect daily updates.\n' echo -e '[i] Updating via Git (Expect daily updates).\n'
## Make sure we are in the correct folder ## Make sure we are in the correct folder
mkdir -p "${gitpath}/" \ mkdir -p "${gitpath}/" \
|| sudo mkdir -p "${gitpath}/" || sudo mkdir -p "${gitpath}/"
cd "${gitpath}/" cd "${gitpath}/"
## Are we in a git repo? ## Are we in a Git repo?
if [[ "$( git rev-parse --is-inside-work-tree )" != "true" ]]; then if [[ "$( git rev-parse --is-inside-work-tree )" != "true" ]]; then
if [[ "$( ls )" = "" ]]; then if [[ "$( ls )" = "" ]]; then
# If directory is empty, just clone # If directory is empty, just clone
@ -172,9 +173,9 @@ function updategit()
fi fi
fi fi
# Is our git remote added? (aka homebrew) # Is our Git remote added? (aka homebrew)
if [[ "$( git remote -v )" != *"${gitremote}"* ]]; then if [[ "$( git remote -v )" != *"${gitremote}"* ]]; then
echo -e '\n[i] Missing git remote:' "${gitremote}" echo -e '\n[i] Missing Git remote:' "${gitremote}"
git init >/dev/null git init >/dev/null
git remote add origin "${gitremote}" 2>/dev/null git remote add origin "${gitremote}" 2>/dev/null
fi fi
@ -478,7 +479,7 @@ fi
## Read in XML ## Read in XML
if [[ "${XML}" -eq 1 ]]; then if [[ "${XML}" -eq 1 ]]; then
## Trim white spaces ## Trim white spaces
FILE=$(echo ${TAGS} | xargs) FILE=$( echo ${TAGS} | xargs )
## Is there a file? ## Is there a file?
if [[ ! -f "${FILE}" ]]; then if [[ ! -f "${FILE}" ]]; then
@ -488,7 +489,7 @@ if [[ "${XML}" -eq 1 ]]; then
if ! hash xmllint 2>/dev/null; then if ! hash xmllint 2>/dev/null; then
echo -e '\n[!] Please install xmllint' 1>&2 echo -e '\n[!] Please install xmllint' 1>&2
echo -e '[i] Kali Linux -> apt install -y libxml2-utils' 1>&2 echo -e '[i] Kali Linux -> apt -y install libxml2-utils' 1>&2
exit 1 exit 1
fi fi
@ -506,13 +507,13 @@ fi
## Print the full path. If pbcopy/xclip is available then copy to the clipboard ## Print the full path. If pbcopy/xclip is available then copy to the clipboard
if [[ "${GETPATH}" -eq 1 ]]; then if [[ "${GETPATH}" -eq 1 ]]; then
for exploit in $(echo ${TAGS}); do for exploit in $( echo ${TAGS} ); do
## Get EDB-ID from input ## Get EDB-ID from input
edbdb="$( echo ${exploit} | rev | cut -d '/' -f1 | rev | cut -d'.' -f1 | tr -dc '0-9' )" edbdb="$( echo ${exploit} | rev | cut -d '/' -f1 | rev | cut -d'.' -f1 | tr -dc '0-9' )"
## Check files.csv ## Check files.csv
location=$( cut -d, -f2 "${csvpath}" | grep -m 1 -E "/${edbdb}(\..*)?$" ) location=$( cut -d ',' -f 2 "${csvpath}" | grep -m 1 -E "/${edbdb}(\..*)?$" )
title=$( grep -m 1 "${location}" "${csvpath}" | cut -d, -f3 | sed 's/"//g' ) title=$( grep -m 1 "${location}" "${csvpath}" | cut -d ',' -f 3 | sed 's/"//g' )
## Join paths ## Join paths
location="${gitpath}/${location}" location="${gitpath}/${location}"
@ -557,8 +558,8 @@ if [[ "${GETPATH}" -eq 1 ]]; then
fi fi
if [[ "${MIRROR}" -eq 1 ]]; then if [[ "${MIRROR}" -eq 1 ]]; then
cp -i "${location}" "$(pwd)/" cp -i "${location}" "$( pwd )/"
echo "Copied to '$(pwd)/'" echo "Copied to '$( pwd )/'"
echo -e "\n" echo -e "\n"
fi fi
else else
@ -596,7 +597,7 @@ fi
COL1=$(( $( tput cols ) - COL2 - 1 )) COL1=$(( $( tput cols ) - COL2 - 1 ))
## Remove leading space ## Remove leading space
TAGS="$(echo ${TAGS} | sed -e 's/^[[:space:]]//')" TAGS="$( echo ${TAGS} | sed -e 's/^[[:space:]]//' )"
## Print header if NOT in JSON ("--json") ## Print header if NOT in JSON ("--json")
if [[ "${JSON}" -eq 0 ]]; then if [[ "${JSON}" -eq 0 ]]; then