Code cleanup - adds comments & formatting

This commit is contained in:
g0tmi1k 2016-11-07 12:24:58 +00:00
parent 9f26e75621
commit 55bbc4f153

View file

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
# Name: SearchSploit - Exploit-DB's CLI search tool # Name: SearchSploit - Exploit-DB's CLI search tool
# Version: 3.7 (Release date: 2016-10-26) # Version: 3.7.1 (Release date: 2016-11-07)
# Written by: Offensive Security, Unix-Ninja & g0tmi1k # Written by: Offensive Security, Unix-Ninja & g0tmi1k
# Homepage: https://github.com/offensive-security/exploit-database # Homepage: https://github.com/offensive-security/exploit-database
# #
@ -306,7 +306,7 @@ function nmapxml()
#searchsploitout #searchsploitout
echo "${software}" >> /tmp/searchsploitout echo "${software}" >> /tmp/searchsploitout
## Read in from file (so there isn't any duplicates but unable to print out IPs) ## Read in from file (so there are no duplicates - ...but unable to print out IPs)
cat /tmp/searchsploitout | tr '[:upper:]' '[:lower:]' | awk '!x[$0]++' | while read software; do cat /tmp/searchsploitout | tr '[:upper:]' '[:lower:]' | awk '!x[$0]++' | while read software; do
searchsploitout searchsploitout
done done
@ -533,7 +533,7 @@ if [[ "${GETPATH}" -eq 1 ]]; then
fi fi
## If we are doing an exact match, do not check folder path (Implies "-t"). ## If we are doing an exact match ("-e")? If so, do NOT check folder path (Implies "-t").
if [[ "${EXACT}" -eq 1 ]]; then if [[ "${EXACT}" -eq 1 ]]; then
FILEPATH=0 FILEPATH=0
fi fi
@ -558,7 +558,7 @@ 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 ## Print header if NOT in JSON ("--json")
if [[ "${JSON}" -eq 0 ]]; then if [[ "${JSON}" -eq 0 ]]; then
drawline drawline
printf "%-${COL1}s %s" " Exploit Title" printf "%-${COL1}s %s" " Exploit Title"
@ -596,13 +596,13 @@ else
fi fi
## If we are not to use the path name ## If we are NOT to use the path name ("-t"/"-e")
if [[ "${FILEPATH}" -eq 0 ]]; then if [[ "${FILEPATH}" -eq 0 ]]; then
SEARCH="${SEARCH} | awk -F '[,]' '${CASE_TAG_FGREP}(\$3) ~ /${AWK_SEARCH}/ {print}'" SEARCH="${SEARCH} | awk -F '[,]' '${CASE_TAG_FGREP}(\$3) ~ /${AWK_SEARCH}/ {print}'"
fi fi
## If we are to use colour, add the value here ## If we are to use colour ("--colour"), add the value here
if [[ "${COLOUR_TAG}" ]] && [[ "${JSON}" -eq 0 ]]; then if [[ "${COLOUR_TAG}" ]] && [[ "${JSON}" -eq 0 ]]; then
COLOUR_TAG="grep --color=always -iE \"${COLOUR_TAG}|$\"" COLOUR_TAG="grep --color=always -iE \"${COLOUR_TAG}|$\""
fi fi
@ -617,15 +617,15 @@ fi
## Magic search Fu ## Magic search Fu
## Web link format? ## Web link format ("--www")?
if [[ "${WEBLINK}" -eq 1 ]]; then if [[ "${WEBLINK}" -eq 1 ]]; then
## Just the EDB-ID?
OUTPUT="$( eval ${SEARCH} \ OUTPUT="$( eval ${SEARCH} \
| awk -F "\"*,\"*" '{ printf "%-'${FORMAT}'s | %s\n", $3, "https://www.exploit-db.com/exploits/"$1"/"}' )" | awk -F "\"*,\"*" '{ printf "%-'${FORMAT}'s | %s\n", $3, "https://www.exploit-db.com/exploits/"$1"/"}' )"
## Just the EDB-ID ("--id")?
elif [[ "${EDBID}" -eq 1 ]]; then elif [[ "${EDBID}" -eq 1 ]]; then
## Print JSON format (full options)
OUTPUT="$( eval ${SEARCH} \ OUTPUT="$( eval ${SEARCH} \
| awk -F "\"*,\"*" '{ printf "%-'${FORMAT}'s | %s\n", $3, $1 }' )" | awk -F "\"*,\"*" '{ printf "%-'${FORMAT}'s | %s\n", $3, $1 }' )"
## Print JSON format (full options) ("--json")?
elif [[ "${JSON}" -eq 1 ]]; then elif [[ "${JSON}" -eq 1 ]]; then
OUTPUT="$( eval ${SEARCH} \ OUTPUT="$( eval ${SEARCH} \
| awk -F "\"*,\"*" '{ printf "\r\t\t'{'\"Exploit\":\"%s\",\"Path\":\"'${gitpath}/'%s\",\"EDB-ID\":%s},\n", $3, $2, $1 }' \ | awk -F "\"*,\"*" '{ printf "\r\t\t'{'\"Exploit\":\"%s\",\"Path\":\"'${gitpath}/'%s\",\"EDB-ID\":%s},\n", $3, $2, $1 }' \
@ -643,9 +643,12 @@ if [[ "${COLOUR_TAG}" ]] && [[ "${JSON}" -eq 0 ]]; then
OUTPUT=$( echo -e "${OUTPUT}" | eval ${COLOUR_TAG} ) OUTPUT=$( echo -e "${OUTPUT}" | eval ${COLOUR_TAG} )
fi fi
## Show content
echo "${OUTPUT}" echo "${OUTPUT}"
## Print footer if not in JSON
## Print footer if NOT in JSON ("--json")
if [[ "${JSON}" -eq 0 ]]; then if [[ "${JSON}" -eq 0 ]]; then
drawline drawline
## Print JSON footer ## Print JSON footer
@ -654,5 +657,6 @@ else
echo "}" echo "}"
fi fi
## Done ## Done
exit 0 exit 0