anais-apk-forensic 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +249 -0
  3. package/anais.sh +669 -0
  4. package/analysis_tools/__pycache__/apk_basic_info.cpython-313.pyc +0 -0
  5. package/analysis_tools/__pycache__/apk_basic_info.cpython-314.pyc +0 -0
  6. package/analysis_tools/__pycache__/check_zip_encryption.cpython-313.pyc +0 -0
  7. package/analysis_tools/__pycache__/check_zip_encryption.cpython-314.pyc +0 -0
  8. package/analysis_tools/__pycache__/detect_obfuscation.cpython-313.pyc +0 -0
  9. package/analysis_tools/__pycache__/detect_obfuscation.cpython-314.pyc +0 -0
  10. package/analysis_tools/__pycache__/dex_payload_hunter.cpython-314.pyc +0 -0
  11. package/analysis_tools/__pycache__/entropy_analyzer.cpython-314.pyc +0 -0
  12. package/analysis_tools/__pycache__/error_logger.cpython-313.pyc +0 -0
  13. package/analysis_tools/__pycache__/error_logger.cpython-314.pyc +0 -0
  14. package/analysis_tools/__pycache__/find_encrypted_payload.cpython-314.pyc +0 -0
  15. package/analysis_tools/__pycache__/fix_apk_headers.cpython-313.pyc +0 -0
  16. package/analysis_tools/__pycache__/fix_apk_headers.cpython-314.pyc +0 -0
  17. package/analysis_tools/__pycache__/manifest_analyzer.cpython-313.pyc +0 -0
  18. package/analysis_tools/__pycache__/manifest_analyzer.cpython-314.pyc +0 -0
  19. package/analysis_tools/__pycache__/network_analyzer.cpython-313.pyc +0 -0
  20. package/analysis_tools/__pycache__/network_analyzer.cpython-314.pyc +0 -0
  21. package/analysis_tools/__pycache__/report_generator.cpython-313.pyc +0 -0
  22. package/analysis_tools/__pycache__/report_generator.cpython-314.pyc +0 -0
  23. package/analysis_tools/__pycache__/report_generator_modular.cpython-314.pyc +0 -0
  24. package/analysis_tools/__pycache__/sast_scanner.cpython-313.pyc +0 -0
  25. package/analysis_tools/__pycache__/sast_scanner.cpython-314.pyc +0 -0
  26. package/analysis_tools/__pycache__/so_string_analyzer.cpython-314.pyc +0 -0
  27. package/analysis_tools/__pycache__/yara_enhanced_analyzer.cpython-314.pyc +0 -0
  28. package/analysis_tools/__pycache__/yara_results_processor.cpython-314.pyc +0 -0
  29. package/analysis_tools/apk_basic_info.py +85 -0
  30. package/analysis_tools/check_zip_encryption.py +142 -0
  31. package/analysis_tools/detect_obfuscation.py +650 -0
  32. package/analysis_tools/dex_payload_hunter.py +734 -0
  33. package/analysis_tools/entropy_analyzer.py +335 -0
  34. package/analysis_tools/error_logger.py +75 -0
  35. package/analysis_tools/find_encrypted_payload.py +485 -0
  36. package/analysis_tools/fix_apk_headers.py +154 -0
  37. package/analysis_tools/manifest_analyzer.py +214 -0
  38. package/analysis_tools/network_analyzer.py +287 -0
  39. package/analysis_tools/report_generator.py +506 -0
  40. package/analysis_tools/report_generator_modular.py +885 -0
  41. package/analysis_tools/sast_scanner.py +412 -0
  42. package/analysis_tools/so_string_analyzer.py +406 -0
  43. package/analysis_tools/yara_enhanced_analyzer.py +330 -0
  44. package/analysis_tools/yara_results_processor.py +368 -0
  45. package/analyzer_config.json +113 -0
  46. package/apkid/__init__.py +32 -0
  47. package/apkid/__pycache__/__init__.cpython-313.pyc +0 -0
  48. package/apkid/__pycache__/__init__.cpython-314.pyc +0 -0
  49. package/apkid/__pycache__/apkid.cpython-313.pyc +0 -0
  50. package/apkid/__pycache__/apkid.cpython-314.pyc +0 -0
  51. package/apkid/__pycache__/main.cpython-313.pyc +0 -0
  52. package/apkid/__pycache__/main.cpython-314.pyc +0 -0
  53. package/apkid/__pycache__/output.cpython-313.pyc +0 -0
  54. package/apkid/__pycache__/rules.cpython-313.pyc +0 -0
  55. package/apkid/apkid.py +266 -0
  56. package/apkid/main.py +98 -0
  57. package/apkid/output.py +177 -0
  58. package/apkid/rules/apk/common.yara +68 -0
  59. package/apkid/rules/apk/obfuscators.yara +118 -0
  60. package/apkid/rules/apk/packers.yara +1197 -0
  61. package/apkid/rules/apk/protectors.yara +301 -0
  62. package/apkid/rules/dex/abnormal.yara +104 -0
  63. package/apkid/rules/dex/anti-vm.yara +568 -0
  64. package/apkid/rules/dex/common.yara +60 -0
  65. package/apkid/rules/dex/compilers.yara +434 -0
  66. package/apkid/rules/dex/obfuscators.yara +602 -0
  67. package/apkid/rules/dex/packers.yara +761 -0
  68. package/apkid/rules/dex/protectors.yara +520 -0
  69. package/apkid/rules/dll/common.yara +38 -0
  70. package/apkid/rules/dll/obfuscators.yara +43 -0
  71. package/apkid/rules/elf/anti-vm.yara +43 -0
  72. package/apkid/rules/elf/common.yara +54 -0
  73. package/apkid/rules/elf/obfuscators.yara +991 -0
  74. package/apkid/rules/elf/packers.yara +1128 -0
  75. package/apkid/rules/elf/protectors.yara +794 -0
  76. package/apkid/rules/res/common.yara +43 -0
  77. package/apkid/rules/res/obfuscators.yara +46 -0
  78. package/apkid/rules/res/protectors.yara +46 -0
  79. package/apkid/rules.py +77 -0
  80. package/bin/anais +3 -0
  81. package/dist/cli.js +82 -0
  82. package/dist/index.js +123 -0
  83. package/dist/types/index.js +2 -0
  84. package/dist/utils/index.js +21 -0
  85. package/dist/utils/output.js +44 -0
  86. package/dist/utils/paths.js +107 -0
  87. package/docs/ARCHITECTURE.txt +353 -0
  88. package/docs/Workflow and Reference.md +445 -0
  89. package/package.json +70 -0
  90. package/rules/yara_general_rules.yar +323 -0
  91. package/scripts/dynamic_analysis_helper.sh +334 -0
  92. package/scripts/frida/dpt_dex_dumper.js +145 -0
  93. package/scripts/frida/frida_dex_dump.js +145 -0
  94. package/scripts/frida/frida_hooks.js +437 -0
  95. package/scripts/frida/frida_websocket_extractor.js +154 -0
  96. package/scripts/setup.sh +206 -0
  97. package/scripts/validate_framework.sh +224 -0
  98. package/src/cli.ts +91 -0
  99. package/src/index.ts +123 -0
  100. package/src/types/index.ts +44 -0
  101. package/src/utils/index.ts +6 -0
  102. package/src/utils/output.ts +50 -0
  103. package/src/utils/paths.ts +72 -0
  104. package/tsconfig.json +14 -0
