0x01 PEASS-ng 介绍 PEAS-ng 是一款适用于 Windows 和 Linux/Unix* 和 MacOS 的权限提升工具。
PEAS-ng 工具搜索可能的本地权限提升路径,可以利用这些路径并将它们以漂亮的颜色打印输出,可以方便轻松识别错误配置。
0x02 辅助提权(WinPEAS) WinPEAS.exe 使用 WinPEAS.exe 的目标是在 Windows 环境中搜索可能的权限提升路径,需要目标系统(.Net >= 4.5.2)环境,支持打印输出颜色。
WinPEAS.exe 使用 ANSI 颜色对打印输出的内容进行着色,如果使用 winpeas.exe 从 Windows 控制台执行,则需要设置注册表值以查看颜色(并打开新的 CMD):
1 REG ADD HKCU\Console /v VirtualTerminalLevel /t REG_DWORD /d 1
WinPEAS.exe 打印输出的颜色一共有以下几种类型,分别代表不同意思:
1 2 3 4 5 红色(Red):表示对对象的特殊权限或配置错误(从渗透测试者的角度来看) 绿色(Green):表示某些保护已启用或配置良好(从防守者的角度来看) 青色(Cyan:表示活跃用户 蓝色(Blue):表示禁用的用户 浅黄色(LightYellow):表示链接
WinPEAS.exe 使用 help 参数查看帮助如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 quiet 不打印banner notcolor 不使用ansi颜色(全白) domain 枚举域信息 systeminfo 查询系统信息 userinfo 查询用户信息 processinfo 查询进程信息 servicesinfo 查询服务信息 applicationsinfo 查询已安装的应用程序信息 networkinfo 查询网络信息 windowscreds 搜索Windows凭据 browserinfo 搜索浏览器信息 filesinfo 搜索可能包含凭据的通用文件 fileanalysis 搜索可能包含凭据的特定文件 eventsinfo 显示感兴趣的事件信息 wait 在两次检查之间等待用户输入debug 显示调试信息-内存使用情况,方法执行时间 log [=logfile] 记录所有输出到定义为logfile的文件,如果未指定则记录到"out.txt" 额外的检查(慢): -lolbas 运行额外的LOLBAS检查 -linpeas=[url] 运行额外的linpeas.sh检查默认的WSL分发,也可以选择提供定制的linpeas.sh url(默认值:https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh)
WinPEAS.exe 不指定类型的话,默认是运行所有类型检查,可以将结果保存到指定文件中,方便后续查看分析。
1 winPEASany.exe log =result.txt
WinPEAS.exe 执行过程中可能会有一些报错信息,正常情况,等待执行结束即可。
WinPEAS.exe 保存输出的文件(result.txt)默认编码是 UTF-8,需要将其编码类型修改为 ANSI,否则显示中文将会乱码。
然后再使用 type 命令查看文件(result.txt)即可。
WinPEAS.exe 使用默认所有检查内容清单如下:
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 系统信息 系统基本信息 使用Watson搜索漏洞 枚举 Microsoft 更新 PS,审计,WEF和LAPS设置 LSA保护 凭据保护 WDigest 缓存的cred数量 环境变量 网络设置 当前驱动器信息 AV反病毒 Windows Defender UAC配置 NTLM设置 本地组策略 Applocker配置和bypass建议 打印机 命名管道 AMSI供应商 系统监视器 .NET 版本 用户信息 用户信息 当前令牌特权 剪贴板文本 当前登录用户 RDP会话 曾经登录过的用户 自动登录凭据 主文件夹 密码策略 本地用户详细信息 登录会话 流程信息 有趣的过程(非Microsoft) 服务信息 有趣的服务(非 Microsoft)信息 可修改的服务 可写服务注册表binpath PATH DLL劫持 应用信息 当前活动窗口 安装的软件 自动运行 计划任务 设备驱动程序 网络信息 当前net shares 映射驱动器(WMI) hosts文件 网络接口 监听端口 防火墙规则 DNS缓存(限制70) 网络设置 Windows凭据 Windows保险库 凭证管理器 保存的 RDP 设置 最近运行的命令 PS默认成绩单文件 DPAPI万能密钥 DPAPI凭据文件 远程桌面连接管理器凭据 Kerberos票据 无线网络 AppCmd.exe SSClient.exe SCCM 安全包凭证 AlwaysInstallElevated WSUS 浏览器的信息 Firefox 数据库 Firefox 历史上的凭据 Chrome 数据库 chrome 历史上的凭据 当前的 IE 选项卡 IE历史上的凭据 IE 收藏夹 提取已保存的密码:Firefox、Chrome、Opera、Brave 有趣的文件和注册表 Putty 会话 Putty SSH 主机密钥 SuperPutty 信息 OneDrive同步的Office365终端 注册表中的SSH密钥 Cloud 凭证 检查无人参与的文件 检查SAM和SYSTEM备份 检查缓存的GPP密码 检查并从McAffe SiteList.xml文件中提取凭据 可能有凭据的注册表 用户homes中可能存在的凭证文件 回收站内可能的密码文件 可能包含凭据的文件(这需要几分钟) 用户文件(限制 100 个) Oracle SQL Developer 配置文件检查 Slack 文件搜索 Outlook 下载 机器和用户证书文件 Office最近的文件 隐藏的文件和文件夹 具有写入权限的非默认文件夹中的可执行文件 WSL检查 事件信息 登录+显式登录事件 进程创建事件 PowerShell事件 电源开/关的事件 附加(慢)检查 LOLBAS 搜索 在默认WSL分发中运行linpea .sh
WinPEAS.bat 使用 WinPEAS.bat 用于搜索在 Windows 主机上提升权限的可能路径。WinPEAS.bat 是为不支持 WinPEAS.exe 的 Windows 系统制作的批处理脚本,需要目标系统(.Net 4)环境,不支持打印输出颜色。如果要搜索可能包含密码的文件和注册表,需要在 WinPEAS.bat 脚本开头的long变量设置为 yes 。
winPEAS.bat 可以使用如下命令,将脚本执行的结果保存到指定文件中,方便后续查看分析。
1 .\winPEAS.bat > result.txt
然后再使用 type 命令查看文件(result.txt)即可。
WinPEAS.bat 默认检查内容清单如下:
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 Systeminfo --SO 版本和补丁-- (windows 建议) 常见的已知漏洞(2K、XP、2K3、2K8、Vista、7) Audit 设置 WEF 设置 LAPS 安装? LSA 保护? 凭据保护? WDigest? 缓存的cred数量 UAC 设置 检测是否有反病毒运行? PS 设置 挂载的磁盘 SCCM 安装? 远程桌面凭据管理器? WSUS 设置 进程列表 正在执行的二进制文件的有趣文件权限 在启动时运行的二进制文件的有趣文件权限 始终安装提升? 网络信息 用户信息 当前用户权限 服务二进制权限 检查是否有修改任何服务注册表的权限 未引用的服务路径 PATH 中的 DLL 劫持 Windows 保险库 DPAPI 主密钥 AppCmd.exe? 检查无人参与的文件 检查 SAM 和 SYSTEM 备份 检查缓存的 GPP 密码 检查 McAffe SiteList.xml 文件 检查Cloud凭据 搜索已知的注册表以在其中包含密码和密钥(Winlogon ...) 搜索已知文件以在其中包含密码(可能需要几分钟) 如果很长,搜索里面有密码的文件 如果很长,搜索注册表里面有密码 日期和时间 环境变量 已安装的软件 运行的进程 当前Shares 网络接口 使用的端口 防火墙 ARP Routes Hosts 缓存的 DNS 当前用户的信息(PRIVILEGES) 列出组(有关administrators的信息) 当前登录用户
exe与bat结果对比 从脚本工具执行的结果来看,WinPEAS.exe 比 WinPEAS.bat 搜集到的信息多得多 ,所以一般情况下优先使用 WinPEAS.exe 搜集信息。如果目标系统不支持 WinPEAS.exe,再选择使用 WinPEAS.bat 脚本工具。
0x03 辅助提权(LinPEAS) LinPEAS 介绍 LinPEAS 是一个没有任何依赖的脚本,它使用/bin/sh语法,用于搜索在 Linux/Unix*/MacOS 主机上搜索可能的权限提升路径。默认情况下,LinPEAS 不会向磁盘写入任何内容,也不会尝试以任何其他用户身份使用 su 。
该脚本工具枚举并搜索主机内部可能的错误配置(已知漏洞、用户、进程和文件权限、特殊文件权限、可读/可写文件、暴力破解其他用户(top1000pwds)、密码…),并用颜色突出显示可能的错误配置。
LinPEAS.sh 使用 -h 参数查看帮助如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 -h 显示这条消息 -q 不显示banner -e 执行额外的枚举 -s SuperFast(不检查一些耗时的检查) - 隐身模式 -a 所有检查(进程和 su brute 的 1 分钟)- Noisy 模式,主要用于 CTF -w 在大块检查之间等待执行 -N 不使用颜色 -D 调试模式 -P 指示将用于运行“sudo -l”并通过“su”暴力破解其他用户帐户的密码 -o 仅执行选定的检查(system_information、container、procs_crons_timers_srvcs_sockets、network_information、users_information、software_information、interesting_files)。选择一个逗号分隔的列表。 -L 强制执行 linpeas。 -M 强制执行 macpeas。 -d <IP/NETMASK> 使用 fping 或 ping 发现主机。例如:-d 192.168.0.1/24 -p <PORT(s)> -d <IP/NETMASK> 发现正在寻找 TCP 开放端口的主机(通过 nc)。默认情况下端口 22,80,443,445,3389 和您指定的另一个端口将被扫描(如果您不想添加更多,请选择 22)。您还可以添加端口列表。例如:-d 192.168.0.1/24 -p 53,139 -i <IP> [-p <PORT(s)>] 使用 nc 扫描 IP。默认情况下(无 -p),将扫描 nmap 的 top1000,但您可以选择端口列表。例如:-i 127.0.0.1 -p 53,80,443,8000,8080 -t 自动网络扫描(主机发现和端口扫描) - 此选项写入文件 请注意,如果指定一些网络扫描(选项 -d/-p/-i 但不是 -t),则不会执行 PE 检查
LinPEAS.sh 打印输出的颜色一共有以下几种类型:
LinPEAS.sh 各颜色代表意思如下:
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 红色/黄色(RED/YELLOW): 用于识别导致 PE 的配置(95%肯定) 红色(RED): 识别可能导致 PE 的可疑配置 可能的可利用内核 kernel 版本 易受攻击的 sudo 版本 识别以 root 身份运行的进程 未挂载的 devices 危险的 fstab 权限 有趣目录中的可写文件 具有某些易受攻击版本的 SUID/SGID 二进制文件(它还指定易受攻击的版本) 可用于在 sudo -l(无密码)中提升权限的 SUDO 二进制文件(https://gtfobins.github.io/) 检查 /etc/doas.conf netstat 中的 127.0.0.1 可能包含密码的已知文件 有趣的二进制文件中的功能 二进制文件的有趣功能 有关 cron 作业的信息中的可写文件夹和通配符 PATH 中的可写文件夹 可能导致root的组 可能包含密码的文件 可疑的 cronjobs 浅青色(LightCyan): 有控制台 shell 的用户 蓝色(Blue): 没有控制台 shell 的用户 已挂载的 devices 绿色(Green): 由 root 运行的常用进程 挂载常见的不感兴趣的 devices 不危险的 fstab 权限 SUID/SGID 通用二进制文件(该二进制文件已在其他机器中找到,并且 searchsploit 未识别任何易受攻击的版本) 路径中的常见 .sh 文件 执行进程的用户的通用名称 常见的 cronjobs 浅洋红色(LightMagenta): 当前用户名
LinPEAS(Linux/Unix*) 只需 linpeas.sh 在 Linux/Unix* 系统中执行, linPEAS 版本将自动执行。
1 2 3 4 ./linpeas.sh ./linpeas.sh > result.txt
LinPEAS(MacOS) 只需 linpeas.sh 在 MacOS 系统中执行, MacPEAS 版本将自动执行。
1 2 3 4 ./linpeas.sh ./linpeas.sh > result.txt
0x04 PEASS-ng 导出报告 PEASS-ng 支持将检测的导出结果转换为 json、html、pdf 等格式的报告。
首先将 PEASS-ng 的检测结果导出到文件中,可以使用如下命令:
1 2 3 4 5 Linux/Unix*/MacOS环境: ./linpeas.sh > result.txt Windows环境: winPEAS.bat > result.txt winPEASany.exe log =result.txt
然后使用 peas2json.py 将检测结果导出的文件转化为 json 格式文件。
1 python3 peas2json.py result.txt peass.json
最后将 json 格式文件转化为 html 或者 pdf 格式报告。
1 2 python3 json2html.py peass.json peass.html python3 json2pdf.py peass.json peass.pdf
pdf 报告效果如下:
html 报告效果如下:
Metasploit 可以使用此模块从获得的 meterpreter 或 shell 会话中自动执行 PEASS 脚本。
将 peass.rb 文件复制到 metasploit 安装中的路径 modules/post/multi/gather/
在 kali 中,可以执行如下命令安装模块:
1 2 3 sudo cp ./peass.rb /usr/share/metasploit-framework/modules/post/multi/gather/sudo wget https://raw.githubusercontent.com/carlospolop/PEASS-ng/master/metasploit/peass.rb -O /usr/share/metasploit-framework/modules/post/multi/gather/peass.rb
安装完成后,可以 reload_all 在正在运行的 msfconsole 中进行操作,或者下次启动新的 msfconsole 时,将自动加载 PEASS 模块。
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 msf6 exploit(multi/handler) > use post/multi/gather/peass msf6 post(multi/gather/peass) > show info Name: Multi PEASS launcher Module: post/multi/gather/peass Platform: BSD, Linux, OSX, Unix, Windows Arch: Rank: Normal Provided by: Carlos Polop <@carlospolopm> Compatible session types: Meterpreter Shell Basic options: Name Current Setting Required Description ---- --------------- -------- ----------- PARAMETERS no Parameters to pass to the script PASSWORD um1xipfws17nkw1bi1ma3bh7tzt4mo3e no Password to encrypt and obfuscate the script (randomly generated). The length must be 32B. If no password is set , only base64 will be used . PEASS_URL https://raw.githubusercontent.com/carlospolop/PEASS-ng/master/winPEAS/wi yes Path to the PEASS script. Accepted: http(s):// URL or absolute local path. Linpeas: https://raw.githubusercontent.com/carlospolop/PEASS-ng nPEASexe/binaries/Obfuscated%20Releases/winPEASany.exe /master/linPEAS/linpeas.sh SESSION yes The session to run this module on. SRVHOST no Set your metasploit instance IP if you want to download the PEASS script from here via http(s) instead of uploading it. SRVPORT 443 no Port to download the PEASS script from using http(s) (only used if SRVHOST) SSL true no Indicate if you want to communicate with https (only used if SRVHOST) SSLCert no Path to a custom SSL certificate (default is randomly generated) TEMP_DIR no Path to upload the obfuscated PEASS script inside the compromised machine. By default "C:\Windows\System32\spool\drivers\color" is used in Windows and "/tmp" in Unix. TIMEOUT 900 no Timeout of the execution of the PEASS script (15min by default) URIPATH /mvpo.txt no URI path to download the script from there (only used if SRVHOST) Description: This module will launch the indicated PEASS (Privilege Escalation Awesome Script Suite) script to enumerate the system. You need to indicate the URL or local path to LinPEAS if you are in some Unix or to WinPEAS if you are in Windows. By default this script will upload the PEASS script to the host (encrypted and/or encoded) and will load it and execute it. You can configure this module to download the encrypted/encoded PEASS script from this metasploit instance via HTTP instead of uploading it. References: https://github.com/carlospolop/PEASS-ng https://www.youtube.com/watch?v=9_fJv_weLU0