发布于2022年11月4日3年前 如何使用RedShell将命令执行记录在Cobalt Strike团队服务器中 概述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 [email protected]:50050 ║ ╟───────────────────────┼───────────────────────────────────────────────────────╢ ║ Socks port status │ Disconnected ║ ╚═══════════════════════╧═══════════════════════════════════════════════════════╝或者,我们也可以从配置文件中加载配置信息。需要注意的是,团队服务求的密码是无法从配置文件中读取的。在RedShell中输入密码之后,工具将会帮助我们自动跟服务器进行连接:$ cat config.txt cs_host=127.0.0.1 cs_port=12345 cs_user=somedudeRedShell> 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 [email protected]: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 [email protected]: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 [email protected]: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 helpRedShell还提供了Tab键命令补全,或通过CTRL+ l组合键来清理终端窗口信息。许可证协议本项目的开发与发布遵循Apache 2.0开源许可证协议。项目地址RedShell:【GitHub传送门】
创建帐户或登录后发表意见