Skip to content

Instantly share code, notes, and snippets.

@kazkansouh
Created August 28, 2020 10:29
Show Gist options
  • Save kazkansouh/0471361874b618f14000c28236e2c806 to your computer and use it in GitHub Desktop.
Save kazkansouh/0471361874b618f14000c28236e2c806 to your computer and use it in GitHub Desktop.
Wrapper script for searchsploit that uses jq to sort the results by date.
#! /bin/bash
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Copyright Karim Kanso, 2020. All rights reserved. Licenced under GPLv3
SEARCHSPLOIT=searchsploit
THISNAME=$(basename $0)
function show_help() {
echo "${THISNAME} [--before yyyy-mm-dd] [--after yyyy-mm-dd] searchsploit args ..."
echo
echo "Runs searchsploit with -j, and sorts results by date."
echo
echo "Chaining searchsploit help:"
exec ${SEARCHSPLOIT} --help
}
BEFORE="9999-99-99"
AFTER="0000-00-00"
while test $# -gt 0;
do
case $1 in
--before)
if test $# -lt 2; then
echo "Before missing argument"
show_help
exit 1
fi
case $2 in
[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9])
;;
*)
echo "Before invalid"
show_help
exit 1
;;
esac
BEFORE=$2
shift
;;
--after)
if test $# -lt 2; then
echo "After missing argument"
show_help
exit 1
fi
case $2 in
[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9])
;;
*)
echo "After invalid"
show_help
exit 1
;;
esac
AFTER=$2
shift
;;
--help)
show_help
exit 0
;;
-x|-m|-h)
exec ${SEARCHSPLOIT} "$@"
;;
*)
#echo "Running searchsploit with date range from ${AFTER} to ${BEFORE}"
${SEARCHSPLOIT} -j "$@" | \
jq -r "$(cat <<EOF
.RESULTS_EXPLOIT |
sort_by(.Date) |
.[] |
select(."Date" >= "${AFTER}") |
select(."Date" <= "${BEFORE}") |
[ ."EDB-ID", ."Date", ."Platform", ."Title"] |
@csv
EOF
)" | \
column -s'",' -t
exit 0
;;
esac
shift
done
echo "Nothing to do, provide search terms"
show_help
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment