Mixins
git-svn-id: file:///home/svn/incoming/trunk@3123 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
parent
7403e8bf23
commit
f4d6a11fd7
|
@ -0,0 +1,149 @@
|
|||
require 'msf/core'
|
||||
|
||||
module Msf
|
||||
|
||||
###
|
||||
#
|
||||
# This module exposes methods for querying a remote MSSQL service
|
||||
#
|
||||
###
|
||||
module Exploit::Remote::MSSQL
|
||||
|
||||
include Exploit::Remote::Udp
|
||||
include Exploit::Remote::Tcp
|
||||
|
||||
#
|
||||
# Creates an instance of a MSSQL exploit module.
|
||||
#
|
||||
def initialize(info = {})
|
||||
super
|
||||
|
||||
# Register the options that all FTP exploits may make use of.
|
||||
register_options(
|
||||
[
|
||||
Opt::RHOST,
|
||||
Opt::RPORT(1433),
|
||||
], Msf::Exploit::Remote::MSSQL)
|
||||
end
|
||||
|
||||
#
|
||||
# This method sends a UDP query packet to the server and
|
||||
# parses out the reply packet into a hash
|
||||
#
|
||||
def mssql_ping
|
||||
data = { }
|
||||
|
||||
ping_sock = Rex::Socket::Udp.create(
|
||||
'PeerHost' => datastore['RHOST'],
|
||||
'PeerPort' => 1434,
|
||||
'Context' =>
|
||||
{
|
||||
'Msf' => framework,
|
||||
'MsfExploit' => self,
|
||||
})
|
||||
|
||||
|
||||
ping_sock.put("\x02")
|
||||
resp, saddr, sport = ping_sock.recvfrom()
|
||||
ping_sock.close
|
||||
|
||||
return data if not resp
|
||||
return data if resp.length == 0
|
||||
|
||||
var = nil
|
||||
resp.slice!(0, resp.index('ServerName'))
|
||||
resp.split(';').each { |d|
|
||||
if (not var)
|
||||
var = d
|
||||
else
|
||||
data[var] = d
|
||||
var = nil
|
||||
end
|
||||
}
|
||||
return data
|
||||
end
|
||||
|
||||
#
|
||||
# This method connects to the server over TCP and attempts
|
||||
# to authenticate with the supplied username and password
|
||||
# The global socket is used and left connected after auth
|
||||
#
|
||||
def mssql_login(user='sa', pass='')
|
||||
p_hdr = "\x02\x00\x02\x00\x00\x00\x02\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
||||
|
||||
p_pk2 = "\x30\x30\x30\x30\x30\x30\x61\x30\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x20\x18\x81\xb8\x2c\x08\x03"+
|
||||
"\x01\x06\x0a\x09\x01\x01\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x73\x71\x75\x65\x6c\x64\x61"+
|
||||
"\x20\x31\x2e\x30\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x0b\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00"
|
||||
|
||||
p_pk3 = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x04\x02\x00\x00\x4d\x53\x44"+
|
||||
"\x42\x4c\x49\x42\x00\x00\x00\x07\x06\x00\x00"+
|
||||
"\x00\x00\x0d\x11\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00"
|
||||
|
||||
|
||||
p_lang = "\x02\x01\x00\x47\x00\x00\x02\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
|
||||
"\x00\x00\x00\x00\x00\x00\x30\x30\x30\x00\x00"+
|
||||
"\x00\x03\x00\x00\x00"
|
||||
|
||||
user = user.slice(0, 29)
|
||||
pass = pass.slice(0, 29)
|
||||
|
||||
ulen = user.length.chr
|
||||
plen = pass.length.chr
|
||||
|
||||
user << ("\x00" * (30-user.length))
|
||||
pass << ("\x00" * (30-pass.length))
|
||||
|
||||
p_login = p_hdr + user + ulen + pass + plen
|
||||
p_login << p_pk2 + plen + pass + p_pk3
|
||||
|
||||
connect
|
||||
sock.put(p_login)
|
||||
sock.put(p_lang)
|
||||
resp = sock.get_once
|
||||
|
||||
if (resp and resp.length > 10 and resp[8] == 0xe3)
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -0,0 +1,116 @@
|
|||
module Msf
|
||||
|
||||
###
|
||||
#
|
||||
# This module provides methods for communicating with a host over UDP
|
||||
#
|
||||
###
|
||||
module Exploit::Remote::Udp
|
||||
|
||||
#
|
||||
# Initializes an instance of an exploit module that exploits a
|
||||
# vulnerability in a UDP service
|
||||
#
|
||||
def initialize(info = {})
|
||||
super
|
||||
|
||||
register_options(
|
||||
[
|
||||
Opt::RHOST,
|
||||
Opt::RPORT,
|
||||
], Msf::Exploit::Remote::Udp)
|
||||
end
|
||||
|
||||
#
|
||||
# Creates a UDP socket for communicating with a remote host
|
||||
#
|
||||
def connect_udp(global = true)
|
||||
nsock = Rex::Socket::Udp.create(
|
||||
'PeerHost' => datastore['RHOST'],
|
||||
'PeerPort' => datastore['RPORT'].to_i,
|
||||
'LocalHost' => datastore['CHOST'] || "0.0.0.0",
|
||||
'LocalPort' => datastore['CPORT'] ? datastore['CPORT'].to_i : 0,
|
||||
'Context' =>
|
||||
{
|
||||
'Msf' => framework,
|
||||
'MsfExploit' => self,
|
||||
})
|
||||
|
||||
# Set this socket to the global socket as necessary
|
||||
self.udp_sock = nsock if (global)
|
||||
|
||||
# Add this socket to the list of sockets created by this exploit
|
||||
sockets << nsock
|
||||
|
||||
return nsock
|
||||
end
|
||||
|
||||
#
|
||||
# Closes the UDP socket
|
||||
#
|
||||
def disconnect_udp(nsock = self.udp_sock)
|
||||
begin
|
||||
if (nsock)
|
||||
nsock.shutdown
|
||||
nsock.close
|
||||
end
|
||||
rescue IOError
|
||||
end
|
||||
|
||||
if (nsock == udp_sock)
|
||||
self.udp_sock = nil
|
||||
end
|
||||
|
||||
# Remove this socket from the list of sockets created by this exploit
|
||||
sockets.delete(nsock)
|
||||
end
|
||||
|
||||
#
|
||||
# Performs cleanup, disconnects the socket if necessary
|
||||
#
|
||||
def cleanup
|
||||
super
|
||||
|
||||
disconnect_udp
|
||||
end
|
||||
|
||||
##
|
||||
#
|
||||
# Wrappers for getters
|
||||
#
|
||||
##
|
||||
|
||||
#
|
||||
# Returns the target host
|
||||
#
|
||||
def rhost
|
||||
datastore['RHOST']
|
||||
end
|
||||
|
||||
#
|
||||
# Returns the remote port
|
||||
#
|
||||
def rport
|
||||
datastore['RPORT']
|
||||
end
|
||||
|
||||
#
|
||||
# Returns the local host
|
||||
#
|
||||
def lhost
|
||||
datastore['LHOST']
|
||||
end
|
||||
|
||||
#
|
||||
# Returns the local port
|
||||
#
|
||||
def lport
|
||||
datastore['LPORT']
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
attr_accessor :udp_sock
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue