1
votes

Conversion de données GeoLite2 pour une utilisation avec xtables Geoip

Je m'excuse si cela a été traité ici ou ailleurs. J'ai lu les articles en 2016.

Mon système Debian a arrêté de mettre à jour la base de données xtables geoip. Après enquête, il a découvert que cela était dû au fait que Maxmind avait abandonné le support des anciennes bases de données GeoIP. Je suis allé jusqu'à installer et configurer le programme geoipupdate de Maxmind pour la base de données GeoLite2 et à le programmer chaque semaine dans crontab.

À ce stade, je suis perplexe. geoipupdate renvoie une base de données .mmdb. Ceci n'est pas utilisable par les scripts fournis par Debian qui convertissent les fichiers .CSV en fichiers de code de pays dans / usr / share / xt_geoip / LE et / usr / share / xt_geoip / BE.

Le paquet debian xtables-addons n'a pas été mis à jour pour gérer cette situation.

Une assistance ou un pointeur vers une solution sera reçu avec gratitude. À l'heure actuelle, j'utilise toujours la dernière base de données valide qui a maintenant plus de six mois.


0 commentaires

3 Réponses :


0
votes

Jetez un œil à GeoLite2xtables: - https://github.com/mschmitt/GeoLite2xtables

Vous pouvez télécharger un zip (ou un clone git). Il a un exemple de workflow (commandes shell) pour l'ancien GeoLite CSV (qui est probablement ce que vous avez qui a cessé de fonctionner début janvier 2019) et GeoLite2 CSV (que vous pouvez utiliser à la place).


1 commentaires

Cela devrait faire l'affaire. Étonnant que ce problème n'ait pas été signalé dans de nombreux autres endroits, car je dois croire que la géolocalisation xtables est utilisée sur de nombreux sites.



0
votes

Vous pouvez également télécharger la source depuis le projet du xtable-addon (soit directement, soit depuis la version sid du paquet xtables-addons-common) et récupérer les versions mises à jour des scripts.

https://sourceforge.net/projects/xtables-addons/ fichiers / Xtables-addons /

Voir la réponse askubuntu suivante: https://askubuntu.com/questions/1117669/xtables-addons-issues-with- maxmind-geolite2


0 commentaires

0
votes

J'ai fini par écrire ce script, qui s'exécute désormais chaque semaine. Jusqu'à présent (trois mois plus tard), cela semble satisfaisant.

cat update-geoip.sh

#!/bin/bash -e

GEOLITE_URL="https://geolite.maxmind.com/download/geoip/database/GeoLite2-Country-CSV.zip"
GEOLITE_ZIP="GeoLite2-Country-CSV.zip"
COUNTRY_URL="http://download.geonames.org/export/dump/countryInfo.txt"

#
# Switch to the GeoIP directory if not already there
#
echo "--> cd /usr/share/xt_geoip"
cd /usr/share/xt_geoip

#
# Remove anything remaining from previous failed runs
#
# Note:  DO NOT delete the existing BE and LE subfolders at this
#        time.  If the download fails the result would be no
#        database at all.
#
echo "--> rm -r GeoLite2*"
rm -r -f GeoLite2*
echo "--> rm countryInfo.txt"
rm -f countryInfo.txt
echo "--> rm GeoIP-legacy.csv"
rm -f GeoIP-legacy.csv

#
# Get the GeoIP ZIP file
#
echo "--> wget --no-check-certificate $GEOLITE_URL"
wget --no-check-certificate $GEOLITE_URL

#
# See if the ZIP file now exists
#
if [ ! -e $GEOLITE_ZIP ]; then
  echo "--> GeoIP ZIP file did not download"
  echo "--> Send email to root and stop here"
  /usr/sbin/sendmail root << EOM
From: Update_GeoIP
To: root
Subject: GeoIP update failed

GeoIP update failed.
Unable to download GeoIP ZIP file
$GEOLITE_ZIP
EOM
  exit
fi

#
# Unzip the ZIP file
#
echo "--> unzip $GEOLITE_ZIP"
unzip $GEOLITE_ZIP

#
# Delete the ZIP file
#
#echo "--> rm $GEOLITE_ZIP"
rm $GEOLITE_ZIP

#
# Move the received data directory to a standard name
#
echo "--> mv GeoLite2-Country-CSV_* GeoLite2"
mv GeoLite2-Country-CSV_* GeoLite2

#
# See if the critical GeoIP data files now exist
#
if [ ! -e "GeoLite2/GeoLite2-Country-Blocks-IPv4.csv" ] ||
   [ ! -e "GeoLite2/GeoLite2-Country-Blocks-IPv6.csv" ]; then
  echo "--> GeoIP data files are missing"
  echo "--> Send email to root and stop here"
  /usr/sbin/sendmail root << EOM
From: Update_GeoIP
To: root
Subject: GeoIP update failed

GeoIP update failed.
GeoIP data file(s) are missing
GeoLite2/GeoLite2-Country-Blocks-IPv4.csv
GeoLite2/GeoLite2-Country-Blocks-IPv6.csv
EOM
  exit
fi

#
# Get the country info data file
#
echo "--> wget --no-check-certificate $COUNTRY_URL"
wget --no-check-certificate $COUNTRY_URL

#
# See if the country info data file now exists
#
if [ ! -e "countryInfo.txt" ]; then
  echo "--> Country info data file did not download"
  echo "--> Send email to root and stop here"
  /usr/sbin/sendmail root << EOM
From: Update_GeoIP
To: root
Subject: GeoIP update failed

GeoIP update failed.
Unable to download country info data file
$COUNTRY_URL
EOM
  exit
fi

#
# Build an old format data file from the new format data files
#
echo "--> cat ./GeoLite2/GeoLite2-Country-Blocks-IPv{4,6}.csv | ./convert_GeoLite2.pl ./countryInfo.txt > /usr/share/xt_geoip/GeoIP-legacy.csv"
cat ./GeoLite2/GeoLite2-Country-Blocks-IPv{4,6}.csv | ./convert_GeoLite2.pl ./countryInfo.txt > /usr/share/xt_geoip/GeoIP-legacy.csv

#
# Delete the downloaded data files
#
echo "--> rm -r GeoLite2"
rm -r GeoLite2
echo "--> rm countryInfo.txt"
rm country_Info.txt

#
# Preserve the old BE and LE directories just in case
#
echo "--> rm -r -f LastBE LastLE"
rm -r -f LastBE LastLE
echo "--> mv BE LastBE"
mv BE LastBE
echo "--> mv LE LastLE"
mv LE LastLE

#
# Convert the generated database to the xtables GeoIP format
#
echo "--> /usr/lib/xtables-addons/xt_geoip_build -D /usr/share/xt_geoip ./GeoIP-legacy.csv"
/usr/lib/xtables-addons/xt_geoip_build -D /usr/share/xt_geoip ./GeoIP-legacy.csv

#
# Delete the remaining data files
#
echo "--> rm countryInfo.txt"
rm countryInfo.txt
echo "--> rm GeoIP-legacy.csv"
rm GeoIP-legacy.csv

#
# Notify root that the update succeeded
#
echo "--> Send notification email to root"
/usr/sbin/sendmail root << EOM
From: Update_GeoIP
To: root
Subject: Weekly update of xtables GeoIP completed

Weekly update of xtables GeoIP database successful.
EOM
echo "xtables GeoIP database update completed"


0 commentaires