Module: Msf::Exploit::Remote::DCERPC_MGMT

Included in:
DCERPC
Defined in:
lib/msf/core/exploit/remote/dcerpc_mgmt.rb

Overview

This module provides service-specific methods for the DCERPC exploit mixin

Constant Summary collapse

NDR =
Rex::Encoder::NDR

Instance Method Summary collapse

Instance Method Details

#dcerpc_mgmt_connect(dport = 135) ⇒ Object

Connect to remote management interface



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/msf/core/exploit/remote/dcerpc_mgmt.rb', line 12

def dcerpc_mgmt_connect(dport=135)
  Rex::Socket::Tcp.create(
    'PeerHost'  => rhost,
    'PeerPort'  => dport,
    'Proxies'   => proxies,
    'Context'   =>
      {
        'Msf'        => framework,
        'MsfExploit' => self,
      }
  )
end

#dcerpc_mgmt_inq_if_ids(dport = 135) ⇒ Object

List all interfaces registered with this remote management interface



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
# File 'lib/msf/core/exploit/remote/dcerpc_mgmt.rb', line 28

def dcerpc_mgmt_inq_if_ids(dport=135)
  res = []

  begin

    eps = dcerpc_mgmt_connect(dport)

    eph = dcerpc_handle('afa8bd80-7d8a-11c9-bef4-08002b102989', '1.0', 'ncacn_ip_tcp', [dport])
    opt = { 'Msf' => framework, 'MsfExploit' => self }

    dce = Rex::Proto::DCERPC::Client.new(eph, eps, opt)

    dce.call(0, '')

    if (dce.last_response != nil and dce.last_response.stub_data != nil)
      buff = dce.last_response.stub_data

      retstat = buff[0,4].unpack('N')[0]
      ifcount = buff[4,4].unpack('V')[0]
      ifstats = buff[12, 4 * ifcount]
      iflists = buff[12 + (4 * ifcount), buff.length]

      ifidx = 0
      while(ifidx < ifcount * 20)
        intf = Rex::Proto::DCERPC::UUID.uuid_unpack(iflists[ifidx, 16])
        vers = iflists[ifidx + 16,4].unpack('vv').map{|c| c.to_s}.join('.')
        res << [intf, vers]
        ifidx += 20
      end
    end

  rescue ::Interrupt
    raise $!
  rescue ::Exception => e
    print_status("Remote Management Interface Error: #{e}")
    res = nil
  end

  eps.close if eps

  res
end

#dcerpc_mgmt_inq_if_stats(dport = 135) ⇒ Object



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
# File 'lib/msf/core/exploit/remote/dcerpc_mgmt.rb', line 72

def dcerpc_mgmt_inq_if_stats(dport=135)
  res = []

  begin

    eps = dcerpc_mgmt_connect(dport)

    eph = dcerpc_handle('afa8bd80-7d8a-11c9-bef4-08002b102989', '1.0', 'ncacn_ip_tcp', [dport])
    opt = { 'Msf' => framework, 'MsfExploit' => self }

    dce = Rex::Proto::DCERPC::Client.new(eph, eps, opt)

    dce.call(1, NDR.long(1024) )

    if (dce.last_response != nil and dce.last_response.stub_data != nil)
      buff = dce.last_response.stub_data
      rcnt = buff[0,4].unpack('V')[0]
      0.upto(rcnt-1) do |s|
        res << buff[8 + (4*s), 4].unpack('V')[0]
      end
    end

  rescue ::Interrupt
    raise $!
  rescue ::Exception => e
    print_status("Remote Management Interface Error: #{e}")
    res = nil
  end

  eps.close if eps

  res
end

#dcerpc_mgmt_inq_princ_name(dport = 135) ⇒ Object



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
# File 'lib/msf/core/exploit/remote/dcerpc_mgmt.rb', line 168

def dcerpc_mgmt_inq_princ_name(dport=135)
  res = nil

  begin

    eps = dcerpc_mgmt_connect(dport)

    eph = dcerpc_handle('afa8bd80-7d8a-11c9-bef4-08002b102989', '1.0', 'ncacn_ip_tcp', [dport])
    opt = { 'Msf' => framework, 'MsfExploit' => self }

    dce = Rex::Proto::DCERPC::Client.new(eph, eps, opt)

    dce.call(4,
      NDR.long(2) +
      NDR.long(256)
    )

    if (dce.last_response != nil and dce.last_response.stub_data != nil)
      buff = dce.last_response.stub_data
      res  = buff
    end

  rescue ::Interrupt
    raise $!
  rescue ::Exception => e
    print_status("Remote Management Interface Error: #{e}")
    res = nil
  end

  eps.close if eps

  res
end

#dcerpc_mgmt_is_server_listening(dport = 135) ⇒ Object



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
# File 'lib/msf/core/exploit/remote/dcerpc_mgmt.rb', line 106

def dcerpc_mgmt_is_server_listening(dport=135)
  res = nil

  begin

    eps = dcerpc_mgmt_connect(dport)

    eph = dcerpc_handle('afa8bd80-7d8a-11c9-bef4-08002b102989', '1.0', 'ncacn_ip_tcp', [dport])
    opt = { 'Msf' => framework, 'MsfExploit' => self }

    dce = Rex::Proto::DCERPC::Client.new(eph, eps, opt)

    dce.call(2, '')

    if (dce.last_response != nil and dce.last_response.stub_data != nil)
      buff = dce.last_response.stub_data
      res  = buff[0,4].unpack('V')[0]
    end

  rescue ::Interrupt
    raise $!
  rescue ::Exception => e
    print_status("Remote Management Interface Error: #{e}")
    res = nil
  end

  eps.close if eps

  res
end

#dcerpc_mgmt_stop_server_listening(dport = 135) ⇒ Object



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
# File 'lib/msf/core/exploit/remote/dcerpc_mgmt.rb', line 137

def dcerpc_mgmt_stop_server_listening(dport=135)
  res = nil

  begin

    eps = dcerpc_mgmt_connect(dport)

    eph = dcerpc_handle('afa8bd80-7d8a-11c9-bef4-08002b102989', '1.0', 'ncacn_ip_tcp', [dport])
    opt = { 'Msf' => framework, 'MsfExploit' => self }

    dce = Rex::Proto::DCERPC::Client.new(eph, eps, opt)

    dce.call(3, '')

    if (dce.last_response != nil and dce.last_response.stub_data != nil)
      buff = dce.last_response.stub_data
      res  = buff[0,4].unpack('V')[0]
    end

  rescue ::Interrupt
    raise $!
  rescue ::Exception => e
    print_status("Remote Management Interface Error: #{e}")
    res = nil
  end

  eps.close if eps

  res
end