NAS: Implement patching of ID; Fix patching of EPSID
this needs more work: * unify handling of EPSID and ID * implement other ID types than IMSI
This commit is contained in:
parent
f0206b949b
commit
67f9e9b72f
|
@ -25,6 +25,24 @@ from scapy.all import SCTP
|
||||||
|
|
||||||
from pycrate_asn1dir import S1AP
|
from pycrate_asn1dir import S1AP
|
||||||
from pycrate_mobile import NAS
|
from pycrate_mobile import NAS
|
||||||
|
from pycrate_core.charpy import Charpy
|
||||||
|
|
||||||
|
IMSI_REPLACEMENT_BYTES = b'\x29\x26\x24' + b'\x00' * 5
|
||||||
|
|
||||||
|
def get_key_or_none(elem, k):
|
||||||
|
try:
|
||||||
|
id = elem[k]
|
||||||
|
return id
|
||||||
|
except ValueError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def has_key(elem, k):
|
||||||
|
try:
|
||||||
|
id = elem[k]
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def handle_nas_pdu(pdu, dl, regen = False):
|
def handle_nas_pdu(pdu, dl, regen = False):
|
||||||
log.debug("Processing %s NAS PDU: %s" % ("Downlink" if dl else "Uplink", pdu.hex()))
|
log.debug("Processing %s NAS PDU: %s" % ("Downlink" if dl else "Uplink", pdu.hex()))
|
||||||
|
@ -32,19 +50,34 @@ def handle_nas_pdu(pdu, dl, regen = False):
|
||||||
if code:
|
if code:
|
||||||
log.error("Failed to parse NAS payload")
|
log.error("Failed to parse NAS payload")
|
||||||
return None
|
return None
|
||||||
|
#print(msg.CLASS)
|
||||||
|
|
||||||
|
if has_key(msg, 'ID'):
|
||||||
|
id = msg['ID'][1]
|
||||||
|
#for k in id:
|
||||||
|
# print("--- %s, %s" % (k, k.show()))
|
||||||
|
id_type = id['Type'].get_val()
|
||||||
|
if id_type == 1: # IMSI
|
||||||
|
id.from_bytes(Charpy(IMSI_REPLACEMENT_BYTES))
|
||||||
|
else:
|
||||||
|
raise FooErr
|
||||||
|
print("+++ %s" % (id))
|
||||||
|
regen = True
|
||||||
|
|
||||||
# Try to find EPSID (may contain IMSI)
|
# Try to find EPSID (may contain IMSI)
|
||||||
# TODO: also patch IMEI / IMEISV
|
# TODO: also patch IMEI / IMEISV
|
||||||
try:
|
if has_key(msg, 'EPSID'):
|
||||||
epsid = msg['EPSID'][1]
|
epsid = msg['EPSID'][1]
|
||||||
# Check if EPSID contains exactly IMSI
|
# Check if EPSID contains exactly IMSI
|
||||||
if epsid[2].get_val() == 1:
|
id_type = epsid['Type'].get_val()
|
||||||
|
print("ID type: %d" % (id_type))
|
||||||
|
if id_type == 1:
|
||||||
log.info("Cleaning %s" % epsid.repr())
|
log.info("Cleaning %s" % epsid.repr())
|
||||||
# 262420000000000, Vodafone GmbH, Germany
|
# 262420000000000, Vodafone GmbH, Germany
|
||||||
epsid.from_bytes('\x29\x26\x24' + '\x00' * 5)
|
epsid.from_bytes(Charpy(IMSI_REPLACEMENT_BYTES))
|
||||||
regen = True
|
else:
|
||||||
except:
|
raise FooErr
|
||||||
pass
|
regen = True
|
||||||
|
|
||||||
return msg.to_bytes() if regen else pdu
|
return msg.to_bytes() if regen else pdu
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue