Add update-geoipdb script

This commit is contained in:
Brendan Coles
2019-02-17 05:42:45 +00:00
parent 1583a10a5a
commit b46472ada6
3 changed files with 84 additions and 4 deletions

View File

@@ -131,10 +131,7 @@ beef:
dns_hostname_lookup: false
# IP Geolocation
# NOTE: requires MaxMind database:
# /usr/bin/curl -O https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz
# /bin/gunzip GeoLite2-City.tar.gz && /bin/tar xvf GeoLite2-City.tar && /bin/rm GeoLite2-City.tar
# /bin/mkdir -p /opt/GeoIP && /bin/mv GeoLite2-City_*/* /opt/GeoIP && /bin/rmdir GeoLite2-City_*
# NOTE: requires MaxMind database. Run ./updated-geoipdb to install.
geoip:
enable: true
database: '/opt/GeoIP/GeoLite2-City.mmdb'

View File

@@ -19,6 +19,7 @@ module Core
unless File.exists? geoip_file
print_error "[GeoIP] Could not find MaxMind GeoIP database: '#{geoip_file}'"
print_more "Run ./update-geoipdb to install"
@enabled = false
return
end

82
update-geoipdb Executable file
View File

@@ -0,0 +1,82 @@
#!/bin/bash
#
# Copyright (c) 2006-2019 Wade Alcorn - wade@bindshell.net
# Browser Exploitation Framework (BeEF) - http://beefproject.com
# See the file 'doc/COPYING' for copying permission
#
# Install the MaxMind GeoIP database
set -euo pipefail
IFS=$'\n\t'
GEOIP_PATH="/opt/GeoIP"
info() { echo -e "\\033[1;36m[INFO]\\033[0m $*"; }
warn() { echo -e "\\033[1;33m[WARNING]\\033[0m $*"; }
fatal() { echo -e "\\033[1;31m[FATAL]\\033[0m $*"; exit 1 ; }
command_exists () {
command -v "${1}" >/dev/null 2>&1
}
get_permission () {
warn "This script will install the MaxMind GeoLite database in ${GEOIP_PATH}"
read -rp "Are you sure you wish to continue (Y/n)? "
if [ "$(echo "${REPLY}" | tr "[:upper:]" "[:lower:]")" = "n" ] ; then
fatal 'Installation aborted'
fi
}
check_deps() {
if ! command_exists /usr/bin/curl
then
fatal "/usr/bin/curl is not installed"
fi
if ! command_exists /bin/gunzip
then
fatal "/bin/gunzip is not installed"
fi
if ! command_exists /bin/tar
then
fatal "/bin/tar is not installed"
fi
}
check_perms() {
/bin/mkdir -p "${GEOIP_PATH}"
if ! [ -w "${GEOIP_PATH}" ]
then
fatal "${GEOIP_PATH} is not writable"
fi
}
install() {
info 'Downloading MaxMind GeoLite2-City database ...'
/usr/bin/curl -O https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz
info 'Extracting GeoLite2-City.tar.gz ...'
/bin/gunzip GeoLite2-City.tar.gz
/bin/tar xvf GeoLite2-City.tar
info "Installing to ${GEOIP_PATH} ..."
/bin/mv GeoLite2-City_*/* "${GEOIP_PATH}"
info 'Cleaning up ...'
/bin/rm GeoLite2-City.tar
/bin/rmdir GeoLite2-City_*
info 'Done!'
}
main() {
get_permission
check_deps
check_perms
install
}
main "$@"