2005-09-23 09:14:03 +00:00
|
|
|
#!/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$'
|
|
|
|
|
2005-10-02 06:53:39 +00:00
|
|
|
write_data = ('A' * (1024 * 8))
|
2005-09-23 09:14:03 +00:00
|
|
|
filename = 'smb_tester.txt'
|
|
|
|
|
|
|
|
s = Rex::Socket.create_tcp(
|
|
|
|
'PeerHost' => @@host,
|
|
|
|
'PeerPort' => @@port
|
|
|
|
)
|
|
|
|
|
|
|
|
c = Klass.new(s, true)
|
2005-10-02 06:53:39 +00:00
|
|
|
c.client.evasion_level = 0
|
2005-09-23 09:14:03 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
c.login('*SMBSERVER', user, pass)
|
|
|
|
c.connect(share)
|
|
|
|
|
2005-10-02 06:53:39 +00:00
|
|
|
f = c.open(filename, 'rwct')
|
2005-09-23 09:14:03 +00:00
|
|
|
f << write_data
|
|
|
|
f.close
|
|
|
|
|
2005-10-02 06:53:39 +00:00
|
|
|
f = c.open(filename, 'ro')
|
2005-09-23 09:14:03 +00:00
|
|
|
d = f.read()
|
|
|
|
f.close
|
|
|
|
|
|
|
|
c.delete(filename)
|
|
|
|
c.disconnect(share)
|
2005-10-02 06:53:39 +00:00
|
|
|
|
2005-09-23 09:14:03 +00:00
|
|
|
assert_equal(write_data, d)
|
2005-10-02 06:53:39 +00:00
|
|
|
|
|
|
|
c.connect('IPC$')
|
|
|
|
f = c.create_pipe('\BROWSER')
|
|
|
|
|
2005-09-23 09:14:03 +00:00
|
|
|
rescue
|
|
|
|
puts $!.to_s + $!.backtrace.join("\n")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
s.close
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|