background image


Chapter 16

The next call is 


, which is used to provide an error message 

or to indicate that an action was not possible:


print_error("you have been pwnd!")

[-] you have been pwnd!
=> nil

Base API Calls

Meterpreter includes many API calls that you can use in your scripts to provide 
additional functionality or customization. You can use several reference points 
for these API calls. The one most often used by scripting newbies looks at how 
the Meterpreter console user interface (UI) uses the calls; these can be used 
as a base to continue writing scripts. To access this code, read the files under 



Back|Track. If you create a listing of the folder contents, you can see the files 
that contain various commands that you can use:


ls -F /opt/framework3/msf3/lib/rex/post/meterpreter/ui/console/


core.rb  espia.rb  incognito.rb  networkpug.rb  priv/  priv.rb  sniffer.rb  
stdapi/  stdapi.rb

Within these scripts are the various Meterpreter core, desktop interaction, 

privileged operations, and many more commands. Review these scripts to 
become intimately familiar with how Meterpreter operates within a compro-
mised system.

Meterpreter Mixins

The Meterpreter mixins are a series of calls that represent the most common 
tasks undertaken in a Meterpreter script. These calls are not available in 



and can be used only when creating a script for Meterpreter. Following is a 
list of some of the most notable calls:


Executes the given command as hidden and channelized. 

The output of the command is provided as a multiline string.

eventlog_clear(evt = "")

Clears a given event log or all event logs if none 

is given. Returns an array of event logs that were cleared.


Enumerates the event logs and returns an array contain-

ing the names of the event logs.


Returns a string with the MD5 checksum 

of a given local file.


Returns a string with the SHA1 check-

sum of a given local file.


Returns a string with the SHA256 

checksum of a given local file.