Skip to content

Commit 6726b38

Browse files
authored
Merge branch 'master' into update_MS-RPC_Fuzzer_20250715_182932
2 parents c12fffb + 82ebc4f commit 6726b38

File tree

13 files changed

+691
-48
lines changed

13 files changed

+691
-48
lines changed

searchindex.js

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- [Enable Nexmon Monitor And Injection On Android](generic-methodologies-and-resources/pentesting-wifi/enable-nexmon-monitor-and-injection-on-android.md)
2929
- [Evil Twin EAP-TLS](generic-methodologies-and-resources/pentesting-wifi/evil-twin-eap-tls.md)
3030
- [Phishing Methodology](generic-methodologies-and-resources/phishing-methodology/README.md)
31+
- [Clipboard Hijacking](generic-methodologies-and-resources/phishing-methodology/clipboard-hijacking.md)
3132
- [Clone a Website](generic-methodologies-and-resources/phishing-methodology/clone-a-website.md)
3233
- [Detecting Phishing](generic-methodologies-and-resources/phishing-methodology/detecting-phising.md)
3334
- [Discord Invite Hijacking](generic-methodologies-and-resources/phishing-methodology/discord-invite-hijacking.md)
@@ -76,6 +77,7 @@
7677
# 🧙‍♂️ Generic Hacking
7778

7879
- [Brute Force - CheatSheet](generic-hacking/brute-force.md)
80+
- [Esim Javacard Exploitation](generic-hacking/esim-javacard-exploitation.md)
7981
- [Exfiltration](generic-hacking/exfiltration.md)
8082
- [Reverse Shells (Linux, Windows, MSFVenom)](generic-hacking/reverse-shells/README.md)
8183
- [MSFVenom - CheatSheet](generic-hacking/reverse-shells/msfvenom.md)

src/binary-exploitation/common-binary-protections-and-bypasses/relro.md

Lines changed: 85 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,106 @@
44

55
## Relro
66

7-
**RELRO** stands for **Relocation Read-Only**, and it's a security feature used in binaries to mitigate the risks associated with **GOT (Global Offset Table)** overwrites. There are two types of **RELRO** protections: (1) **Partial RELRO** and (2) **Full RELRO**. Both of them reorder the **GOT** and **BSS** from ELF files, but with different results and implications. Speciifically, they place the **GOT** section _before_ the **BSS**. That is, **GOT** is at lower addresses than **BSS**, hence making it impossible to overwrite **GOT** entries by overflowing variables in the **BSS** (rembember writing into memory happens from lower toward higher addresses).
7+
**RELRO** stands for **Relocation Read-Only** and it is a mitigation implemented by the linker (`ld`) that turns a subset of the ELF’s data segments **read-only after all relocations have been applied**. The goal is to stop an attacker from overwriting entries in the **GOT (Global Offset Table)** or other relocation-related tables that are dereferenced during program execution (e.g. `__fini_array`).
88

9-
Let's break down the concept into its two distinct types for clarity.
9+
Modern linkers implement RELRO by **re–ordering** the **GOT** (and a few other sections) so they live **before** the **.bss** and – most importantly – by creating a dedicated `PT_GNU_RELRO` segment that is remapped `R–X` right after the dynamic loader finishes applying relocations. Consequently, typical buffer overflows in the **.bss** can no longer reach the GOT and arbitrary‐write primitives cannot be used to overwrite function pointers that sit inside a RELRO-protected page.
1010

11-
### **Partial RELRO**
11+
There are **two levels** of protection that the linker can emit:
1212

13-
**Partial RELRO** takes a simpler approach to enhance security without significantly impacting the binary's performance. Partial RELRO makes **the .got read only (the non-PLT part of the GOT section)**. Bear in mind that the rest of the section (like the .got.plt) is still writeable and, therefore, subject to attacks. This **doesn't prevent the GOT** to be abused **from arbitrary write** vulnerabilities.
13+
### Partial RELRO
1414

