hammackj

Using the librex gem

I started automating the release of the librex gem and I thought it might be useful if I did a quick post on how to use the library.

So for starters librex is a repackaging of a core library from Metasploit. At my last job, I needed a way to interact with Windows shares and other rpc functionality from ruby. Rex was the only implementation of SMB in ruby that I could find. With permission from HDM I created a gem and published it on rubygems.

This is a quick example of how to interact with a Windows Share/computer using SMB via the Rex library.

#!/usr/bin/env ruby

#Jacob Hammack
#Jacob.Hammack@hammackj.com
#An Example for connecting to a Windows Share.

require 'rubygems'
require 'rex'

host = ""
username = ""
password = ""
#hostname is interesting, new windows require the actual hostname of the box
#to connect so this may not work on 7
hostname = "*SMBSERVER"
domain = ""

begin
    sock = Rex::Socket::Tcp.create('PeerHost' => host, 'PeerPort' => 139)
    smb = Rex::Proto::SMB::SimpleClient.new(sock)

    puts "[*] Logging in to #{host}"
    smb.login(hostname, username, password, domain)
    smb.connect("Admin$")

    if smb.client.auth_user
        puts "[*] Connected to Admin$"
    else
        puts "[!] Unable to Connect to Admin$"
    end

    sock.close
rescue Exception => e
    puts "#{e.messaage}\n#{e.backtrace}\n\n"
end

If there are any requests I will do more examples for the different stuff Rex can do for you. For now back to the debugger =)