background image

242

Chapter 16

The next call is 

print_error()

, 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 

/opt/framework3/msf3/lib/rex/post/meterpreter/ui/console/command_dispatcher/

 in 

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

root@bt:~# 

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

command_dispatcher/

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 

irb

 

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

cmd_exec(cmd)

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.

eventlog_list()

Enumerates the event logs and returns an array contain-

ing the names of the event logs.

file_local_digestmd5(file2md5)

Returns a string with the MD5 checksum 

of a given local file.

file_local_digestsha1(file2sha1)

Returns a string with the SHA1 check-

sum of a given local file.

file_local_digestsha2(file2sha2)

Returns a string with the SHA256 

checksum of a given local file.