Hosting/File Transfer with SMB

Moving files to and from a compromised Linux machine is, in general, pretty easy. You’ve got nc, wget, curl, and if you get really desperate, base64 copy and paste. Windows, is another issue all together. PowerShell makes this somewhat easier, but for a lot of the PWK labs, the systems are too old to have PowerShell. The course material goes over a few ways to achieve this, but they don’t cover my favorite - SMB. This may be less realistic in an environment where you have to connect from a victim machine back to your attacker box over the public internet (where SMB could be blocked), but for environments like PWK labs and HTB where you are vpned into the same LAN as your targets, it works great.

Overview

The goal here is to get easy file transfer to and from a compromised Windows host. To do this, we’ll create an SMB share on our local box, and then connect to that share from the compromised Windows host. From there, we can copy files into the shared folder on either host, and then access them on the other host.

Server

Installation

The Impacket tool set comes pre-installed on Kali. If you don’t have it for some reason, you can install it with apt install python-impacket. You can also clone the Secure Auth Corp Impacket git repo if you want the most up to date version.

Starting the Server

To get the server up and running on our local box, simple enter the following syntax:

  • shareName - can be anything you want, but you’ll need to know this in order to connect back to the share

  • sharePath - the folder you want shared

Example

For example, I keep a tools directory with a bunch of common stuff I might need as I work though my labs:

Others like to create an smb directory for each target and drop the necessary files into it.

Then I can share this directory as follows:

Client

Syntax

From the Windows host, we need to use the build in net use command to connect to our shared drive. Here’s three examples of the syntax:

The first command will list all currently connected shares. The second will create a connection to the named shared at the given host (in our case, typically an IP address). The third command will close that connection.

Once that runs, you can reference the share by it’s full UNC path.

Examples

With Shell

Let’s say we wanted to copy a privesc binary to the host. We could do the following.

Connect to the share:

Copy the file:

To Get Shell From RCE

In a different case, I only had access to a MySQL database, and wanted to get a full shell. I used xp_cmdshell to map my drive, copy nc to the host, and run it:

Opsec Notes

Locally

When you run this server, you’ve created an unauthenticated share on the network that anyone can read and write to. That’s why it’s important not to share anything sensitive (like your notes directory), as someone could mess with or delete them.

It’s also a good idea to take down the share when you’re not using it.

You will be able to tell when a new host connects to your share, and when they disconnect:

On Target

There is an option to net use to allow you to reference a connected share by a new drive letter. To do this, just run:

From there, you can go to that drive and it’s easier to interact with. It’s also very unsafe opsec. A user on the box is unlikely to see a mapped share, but might very well notice a new drive letter. The same goes for others in the labs with you attacking the same box. It’s worth the extra trouble to just use the UNC path.

Last updated