15-
Note: By default, GCC compiles binaries with Partial RELRO.
15+
* Produced with the flag `-Wl,-z,relro` (or just `-z relro` when invoking `ld` directly).
16+
* Only the **non-PLT** part of the **GOT** (the part used for data relocations) is put into the read-only segment. Sections that need to be modified at run-time – most importantly **.got.plt** which supports **lazy binding** – remain writable.
17+
* Because of that, an **arbitrary write** primitive can still redirect execution flow by overwriting a PLT entry (or by performing **ret2dlresolve**).
18+
* The performance impact is negligible and therefore **almost every distribution has been shipping packages with at least Partial RELRO for years (it is the GCC/Binutils default as of 2016)**.
1619

17-
### **Full RELRO**
20+
### Full RELRO
1821

19-
**Full RELRO** steps up the protection by **making the entire GOT (both .got and .got.plt) and .fini_array** section completely **read-only.** Once the binary starts all the function addresses are resolved and loaded in the GOT, then, GOT is marked as read-only, effectively preventing any modifications to it during runtime.
22+
* Produced with **both** flags `-Wl,-z,relro,-z,now` (a.k.a. `-z relro -z now`). `-z now` forces the dynamic loader to resolve **all** symbols up-front (eager binding) so that **.got.plt** never needs to be written again and can safely be mapped read-only.
23+
* The entire **GOT**, **.got.plt**, **.fini_array**, **.init_array**, **.preinit_array** and a few additional internal glibc tables end up inside a read-only `PT_GNU_RELRO` segment.
24+
* Adds measurable start-up overhead (all dynamic relocations are processed at launch) but **no run-time overhead**.
2025

21-
However, the trade-off with Full RELRO is in terms of performance and startup time. Because it needs to resolve all dynamic symbols at startup before marking the GOT as read-only, **binaries with Full RELRO enabled may experience longer load times**. This additional startup overhead is why Full RELRO is not enabled by default in all binaries.
26+
Since 2023 several mainstream distributions have switched to compiling the **system tool-chain** (and most packages) with **Full RELRO by default** – e.g. **Debian 12 “bookworm” (dpkg-buildflags 13.0.0)** and **Fedora 35+**. As a pentester you should therefore expect to encounter binaries where **every GOT entry is read-only**.
2227

23-
It's possible to see if Full RELRO is **enabled** in a binary with:
28+
---
29+
30+
## How to Check the RELRO status of a binary
2431

2532
```bash
26-
readelf -l /proc/ID_PROC/exe | grep BIND_NOW
33+
$ checksec --file ./vuln
34+
[*] '/tmp/vuln'
35+
Arch: amd64-64-little
36+
RELRO: Full
37+
Stack: Canary found
38+
NX: NX enabled
39+
PIE: No PIE (0x400000)
2740
```
2841

