forked from superkojiman/pwnbox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.sh
executable file
·101 lines (88 loc) · 2.94 KB
/
run.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
#!/usr/bin/env bash
# Run superkojiman/pwnbox container in docker.
#
# Store your .gdbinit, .radare2rc, .vimrc, etc in a ./rc directory and
# the contents will be copied to /root/ in the container.
ESC="\x1B["
RESET=$ESC"39m"
RED=$ESC"31m"
GREEN=$ESC"32m"
BLUE=$ESC"34m"
# check if jq is installed
which jq > /dev/null 2>&1
if [[ $? -ne 0 ]]; then
echo -e "${RED}Install jq and try again${RESET}"
echo -e "${RED}macOS: brew install jq${RESET}"
echo -e "${RED}Debian/Ubuntu: sudo apt install jq${RESET}"
echo -e "${RED}Fedora: sudo dnf install jq${RESET}"
exit 0
fi
if [[ -z ${1} ]]; then
echo -e "${RED}Missing argument CTF name.${RESET}"
exit 0
fi
ctf_name=${1}
# Create a volume for this container
docker create -v /root/work --name ${ctf_name}_data superkojiman/pwnbox
# Get the volume name for the delete script
vol_name=`docker inspect ${ctf_name}_data | jq '.[].Mounts[].Name' | sed 's/\"//g'`
# Create docker container and run in the background
# Add this if you need to modify anything in /proc: --privileged
docker run -it \
-h ${ctf_name} \
-d \
--security-opt seccomp:unconfined \
--name ${ctf_name} \
--volumes-from ${ctf_name}_data \
--privileged \
superkojiman/pwnbox
# Tar config files in rc and extract it into the container
if [[ -d rc ]]; then
cd rc
if [[ -f rc.tar ]]; then
rm -f rc.tar
fi
for i in .*; do
if [[ ! ${i} == "." && ! ${i} == ".." ]]; then
tar rf rc.tar ${i}
fi
done
cd - > /dev/null 2>&1
cat rc/rc.tar | docker cp - ${ctf_name}:/root/
rm -f rc/rc.tar
else
echo -e "${RED}No rc directory found. Nothing to copy to container.${RESET}"
fi
# Create stop/rm script for container
cat << EOF > ${ctf_name}-stop.sh
#!/bin/bash
echo "Removing ${ctf_name} containers and volumes"
docker stop ${ctf_name}
docker rm ${ctf_name}
docker rm ${ctf_name}_data
docker volume rm ${vol_name}
rm -f ${ctf_name}-attach.sh
rm -f ${ctf_name}-stop.sh
EOF
chmod 755 ${ctf_name}-stop.sh
# Create a script to quickly re-attach to the container's tmux
cat << EOF > ${ctf_name}-attach.sh
#!/bin/bash
docker exec -it ${ctf_name} tmux ls > /dev/null 2>&1
if [[ \$? -eq 0 ]]; then
docker exec -it ${ctf_name} tmux -u a -d -t ${ctf_name}
else
echo "No tmux session found. Starting a new one."
docker exec -it ${ctf_name} tmux -u new -s ${ctf_name} -c /root/work
fi
EOF
chmod 755 ${ctf_name}-attach.sh
# Drop into a tmux shell
echo -e "${GREEN} ______ ${RESET}"
echo -e "${GREEN}___________ ___________ /___________ __${RESET}"
echo -e "${GREEN}___ __ \\_ | /| / /_ __ \\_ __ \\ __ \\_ |/_/${RESET}"
echo -e "${GREEN}__ /_/ /_ |/ |/ /_ / / / /_/ / /_/ /_> < ${RESET}"
echo -e "${GREEN}_ .___/____/|__/ /_/ /_//_.___/\\____//_/|_| ${RESET}"
echo -e "${GREEN}/_/ by superkojiman ${RESET}"
echo ""
docker exec -it ${ctf_name} tmux -u new -s ${ctf_name} -c /root/work