0x00前言普通用户(或LocalService用户)使用的Token有哪些特殊方法?特权可以提升吗?如何判断?本文将结合自己的经验,参考很多开源工具和资料,尝试总结一下这门技术,分享学习心得。参考开源工具和资料:HotPotato:https://github.com/foxglovesec/Potatopowershell版HotPotato:https://github.com/Kevin-Robertson/TaterRottenPotato:https://github.com/breenmachine/RottenPotatoNGlonelypotato:https://github.com/decoder-it/lonelypotato多汁土豆:https://github.com/ohpe/juicy-potatohttps://github.com/hatRiot/token-privhttps://foxglovesecurity.com/2017/08/25/abusing-token-privileges-for-windows-local-privilege-escalation/https://foxglovesecurity.com/2016/01/16/hot-potato/https://foxglovesecurity.com/2016/09/26/rotten-potato-privilege-escalation-from-service-accounts-to-system/https://foxglovesecurity.com/2017/08/25/abusing-token-privileges-for-windows-local-privilege-escalation/0x01Introduction本文将介绍以下内容:简要利用思路SeImpersonatePrivilege权限对应利用思路及开源代码SeAssignPrimaryPrivilege对应利用思路及开源e代码SeTcbPrivilege对应的使用思路与开源代码SeBackupPrivilege对应的利用思路与开源代码SeRestorePrivilege对应的使用思路与开源代码SeCreateTokenPrivilege权限对应的使用思路与开源代码SeLoadDriverPrivilege权限对应的使用思路与开源代码SeTakeOwnershipPrivilege权限对应的使用思路与开源代码SeDebugPrivilege权限对应的使用思路与开源代码0x02简要的使用思路1.获得权限后target的权限,查看可用权限whoami/priv例如普通用户的权限如下图。管理员用户的权限如下图所示。iis用户的权限如下图所示。PrivilegeName项表示权限,State表示权限状态。我们可以通过WinAPIAdjustTokenPrivileges将权限设置为Disabled或Enabled。实现代码参考:https://github.com/3gstudent/Homework-of-C-Language/blob/master/EnablePrivilegeandGetTokenInformation.cpp代码实现指定权限(SeDebugPrivilege),并检查当前用户名和权限2.如果包含以下九种权限,我们还可以进一步使用SeImpersonatePrivilegeSeAssignPrimaryPrivilegeSeTcbPrivilegeSeBackupPriviledDrivegeSeRestorePrivilegeSePrivierTokenSeTakeOwnershipPrivilegeSeDebugPrivilege注:iis或sqlserver的用户通常有SeImpersonatePrivilege和SeAssignPrimaryPrivilege。备份服务用户通常有SeBackupPrivilege和SeRestorePrivilege0x03SeImpersonatePrivilege。/abusing_token_eop_1.0.txt#L327SeImpersonatePrivilegeImpersonateaclientafterauthentication具有此权限的进程可以模拟现有令牌,但不能创建新令牌以下用户具有此权限:本地管理员组的成员和本地服务帐户由Service启动的服务控制管理中心由组件对象模型(COM)基础结构启动并配置为在特定帐户下运行的COM服务器通常是iis或sqlserver用户有这个权限。使用NTLMRelaytoLocalNegotiation获取System用户的Token。您可以使用开源工具RottenPotato、lonelypotato或JuicyPotato通过WinAPICreateProcessWithToken创建一个新进程。传递给System用户的Token必须有SeImpersonatePrivilege权限才能成功创建Token。System权限测试代码参考:https://github.com/3gstudent/Homework-of-C-Language/blob/master/EnableSeImpersonatePrivilege.cpp代码实现当前进程的SeImpersonatePrivilege权限,调用CreateProcessWithToken,传入当前进程的token,创建一个进程,配合RottenPotato,可用于将权限从LocalService提升到System权限0x04SeAssignPrimaryPrivilege权限利用思路参考:https://github.com/hatRiot/token-priv/blob/master/abusing_token_eop_1.0.txt#L359SeAssignPrimaryPrivilege为进程(新建或挂起的进程)分配token通常,iis或者sqlserver用户有这个权限。思路一、使用NTLMRelaytoLocalNegotiation获取System用户的Token。通过WinAPICreateProcessAsUser新建一个进程,传入System用户的Token。Token具有系统权限供参考。测试代码:https://github.com/3gstudent/Homework-of-C-Language/blob/master/EnableSeAssignPrimaryTokenPrivilege.cpp代码实现了当前进程的SeAssignPrimaryTokenPrivilege权限,调用CreateProcessAsUser,传入当前进程的Token,创建一个进程,配合RottenPotato,可以用来将LocalService的权限提升到System权限。使用思路2使用NTLMRelaytoLocalNegotiation获取System用户的Token。通过WinAPICreateProcess创建一个挂起的新进程,并将参数设置为CREATE_SUSPENDED。使用WinAPINtSetInformationProcess将新进程的Token替换为System用户的Token。Token有System权限0x05SeTcbPrivilege权限利用思路参考:https://github.com/hatRiot/token-priv/blob/master/abusing_token_eop_1.0.txt#L418SeTcbPrivilege相当于获取系统的***权限利用思路.调用LsaLogonUser获取Token将Token添加到LocalSystem帐户组中。Token具有系统权限以供参考。测试代码:https://github.com/3gstudent/Homework-of-C-Language/blob/master/EnableSeTcbPrivilege.cpp代码实现进程当前SeTcbPrivilege权限,登录用户test1,添加到LocalSystem账号组,获取System权限,创建注册表项HKEY_LOCAL_MACHINE\SOFTWARE\testtcb0x06SeBackupPrivilege权限使用思路参考:https://github.com/hatRiot/token-priv/blob/master/abusing_token_eop_1.0.txt#L495SeBackupPrivilege用于实现备份操作,对当前系统中的任意文件具有读取权限。使用思路是读取注册表HKEY_LOCAL_MACHINE\SAM、HKEY_LOCAL_MACHINE\SECURITY和HKEY_LOCAL_MACHINE\SYSTEM导出当前系统所有用户hashmimikatz命令如下:lsadump::sam/sam:SamBkup.hiv/system:SystemBkup.hiv测试代码参考:https://github.com/3gstudent/Homework-of-C-Language/blob/master/EnableSeBackupPrivilege.cpp代码实现了当前进程的SeBackupPrivilege权限,读取Registry,将其保存为文件C:\\test\\SAM、C:\\test\\SECURITY和C:\\test\\SYSTEM0x07使用SeRestorePrivilege权限的参考资料:https://github.com/hatRiot/token-priv/blob/master/abusing_token_eop_1.0.txt#L528SeRestorePrivilege用于实现recovery操作,对当前系统任意文件具有写权限使用思路1获取SeRestorePrivilege权限,修改注册表HKLM\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Image文件执行选项劫持exe文件的启动以实现提权或将其用作后门。思路2获取SeRestorePrivilege权限,将dll文件写入任意路径,实现dll劫持,实现提权或者做后门。测试代码参考:https://github.com/3gstudent/Homework-of-C-Language/blob/master/EnableSeRestorePrivilege.cpp该代码实现了当前进程的SeRestorePrivilege权限,并创建注册表项HKEY_LOCAL_MACHINE\SOFTWARE\testrestore0x08SeCreateTokenPrivilege权限参考资料:https://github.com/hatRiot/token-priv/blob/master/abusing_token_eop_1.0.txt#L577SeCreateTokenPrivilege用于创建PrimaryToken使用思路CreatedthroughWinAPIZwCreateToken创建一个主令牌并将令牌添加到本地管理员组。Token具有系统权限以供参考。测试代码:https://github.com/3gstudent/Homework-of-C-Language/blob/master/EnableSeCreateTokenPrivilege.cpp代码实现启用当前进程的SeCreateTokenPrivilege权限,创建一个PrimaryToken,添加到本地管理员组,启用SeDebugPrivilege和SeTcbPrivilege权限0x09SeLoadDriverPrivilege权限使用思路参考:https://github.com/hatRiot/token-priv/blob/master/abusing_token_eop_1.0.txt#L626SeLoadDriverPrivilege用于加载驱动文件并使用创建驱动文件注册表的思路System\CurrentControlSet\CAPCOM/vType/tREG_DWORD/d1加载驱动文件Capcom.sysCapcom.sys存在漏洞。系统加载后,可以从普通用户权限提升到系统权限。漏洞利用代码可在:https://github.com/tandasat/ExploitCapcom获取系统权限的测试代码参考:https://github.com/3gstudent/Homework-of-C-Language/blob/master/EnableSeLoadDriverPrivilege.cpp代码实现了当前进程的SeLoadDriverPrivilege权限,读取注册表项hkcu\System\CurrentControlSet\CAPCOM加载驱动文件Capcom.sys0x0ASeTakeOwnershipPrivilege权限使用参考:https://github.com/hatRiot/token-priv/blob/master/abusing_token_eop_1.0.txt#L688SeTakeOwnershipPrivilege与SeRestorePrivilege类似。它对当前系统中的任何文件都有写权限。使用思路1获取SeTakeOwnershipPrivilege权限,修改注册表HKLM\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\ImageFileExecutionOptions劫持exe文件的启动实现提权或者作为后门获取SeTakeOwnershipPrivilege权限,编写dll文件到任意路径实现dll劫持提权或做后门的测试代码参考:https://github.com/3gstudent/Homework-of-C-Language/blob/master/EnableSeTakeOwnershipPrivilege.cpp代码实现SeTakeOwnershipPrivilege当前进程的权限并修改注册表项hklm\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\ImageFileExecutionOptions的权限,普通用户权限对其有完全操作权限后续写操作:regadd"hklm\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Image文件执行选项"/vtakeownership/tREG_SZ/d"C:\\Windows\\System32\\calc.exe"0x0BSeDebugPrivilege权限参考:https://github.com/hatRiot/token-priv/blob/master/abusing_token_eop_1.0.txt#L736SeDebugPrivilege用于调试指定进程,包括包括读写内存,经常用来实现dll注入。使用idea查找具有System权限的进程。Dll注入获取系统权限。测试代码参考:https://github.com/3gstudent/Homework-of-C-Language/blob/master/EnableSeDebugPrivilege.cpp代码实现了当前进程的SeDebugPrivilege权限,将dll0x0C注入指定进程。小结本文总结了普通用户(或LocalService用户)Token中9种权限的使用方法,分析了使用思路,完善了实现代码