@@ -0,0 +1,445 @@
1
+ # 🔍 Android Malware Analysis - Quick Reference Guide
2
+
3
+ ## 📌 Workflow Overview
4
+
5
+ ```
6
+ START
7
+
8
+ ┌─────────────────────────────────┐
9
+ │ 1. INITIAL ASSESSMENT │
10
+ │ - File hash (SHA256, MD5) │
11
+ │ - File size │
12
+ │ - Basic APK info │
13
+ └────────────┬────────────────────┘
14
+
15
+ ┌─────────────────────────────────┐
16
+ │ 2. PROTECTION CHECK │
17
+ │ - ZIP encryption? │
18
+ │ - Password protected? │
19
+ │ - Header manipulation? │
20
+ └────────────┬────────────────────┘
21
+
22
+ Protected?
23
+ ├─ YES → Fix Headers
24
+ └─ NO → Continue
25
+
26
+ ┌─────────────────────────────────┐
27
+ │ 3. DECOMPILATION │
28
+ │ - APKTool (SMALI) │
29
+ │ - JADX (Java source) │
30
+ └────────────┬────────────────────┘
31
+
32
+ ┌─────────────────────────────────┐
33
+ │ 4. OBFUSCATION DETECTION │
34
+ │ - ProGuard/R8? │
35
+ │ - DPT-Shell? │
36
+ │ - DexProtector? │
37
+ │ - Bangcle? │
38
+ └────────────┬────────────────────┘
39
+
40
+ Advanced Protection?
41
+ ├─ YES → DYNAMIC ANALYSIS
42
+ │ ↓
43
+ │ ┌──────────────────────┐
44
+ │ │ - Install on device │
45
+ │ │ - Run app │
46
+ │ │ - Frida hooks │
47
+ │ │ - DEX dump │
48
+ │ │ - Re-analyze │
49
+ │ └──────────────────────┘
50
+
51
+ └─ NO → STATIC ANALYSIS
52
+
53
+ ┌─────────────────────────────────┐
54
+ │ 5. STATIC ANALYSIS (SAST) │
55
+ │ - Pattern matching │
56
+ │ - Vulnerability detection │
57
+ │ - Code review │
58
+ └────────────┬────────────────────┘
59
+
60
+ ┌─────────────────────────────────┐
61
+ │ 6. ARTIFACT EXTRACTION │
62
+ │ - Network URLs │
63
+ │ - Domains & IPs │
64
+ │ - C2 indicators │
65
+ │ - Crypto wallets │
66
+ └────────────┬────────────────────┘
67
+
68
+ ┌─────────────────────────────────┐
69
+ │ 7. MANIFEST ANALYSIS │
70
+ │ - Permissions │
71
+ │ - Components │
72
+ │ - Misconfigurations │
73
+ └────────────┬────────────────────┘
74
+
75
+ ┌─────────────────────────────────┐
76
+ │ 8. YARA SCANNING │
77
+ │ - Known malware families │
78
+ │ - Suspicious patterns │
79
+ │ - IOC matching │
80
+ └────────────┬────────────────────┘
81
+
82
+ ┌─────────────────────────────────┐
83
+ │ 9. REPORT GENERATION │
84
+ │ - Findings summary │
85
+ │ - Risk scoring │
86
+ │ - Evidence (code snippets) │
87
+ │ - Recommendations │
88
+ └─────────────────────────────────┘
89
+
90
+ END
91
+ ```
92
+
93
+ ## 🎯 Quick Commands
94
+
95
+ ### Static Analysis
96
+
97
+ ```bash
98
+ # Full analysis
99
+ ./malware_analyzer.sh app.apk
100
+
101
+ # With custom YARA rules
102
+ yara -r custom_rules.yar decompiled_dir/
103
+ ```
104
+
105
+ ### Dynamic Analysis
106
+
107
+ ```bash
108
+ # Install Frida server
109
+ ./dynamic_analysis_helper.sh install-frida
110
+
111
+ # Dump DEX files
112
+ ./dynamic_analysis_helper.sh dex-dump com.malware.app
113
+
114
+ # Hook crypto operations
115
+ ./dynamic_analysis_helper.sh hook-crypto com.malware.app
116
+
117
+ # Hook network
118
+ ./dynamic_analysis_helper.sh hook-network com.malware.app
119
+
120
+ # Pull dumps
121
+ ./dynamic_analysis_helper.sh pull-dumps
122
+ ```
123
+
124
+ ### Manual Frida Usage
125
+
126
+ ```bash
127
+ # List processes
128
+ frida-ps -U
129
+
130
+ # Attach to app
131
+ frida -U -f com.malware.app
132
+
133
+ # Run script
134
+ frida -U -f com.malware.app -l script.js --no-pause
135
+ ```
136
+
137
+ ## 🔥 Common Attack Patterns
138
+
139
+ ### 1. Banking Trojan
140
+
141
+ **Indicators:**
142
+
143
+ - Accessibility service abuse
144
+ - Overlay windows (SYSTEM_ALERT_WINDOW)
145
+ - SMS interception
146
+ - Screen recording
147
+ - Contact list access
148
+
149
+ **Detection:**
150
+
151
+ ```bash
152
+ # Look for
153
+ - AccessibilityService implementation
154
+ - WindowManager.addView
155
+ - TYPE_SYSTEM_OVERLAY
156
+ - MediaProjection
157
+ ```
158
+
159
+ ### 2. Crypto Wallet Stealer
160
+
161
+ **Indicators:**
162
+
163
+ - Wallet app package names
164
+ - Mnemonic/seed phrase keywords
165
+ - Clipboard monitoring
166
+ - Keylogging via accessibility
167
+
168
+ **Detection:**
169
+
170
+ ```bash
171
+ # Search for
172
+ - im.token.app
173
+ - io.metamask
174
+ - "mnemonic"
175
+ - "seed phrase"
176
+ - ClipboardManager
177
+ ```
178
+
179
+ ### 3. Spyware
180
+
181
+ **Indicators:**
182
+
183
+ - Location tracking
184
+ - Contact exfiltration
185
+ - Call log access
186
+ - SMS reading
187
+ - Camera/microphone access
188
+
189
+ **Detection:**
190
+
191
+ ```bash
192
+ # Check permissions
193
+ - ACCESS_FINE_LOCATION
194
+ - READ_CONTACTS
195
+ - READ_CALL_LOG
196
+ - READ_SMS
197
+ - CAMERA, RECORD_AUDIO
198
+ ```
199
+
200
+ ### 4. C2 Malware
201
+
202
+ **Indicators:**
203
+
204
+ - WebSocket connections
205
+ - Suspicious domains (.top, .xyz)
206
+ - Periodic network checks
207
+ - Command execution
208
+
209
+ **Detection:**
210
+
211
+ ```bash
212
+ # Look for
213
+ - wss:// connections
214
+ - Suspicious TLDs
215
+ - AlarmManager (periodic tasks)
216
+ - Runtime.exec
217
+ ```
218
+
219
+ ## 🛡️ Protection Types & Bypass Methods
220
+
221
+ ### ProGuard/R8
222
+
223
+ **Characteristics:**
224
+
225
+ - Short class/method names (a.java, b(), c)
226
+ - Package flattening
227
+ - String encryption
228
+
229
+ **Analysis:**
230
+
231
+ - ✅ Static analysis possible
232
+ - Use JADX with deobfuscation
233
+ - Focus on network/crypto APIs
234
+
235
+ ### DPT-Shell
236
+
237
+ **Characteristics:**
238
+
239
+ - libdpt.so present
240
+ - DEX header manipulation
241
+ - Native code decryption
242
+
243
+ **Bypass:**
244
+
245
+ ```bash
246
+ 1. Install APK on rooted device
247
+ 2. Run app to trigger unpacking
248
+ 3. frida-dexdump -U -f com.app
249
+ 4. Analyze dumped DEX
250
+ ```
251
+
252
+ ### DexProtector
253
+
254
+ **Characteristics:**
255
+
256
+ - libprotect.so / libexec.so
257
+ - String encryption
258
+ - Control flow obfuscation
259
+
260
+ **Bypass:**
261
+
262
+ - Same as DPT-Shell
263
+ - Use memory dumps
264
+ - Hook native functions
265
+
266
+ ### Bangcle
267
+
268
+ **Characteristics:**
269
+
270
+ - libbangcle.so
271
+ - Application class wrapper
272
+ - DEX encryption
273
+
274
+ **Bypass:**
275
+
276
+ - Dynamic unpacking required
277
+ - Dump from /data/data/app/
278
+
279
+ ## 📊 Risk Scoring Guide
280
+
281
+ | Score | Level | Description | Action |
282
+ | ------ | ----------- | ------------------- | ----------------- |
283
+ | 0-19 | 🟢 LOW | Minor issues | Review & monitor |
284
+ | 20-39 | 🟡 MEDIUM | Security concerns | Investigate |
285
+ | 40-69 | 🟠 HIGH | Suspicious behavior | Detailed analysis |
286
+ | 70-100 | 🔴 CRITICAL | Confirmed malware | Immediate action |
287
+
288
+ ## 🔍 Key Files to Check
289
+
290
+ ### AndroidManifest.xml
291
+
292
+ ```xml
293
+ <!-- Dangerous permissions -->
294
+ <uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE"/>
295
+ <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
296
+ <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
297
+
298
+ <!-- Exported components without protection -->
299
+ <service android:name=".MaliciousService" android:exported="true"/>
300
+
301
+ <!-- Debuggable flag -->
302
+ <application android:debuggable="true">
303
+ ```
304
+
305
+ ### SMALI Code Patterns
306
+
307
+ ```smali
308
+ # Runtime.exec usage
309
+ invoke-virtual {v0, v1}, Ljava/lang/Runtime;->exec(Ljava/lang/String;)
310
+
311
+ # DexClassLoader
312
+ invoke-direct {v0, v1, v2, v3, v4}, Ldalvik/system/DexClassLoader;-><init>
313
+
314
+ # Accessibility Service
315
+ Landroid/accessibilityservice/AccessibilityService;
316
+ ```
317
+
318
+ ### Java Code Patterns
319
+
320
+ ```java
321
+ // Dynamic code loading
322
+ DexClassLoader loader = new DexClassLoader(dexPath, ...);
323
+
324
+ // Native library loading
325
+ System.loadLibrary("suspicious");
326
+
327
+ // Root detection bypass
328
+ Runtime.getRuntime().exec("su");
329
+
330
+ // Reflection abuse
331
+ Method method = clazz.getDeclaredMethod("hidden", ...);
332
+ method.invoke(instance, ...);
333
+ ```
334
+
335
+ ## 🎓 Analysis Checklist
336
+
337
+ ### Initial Triage
338
+
339
+ - [ ] Calculate file hashes
340
+ - [ ] Check file size (unusually large/small?)
341
+ - [ ] Verify APK signature
342
+ - [ ] Extract basic info (package, version)
343
+ - [ ] Check VirusTotal/online scanners
344
+
345
+ ### Static Analysis
346
+
347
+ - [ ] Decompile with APKTool
348
+ - [ ] Decompile with JADX
349
+ - [ ] Detect obfuscation type
350
+ - [ ] Analyze AndroidManifest.xml
351
+ - [ ] Review dangerous permissions
352
+ - [ ] Check exported components
353
+ - [ ] Scan with YARA rules
354
+ - [ ] Extract network artifacts
355
+ - [ ] Review native libraries
356
+ - [ ] Check assets directory
357
+
358
+ ### Dynamic Analysis (if needed)
359
+
360
+ - [ ] Setup isolated environment
361
+ - [ ] Install APK on test device
362
+ - [ ] Monitor network traffic
363
+ - [ ] Hook sensitive APIs with Frida
364
+ - [ ] Dump DEX from memory
365
+ - [ ] Capture screenshots/screen recording
366
+ - [ ] Monitor file system changes
367
+ - [ ] Check IPC/broadcasts
368
+
369
+ ### Documentation
370
+
371
+ - [ ] Document all findings
372
+ - [ ] Include code evidence
373
+ - [ ] List IOCs (domains, IPs, hashes)
374
+ - [ ] Calculate risk score
375
+ - [ ] Provide remediation steps
376
+ - [ ] Generate final report
377
+
378
+ ## 📱 Testing Environment Setup
379
+
380
+ ### Recommended Setup
381
+
382
+ ```
383
+ Host Machine (macOS/Linux)
384
+ ├── Analysis tools (APKTool, JADX, YARA)
385
+ ├── Python environment
386
+ └── Frida tools
387
+
388
+ Android Emulator/Device
389
+ ├── Rooted (Magisk)
390
+ ├── Android 7-10 (best for analysis)
391
+ ├── Frida server installed
392
+ ├── SSL bypass modules
393
+ └── Network monitoring (tcpdump/mitmproxy)
394
+ ```
395
+
396
+ ### Device Prep
397
+
398
+ ```bash
399
+ # Root check
400
+ adb shell su -c "id"
401
+
402
+ # Install Frida server
403
+ ./dynamic_analysis_helper.sh install-frida
404
+
405
+ # Disable SSL pinning (if using Magisk)
406
+ # Install TrustMeAlready or similar module
407
+
408
+ # Network monitoring
409
+ adb shell tcpdump -i wlan0 -w /sdcard/capture.pcap
410
+ ```
411
+
412
+ ## 🚨 Red Flags
413
+
414
+ Immediate investigation if found:
415
+
416
+ - ✋ BIND_ACCESSIBILITY_SERVICE permission
417
+ - ✋ SYSTEM_ALERT_WINDOW + banking app targeting
418
+ - ✋ WebSocket to suspicious domain
419
+ - ✋ Crypto wallet package names + clipboard access
420
+ - ✋ SMS_RECEIVED + abortBroadcast
421
+ - ✋ REQUEST_INSTALL_PACKAGES permission
422
+ - ✋ Native protection + network activity
423
+ - ✋ String encryption + C2 patterns
424
+ - ✋ Screen recording + accessibility
425
+ - ✋ Root detection bypass + data exfiltration
426
+
427
+ ## 📚 Additional Resources
428
+
429
+ ### Tools
430
+
431
+ - **APKTool:** https://ibotpeaches.github.io/Apktool/
432
+ - **JADX:** https://github.com/skylot/jadx
433
+ - **Frida:** https://frida.re/
434
+ - **Androguard:** https://github.com/androguard/androguard
435
+ - **YARA:** https://virustotal.github.io/yara/
436
+
437
+ ### Learning
438
+
439
+ - **OWASP MSTG:** https://mas.owasp.org/
440
+ - **Android Security:** https://source.android.com/security
441
+ - **Malware Analysis:** https://www.malware-traffic-analysis.net/
442
+
443
+ ---
444
+
445
+ **Remember:** Always analyze malware in isolated environment!
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "anais-apk-forensic",
3
+ "version": "1.0.0",
4
+ "description": "Comprehensive APK security analysis and forensic investigation tool for Android applications",
5
+ "main": "dist/index.js",
6
+ "bin": {
7
+ "anais": "./bin/anais"
8
+ },
9
+ "scripts": {
10
+ "build": "tsc",
11
+ "prepublishOnly": "npm run build",
12
+ "postinstall": "chmod +x anais.sh scripts/*.sh 2>/dev/null || true",
13
+ "start": "npm run build && node dist/cli.js",
14
+ "test": "echo \"No tests yet\" && exit 0"
15
+ },
16
+ "dependencies": {
17
+ "@types/node": "^20.0.0"
18
+ },
19
+ "devDependencies": {
20
+ "typescript": "^5.0.0",
21
+ "ts-node": "^10.0.0"
22
+ },
23
+ "keywords": [
24
+ "apk",
25
+ "android",
26
+ "forensics",
27
+ "security",
28
+ "analysis",
29
+ "malware",
30
+ "sast",
31
+ "yara",
32
+ "decompile",
33
+ "reverse-engineering",
34
+ "mobile-security",
35
+ "penetration-testing"
36
+ ],
37
+ "author": "reezcode",
38
+ "license": "MIT",
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "https://github.com/reezcode/Anais-APK-Forensic-Automation.git"
42
+ },
43
+ "homepage": "https://github.com/reezcode/Anais-APK-Forensic-Automation#readme",
44
+ "bugs": {
45
+ "url": "https://github.com/reezcode/Anais-APK-Forensic-Automation/issues"
46
+ },
47
+ "engines": {
48
+ "node": ">=14.0.0",
49
+ "python": ">=3.8.0"
50
+ },
51
+ "files": [
52
+ "dist",
53
+ "bin",
54
+ "src",
55
+ "anais.sh",
56
+ "analyzer_config.json",
57
+ "analysis_tools",
58
+ "scripts",
59
+ "rules",
60
+ "apkid",
61
+ "docs",
62
+ "README.md",
63
+ "LICENSE",
64
+ "tsconfig.json"
65
+ ],
66
+ "os": [
67
+ "darwin",
68
+ "linux"
69
+ ]
70
+ }