Screen width will not affect the results
This commit is contained in:
parent
1ee96838d2
commit
9f26e75621
1 changed files with 64 additions and 59 deletions
123
searchsploit
123
searchsploit
|
@ -41,6 +41,7 @@ TAGS=""
|
||||||
SEARCH=""
|
SEARCH=""
|
||||||
CASE_TAG_GREP="-i"
|
CASE_TAG_GREP="-i"
|
||||||
CASE_TAG_FGREP="tolower"
|
CASE_TAG_FGREP="tolower"
|
||||||
|
AWK_SEARCH=""
|
||||||
|
|
||||||
|
|
||||||
## Set LANG variable to avoid illegal byte sequence errors
|
## Set LANG variable to avoid illegal byte sequence errors
|
||||||
|
@ -312,6 +313,44 @@ function nmapxml()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
## Build search terms
|
||||||
|
function buildterms()
|
||||||
|
{
|
||||||
|
tag="${1}"
|
||||||
|
|
||||||
|
## If we are to use colour ("--colour"), add the values to search for between "or"
|
||||||
|
if [[ "${COLOUR}" -eq 1 ]]; then
|
||||||
|
if [[ "${COLOUR_TAG}" ]]; then
|
||||||
|
COLOUR_TAG="${COLOUR_TAG}|"
|
||||||
|
fi
|
||||||
|
COLOUR_TAG="${COLOUR_TAG}${tag}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Search both title AND path
|
||||||
|
if [[ "${FILEPATH}" -eq 1 ]]; then
|
||||||
|
## Search command for each term (with case sensitive flag, "-c")
|
||||||
|
SEARCH="${SEARCH} | grep --color=never -F ${CASE_TAG_GREP} \"${tag}\""
|
||||||
|
## Search just the title, NOT the path ("-t"/"-e")
|
||||||
|
else
|
||||||
|
## If there is already a value, prepend text to get ready
|
||||||
|
if [[ "${AWK_SEARCH}" ]]; then
|
||||||
|
AWK_SEARCH="${AWK_SEARCH}/ && ${CASE_TAG_FGREP}(\$3) ~ /"
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Escape any slashes
|
||||||
|
tag="$( echo ${tag} | sed 's_/_\\/_g' )"
|
||||||
|
|
||||||
|
## Case sensitive ("-c")?
|
||||||
|
if [[ "${SCASE}" -eq 1 ]]; then
|
||||||
|
AWK_SEARCH="${AWK_SEARCH}${tag}"
|
||||||
|
else
|
||||||
|
AWK_SEARCH="${AWK_SEARCH}$( echo ${tag} | tr '[:upper:]' '[:lower:]' )"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Check for empty args
|
## Check for empty args
|
||||||
if [[ $# -eq 0 ]]; then
|
if [[ $# -eq 0 ]]; then
|
||||||
usage >&2
|
usage >&2
|
||||||
|
@ -541,71 +580,31 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
## EXACT search command?
|
## Read in id, title and path, separated between commas (as these are the only visible fields)
|
||||||
if [[ "${EXACT}" -eq 1 ]]; then
|
SEARCH="awk -F '[,]' '{print \$1\",\"\$2\",\"\$3}' \"${csvpath}\""
|
||||||
## Case sensitive?
|
|
||||||
if [[ "${SCASE}" -eq 1 ]]; then
|
|
||||||
SEARCH="${TAGS}"
|
|
||||||
else
|
|
||||||
## Case insensitive
|
|
||||||
SEARCH="$( echo ${TAGS} | tr '[:upper:]' '[:lower:]' )"
|
|
||||||
fi
|
|
||||||
|
|
||||||
## If we are to use colour, add the values to search for
|
|
||||||
if [[ "${COLOUR}" -eq 1 ]]; then
|
## EXACT search command ("-e")?
|
||||||
COLOUR_TAG="${SEARCH}"
|
if [[ "${EXACT}" -eq 1 ]]; then
|
||||||
fi
|
buildterms "${TAGS}"
|
||||||
## or AND search command?
|
## or AND search command?
|
||||||
else
|
else
|
||||||
## For each term
|
## For each term
|
||||||
for tag in ${TAGS}; do
|
for TAG in ${TAGS}; do
|
||||||
## If we are to use colour, add the values to search for between "or"
|
buildterms "${TAG}"
|
||||||
if [[ "${COLOUR}" -eq 1 ]]; then
|
|
||||||
if [[ "${COLOUR_TAG}" ]]; then
|
|
||||||
COLOUR_TAG="${COLOUR_TAG}\|"
|
|
||||||
fi
|
|
||||||
COLOUR_TAG="${COLOUR_TAG}${tag}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
## Search both title AND path?
|
|
||||||
if [[ "${FILEPATH}" -eq 1 ]]; then
|
|
||||||
## Is there a value already?
|
|
||||||
if [[ "${SEARCH}" ]]; then
|
|
||||||
SEARCH="${SEARCH} |"
|
|
||||||
fi
|
|
||||||
|
|
||||||
## Search command for each term
|
|
||||||
SEARCH="${SEARCH} fgrep ${CASE_TAG_GREP} \"${tag}\""
|
|
||||||
## Search just the title, not the path
|
|
||||||
else
|
|
||||||
## If there is already a value, prepend text to get ready
|
|
||||||
if [[ "${SEARCH}" ]]; then
|
|
||||||
SEARCH="${SEARCH}/ && ${CASE_TAG_FGREP}(\$1) ~ /"
|
|
||||||
fi
|
|
||||||
|
|
||||||
## Escape any slashes
|
|
||||||
tag="$( echo ${tag} | sed 's_/_\\/_g' )"
|
|
||||||
|
|
||||||
## Case sensitive?
|
|
||||||
if [[ "${SCASE}" -eq 1 ]]; then
|
|
||||||
SEARCH="${SEARCH}${tag}"
|
|
||||||
else
|
|
||||||
SEARCH="${SEARCH}$( echo ${tag} | tr '[:upper:]' '[:lower:]' )"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
## If we are not to use the path name
|
## If we are not to use the path name
|
||||||
if [[ "${FILEPATH}" -eq 0 ]]; then
|
if [[ "${FILEPATH}" -eq 0 ]]; then
|
||||||
SEARCH="awk -F '[|]' '${CASE_TAG_FGREP}(\$1) ~ /${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, add the value here
|
||||||
if [[ "${COLOUR_TAG}" ]] && [[ "${JSON}" -eq 0 ]]; then
|
if [[ "${COLOUR_TAG}" ]] && [[ "${JSON}" -eq 0 ]]; then
|
||||||
SEARCH="${SEARCH} | grep --color=always -ie \"\${COLOUR_TAG}\""
|
COLOUR_TAG="grep --color=always -iE \"${COLOUR_TAG}|$\""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
@ -620,22 +619,28 @@ fi
|
||||||
## Magic search Fu
|
## Magic search Fu
|
||||||
## Web link format?
|
## Web link format?
|
||||||
if [[ "${WEBLINK}" -eq 1 ]]; then
|
if [[ "${WEBLINK}" -eq 1 ]]; then
|
||||||
OUTPUT="$( awk -F "\"*,\"*" '{ printf "%-'${FORMAT}'s | %s\n", $3, "https://www.exploit-db.com/exploits/"$1"/"}' "${csvpath}" \
|
|
||||||
| eval "${SEARCH}" )"
|
|
||||||
## Just the EDB-ID?
|
## Just the EDB-ID?
|
||||||
|
OUTPUT="$( eval ${SEARCH} \
|
||||||
|
| awk -F "\"*,\"*" '{ printf "%-'${FORMAT}'s | %s\n", $3, "https://www.exploit-db.com/exploits/"$1"/"}' )"
|
||||||
elif [[ "${EDBID}" -eq 1 ]]; then
|
elif [[ "${EDBID}" -eq 1 ]]; then
|
||||||
OUTPUT="$( awk -F "\"*,\"*" '{ printf "%-'${FORMAT}'s | %s\n", $3, $1}' "${csvpath}" \
|
|
||||||
| eval "${SEARCH}" )"
|
|
||||||
## Print JSON format (full options)
|
## Print JSON format (full options)
|
||||||
|
OUTPUT="$( eval ${SEARCH} \
|
||||||
|
| awk -F "\"*,\"*" '{ printf "%-'${FORMAT}'s | %s\n", $3, $1 }' )"
|
||||||
elif [[ "${JSON}" -eq 1 ]]; then
|
elif [[ "${JSON}" -eq 1 ]]; then
|
||||||
OUTPUT="$( awk -F "\"*,\"*" '{ printf "\r\t\t'{'\"Exploit\":\"%s\",\"Path\":\"'${gitpath}/'%s\",\"EDB-ID\":%s},\n", $3, $2, $1}' "${csvpath}" \
|
OUTPUT="$( eval ${SEARCH} \
|
||||||
| eval "${SEARCH}" \
|
| awk -F "\"*,\"*" '{ printf "\r\t\t'{'\"Exploit\":\"%s\",\"Path\":\"'${gitpath}/'%s\",\"EDB-ID\":%s},\n", $3, $2, $1 }' \
|
||||||
| sed '$ s/,$//g' )"
|
| sed '$ s/,$//g' )"
|
||||||
## Default view
|
## Default view
|
||||||
else
|
else
|
||||||
OUTPUT="$( awk -F "\"*,\"*" '{ printf "%-'${FORMAT}'s | %s\n", $3, $2}' "${csvpath}" \
|
OUTPUT="$( eval ${SEARCH} \
|
||||||
| eval "${SEARCH}" \
|
| awk -F "\"*,\"*" '{ printf "%-'${FORMAT}'s | %s\n", $3, $2 }' \
|
||||||
| sed "s/| platforms/| ./" )"
|
| sed "s/| platforms/| /" )"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
## Display colour highlights ("--colour")?
|
||||||
|
if [[ "${COLOUR_TAG}" ]] && [[ "${JSON}" -eq 0 ]]; then
|
||||||
|
OUTPUT=$( echo -e "${OUTPUT}" | eval ${COLOUR_TAG} )
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "${OUTPUT}"
|
echo "${OUTPUT}"
|
||||||
|
|
Loading…
Add table
Reference in a new issue