diff --git a/.env b/.env deleted file mode 100644 index 69993ab..0000000 --- a/.env +++ /dev/null @@ -1,5 +0,0 @@ -# MySQL Config -MYSQL_HOST=[MYSQL_HOST] -MYSQL_USER=[MYSQL_USER] -MYSQL_PASSWORD=[MYSQL_PASSWORD] -MYSQL_DB=[MYSQL_DB] diff --git a/.env.dist b/.env.dist new file mode 100644 index 0000000..cc47f1a --- /dev/null +++ b/.env.dist @@ -0,0 +1,5 @@ +# MySQL Config +MYSQL_HOST= +MYSQL_USER= +MYSQL_PASSWORD= +MYSQL_DB= diff --git a/simple_IMSI-catcher.py b/simple_IMSI-catcher.py index 96347bf..d4c40e6 100644 --- a/simple_IMSI-catcher.py +++ b/simple_IMSI-catcher.py @@ -22,19 +22,9 @@ import ctypes import json from optparse import OptionParser -from decouple import config import datetime import io import socket -import MySQLdb as mdb - -con = mdb.connect( - config("MYSQL_HOST"), - config("MYSQL_USER"), - config("MYSQL_PASSWORD"), - config("MYSQL_DB") -) -cur = con.cursor() imsitracker = None @@ -170,11 +160,23 @@ def textfile(self, filename): self.textfile = filename def mysql_file(self): - self.db = con.cursor() - if self.db: - print("mysql connection is success :)") + global con + global cur + import os.path + if os.path.isfile('.env'): + import MySQLdb as mdb + from decouple import config + con = mdb.connect(config("MYSQL_HOST"), config("MYSQL_USER"), config("MYSQL_PASSWORD"), config("MYSQL_DB")) + cur = con.cursor() + # Check MySQL connection + if cur: + print("mysql connection is success :)") + else: + print("mysql connection is failed!") + exit() else: - print("mysql connection is failed!") + print("create file .env first") + exit() def output(self, cpt, tmsi1, tmsi2, imsi, imsicountry, imsibrand, imsioperator, mcc, mnc, lac, cell, now, packet=None): print("{:7s} ; {:10s} ; {:10s} ; {:17s} ; {:12s} ; {:10s} ; {:21s} ; {:4s} ; {:5s} ; {:6s} ; {:6s} ; {:s}".format(str(cpt), tmsi1, tmsi2, imsi, imsicountry, imsibrand, imsioperator, str(mcc), str(mnc), str(lac), str(cell), now.isoformat())) @@ -212,13 +214,11 @@ def pfields(self, cpt, tmsi1, tmsi2, imsi, mcc, mnc, lac, cell, packet=None): tmsi1 = None if tmsi2 == "": tmsi2 = None - + # Example query query = ("INSERT INTO `imsi` (`tmsi1`, `tmsi2`, `imsi`,`mcc`, `mnc`, `lac`, `cell_id`, `stamp`, `deviceid`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)") arg = (tmsi1, tmsi2, imsi, mcc, mnc, lac, cell, now, "rtl") cur.execute(query, arg) con.commit() - else: - print("Failed! check your db connection") def header(self): print("{:7s} ; {:10s} ; {:10s} ; {:17s} ; {:12s} ; {:10s} ; {:21s} ; {:4s} ; {:5s} ; {:6s} ; {:6s} ; {:s}".format("Nb IMSI", "TMSI-1", "TMSI-2", "IMSI", "country", "brand", "operator", "MCC", "MNC", "LAC", "CellId", "Timestamp"))