Welcome to pymsfrpc’s documentation!

Indices and tables

Getting started

install from pip.

sudo pip3 install pymsfrpc

open msfconsole and setup the server.

msf> load msgrpc

This will output the username and password of the server. Type this out in a python script. To properly index a returned dict use the b tag before the index str.

from pymsfrpc import msfrpc
ip = "your server ip"
user = "your username"
passwd = "your passwd"
c = msfrpc.Client(ip,user,passwd)
output = c.get_version()

Docs and reference

AuthError is thrown when a problem occurs during authentication
ConnectionError occurs when the script can’t be connected to the server
Client(str adress, str username, str password)

This object contains all the methods dealing with interacting with the server. It takes arguments for the ip of the server, the username and the password.

Returns a binary formated dict with the ruby and metasploit versions
Returns a binary formated dict with the consoles and each id, prompt and if they are busy
Creates a console, returns a binary formated dict with the id and prompt.
Client.destroy_console(str id)
Destroys a console based on the id of the console.
Client.read_console(str id)
Reads the text from a console given the id
Client.write_console(str id, str cmd, bool process=True)
Writes to the console given the id the text inside cmd. If process doesn’t equal True the command will not execute.
Lists all the sessions
Client.stop_sessions(str id)
stops the session with the given id
Client.write_shell(str ses_id, str data, bool process=true)
writes data to a shell using a session id. If process is not true it does not execute
Client.read_shell(str ses_id)
reads data from a shell using a session id
Client.read_meterpreter(str ses_id)
reads data from a meterpreter session
Client.write_meterpreter(str ses_id str data)
sends a command to a meterpreter session
Client.run_module(str _type, str name, str HOST, str PORT, bool payload=false)
runs a given module where _type is the type of module, name is the name, and host and port are the ip and port. PAYLOAD MUST BE TRUE IF USING THE PAYLOAD TYPE

Port other methods

The metasploit project has more methods in the pro version. I can’t properly test any of the modules because I don’t own a copy of the pro version. So instead I can show you how one would port the method.
from pymsfrpc import msfrpc
ip = "your ip"
user = "your user"
passwd = "your passwd"
c = msfrpc.Client(ip,user,passwd)
c.send_command(["your call",self.token])

If there are any args they are added after the token.