class RpcClient

This library should contain all methods to communicate with msfrpc. See framework/documentation/msfrpc.txt for further information. msfrpcd -S -U wpscan -P wpscan -f -t Web -u /RPC2 name = exploit/unix/webapp/php_include

Public Class Methods

new() click to toggle source
# File lib/wpscan/msfrpc_client.rb, line 28
def initialize
  @config = {}
  @config['host'] = "127.0.0.1"
  @config['path'] = "/RPC2"
  @config['port'] = 55553
  @config['user'] = "wpscan"
  @config['pass'] = "wpscan"
  @auth_token = nil
  @last_auth = nil

  begin
     @server = XMLRPC::Client.new3( :host => @config["host"], :path => @config["path"], :port =>  @config["port"], :user => @config["user"], :password => @config["pass"])
  rescue => e
    puts "[ERROR] Could not create XMLRPC object."
    puts e.faultCode
    puts e.faultString
  end
end

Public Instance Methods

authenticate() click to toggle source

check authentication

# File lib/wpscan/msfrpc_client.rb, line 65
def authenticate()
  login() if @auth_token.nil?
  login() if (Time.now - @last_auth > 600)
end
exploit(name, opts) click to toggle source

execute exploit

# File lib/wpscan/msfrpc_client.rb, line 93
def exploit(name, opts)
  authenticate()
  @server.call('module.execute', @auth_token, 'exploit', name, opts)
end
get_exploit_info(name) click to toggle source

retrieve information about the exploit

# File lib/wpscan/msfrpc_client.rb, line 72
def get_exploit_info(name)
  authenticate()
  @server.call('module.info', @auth_token, 'exploit', name)
end
get_options(name) click to toggle source

retrieve exploit options

# File lib/wpscan/msfrpc_client.rb, line 79
def get_options(name)
  authenticate()
  @server.call('module.options', @auth_token, 'exploit',name)
end
get_payloads(name) click to toggle source

retrieve the exploit payloads

# File lib/wpscan/msfrpc_client.rb, line 86
def get_payloads(name)
  authenticate()
  @server.call('module.compatible_payloads', @auth_token, name)
end
jobs() click to toggle source

list msf jobs

# File lib/wpscan/msfrpc_client.rb, line 100
def jobs()
  authenticate()
  @server.call('job.list', @auth_token)
end
kill_session(id) click to toggle source

kill msf session

# File lib/wpscan/msfrpc_client.rb, line 114
def kill_session(id)
  authenticate()
  @server.call('session.stop', @auth_token, id)
end
login() click to toggle source

login to msfrpcd

# File lib/wpscan/msfrpc_client.rb, line 49
def login()
  result = @server.call("auth.login", @config['user'], @config['pass'])

  if result['result'] == "success"
    @auth_token = result['token']
    @last_auth = Time.new
    logged_in = true
  else
    puts "[ERROR] Invalid login credentials provided to msfrpcd."
    logged_in = false
  end
 
end
meterpreter_read(id) click to toggle source
# File lib/wpscan/msfrpc_client.rb, line 133
def meterpreter_read(id)
  authenticate()
  @server.call('session.meterpreter_read', @auth_token, id)
end
meterpreter_write(id, data) click to toggle source
# File lib/wpscan/msfrpc_client.rb, line 138
def meterpreter_write(id, data)
  authenticate()
  @server.call('session.meterpreter_write', @auth_token, id, data)
end
read_shell(id) click to toggle source

reads any pending output from session

# File lib/wpscan/msfrpc_client.rb, line 121
def read_shell(id)
  authenticate()
  @server.call('session.shell_read', @auth_token, id)
end
sessions() click to toggle source

list msf sessions

# File lib/wpscan/msfrpc_client.rb, line 107
def sessions()
  authenticate()
  @server.call('session.list', @auth_token)
end
write_shell(id, data) click to toggle source

writes the specified input into the session

# File lib/wpscan/msfrpc_client.rb, line 128
def write_shell(id, data)
  authenticate()
  @server.call('session.shell_write', @auth_token, id, data)
end