metasploit-framework

https://github.com/rapid7/metasploit-framework

Ruby

Metasploit Framework

Msf::Post::Common#cmd_exec

Executes +cmd+ on the remote system

On Windows meterpreter, this will go through CreateProcess as the
"commandLine" parameter. This means it will follow the same rules as
Windows' path disambiguation. For example, if you were to call this method
thusly:

    cmd_exec("c:\\program files\\sub dir\\program name")

Windows would look for these executables, in this order, passing the rest
of the line as arguments:

    c:\program.exe
    c:\program files\sub.exe
    c:\program files\sub dir\program.exe
    c:\program files\sub dir\program name.exe

On POSIX meterpreter, if +args+ is set or if +cmd+ contains shell
metacharacters, the server will run the whole thing in /bin/sh. Otherwise,
(cmd is a single path and there are no arguments), it will execve the given
executable.

On Java, it is passed through Runtime.getRuntime().exec(String) and PHP
uses proc_open() both of which have similar semantics to POSIX.

On shell sessions, this passes +cmd+ directly the session's
+shell_command_token+ method.

Returns a (possibly multi-line) String.

Source | Google | Stack overflow

Edit

git clone [email protected]:rapid7/metasploit-framework.git

cd metasploit-framework

open lib/msf/core/post/common.rb

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-Msf--Post--Common-cmd_exec-for-pr


# Commit to git

git add lib/msf/core/post/common.rbgit commit -m "better docs for Msf::Post::Common#cmd_exec"


# Open pull request

gem install hub # on a mac you can `brew install hub`

hub fork

git push <your name> -your-name--update-docs-Msf--Post--Common-cmd_exec-for-pr

hub pull-request


# Celebrate!