Skip to content

Commit eef509e

Browse files
committed
Merge branch 'master' of github.com:HackTricks-wiki/hacktricks
2 parents 13dfd96 + 41faee9 commit eef509e

86 files changed

Lines changed: 5536 additions & 3893 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/AI/AI-llm-architecture/3.-token-embeddings.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,29 @@ Combined Embedding = Token Embedding + Positional Embedding
173173
- **Contextual Awareness:** The model can differentiate between tokens based on their positions.
174174
- **Sequence Understanding:** Enables the model to understand grammar, syntax, and context-dependent meanings.
175175

176+
## **Positional Embeddings in Modern LLMs**
177+
178+
### **Rotary Positional Embeddings (RoPE)**
179+
180+
RoPE encodes position by applying a position-dependent rotation to pairs of dimensions in the query/key vectors, turning absolute positions into relative phase differences. This provides relative position information while keeping embedding dimensionality unchanged and is widely used in recent decoder-only LLMs.
181+
182+
For how token and positional embeddings are combined inside the model, see [the LLM architecture page](5.-llm-architecture.md).
183+
184+
### **Extending Context Windows in RoPE-Based Models**
185+
186+
Recent work shows that context length is often limited by the positional encoding scheme rather than the token embedding matrix itself.
187+
188+
- **Position Interpolation (PI):** Rescales position indices so longer sequences map into the range seen during training, enabling extension with minimal fine-tuning. Example:
189+
190+
```python
191+
# Position Interpolation (PI) intuition
192+
orig_ctx = 2048
193+
new_ctx = 8192
194+
scaled_pos = pos * (orig_ctx / new_ctx)
195+
```
196+
197+
- **YaRN:** A compute-efficient RoPE extension strategy that modifies RoPE scaling/interpolation to extrapolate to longer contexts with fewer additional training steps.
198+
176199
## Code Example
177200

