Skip to content

Commit 3f2d215

Browse files
committed
Merge branch 'master' of github.com:HackTricks-wiki/hacktricks
2 parents 789a2b7 + 63b0174 commit 3f2d215

File tree

3 files changed

+92
-6
lines changed

3 files changed

+92
-6
lines changed

src/generic-methodologies-and-resources/basic-forensic-methodology/malware-analysis.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,18 @@ When the information is saved in logs you can **check statistics like how many t
171171

172172
---
173173

174+
### Android in-app native telemetry (no root)
175+
176+
On Android, you can instrument native code inside the target app process by preloading a tiny logger library before other JNI libs initialize. This gives early visibility into native behavior without system-wide hooks or root. A popular approach is SoTap: drop libsotap.so for the right ABI into the APK and inject a System.loadLibrary("sotap") call early (e.g., static initializer or Application.onCreate), then collect logs from internal/external paths or Logcat fallback.
177+
178+
See the Android native reversing page for setup details and log paths:
179+
180+
{{#ref}}
181+
../../mobile-pentesting/android-app-pentesting/reversing-native-libraries.md
182+
{{#endref}}
183+
184+
---
185+
174186
## Deobfuscating Dynamic Control-Flow (JMP/CALL RAX Dispatchers)
175187

176188
Modern malware families heavily abuse Control-Flow Graph (CFG) obfuscation: instead of a direct jump/call they compute the destination at run-time and execute a `jmp rax` or `call rax`. A small *dispatcher* (typically nine instructions) sets the final target depending on the CPU `ZF`/`CF` flags, completely breaking static CFG recovery.
@@ -262,5 +274,6 @@ idc.set_callee_name(call_ea, resolved_addr, 0) # IDA 8.3+
262274
## References
263275

264276
- [Unit42 – Evolving Tactics of SLOW#TEMPEST: A Deep Dive Into Advanced Malware Techniques](https://unit42.paloaltonetworks.com/slow-tempest-malware-obfuscation/)
277+
- SoTap: Lightweight in-app JNI (.so) behavior logger – [github.com/RezaArbabBot/SoTap](https://github.com/RezaArbabBot/SoTap)
265278

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

src/mobile-pentesting/android-app-pentesting/reversing-native-libraries.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,42 @@ Java.perform(function () {
6363
```
6464
Frida will work out of the box on PAC/BTI-enabled devices (Pixel 8/Android 14+) as long as you use frida-server 16.2 or later – earlier versions failed to locate padding for inline hooks.
6565

66+
### Process-local JNI telemetry via preloaded .so (SoTap)
67+
68+
When full-featured instrumentation is overkill or blocked, you can still gain native-level visibility by preloading a small logger inside the target process. SoTap is a lightweight Android native (.so) library that logs the runtime behavior of other JNI (.so) libraries within the same app process (no root required).
69+
70+
Key properties:
71+
- Initializes early and observes JNI/native interactions inside the process that loads it.
72+
- Persists logs using multiple writable paths with graceful fallback to Logcat when storage is restricted.
73+
- Source-customizable: edit sotap.c to extend/adjust what gets logged and rebuild per ABI.
74+
75+
Setup (repack the APK):
76+
1) Drop the proper ABI build into the APK so the loader can resolve libsotap.so:
77+
- lib/arm64-v8a/libsotap.so (for arm64)
78+
- lib/armeabi-v7a/libsotap.so (for arm32)
79+
2) Ensure SoTap loads before other JNI libs. Inject a call early (e.g., Application subclass static initializer or onCreate) so the logger is initialized first. Smali snippet example:
80+
```smali
81+
const-string v0, "sotap"
82+
invoke-static {v0}, Ljava/lang/System;->loadLibrary(Ljava/lang/String;)V
83+
```
84+
3) Rebuild/sign/install, run the app, then collect logs.
85+
86+
Log paths (checked in order):
87+
```
88+
/data/user/0/%s/files/sotap.log
89+
/data/data/%s/files/sotap.log
90+
/sdcard/Android/data/%s/files/sotap.log
91+
/sdcard/Download/sotap-%s.log
92+
# If all fail: fallback to Logcat only
93+
```
94+
95+
Notes and troubleshooting:
96+
- ABI alignment is mandatory. A mismatch will raise UnsatisfiedLinkError and the logger won’t load.
97+
- Storage constraints are common on modern Android; if file writes fail, SoTap will still emit via Logcat.
98+
- Behavior/verbosity is intended to be customized; rebuild from source after editing sotap.c.
99+
100+
This approach is useful for malware triage and JNI debugging where observing native call flows from process start is critical but root/system-wide hooks aren’t available.
101+
66102
---
67103

68104
### Recent vulnerabilities worth hunting for in APKs
@@ -93,6 +129,9 @@ When you spot *third-party* `.so` files inside an APK, always cross-check their
93129
### References
94130

95131
- Frida 16.x change-log (Android hooking, tiny-function relocation) – [frida.re/news](https://frida.re/news/)
96-
- NVD advisory for `libwebp` overflow CVE-2023-4863 – [nvd.nist.gov](https://nvd.nist.gov/vuln/detail/CVE-2023-4863)
132+
- NVD advisory for `libwebp` overflow CVE-2023-4863 – [nvd.nist.gov](https://nvd.nist.gov/vuln/detail/CVE-2023-4863)
133+
- SoTap: Lightweight in-app JNI (.so) behavior logger – [github.com/RezaArbabBot/SoTap](https://github.com/RezaArbabBot/SoTap)
134+
- SoTap Releases – [github.com/RezaArbabBot/SoTap/releases](https://github.com/RezaArbabBot/SoTap/releases)
135+
- How to work with SoTap? – [t.me/ForYouTillEnd/13](https://t.me/ForYouTillEnd/13)
97136

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

src/mobile-pentesting/android-app-pentesting/smali-changes.md

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Smali - Decompiling/\[Modifying]/Compiling
1+
# Smali - Decompiling/[Modifying]/Compiling
22

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

@@ -25,7 +25,7 @@ If **apktool** gives you any error, try[ installing the **latest version**](http
2525

2626
Some **interesting files you should look are**:
2727

28-
- _res/values/strings.xml_ (and all xmls inside res/values/\*)
28+
- _res/values/strings.xml_ (and all xmls inside res/values/*)
2929
- _AndroidManifest.xml_
3030
- Any file with extension _.sqlite_ or _.db_
3131

@@ -162,7 +162,7 @@ invoke-static {v5, v1}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/Strin
162162

163163
Recommendations:
164164

165-
- If you are going to use declared variables inside the function (declared v0,v1,v2...) put these lines between the _.local \<number>_ and the declarations of the variables (_const v0, 0x1_)
165+
- If you are going to use declared variables inside the function (declared v0,v1,v2...) put these lines between the _.local <number>_ and the declarations of the variables (_const v0, 0x1_)
166166
- If you want to put the logging code in the middle of the code of a function:
167167
- Add 2 to the number of declared variables: Ex: from _.locals 10_ to _.locals 12_
168168
- The new variables should be the next numbers of the already declared variables (in this example should be _v10_ and _v11_, remember that it starts in v0).
@@ -186,8 +186,42 @@ move-result-object v12
186186
invoke-virtual {v12}, Landroid/widget/Toast;->show()V
187187
```
188188

189+
### Loading a Native Library at Startup (System.loadLibrary)
189190

190-
{{#include ../../banners/hacktricks-training.md}}
191+
Sometimes you need to preload a native library so it initializes before other JNI libs (e.g., to enable process-local telemetry/logging). You can inject a call to System.loadLibrary() in a static initializer or early in Application.onCreate(). Example smali for a static class initializer (<clinit>):
192+
193+
```smali
194+
.class public Lcom/example/App;
195+
.super Landroid/app/Application;
196+
197+
.method static constructor <clinit>()V
198+
.registers 1
199+
const-string v0, "sotap" # library name without lib...so prefix
200+
invoke-static {v0}, Ljava/lang/System;->loadLibrary(Ljava/lang/String;)V
201+
return-void
202+
.end method
203+
```
204+
205+
Alternatively, place the same two instructions at the start of your Application.onCreate() to ensure the library loads as early as possible:
206+
207+
```smali
208+
.method public onCreate()V
209+
.locals 1
210+
211+
const-string v0, "sotap"
212+
invoke-static {v0}, Ljava/lang/System;->loadLibrary(Ljava/lang/String;)V
213+
214+
invoke-super {p0}, Landroid/app/Application;->onCreate()V
215+
return-void
216+
.end method
217+
```
218+
219+
Notes:
220+
- Make sure the correct ABI variant of the library exists under lib/<abi>/ (e.g., arm64-v8a/armeabi-v7a) to avoid UnsatisfiedLinkError.
221+
- Loading very early (class static initializer) guarantees the native logger can observe subsequent JNI activity.
191222

223+
## References
192224

225+
- SoTap: Lightweight in-app JNI (.so) behavior logger – [github.com/RezaArbabBot/SoTap](https://github.com/RezaArbabBot/SoTap)
193226

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

0 commit comments

Comments
 (0)