-
Notifications
You must be signed in to change notification settings - Fork 98
/
setup.sh
214 lines (189 loc) · 7.06 KB
/
setup.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/data/data/com.termux/files/usr/bin/bash
#colors
red='\033[1;31m'
yellow='\033[1;33m'
reset='\033[0m'
ALPINEDIR="${PREFIX}/share/apkmod"
BINDIR="${PREFIX}/bin"
LIBDIR="${ALPINEDIR}/usr/lib"
APKTOOL_VERSION="2.6.1"
APKTOOL_URL="https://github.com/Hax4us/Apkmod/releases/download/v${APKTOOL_VERSION}/apktool-${APKTOOL_VERSION}.apk"
JADX_VERSION="1.3.2"
JADX_URL=https://github.com/skylot/jadx/releases/download/v${JADX_VERSION}/jadx-${JADX_VERSION}.zip
AAPT_URL="https://github.com/Hax4us/Apkmod/releases/download/v${APKTOOL_VERSION}/aapt_@[email protected]"
detect_os() {
if [ -e $BINDIR/termux-info ]; then
OS=TERMUX
#AAPT="-a /usr/bin/aapt2"
else
grep kali /etc/os-release > /dev/null 2>&1
if [ $? -eq 0 ]; then
OS=KALI
AAPT="--use-aapt2"
else
printf "${red}[!] ${yellow}Unsupported system\n"
exit 1
fi
fi
}
install_deps_kali() {
printf "[*] Installing dependencies...\n"
apt-get install metasploit-framework bc apktool default-jdk -y > /dev/null
wget https://github.com/hax4us/Apkmod/raw/master/apkmod.sh -O $PREFIX/bin/apkmod && chmod +x $PREFIX/bin/apkmod
printf "[*] Done\n"
}
setup_alpine() {
if [ ! "$1" = "--without-alpine" ]; then
wget https://raw.githubusercontent.com/Hax4us/Apkmod/master/scripts/TermuxAlpine.sh -O TermuxAlpine.sh
bash TermuxAlpine.sh
fi
mkdir -p ${ALPINEDIR}/root/.bind
cat <<EOF | apkmalpine
apk add openjdk8 libbsd zlib expat libpng protobuf libunwind
EOF
}
install_deps() {
for pkg in aapt apksigner wget bc busybox sed; do
if [ ! -f ${BINDIR}/${pkg} ]; then
apt install ${pkg} -y
fi
done
case "$(getprop ro.product.cpu.abi)" in
arm64-v8a)
ARCH=aarch64
;;
armeabi|armeabi-v7a)
ARCH=arm
;;
#x86|i686)
# ARCH=x86
# ;;
#x86_64)
# ARCH=x86_64
# ;;
*)
printf "your device "$(uname -m)" is not supported yet"
exit 1
;;
esac
wget ${AAPT_URL/@ARCH@/${ARCH}} -O aapt.tar.gz && tar -xf aapt.tar.gz -C ${LIBDIR} && rm aapt.tar.gz
for i in aapt aapt2; do
mv ${LIBDIR}/android/${i} ${ALPINEDIR}/usr/bin
done
wget ${APKTOOL_URL} -O ${ALPINEDIR}/opt/apktool.jar
wget https://github.com/hax4us/Apkmod/raw/master/apkmod.sh -O ${BINDIR}/apkmod
chmod +x ${BINDIR}/apkmod
chmod +x ${ALPINEDIR}/usr/bin/aapt
chmod +x ${ALPINEDIR}/usr/bin/aapt2
rm -rf ~/.apkmod && mkdir -p ~/.apkmod/framework
mkdir -p ~/.apkmod/hooks
for file in apkmod.p12 signkill.jar hooks/hook2.smali hooks/hook.smali hooks/hook2.dex; do
wget https://github.com/hax4us/Apkmod/raw/master/$file -O ~/.apkmod/$file
done
}
install_scripts() {
for script in signkill.sh apktool_termux.sh apktool_alpine.sh apk.rb jadx_termux.sh jadx_alpine.sh; do
wget https://github.com/hax4us/Apkmod/raw/master/scripts/${script} -O ${script}
done
mv apktool_termux.sh ${BINDIR}/apktool && chmod +x ${BINDIR}/apktool
mv apktool_alpine.sh ${ALPINEDIR}/bin/apktool && chmod +x ${ALPINEDIR}/bin/apktool
mv jadx_termux.sh $BINDIR/jadx && chmod +x $BINDIR/jadx
mv jadx_alpine.sh $ALPINEDIR/bin/jadx && chmod +x $ALPINEDIR/bin/jadx
mv signkill.sh $BINDIR/signkill && chmod +x $BINDIR/signkill
#mv signapk_termux.sh $BINDIR/signapk && chmod +x $BINDIR/signapk
#mv signapk_alpine.sh $ALPINEDIR/bin/signapk && chmod +x $ALPINEDIR/bin/signapk
if [ -d ${HOME}/metasploit-framework -a -d ${PREFIX}/opt/metasploit-framework ]; then
printf "${red}[!] More than one metasploit detected ,\nremove anyone from them and reinstall Apkmod\notherwise apkmod will not work as expected${reset}"
elif [ -d ${HOME}/metasploit-framework ]; then
msf_dir=${HOME}/metasploit-framework
mv apk.rb ${msf_dir}/lib/msf/core/payload/
elif [ -d ${PREFIX}/opt/metasploit-framework ]; then
msf_dir=${PREFIX}/opt/metasploit-framework
mv apk.rb ${msf_dir}/lib/msf/core/payload/
else
printf "${red}[!] Metasploit is not installed hence -b ( bind ) option will not work${reset}"
HAS_METASPLOIT="no"
fi
}
do_patches() {
cd ${msf_dir}
for i in "msfvenom" "lib/msf/core/payload_generator.rb"; do
if [ ! -e "${i}.orig" ]; then
cp ${i} ${i}.orig
fi
done
busybox grep "#patched" msfvenom > /dev/null
if [ $? -ne 0 ]; then
line_num=$(busybox grep -n "help" msfvenom | cut -d ":" -f1)
line_num=$((${line_num}-1))
busybox awk -v "n=${line_num}" -v "s=\n\topt.on('--use-aapt','Use aapt for recompiling') do\n\t\topts[:use_aapt] = true\n\tend" '(NR==n) { print s } 1' msfvenom.orig > msfvenom
if [ $? -eq 0 ]; then
printf "#patched" >> msfvenom
else
printf "${red}[!] can't patch msfvenom\n${reset}"
exit 1
fi
fi
busybox grep "#patched" lib/msf/core/payload_generator.rb > /dev/null
if [ $? -ne 0 ]; then
line_num=$(busybox grep -n ":add_code" lib/msf/core/payload_generator.rb | head -n1 | cut -d ":" -f1)
line_num=$((${line_num}-2))
busybox awk -v "n=${line_num}" -v "s=\t# @\!attribute use_aapt\n\t# @return [String] use aapt or not\n\tattr_accessor :use_aapt" '(NR==n) { print s } 1' lib/msf/core/payload_generator.rb.orig > lib/msf/core/payload_generator.rb
if [ $? -ne 0 ]; then
printf "${red}[!] can't patch payload_generator.rb\n${reset}"
exit 1
fi
line_num=$(busybox grep -n "@framework" lib/msf/core/payload_generator.rb | head -n1 | cut -d ":" -f1)
line_num=$((${line_num}-2))
busybox sed -i "${line_num}s/.*/\t@use_aapt = opts.fetch(:use_aapt,false)/" lib/msf/core/payload_generator.rb
if [ $? -ne 0 ]; then
printf "${red}[!] can't patch payload_genereator.rb\n${reset}"
exit 1
fi
line_num=$(busybox grep -n "apk_backdoor.backdoor_apk" lib/msf/core/payload_generator.rb | cut -d ":" -f1)
busybox sed -i "${line_num}s/.*/\t\traw_payload = apk_backdoor.backdoor_apk(template, generate_raw_payload, use_aapt)/" lib/msf/core/payload_generator.rb
if [ $? -eq 0 ]; then
printf "#patched" >> lib/msf/core/payload_generator.rb
else
printf "${red}[!] can't patch payload_generator.rb\n${reset}"
exit 1
fi
fi
#sed -i "s#AAPT=.*#AAPT=\"$AAPT\"#" $BINDIR/apkmod
if [ $OS = "KALI" ]; then
sed -i "s#AAPT=.*#AAPT=\"$AAPT\"#" $BINDIR/apkmod
sed -i s/"apktool b"/"apktool b --use-aapt2"/g /usr/share/metasploit-framework/lib/msf/core/payload/apk.rb
fi
}
jadx() {
wget ${JADX_URL}
mkdir -p ${ALPINEDIR}/usr/lib/jadx
unzip jadx-${JADX_VERSION}.zip -d ${ALPINEDIR}/usr/lib/jadx
}
##################
# MAIN DRIVER #
##################
detect_os
if [ $OS = "TERMUX" ]; then
termux-wake-lock
# Temporary check for alpine version
# so that if user has already installed
# TermuxAlpine then check if this alpine
# was installed by apkmod or not.
#if [ -d $PREFIX/share/TermuxAlpine ]; then
# if [ "$(cat $PREFIX/share/TermuxAlpine/etc/alpine-release)" = "3.10.2" ]; then
# mv $PREFIX/share/TermuxAlpine $ALPINEDIR
# fi
#fi
setup_alpine "$1"
install_deps
install_scripts
jadx
termux-wake-unlock
if [ ! "$HAS_METASPLOIT" = "no" ]; then
do_patches
fi
else
install_deps_kali
do_patches_kali
fi