178201
Following with the code example from [https://github.com/rasbt/LLMs-from-scratch/blob/main/ch02/01_main-chapter-code/ch02.ipynb](https://github.com/rasbt/LLMs-from-scratch/blob/main/ch02/01_main-chapter-code/ch02.ipynb):
@@ -219,4 +242,6 @@ print(input_embeddings.shape) # torch.Size([8, 4, 256])
219242
- [https://www.manning.com/books/build-a-large-language-model-from-scratch](https://www.manning.com/books/build-a-large-language-model-from-scratch)
220243

221244

245+
- [https://arxiv.org/abs/2306.15595](https://arxiv.org/abs/2306.15595)
246+
- [https://arxiv.org/abs/2309.00071](https://arxiv.org/abs/2309.00071)
222247
{{#include ../../banners/hacktricks-training.md}}

src/SUMMARY.md

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -122,27 +122,33 @@
122122
- [Cisco - vmanage](linux-hardening/privilege-escalation/cisco-vmanage.md)
123123
- [Containerd (ctr) Privilege Escalation](linux-hardening/privilege-escalation/containerd-ctr-privilege-escalation.md)
124124
- [D-Bus Enumeration & Command Injection Privilege Escalation](linux-hardening/privilege-escalation/d-bus-enumeration-and-command-injection-privilege-escalation.md)
125-
- [Docker Security](linux-hardening/privilege-escalation/docker-security/README.md)
126-
- [Abusing Docker Socket for Privilege Escalation](linux-hardening/privilege-escalation/docker-security/abusing-docker-socket-for-privilege-escalation.md)
127-
- [AppArmor](linux-hardening/privilege-escalation/docker-security/apparmor.md)
128-
- [AuthZ& AuthN - Docker Access Authorization Plugin](linux-hardening/privilege-escalation/docker-security/authz-and-authn-docker-access-authorization-plugin.md)
129-
- [CGroups](linux-hardening/privilege-escalation/docker-security/cgroups.md)
130-
- [Docker --privileged](linux-hardening/privilege-escalation/docker-security/docker-privileged.md)
131-
- [Docker Breakout / Privilege Escalation](linux-hardening/privilege-escalation/docker-security/docker-breakout-privilege-escalation/README.md)
132-
- [release_agent exploit - Relative Paths to PIDs](linux-hardening/privilege-escalation/docker-security/docker-breakout-privilege-escalation/release_agent-exploit-relative-paths-to-pids.md)
133-
- [Docker release_agent cgroups escape](linux-hardening/privilege-escalation/docker-security/docker-breakout-privilege-escalation/docker-release_agent-cgroups-escape.md)
134-
- [Sensitive Mounts](linux-hardening/privilege-escalation/docker-security/docker-breakout-privilege-escalation/sensitive-mounts.md)
135-
- [Namespaces](linux-hardening/privilege-escalation/docker-security/namespaces/README.md)
136-
- [CGroup Namespace](linux-hardening/privilege-escalation/docker-security/namespaces/cgroup-namespace.md)
137-
- [IPC Namespace](linux-hardening/privilege-escalation/docker-security/namespaces/ipc-namespace.md)
138-
- [PID Namespace](linux-hardening/privilege-escalation/docker-security/namespaces/pid-namespace.md)
139-
- [Mount Namespace](linux-hardening/privilege-escalation/docker-security/namespaces/mount-namespace.md)
140-
- [Network Namespace](linux-hardening/privilege-escalation/docker-security/namespaces/network-namespace.md)
141-
- [Time Namespace](linux-hardening/privilege-escalation/docker-security/namespaces/time-namespace.md)
142-
- [User Namespace](linux-hardening/privilege-escalation/docker-security/namespaces/user-namespace.md)
143-
- [UTS Namespace](linux-hardening/privilege-escalation/docker-security/namespaces/uts-namespace.md)
144-
- [Seccomp](linux-hardening/privilege-escalation/docker-security/seccomp.md)
145-
- [Weaponizing Distroless](linux-hardening/privilege-escalation/docker-security/weaponizing-distroless.md)
125+
- [Container Security](linux-hardening/privilege-escalation/container-security/README.md)
126+
- [Runtimes And Engines](linux-hardening/privilege-escalation/container-security/runtimes-and-engines.md)
127+
- [Runtime API And Daemon Exposure](linux-hardening/privilege-escalation/container-security/runtime-api-and-daemon-exposure.md)
128+
- [Authorization Plugins](linux-hardening/privilege-escalation/container-security/authorization-plugins.md)
129+
- [Image Security And Secrets](linux-hardening/privilege-escalation/container-security/image-security-and-secrets.md)
130+
- [Assessment And Hardening](linux-hardening/privilege-escalation/container-security/assessment-and-hardening.md)
131+
- [Sensitive Host Mounts](linux-hardening/privilege-escalation/container-security/sensitive-host-mounts.md)
132+
- [Privileged Containers](linux-hardening/privilege-escalation/container-security/privileged-containers.md)
133+
- [Distroless](linux-hardening/privilege-escalation/container-security/distroless.md)
134+
- [Protections](linux-hardening/privilege-escalation/container-security/protections/README.md)
135+
- [AppArmor](linux-hardening/privilege-escalation/container-security/protections/apparmor.md)
136+
- [Capabilities](linux-hardening/privilege-escalation/container-security/protections/capabilities.md)
137+
- [CGroups](linux-hardening/privilege-escalation/container-security/protections/cgroups.md)
138+
- [Masked Paths](linux-hardening/privilege-escalation/container-security/protections/masked-paths.md)
139+
- [No New Privileges](linux-hardening/privilege-escalation/container-security/protections/no-new-privileges.md)
140+
- [Read Only Paths](linux-hardening/privilege-escalation/container-security/protections/read-only-paths.md)
141+
- [Seccomp](linux-hardening/privilege-escalation/container-security/protections/seccomp.md)
142+
- [SELinux](linux-hardening/privilege-escalation/container-security/protections/selinux.md)
143+
- [Namespaces](linux-hardening/privilege-escalation/container-security/protections/namespaces/README.md)
144+
- [CGroup Namespace](linux-hardening/privilege-escalation/container-security/protections/namespaces/cgroup-namespace.md)
145+
- [IPC Namespace](linux-hardening/privilege-escalation/container-security/protections/namespaces/ipc-namespace.md)
146+
- [PID Namespace](linux-hardening/privilege-escalation/container-security/protections/namespaces/pid-namespace.md)
147+
- [Mount Namespace](linux-hardening/privilege-escalation/container-security/protections/namespaces/mount-namespace.md)
148+
- [Network Namespace](linux-hardening/privilege-escalation/container-security/protections/namespaces/network-namespace.md)
149+
- [Time Namespace](linux-hardening/privilege-escalation/container-security/protections/namespaces/time-namespace.md)
150+
- [User Namespace](linux-hardening/privilege-escalation/container-security/protections/namespaces/user-namespace.md)
151+
- [UTS Namespace](linux-hardening/privilege-escalation/container-security/protections/namespaces/uts-namespace.md)
146152
- [Escaping from Jails](linux-hardening/privilege-escalation/escaping-from-limited-bash.md)
147153
- [Posix Cpu Timers Toctou Cve 2025 38352](linux-hardening/privilege-escalation/linux-kernel-exploitation/posix-cpu-timers-toctou-cve-2025-38352.md)
148154
- [euid, ruid, suid](linux-hardening/privilege-escalation/euid-ruid-suid.md)

src/binary-exploitation/libc-heap/house-of-roman.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This was a very interesting technique that allowed for RCE without leaks via fak
88

99
### Applicability in 2026
1010

11-
- **glibc window:** Works reliably on **2.23–2.28**. On **2.29** the additional `unsorted_chunks` integrity checks make the unsorted‑bin write unreliable, so success drops sharply. From **2.34** onward `__malloc_hook/__free_hook` were removed, making the original target unavailable. Use it only on old libcs (or custom builds that keep the hooks) or for CTF challenges that ship an old libc.
11+
- **glibc window:** Works reliably on **2.23–2.27** (the how2heap PoC tested 2.23–2.25). Starting **2.28**, the "additional checks for unsorted bin integrity" patch makes the unsorted‑bin write unreliable, so success drops sharply. From **2.34** onward `__malloc_hook/__free_hook` were removed, making the original target unavailable. Use it only on old libc's (or custom builds that keep the hooks) or for CTF challenges that ship an old libc.
1212
- **Tcache era (≥2.26):** Tcache will eat your 0x70 allocations and stop the fastbin/unsorted primitives. Disable it (`setenv("GLIBC_TUNABLES","glibc.malloc.tcache_count=0",1);`) **before** any allocation or fill each 0x70 tcache bin with 7 frees to drain it.
1313
- **Safe-linking:** It applies to tcache/fastbin in ≥2.32, but House of Roman only needs **partial pointer overwrite of a libc address already present in fd/bk**, so safe-linking does not help the defender here (the attacker never forges a fresh pointer). The real stopper is the hook removal and the unsorted-bin checks.
1414

@@ -117,9 +117,9 @@ Finally, once the correct address is overwritten, **call `malloc` and trigger th
117117

118118
## Modern tips & variants
119119

120-
- **Unsorted-bin check in 2.29+:** If you must run on 2.29–2.33, corrupt both `fd` **and** `bk` to satisfy the integrity check before triggering the write; otherwise `_int_malloc` aborts. Success rate is very low and usually only viable in brute-force CTF settings.
120+
- **Unsorted-bin hardening (2.28+):** The extra integrity checks on unsorted chunks (size sanity + list linkage) make the classic unsorted‑bin write fragile. To survive `_int_malloc`, you must keep `fd/bk` links consistent and sizes plausible, which usually requires stronger primitives than a simple partial overwrite.
121121
- **Hook removal (2.34+):** With `__malloc_hook` gone, adapt the primitive to land on any writable GOT/global you can later reuse (e.g., overwrite `exit@GOT` in non-PIE binaries) or pivot to a **House of Pie** style top‑chunk hijack to control `top` instead of a hook.
122-
- **Any‑address fastbin alloc (2024 gist):** A recent writeup shows reusing the same grooming to fastbin‑allocate over `__free_hook` or other globals by first landing a libc pointer in fastbin and then re‑pointing it before the fixup. This works on 2.24–2.28 but still dies on 2.29 integrity checks.
122+
- **Any‑address fastbin alloc (romanking98 writeup):** The second part shows repairing the 0x71 freelist and using the unsorted‑bin write to land a fastbin allocation over `__free_hook`, then placing `system("/bin/sh")` and triggering it via `free()` on libc‑2.24 (pre-hook removal).
123123

124124
## References
125125

@@ -128,5 +128,7 @@ Finally, once the correct address is overwritten, **call `malloc` and trigger th
128128
- [https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/house_of_roman/](https://ctf-wiki.mahaloz.re/pwn/linux/glibc-heap/house_of_roman/)
129129
- [https://halloween.synacktiv.com/publications/heap-tricks-never-get-old-insomnihack-teaser-2022.html](https://halloween.synacktiv.com/publications/heap-tricks-never-get-old-insomnihack-teaser-2022.html)
130130
- [https://gist.github.com/romanking98/9aab2804832c0fb46615f025e8ffb0bc](https://gist.github.com/romanking98/9aab2804832c0fb46615f025e8ffb0bc)
131+
- [https://sourceware.org/git/?p=glibc.git;a=blob_plain;f=NEWS;hb=glibc-2.34](https://sourceware.org/git/?p=glibc.git;a=blob_plain;f=NEWS;hb=glibc-2.34)
132+
- [https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=b90ddd08f6dd688e651df9ee89ca3a69ff88cd0c](https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=b90ddd08f6dd688e651df9ee89ca3a69ff88cd0c)
131133

132134
{{#include ../../banners/hacktricks-training.md}}

src/binary-exploitation/rop-return-oriented-programing/ret2vdso.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44

55
## Basic Information
66

7-
There might be **gadgets in the vDSO region**, which is used to change from user mode to kernel mode. In these type of challenges, usually a kernel image is provided to dump the vDSO region.
7+
There might be **gadgets in the vDSO region**, which is a small ELF DSO mapped by the kernel to provide fast user-space implementations of some kernel helpers. In these type of challenges, usually a kernel image is provided to dump the vDSO region.
8+
9+
### Locating the vDSO base and exports
10+
11+
The vDSO base address is passed in the auxiliary vector as `AT_SYSINFO_EHDR`, so if you can read `/proc/<pid>/auxv` (or call `getauxval` in a helper process), you can recover the base without relying on a memory leak. See [Auxiliary Vector (auxv) and vDSO](../basic-stack-binary-exploitation-methodology/elf-tricks.md) for practical ways to obtain it.
12+
13+
Once you have the base, treat the vDSO like a normal ELF DSO (`linux-vdso.so.1`): dump the mapping and use `readelf -Ws`/`objdump -d` (or the kernel reference parser `tools/testing/selftests/vDSO/parse_vdso.c`) to resolve exported symbols and look for gadgets. On x86 32-bit the vDSO commonly exports `__kernel_vsyscall`, `__kernel_sigreturn`, and `__kernel_rt_sigreturn`; on x86_64 typical exports include `__vdso_clock_gettime`, `__vdso_gettimeofday`, and `__vdso_time`. Because the vDSO uses symbol versioning, match the expected version when resolving symbols.
814

915
Following the example from [https://7rocky.github.io/en/ctf/other/htb-cyber-apocalypse/maze-of-mist/](https://7rocky.github.io/en/ctf/other/htb-cyber-apocalypse/maze-of-mist/) it's possible to see how it was possible to dump the vdso section and move it to the host with:
1016

@@ -60,13 +66,16 @@ pop_ebx_pop_esi_pop_ebp_ret = vdso_addr + 0x15cd
6066
6167
### ARM64
6268

63-
After dumping and checking the vdso section of a binary in kali 2023.2 arm64, I couldn't find in there any interesting gadget (no way to control registers from values in the stack or to control x30 for a ret) **except a way to call a SROP**. Check more info int eh example from the page:
69+
After dumping and checking the vdso section of a binary in kali 2023.2 arm64, I couldn't find in there any interesting gadget (no way to control registers from values in the stack or to control x30 for a ret) **except a way to call a SROP**. Check more info in the example from the page:
6470

6571

6672
{{#ref}}
6773
srop-sigreturn-oriented-programming/srop-arm64.md
6874
{{#endref}}
6975

70-
{{#include ../../banners/hacktricks-training.md}}
76+
## References
7177

78+
- [https://man7.org/linux/man-pages/man7/vdso.7.html](https://man7.org/linux/man-pages/man7/vdso.7.html)
79+
- [https://www.kernel.org/doc/Documentation/ABI/stable/vdso](https://www.kernel.org/doc/Documentation/ABI/stable/vdso)
7280

81+
{{#include ../../banners/hacktricks-training.md}}

0 commit comments

Comments
 (0)