-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linGhost.sh
executable file
·371 lines (298 loc) · 13.3 KB
/
linGhost.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
#!/bin/bash
# @Author: SAIKAT KARMAKAR
# @Date: 2021-08-17 20:18:17
# @Last Modified by: SAIKAT KARMAKAR
# @Last Modified time: 2021-08-19 23:22:49
# Print & color information
C=$(printf "\033")
RED="${C}[1;31m"
SED_RED="${C}[1;31m&${C}[0m"
GREEN="${C}[1;32m"
SED_GREEN="${C}[1;32m&${C}[0m"
YELLOW="${C}[1;33m"
SED_YELLOW="${C}[1;33m&${C}[0m"
SED_RED_YELLOW="${C}[1;31;103m&${C}[0m"
BLUE="${C}[1;34m"
SED_BLUE="${C}[1;34m&${C}[0m"
ITALIC_BLUE="${C}[1;34m${C}[3m"
LIGHT_MAGENTA="${C}[1;95m"
SED_LIGHT_MAGENTA="${C}[1;95m&${C}[0m"
LIGHT_CYAN="${C}[1;96m"
SED_LIGHT_CYAN="${C}[1;96m&${C}[0m"
LG="${C}[1;37m" #LightGray
SED_LG="${C}[1;37m&${C}[0m"
DG="${C}[1;90m" #DarkGray
SED_DG="${C}[1;90m&${C}[0m"
NC="${C}[0m"
UNDERLINED="${C}[5m"
ITALIC="${C}[3m"
print_BANNER(){
# if lolcat installed then make it colorful
echo ""
if [ $(which lolcat 2>/dev/null) ];
then
echo " ██ ██ ████████ ██ ██
░██ ░░ ██░░░░░░██░██ ░██
░██ ██ ███████ ██ ░░ ░██ ██████ ██████ ██████
░██ ░██░░██░░░██░██ ░██████ ██░░░░██ ██░░░░ ░░░██░
░██ ░██ ░██ ░██░██ █████░██░░░██░██ ░██░░█████ ░██
░██ ░██ ░██ ░██░░██ ░░░░██░██ ░██░██ ░██ ░░░░░██ ░██
░████████░██ ███ ░██ ░░████████ ░██ ░██░░██████ ██████ ░░██
░░░░░░░░ ░░ ░░░ ░░ ░░░░░░░░ ░░ ░░ ░░░░░░ ░░░░░░ ░░
" | lolcat
else
echo "
[0;1;31;91m▄[0;1;33;93m▄[0m [0;1;33;93m██[0m [0;1;35;95m▄▄[0;1;31;91m▄▄[0m [0;1;32;92m▄[0;1;36;96m▄[0m
[0;1;33;93m█[0;1;32;92m█[0m [0;1;32;92m▀▀[0m [0;1;35;95m██[0;1;31;91m▀▀[0;1;33;93m▀▀[0;1;32;92m█[0m [0;1;36;96m█[0;1;34;94m█[0m [0;1;33;93m█[0;1;32;92m█[0m
[0;1;32;92m█[0;1;36;96m█[0m [0;1;32;92m██[0;1;36;96m██[0m [0;1;31;91m█[0;1;33;93m█▄[0;1;32;92m██[0;1;36;96m██[0;1;34;94m▄[0m [0;1;35;95m█[0;1;31;91m█[0m [0;1;34;94m█[0;1;35;95m█▄[0;1;31;91m██[0;1;33;93m██[0;1;32;92m▄[0m [0;1;34;94m▄█[0;1;35;95m██[0;1;31;91m█▄[0m [0;1;32;92m▄[0;1;36;96m▄█[0;1;34;94m██[0;1;35;95m██[0;1;31;91m▄[0m [0;1;33;93m█[0;1;32;92m██[0;1;36;96m██[0;1;34;94m██[0m
[0;1;36;96m█[0;1;34;94m█[0m [0;1;34;94m██[0m [0;1;33;93m█[0;1;32;92m█▀[0m [0;1;34;94m█[0;1;35;95m█[0m [0;1;31;91m█[0;1;33;93m█[0m [0;1;32;92m▄[0;1;36;96m▄▄[0;1;34;94m▄[0m [0;1;35;95m█[0;1;31;91m█▀[0m [0;1;32;92m█[0;1;36;96m█[0m [0;1;34;94m█[0;1;35;95m█▀[0m [0;1;33;93m▀█[0;1;32;92m█[0m [0;1;36;96m█[0;1;34;94m█▄[0;1;35;95m▄▄[0;1;31;91m▄[0m [0;1;33;93m▀[0m [0;1;36;96m█[0;1;34;94m█[0m
[0;1;34;94m█[0;1;35;95m█[0m [0;1;35;95m██[0m [0;1;32;92m█[0;1;36;96m█[0m [0;1;35;95m█[0;1;31;91m█[0m [0;1;33;93m█[0;1;32;92m█[0m [0;1;36;96m▀[0;1;34;94m▀█[0;1;35;95m█[0m [0;1;31;91m█[0;1;33;93m█[0m [0;1;36;96m█[0;1;34;94m█[0m [0;1;35;95m█[0;1;31;91m█[0m [0;1;32;92m█[0;1;36;96m█[0m [0;1;35;95m▀▀[0;1;31;91m▀▀[0;1;33;93m██[0;1;32;92m▄[0m [0;1;34;94m█[0;1;35;95m█[0m
[0;1;35;95m█[0;1;31;91m█▄[0;1;33;93m▄▄[0;1;32;92m▄▄[0;1;36;96m▄[0m [0;1;34;94m▄[0;1;35;95m▄▄[0;1;31;91m██[0;1;33;93m▄▄[0;1;32;92m▄[0m [0;1;36;96m█[0;1;34;94m█[0m [0;1;31;91m█[0;1;33;93m█[0m [0;1;36;96m██[0;1;34;94m▄▄[0;1;35;95m▄█[0;1;31;91m█[0m [0;1;33;93m█[0;1;32;92m█[0m [0;1;34;94m█[0;1;35;95m█[0m [0;1;31;91m▀[0;1;33;93m██[0;1;32;92m▄▄[0;1;36;96m██[0;1;34;94m▀[0m [0;1;35;95m█[0;1;31;91m▄▄[0;1;33;93m▄▄[0;1;32;92m▄█[0;1;36;96m█[0m [0;1;35;95m█[0;1;31;91m█▄[0;1;33;93m▄▄[0m
[0;1;31;91m▀[0;1;33;93m▀▀[0;1;32;92m▀▀[0;1;36;96m▀▀[0;1;34;94m▀[0m [0;1;35;95m▀[0;1;31;91m▀▀[0;1;33;93m▀▀[0;1;32;92m▀▀[0;1;36;96m▀[0m [0;1;34;94m▀[0;1;35;95m▀[0m [0;1;33;93m▀[0;1;32;92m▀[0m [0;1;35;95m▀▀[0;1;31;91m▀▀[0m [0;1;32;92m▀[0;1;36;96m▀[0m [0;1;35;95m▀[0;1;31;91m▀[0m [0;1;32;92m▀[0;1;36;96m▀▀[0;1;34;94m▀[0m [0;1;33;93m▀▀[0;1;32;92m▀▀[0;1;36;96m▀▀[0m [0;1;33;93m▀▀[0;1;32;92m▀▀[0m
"
fi
echo ""
}
print_title(){
if [ "$VERBOSE" ]; then
END_T2_TIME=$(date +%s 2>/dev/null)
if [ "$START_T2_TIME" ]; then
TOTAL_T2_TIME=$(($END_T2_TIME - $START_T2_TIME))
printf $DG"This check took $TOTAL_T2_TIME seconds\n"$NC
fi
END_T1_TIME=$(date +%s 2>/dev/null)
if [ "$START_T1_TIME" ]; then
TOTAL_T1_TIME=$(($END_T1_TIME - $START_T1_TIME))
printf $DG"The total section execution took $TOTAL_T1_TIME seconds\n"$NC
echo ""
fi
START_T1_TIME=$(date +%s 2>/dev/null)
fi
printf ${BLUE}"════════════════════════════════════╣ $GREEN$1${BLUE} ╠════════════════════════════════════\n"$NC
}
print_2title(){
if [ "$VERBOSE" ];
then
END_T2_TIME=$(date +%s 2>/dev/null)
if [ "$START_T2_TIME" ];
then
TOTAL_T2_TIME=$(($END_T2_TIME - $START_T2_TIME))
printf $DG"This check took $TOTAL_T2_TIME seconds\n"$NC
echo ""
fi
START_T2_TIME=$(date +%s 2>/dev/null)
fi
printf ${BLUE}"╔══════════╣ $GREEN$1\n"$NC #There are 10 "═"
}
print_info(){
printf "${BLUE}╚ ${ITALIC_BLUE}$1\n"$NC
}
print_3title(){
printf ${BLUE}"══╣ $GREEN$1\n"$NC #There are 2 "═"
}
print_list(){
printf ${BLUE}"═╣ $GREEN$1"$NC #There is 1 "═"
}
print_RY(){
printf "${RED}$1:${YELLOW}[+]sudo -u#-1 /bin/bash\n"$NC
}
print_URL(){
printf "${BLUE}$1\n"$NC
}
print_ALL(){
printf "${BLUE}══╣ ${GREEN}$1${BLUE} ╠══\n"$NC
}
print_ROOT(){
printf "${BLUE}$1\n${RED}"
}
# ---------------------------------------------------------------------------------
# Main program starts
# if [ "$(/usr/bin/id -u)" -eq "0" ]; then
# IAMROOT="1"
# MAXPATH_FIND_W="3"
# else
# IAMROOT=""
# MAXPATH_FIND_W="7"
# fi
#Starting with banner printing
print_BANNER
echo "${RED}@Author: SAIKAT KARMAKAR ${BLUE}https://github.com/Aviksaikat/${NC} "
# All variables
idB="euid|egid$baduid"
sudovB="[01].[012345678].[0-9]+|1.9.[01234]|1.9.5p1"
groupsB="\(root\)|\(shadow\)|\(admin\)|\(video\)|\(adm\)|\(wheel\)|\(auth\)"
groupsVB="\(sudo\)|\(docker\)|\(lxd\)|\(disk\)|\(lxc\)"
knw_grps="\(lpadmin\)|\(cdrom\)|\(plugdev\)|\(nogroup\)" #https://www.togaware.com/linux/survivor/Standard_Groups.html
mygroups=$(groups 2>/dev/null | tr " " "|")
if [ "$(/usr/bin/id -u)" -eq "0" ]; then
IAMROOT="1"
MAXPATH_FIND_W="3"
else
IAMROOT=""
MAXPATH_FIND_W="7"
fi
knw_usrs="daemon\W|^daemon$|message\+|syslog|www|www-data|mail|noboby|Debian\-\+|rtkit|systemd\+"
USER=$(whoami 2>/dev/null || echo "UserUnknown")
if [ ! "$HOME" ];
then
if [ -d "/Users/$USER" ];
then
HOME="/Users/$USER"; #Mac home
else
HOME="/home/$USER";
fi
fi
Groups="ImPoSSssSiBlEee"$(groups "$USER" 2>/dev/null | cut -d ":" -f 2 | tr " " "|")
OLDPATH=$PATH
ADDPATH=":/usr/local/sbin\
:/usr/local/bin\
:/usr/sbin\
:/usr/bin\
:/sbin\
:/bin"
spath=":$PATH"
for P in $ADDPATH; do
if [ "${spath##*$P*}" ];
then export PATH="$PATH$P" 2>/dev/null;
fi
done
E=E
echo | sed -${E} "s/o/a/" 2>/dev/null
if [ $? -ne 0 ] ; then
echo | sed -r "s/o/a/" 2>/dev/null
if [ $? -eq 0 ] ; then
E=r
else
echo "${YELLOW}WARNING: No suitable option found for extended regex with sed. Continuing but the results might be unreliable.${NC}"
fi
fi
#-- UI) My user
print_2title "My User"
print_info "https://book.hacktricks.xyz/linux-unix/privilege-escalation#users"
(id || (whoami && groups)) 2>/dev/null | sed -${E} "s,$groupsB,${SED_RED},g" | sed -${E} "s,$groupsVB,${SED_RED_YELLOW},g" | sed "s,$USER,${SED_LIGHT_MAGENTA},g" | sed -${E} "s,$knw_usrs,${SED_GREEN},g" | sed "s,root,${SED_RED}," | sed -${E} "s,$knw_grps,${SED_GREEN},g" | sed -${E} "s,$idB,${SED_RED},g"
echo ""
print_ROOT "Super User Accounts"
awk -F: "($3 == "0") {print}" /etc/passwd 2>/dev/null
echo ""
#-- SY) Sudo
print_2title "Sudo version"
if [ "$(command -v sudo 2>/dev/null)" ];
then
print_info "https://book.hacktricks.xyz/linux-unix/privilege-escalation#sudo-version"
sudo -V 2>/dev/null | grep "Sudo ver" | sed -${E} "s,$sudovB,${SED_RED},"
sv=$(sudo -V 2>/dev/null | head -1 | grep -E "[0-9][a-z]*\.*" | cut -d " " -f3)
#sv=1.27
vsv=1.28
if (( $(echo $sv"<="$vsv | bc -l 2>/dev/null) ));
then
#print_info
print_RY "Exploit"
fi
else echo_not_found "sudo"
fi
echo ""
#-- SY) PATH
print_2title "PATH"
print_info "https://book.hacktricks.xyz/linux-unix/privilege-escalation#writable-path-abuses"
echo "$OLDPATH" 2>/dev/null | sed -${E} "s,$Wfolders|\./|\.:|:\.,${SED_RED_YELLOW},g"
echo "New path exported: $PATH" 2>/dev/null | sed -${E} "s,$Wfolders|\./|\.:|:\. ,${SED_RED_YELLOW},g"
echo ""
print_title "Kernel Info"
#printf "${RED}$(uname -a || cat /proc/version 2>/dev/null)\n"
printf $LG$"Hostname: "$GREEN
hostname 2>/dev/null
printf $LG$"OS: "$GREEN
(uname -o ) 2>/dev/null
printf $LG$"Kernel Version: "$GREEN
(uname -v ) 2>/dev/null
printf $LG$"Kernel Release: "$GREEN
(uname -r ) 2>/dev/null
printf $LG$"System Architecture: "$GREEN
(uname -m ) 2>/dev/null
echo ""
#print_title "Environment Information"
#(env || set) 2>/dev/null
# print_title "CPU Information"
# lscpu 2>/dev/null
print_info "Date"
date 2>/dev/null
echo ""
echo ""
#-- 1AS) Useful software
print_title "Useful Softwares"
command -v "$CONTAINER_CMDS" nmap aws nc ncat netcat nc.traditional wget curl ping gcc g++ make gdb base64 socat python python2 python3 python2.7 python2.6 python3.6 python3.7 perl php ruby xterm doas sudo fetch ctr 2>/dev/null
echo ""
print_title "Cornjobs"
print_URL "https://book.hacktricks.xyz/linux-unix/privilege-escalation#scheduled-cron-jobs"
(crontab -l || ls -al /etc/cron* /etc/at* 2>/dev/null || cat /etc/cron* /etc/at* /etc/anacrontab /var/spool/cron/crontabs/root 2>/dev/null | grep -v "^#"
)
echo ""
print_title "PATH used by systemd"
systemctl show-environment 2>/dev/null
echo ""
print_title "Routing Table"
route 2>/dev/null
echo ""
print_ALL "Hosts in /etc/hosts"
echo ""
cat /etc/hosts 2>/dev/null
echo ""
#Interfaces
print_title "Interfaces"
echo ""
cat /etc/networks 2>/dev/null
(ifconfig || ip a 2>/dev/null)
echo ""
#Neighbours
print_title "Neighbours"
echo ""
(arp -e || arp -a 2>/dev/null)
echo ""
print_title "Open ports"
echo ""
(netstat -punta || ss --ntpu 2>/dev/null) | grep "127.0"
echo ""
if [ "$(command -v nmap 2>/dev/null)" ];then
NMAP_GOOD=$GREEN"nmap${BLUE} is available for network discover & port scanning, you should use it yourself"
printf $YELLOW"[+] $NMAP_GOOD\n$NC"
fi
echo ""
echo ""
print_ALL "Run this for more user information"
echo ""
echo "${YELLOW}for i in \$(cut -d"\:" -f1 /etc/passwd 2>/dev/null);do id \$i;done 2>/dev/null | sort"
echo ""
print_ALL "Trying sudo -l"
echo ""
# try excpet here
$(echo "" | sudo -S -l 2>/dev/null ) || echo "Can"t run try running ${RED}sudo -l${NC} with password"
echo ""
print_ALL "Trying to find ssh keys"
echo ""
path=$(grep -r " .* PRIVATE *" $HOME/.ssh | head -1 | cut -d ":" -f1)
if [ $path ];
then
echo "${RED}ssh keys here ${path}"
else
echo "Can"t access ssh keys look manually"
fi
echo ""
print_title "SUID Binaries"
echo ""
find / -perm -4000 2>/dev/null
#find / -user root -perm -4000 -exec ls -ldb {} \; 2>/dev/null
echo ""
print_title "Other Binary Capabilities"
getcap -r / 2>/dev/null
# print_title "Processes"
# (ps -ef || ps aux 2>/dev/null)
# echo ""
# Writable directories
print_title "Writable Directories"
# find / -perm -222 -type d 2>/dev/null || find / -writable -type d 2>/dev/null || find / -perm -o w -type d 2>/dev/null
WF=`find / -maxdepth $MAXPATH_FIND_W -type d ! -path "/proc/*" -and "(" -writable -or -user $USER ")" 2>/dev/null | sort`
Wfolders=$(printf "%s" "$WF" | tr "\n" "|")"|[^\*][^\ ]*\ \*"
Wfolder="$(printf "%s" "$WF" | grep "tmp\|shm\|home\|Users\|root\|etc\|var\|opt\|bin\|lib\|mnt\|private\|Applications" | head -n1)"
printf "test\ntest\ntest\ntest"| sed -${E} "s,$Wfolders|\./|\.:|:\.,${SED_RED_YELLOW},g" >/dev/null 2>&1
print_title "Dumping Environment"
env 2>/dev/null