Skip to content

Commit

Permalink
Merge pull request Oros42#131 from lapolis/master
Browse files Browse the repository at this point in the history
Fixed the fix
  • Loading branch information
Oros42 authored Jul 13, 2021
2 parents 50ae112 + 4f08104 commit ebba074
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode
venv
.env
test*
36 changes: 20 additions & 16 deletions simple_IMSI-catcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# nicoeg
# dspinellis
# fdl <[email protected]>
# lapolis
# 2020-08-15
# License : CC0 1.0 Universal

Expand Down Expand Up @@ -103,19 +104,21 @@ def str_imsi(self, imsi, packet=""):
country = ""
brand = ""
operator = ""

if mcc in self.mcc_codes:
if mnc in self.mcc_codes[mcc]:
brand, operator, country, _ = self.mcc_codes[mcc][mnc]
new_imsi = mcc + " " + mnc + " " + new_imsi[6:]
new_imsi = f"{mcc} {mnc} {new_imsi[6:]}"
elif mnc + new_imsi[6:7] in self.mcc_codes[mcc]:
mnc += new_imsi[6:7]
brand, operator, country, _ = self.mcc_codes[mcc][mnc]
new_imsi = mcc + " " + mnc + " " + new_imsi[7:]
new_imsi = f"{mcc} {mnc} {new_imsi[7:]}"

else:
country = "Unknown MCC {}".format(mcc)
brand = "Unknown MNC {}".format(mnc)
operator = "Unknown MNC {}".format(mnc)
new_imsi = mcc + " " + mnc + " " + new_imsi[6:]
country = f"Unknown MCC {mcc}"
brand = f"Unknown MNC {mnc}"
operator = f"Unknown MNC {mnc}"
new_imsi = f"{mcc} {mnc} {new_imsi[6:]}"

try:
return new_imsi, country, brand, operator
Expand All @@ -136,9 +139,9 @@ def current_cell(self, mcc, mnc, lac, cell):
if mcc in self.mcc_codes and mnc in self.mcc_codes[mcc]:
brand, operator, country, _ = self.mcc_codes[mcc][mnc]
else:
country = "Unknown MCC {}".format(mcc)
brand = "Unknown MNC {}".format(mnc)
operator = "Unknown MNC {}".format(mnc)
country = f"Unknown MCC {mcc}"
brand = f"Unknown MNC {mnc}"
operator = f"Unknown MNC {mnc}"
self.mcc = str(mcc)
self.mnc = str(mnc)
self.lac = str(lac)
Expand Down Expand Up @@ -179,7 +182,7 @@ def mysql_file(self):
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.encode('utf-8'), imsibrand.encode('utf-8'), imsioperator.encode('utf-8'), str(mcc), str(mnc), str(lac), str(cell), now.isoformat()))
print(f"{str(cpt):7s} ; {tmsi1:10s} ; {tmsi2:10s} ; {imsi:17s} ; {imsicountry:16s} ; {imsibrand:14s} ; {imsioperator:21s} ; {str(mcc):4s} ; {str(mnc):5s} ; {str(lac):6s} ; {str(cell):6s} ; {now.isoformat():s}")

def pfields(self, cpt, tmsi1, tmsi2, imsi, mcc, mnc, lac, cell, packet=None):
imsicountry = ""
Expand All @@ -194,8 +197,8 @@ def pfields(self, cpt, tmsi1, tmsi2, imsi, mcc, mnc, lac, cell, packet=None):

if self.textfilePath:
now = datetime.datetime.now()
txt = open(self.textfilePath, "ab")
txt.write(str(now) + ", " + tmsi1 + ", " + tmsi2 + ", " + imsi + ", " + imsicountry.encode('utf-8') + ", " + imsibrand.encode('utf-8') + ", " + imsioperator.encode('utf-8') + ", " + mcc + ", " + mnc + ", " + lac + ", " + cell + "\n")
txt = open(self.textfilePath, "a")
txt.write(f"{str(now)}, {tmsi1}, {tmsi2}, {imsi}, {imsicountry}, {imsibrand}, {imsioperator}, {mcc}, {mnc}, {lac}, {cell}\n")
txt.close()

if tmsi1 == "":
Expand All @@ -205,10 +208,11 @@ def pfields(self, cpt, tmsi1, tmsi2, imsi, mcc, mnc, lac, cell, packet=None):

if self.sqlite_con:
self.sqlite_con.execute(
u"INSERT INTO observations (stamp, tmsi1, tmsi2, imsi, imsicountry, imsibrand, imsioperator, mcc, mnc, lac, cell) " + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
(now, tmsi1, tmsi2, imsi, imsicountry.encode('utf-8'), imsibrand.encode('utf-8'), imsioperator.encode('utf-8'), mcc, mnc, lac, cell)
u"INSERT INTO observations (stamp, tmsi1, tmsi2, imsi, imsicountry, imsibrand, imsioperator, mcc, mnc, lac, cell) " + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
(now, tmsi1, tmsi2, imsi, imsicountry, imsibrand, imsioperator, mcc, mnc, lac, cell)
)
self.sqlite_con.commit()
pass

if self.mysql_cur:
print("saving data to db...")
Expand All @@ -219,7 +223,7 @@ def pfields(self, cpt, tmsi1, tmsi2, imsi, mcc, mnc, lac, cell, packet=None):
self.mysql_con.commit()

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"))
print(f"{'Nb IMSI':7s} ; {'TMSI-1':10s} ; {'TMSI-2':10s} ; {'IMSI':17s} ; {'country':16s} ; {'brand':14s} ; {'operator':21s} ; {'MCC':4s} ; {'MNC':5s} ; {'LAC':6s} ; {'CellId':6s} ; {'Timestamp':s}")

def register_imsi(self, arfcn, imsi1="", imsi2="", tmsi1="", tmsi2="", p=""):
do_print = False
Expand Down Expand Up @@ -607,7 +611,7 @@ def find_imsi_from_pkt(p):
if options.sniff:
from scapy.all import sniff, UDP
imsitracker.header()
sniff(iface=options.iface, filter="port {} and not icmp and udp".format(options.port), prn=find_imsi_from_pkt, store=0)
sniff(iface=options.iface, filter=f"port {options.port} and not icmp and udp", prn=find_imsi_from_pkt, store=0)
else:
imsitracker.header()
udpserver(port=options.port, prn=find_imsi)

0 comments on commit ebba074

Please sign in to comment.