29-
## Bypass
42+
`checksec` (part of [pwntools](https://github.com/pwncollege/pwntools) and many distributions) parses `ELF` headers and prints the protection level. If you cannot use `checksec`, rely on `readelf`:
3043

31-
If Full RELRO is enabled, the only way to bypass it is to find another way that doesn't need to write in the GOT table to get arbitrary execution.
44+
```bash
45+
# Partial RELRO → PT_GNU_RELRO is present but BIND_NOW is *absent*
46+
$ readelf -l ./vuln | grep -E "GNU_RELRO|BIND_NOW"
47+
GNU_RELRO 0x0000000000600e20 0x0000000000600e20
48+
```
3249

33-
Note that **LIBC's GOT is usually Partial RELRO**, so it can be modified with an arbitrary write. More information in [Targetting libc GOT entries](https://github.com/nobodyisnobody/docs/blob/main/code.execution.on.last.libc/README.md#1---targetting-libc-got-entries)**.**
50+
```bash
51+
# Full RELRO → PT_GNU_RELRO *and* the DF_BIND_NOW flag
52+
$ readelf -d ./vuln | grep BIND_NOW
53+
0x0000000000000010 (FLAGS) FLAGS: BIND_NOW
54+
```
3455

35-
{{#include ../../banners/hacktricks-training.md}}
56+
If the binary is running (e.g. a set-uid root helper), you can still inspect the executable **via `/proc/$PID/exe`**:
57+
58+
```bash
59+
readelf -l /proc/$(pgrep helper)/exe | grep GNU_RELRO
60+
```
61+
62+
---
63+
64+
## Enabling RELRO when compiling your own code
65+
66+
```bash
67+
# GCC example – create a PIE with Full RELRO and other common hardenings
68+
$ gcc -fPIE -pie -z relro -z now -Wl,--as-needed -D_FORTIFY_SOURCE=2 main.c -o secure
69+
```
3670

71+
`-z relro -z now` works for both **GCC/clang** (passed after `-Wl,`) and **ld** directly. When using **CMake 3.18+** you can request Full RELRO with the built-in preset:
3772

73+
```cmake
74+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) # LTO
75+
set(CMAKE_ENABLE_EXPORTS OFF)
76+
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)
77+
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-z,relro,-z,now")
78+
```
79+
80+
---
81+
82+
## Bypass Techniques
83+
84+
| RELRO level | Typical primitive | Possible exploitation techniques |
85+
|-------------|-------------------|----------------------------------|
86+
| None / Partial | Arbitrary write | 1. Overwrite **.got.plt** entry and pivot execution.<br>2. **ret2dlresolve** – craft fake `Elf64_Rela` & `Elf64_Sym` in a writable segment and call `_dl_runtime_resolve`.<br>3. Overwrite function pointers in **.fini_array** / **atexit()** list. |
87+
| Full | GOT is read-only | 1. Look for **other writable code pointers** (C++ vtables, `__malloc_hook` < glibc 2.34, `__free_hook`, callbacks in custom `.data` sections, JIT pages).<br>2. Abuse *relative read* primitives to leak libc and perform **SROP/ROP into libc**.<br>3. Inject a rogue shared object via **DT_RPATH**/`LD_PRELOAD` (if environment is attacker-controlled) or **`ld_audit`**.<br>4. Exploit **format-string** or partial pointer overwrite to divert control-flow without touching the GOT. |
88+
89+
> 💡 Even with Full RELRO the **GOT of loaded shared libraries (e.g. libc itself)** is **only Partial RELRO** because those objects are already mapped when the loader applies relocations. If you gain an **arbitrary write** primitive that can target another shared object’s pages you can still pivot execution by overwriting libc’s GOT entries or the `__rtld_global` stack, a technique regularly exploited in modern CTF challenges.
90+
91+
### Real-world bypass example (2024 CTF – *pwn.college “enlightened”*)
92+
93+
The challenge shipped with Full RELRO. The exploit used an **off-by-one** to corrupt the size of a heap chunk, leaked libc with `tcache poisoning`, and finally overwrote `__free_hook` (outside of the RELRO segment) with a one-gadget to get code execution. No GOT write was required.
3894

95+
---
96+
97+
## Recent research & vulnerabilities (2022-2025)
98+
99+
* **glibc 2.40 de-precates `__malloc_hook` / `__free_hook` (2025)** – Most modern heap exploits that abused these symbols must now pivot to alternative vectors such as **`rtld_global._dl_load_jump`** or C++ exception tables. Because hooks live **outside** of RELRO their removal increases the difficulty of Full-RELRO bypasses.
100+
* **Binutils 2.41 “max-page-size” fix (2024)** – A bug allowed the last few bytes of the RELRO segment to share a page with writable data on some ARM64 builds, leaving a tiny **RELRO gap** that could be written after `mprotect`. Upstream now aligns `PT_GNU_RELRO` to page boundaries, eliminating that edge-case.
101+
102+
---
103+
104+
## References
105+
106+
* Binutils documentation – *`-z relro`, `-z now` and `PT_GNU_RELRO`*
107+
* *“RELRO – Full, Partial and Bypass Techniques”* – blog post @ wolfslittlered 2023
108+
109+
{{#include ../../banners/hacktricks-training.md}}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# eSIM / Java Card VM Exploitation
2+
3+
{{#include ../banners/hacktricks-training.md}}
4+
5+
## Overview
6+
Embedded SIMs (eSIMs) are implemented as **Embedded UICC (eUICC)** smart-cards that run a **Java Card Virtual Machine (JC VM)** on top of a secure element.
7+
Because profiles and applets can be provisioned *over-the-air* (OTA) via Remote SIM Provisioning (RSP), any memory-safety flaw inside the JC VM instantly becomes a remote code-execution primitive **inside the most privileged component of the handset**.
8+
9+
This page describes a real-world full compromise of Kigen’s eUICC (Infineon SLC37 ESA1M2, ARM SC300) caused by missing type-safety checks in the `getfield` and `putfield` bytecodes. The same technique can be re-used against other vendors that omit on-card byte-code verification.
10+
11+
## Attack Surface
12+
1. **Remote Application Management (RAM)**
13+
eSIM profiles may embed arbitrary Java Card applets. Provisioning is performed with standard APDUs that can be tunnelled through SMS-PP (Short Message Service Point-to-Point) or HTTPS. If an attacker owns (or steals) the **RAM keys** for a profile, they can `INSTALL`/`LOAD` a malicious applet remotely.
14+
2. **Java Card byte-code execution**
15+
After installation, the applet executes inside the VM. Missing run-time checks allow memory corruption.
16+
17+
## The Type-Confusion Primitive
18+
`getfield` / `putfield` are supposed to operate only on **object references**. In Kigen eUICC the instructions never validate whether the operand on the stack is an *object* or an *array* reference. Because an `array.length` word lives at the exact same offset as the first instance field of a normal object, an attacker can:
19+
20+
1. Create a byte-array `byte[] buf = new byte[0x100];`
21+
2. Cast it to `Object o = (Object)buf;`
22+
3. Use `putfield` to overwrite *any* 16-bit value inside an adjacent object (including VTABLE / ptr translation entries).
23+
4. Use `getfield` to read *arbitrary* memory once internal pointers are hijacked.
24+
25+
```java
26+
// Pseudo-bytecode sequence executed by the malicious applet
27+
// buf = newarray byte 0x100
28+
// o = (Object) buf // illegal but not verified
29+
// putfield <victimObject+offset>, 0xCAFE // arbitrary write
30+
// ... set up read-what-where gadgets ...
31+
```
32+
The primitive provides **arbitrary read / write** in the eUICC address space – enough to dump the device-unique ECC private key that authenticates the card to the GSMA ecosystem.
33+
34+
## End-to-End Exploitation Workflow
35+
1. **Enumerate firmware** – Use undocumented `GET DATA` item `DF1F`:
36+
```
37+
80 CA DF 1F 00 // → "ECu10.13" (vulnerable)
38+
```
39+
2. **Install malicious applet OTA** – Abuse publicly-known keys of the TS.48 Generic Test Profile and push SMS-PP fragments that transport the CAP file (`LOAD`) followed by an `INSTALL`:
40+
```
41+
// simplified APDU chain
42+
80 E6 02 00 <data> // LOAD (block n)
43+
80 E6 0C 00 <data> // INSTALL for load
44+
```
45+
3. **Trigger type-confusion** – When the applet is selected it performs the write-what-where to hijack a pointer table and leak memory through normal APDU responses.
46+
4. **Extract GSMA certificate key** – Private EC key is copied to the applet’s RAM and returned in chunks.
47+
5. **Impersonate the eUICC** – The stolen key pair + certificates let the attacker authenticate to *any* RSP server as a legitimate card (EID binding may still be required for some operators).
48+
6. **Download and modify profiles** – Plaintext profiles contain highly sensitive fields such as `OPc`, `AMF`, OTA keys and even additional applets. The attacker can:
49+
* Clone a profile to a second eUICC (voice/SMS hijack);
50+
* Patch Java Card applications (e.g. insert STK spyware) before re-uploading;
51+
* Extract operator secrets for large-scale abuse.
52+
53+
## Cloning / Hijacking Demonstration
54+
Installing the same profile on **PHONE A** and **PHONE B** results in the Mobile Switching Centre routing incoming traffic to whichever device most recently registered. One session of Gmail 2FA SMS interception is enough to bypass MFA for the victim.
55+
56+
## Automated Test & Exploit Toolkit
57+
The researchers released an internal tool with a `bsc` (*Basic Security Check*) command that immediately shows whether a Java Card VM is vulnerable:
58+
```
59+
scard> bsc
60+
- castcheck [arbitrary int/obj casts]
61+
- ptrgranularity [pointer granularity/tr table presence]
62+
- locvaraccess [local variable access]
63+
- stkframeaccess [stack frame access]
64+
- instfieldaccess [instance field access]
65+
- objarrconfusion [object/array size field confusion]
66+
```
67+
Modules shipped with the framework:
68+
* `introspector` – full VM and memory explorer (~1.7 MB Java)
69+
* `security-test` – generic verification bypass applet (~150 KB)
70+
* `exploit` – 100 % reliable Kigen eUICC compromise (~72 KB)
71+
72+
## Mitigations
73+
1. **On-card byte-code verification** – enforce full control-flow & data-flow type tracking instead of stack-top only.
74+
2. **Hide array header** – place `length` outside of overlapping object fields.
75+
3. **Harden RAM keys policy** – never ship profiles with public keys; disable `INSTALL` in test profiles (addressed in GSMA TS.48 v7).
76+
4. **RSP server side heuristics** – rate-limit profile downloads per EID, monitor geographic anomalies, validate certificate freshness.
77+
78+
## Quick Checklist for Pentesters
79+
* Query `GET DATA DF1F` – vulnerable firmware string `ECu10.13` indicates Kigen.
80+
* Check if RAM keys are known ‑> attempt OTA `INSTALL`/`LOAD`.
81+
* After applet installation, brute-force simple cast primitive (`objarrconfusion`).
82+
* Try to read Security Domain private keys – success = full compromise.
83+
84+
## References
85+
- [Security Explorations – eSIM security](https://security-explorations.com/esim-security.html)
86+
- [GSMA TS.48 Generic Test Profile v7.0](https://www.gsma.com/get-involved/working-groups/gsma_resources/ts-48-v7-0-generic-euicc-test-profile-for-device-testing/)
87+
- [Java Card VM Specification 3.1](https://docs.oracle.com/en/java/javacard/3.1/jc-vm-spec/F12650_05.pdf)
88+
89+
{{#include ../banners/hacktricks-training.md}}

src/generic-methodologies-and-resources/phishing-methodology/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,14 @@ You can **buy a ___domain with a very similar name** to the victims ___domain **and/or
458458

459459
Use [**Phishious** ](https://github.com/Rices/Phishious)to evaluate if your email is going to end in the spam folder or if it's going to be blocked or successful.
460460

461+
## Clipboard Hijacking / Pastejacking
462+
463+
Attackers can silently copy malicious commands into the victim’s clipboard from a compromised or typosquatted web page and then trick the user to paste them inside **Win + R**, **Win + X** or a terminal window, executing arbitrary code without any download or attachment.
464+
465+
{{#ref}}
466+
clipboard-hijacking.md
467+
{{#endref}}
468+
461469
## References
462470

463471
- [https://zeltser.com/___domain-name-variations-in-phishing/](https://zeltser.com/___domain-name-variations-in-phishing/)

0 commit comments

Comments
 (0)