-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy patheasy_pwn.sh
executable file
·413 lines (331 loc) · 9.25 KB
/
easy_pwn.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
#!/bin/bash
# Sailfish OS easy_pwn
#
# Copyright (C) 2020 <Giuseppe `r3vn` Corti>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# check privileges
if [ "$EUID" -ne 0 ]
then
echo "[!] run as root"
exit 1
fi
# check args
if [ "$#" -lt 2 ]
then
echo "[!] usage: $0 [action] [destination-path]"
exit 1
fi
# set variables
PWN_SH=`readlink -f "$0"`
PWN_DIR=`dirname "$PWN_SH"`
ACTION="$1"
TARGET="$2"
PR_DIR=`dirname "$TARGET"`
CHROOT_NAME=`basename "$TARGET"`
CHROOT_PATH=`readlink -f "$TARGET"`
PWN_ICON=$PWN_DIR/src/icon.png
# import default settings
. $PWN_DIR/mount/settings.sh
kill_chroot() {
# Find processes who's root folder is actually the chroot
# https://askubuntu.com/a/552038
echo "[!] WARNING : killing all chroot processes"
for ROOT in $(find /proc/*/root)
do
# Check where the symlink is pointing to
LINK=$(readlink -f $ROOT)
# If it's pointing to the $CHROOT you set above, kill the process
if echo $LINK | grep -q ${CHROOT_PATH%/}
then
PID=$(basename $(dirname "$ROOT"))
echo "[!] killing $PID"
# store logs on epw-session.log
kill -9 $PID > /tmp/$CHROOT_NAME/epwn-session.log 2>&1
fi
done
sleep 1
}
umount_all(){
# umount the chroot
if mountpoint -q $TARGET/dev/
then
umount -R $TARGET/mnt/easy_pwn
umount -R $TARGET/dev/pts
#umount -R $TARGET/run/display
umount -R $TARGET/run
umount -R $TARGET/tmp/
umount $TARGET/proc/
umount -R $TARGET/dev/
umount -R $TARGET/sys/
umount -R $TARGET/var/lib/dbus
umount -R /run/user/1001/pulse
echo "[+] chroot umounted"
sleep 2
else
echo "[-] chroot not mounted"
fi
}
check_mount() {
# mount dev sys proc
if mountpoint -q $TARGET/dev/
then
echo "[+] chroot mounted"
else
echo "[-] mounting chroot..."
SD_NAME="0"
for dir in $(ls /run/media/$PWN_USER)
do
if mountpoint -q "/run/media/$PWN_USER/$dir"
then
# chroot is located on sdcard
# remounting the sdcard with suid enabled
SD_NAME=$dir
fi
done
if [ "$SD_NAME" != "0" ]
then
echo "[!] warning $CHROOT_NAME seems located on a partition mounted without suid enabled."
echo " we need to remount $SD_NAME with suid enabled in order to proceed."
echo "[?] remount $SD_NAME with setuid enabled? [y/n]"
read -p "[>] " SUID_SELECTION
if [ "$SUID_SELECTION" == "y" ]
then
mount -o remount,suid /media/sdcard/$SD_NAME
echo "[-] sdcard remounted."
sleep 1
else
echo "[-] exit."
exit 1
fi
fi
# create nemo /run/user directory
mkdir -p /run/user/1001
chown -R $PWN_USER:$PWN_USER /run/user/1001
# dev sys proc
mount -t proc proc $TARGET/proc/
mount --rbind --make-rslave /sys $TARGET/sys/
mount --rbind --make-rslave /dev $TARGET/dev/
# mount run
mount --rbind --make-rslave /run $TARGET/run/
# wayland
#mkdir -p $TARGET/run/display
#mount --rbind --make-rslave /run/display $TARGET/run/display
# pulseaudio
mkdir -p $TARGET/run/user/1001/pulse
mount --bind /run/user/100000/pulse /run/user/1001/pulse
# dbus
mkdir -p $TARGET/var/lib/dbus
#mkdir -p $TARGET/run/dbus
#mount --rbind --make-rslave /run/dbus $TARGET/run/dbus
mount --bind --make-slave /var/lib/dbus $TARGET/var/lib/dbus
# mount devpts
mount --bind --make-slave /dev/pts $TARGET/dev/pts
# tmp directory
mkdir -p /tmp/$CHROOT_NAME/
chmod 1777 /tmp/$CHROOT_NAME/
mount --bind --make-slave /tmp/$CHROOT_NAME $TARGET/tmp
# easy_pwn mountpoint
mkdir -p $CHROOT_PATH/mnt/easy_pwn
mount --bind --make-slave $PWN_DIR/mount $CHROOT_PATH/mnt/easy_pwn
# replace chroot iptables binary with sailfish's iptables
cp -ar /sbin/iptables $CHROOT_PATH/sbin/iptables
# copy resolv.conf
cp /etc/resolv.conf $TARGET/resolv.conf
echo "[+] done."
sleep 2
fi
}
update_pwn(){
# update easy_pwn kali scripts
# deploy easy pwn
#echo "[-] easy_pwn deploy..."
#mkdir -p $TARGET/mnt/easy_pwn
#cp -avr -T $PWN_DIR/deploy/easy_pwn $TARGET/mnt/easy_pwn
# deploy xfce configs
echo "[-] user configs deploy..."
mkdir -p $TARGET/home/$PWN_USER/.config
cp -avr -T $PWN_DIR/deploy/configs $TARGET/home/$PWN_USER/.config
# fix nemo user home permissions
echo "[-] fixing permissions..."
chown -R $PWN_USER:$PWN_USER $TARGET/home/$PWN_USER
# add execution permissions on /mnt/easy_pwn
chmod +x $PWN_DIR/mount/desktop/setup_desktop.sh
chmod +x $PWN_DIR/mount/desktop/start_desktop.sh
# add execution permission on wizard.sh
chmod +x $PWN_DIR/wizard.sh
}
install_icon(){
# install .desktop icon on /home/nemo/.local/share/applications
# overwriting the previous
echo "[-] installing $CHROOT_NAME.desktop in /home/$PWN_USER/.local/share/applications..."
sed "s|XX_PWNPATH_XX|$PWN_DIR|g" $PWN_DIR/src/easy_pwn.desktop > /home/$PWN_USER/.local/share/applications/$CHROOT_NAME.desktop
sed -i "s|XX_NAME_XX|$CHROOT_NAME|g" /home/$PWN_USER/.local/share/applications/$CHROOT_NAME.desktop
sed -i "s|XX_CHROOTPATH_XX|$CHROOT_PATH|g" /home/$PWN_USER/.local/share/applications/$CHROOT_NAME.desktop
sed -i "s|XX_ICON_XX|$PWN_ICON|g" /home/$PWN_USER/.local/share/applications/$CHROOT_NAME.desktop
sleep 1
}
start_desktop(){
# start chroot desktop
DESKTOP_ORIENTATION="p" # default portrait
if [ "$OR_LANDSCAPE" == true ]
then
DESKTOP_ORIENTATION="l"
# set env on sfos qxcompositor
#mkdir -p /run/user/1001
#export $(dbus-launch)
export XDG_RUNTIME_DIR=/run/user/100000
# start qxcompositor
echo "[-] starting qxcompositor..."
su $PWN_USER -c "qxcompositor --wayland-socket-name ../../display/wayland-1" &
sleep 3
fi
# start dbus
#echo "[-] starting chroot's dbus..."
#chroot $TARGET /etc/init.d/dbus start
# run kali-side script
echo "[-] chrooting..."
# store chroot output on /tmp/easy_pwn/epwn-session.log
chroot $TARGET su $PWN_USER -c "/mnt/easy_pwn/desktop/start_desktop.sh $DESKTOP_ORIENTATION" >> /tmp/$CHROOT_NAME/epwn-session.log 2>&1
}
get_kali(){
if test -f "/tmp/kalifs-armhf-minimal.tar.xz"
then
echo "[+] found kalifs-armhf-minimal.tar.xz, skipping download"
else
# download latest kalifs armhf build from nethunter mirrors
echo "[-] downloading latest kalifs armhf build from nethunter mirrors..."
# fix for connection issues
ec=18
while [ $ec -ne 0 ]
do
curl --output /tmp/kalifs-armhf-minimal.tar.xz -O -C - $KALI_IMG
ec=$?
done
sleep 1
fi
# untar kalifs archive
echo "[-] unpacking kalifs-armhf-minimal..."
xz -cd /tmp/kalifs-armhf-minimal.tar.xz | tar xvf - -C $PR_DIR
mv $PR_DIR/kali-armhf/ $TARGET/
sleep 1
}
# check extra args
for i; do
case "$i" in
"--landscape")
# enable landscape
OR_LANDSCAPE=true
;;
esac
done
case "$ACTION" in
"create")
# create a new chroot
# download and untar kali rootfs
get_kali
# deploy easy_pwn scripts on chroot
update_pwn
# add desktop launcher
install_icon
# mount dev sys proc
check_mount
# run setup-desktop on kali-side
# requires username as first arg
echo "[-] chrooting..."
chroot $TARGET /mnt/easy_pwn/desktop/setup_desktop.sh $PWN_USER
;;
"desktop")
# start kali desktop
# check mounts
check_mount
# start desktop
start_desktop
;;
"ssh")
# start sshd inside chroot
# listen on: 0.0.0.0:224/tcp
check_mount
echo "[-] chrooting..."
chroot $TARGET /usr/sbin/sshd -p2244
echo "[+] SSHD enabled on tcp port 2244"
;;
"bettercap")
# start bettercap webui
# listen on: 127.0.0.1:80/tcp
check_mount
echo "[-] chrooting..."
chroot $TARGET bettercap -caplet http-ui -iface wlan0
;;
"shell")
# start chroot shell
# mount dev sys proc
check_mount
# run kali-side script
echo "[-] chrooting..."
chroot $TARGET
;;
"update")
# deploy easy_pwn
update_pwn
# install chroot icon
install_icon
echo "[+] done."
;;
"kill")
# experimental
# kill chroot process
kill_chroot
echo "[+] done."
;;
"quit")
# quit chroot
kill_chroot
echo "[-] umounting chroot..."
umount_all
echo "[+] kali session closed"
sleep 3
exit 1
;;
"script")
# execute custom scripts
# check mount
check_mount
# requires 3 args example:
# ./easy_pwn.sh script /media/sdcard/sdtest/epwn rougue_ap
# check args
if [ "$#" -lt 3 ]
then
echo "[!] script require 3 arguments."
echo " usage: $0 script [destination-path] [script_name]"
exit 1
fi
# get requested script name
SCRIPT_NAME="$3"
# check if script main exist
if [[ -f "$CHROOT_PATH/mnt/easy_pwn/scripts/$SCRIPT_NAME/main.sh" ]]
then
# execute the script
echo "[-] loading $SCRIPT_NAME."
chmod +x $CHROOT_PATH/mnt/easy_pwn/scripts/$SCRIPT_NAME/main.sh
echo "[-] chrooting..."
chroot $TARGET /mnt/easy_pwn/scripts/$SCRIPT_NAME/main.sh
else
echo "[!] script '$SCRIPT_NAME' not found."
fi
;;
*)
echo "[!] Usage: $0 {create|desktop|shell|update|kill|bettercap|ssh|script|quit} [kali-rootfs-path]"
exit 1
esac