metasploit-framework/lib/rex/proto/smb/simpleclient.rb.ut.rb

76 lines
1.3 KiB
Ruby

#!/usr/bin/ruby
$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..'))
require 'test/unit'
require 'rex/proto/smb'
require 'rex/proto/dcerpc'
require 'rex/socket'
class Rex::Proto::SMB::Client::UnitTest < Test::Unit::TestCase
Klass = Rex::Proto::SMB::SimpleClient
# Alias over the Rex DCERPC protocol modules
DCERPCPacket = Rex::Proto::DCERPC::Packet
DCERPCClient = Rex::Proto::DCERPC::Client
DCERPCResponse = Rex::Proto::DCERPC::Response
DCERPCUUID = Rex::Proto::DCERPC::UUID
FILE_CREATE = 0x10
FILE_TRUNC = 0x02
FILE_OPEN = 0x01
@@host = '192.168.0.219'
@@port = 445
def test_smb_open_share
user = 'SMBTest'
pass = 'SMBTest'
share = 'C$'
write_data = ('A' * (1024 * 8))
filename = 'smb_tester.txt'
s = Rex::Socket.create_tcp(
'PeerHost' => @@host,
'PeerPort' => @@port
)
c = Klass.new(s, true)
c.client.evasion_level = 0
begin
c.login('*SMBSERVER', user, pass)
c.connect(share)
f = c.open(filename, 'rwct')
f << write_data
f.close
f = c.open(filename, 'ro')
d = f.read()
f.close
c.delete(filename)
c.disconnect(share)
assert_equal(write_data, d)
c.connect('IPC$')
f = c.create_pipe('\BROWSER')
rescue
puts $!.to_s + $!.backtrace.join("\n")
return
end
s.close
end
end