Recently I needed a way of building an executable on a remote machine using only a keyboard. Basically I needed to "type out an executable" (think of it as I had a very basic "ah-hem" shell that I wanted to make more secure). Because my target host was Windows based, it is not as easy as uploading and compiling from source. I could of course simply use tricks found at http://commandlinekungfu.com to download the file, however I wanted to find a solution where this system didn't create any outgoing requests that resulted in the downloading of an executable. The technique described below is already being used by some very common cyber-security tools such as Fasttrack and sqlmap. It is an interesting solution, one that might help you out with a project in the future.

The problem is that you cant simply type out an executable binary. There are multiple characters that are not printable ascii, so your binary will fail if you try. However there are some tools that will allow us to convert the already compiled binary into ascii printable debug scripts, which can be reassembled using the native debug command on windows machines. Thus creating a "portable" binary that is Ascii printable, therefore gives us the ability to "type out an executable"

For this article we will be using the windows Ncat binary (http://nmap.org/ncat/) and since my machine is OSX, the python based tools in our example.

Ncat

Ncat is a feature-packed networking utility which will read and write data across a network from the command line. Ncat was written for the Nmap Project as a much-improved reimplementation of the venerable Netcat. It uses both TCP and UDP for communication and is designed to be a reliable back-end tool to instantly provide network connectivity to other applications and users. Ncat will not only work with IPv4 and IPv6 but provides the user with a virtually limitless number of potential uses.

Because our target is a windows host, we need to download and unpack nmap for Windows (ncat now is packaged with nmap). Because we are going to communicating this executable via ?keyboard? or some other slow method, we would be smart to compress this file as much as possible before we convert it. We will need to use a packer that self decompresses and retains the ability to execute.

UPX is a free, portable, extendable, high-performance executable packer for several different executable formats. It achieves an excellent compression ratio and offers very fast decompression. Your executables suffer no memory overhead or other drawbacks for most of the formats supported, because of in-place decompression.

Next we need to convert the UPX packed binary into a ASCII debug script, using the dbtool listed above:

python ./dbgtool.py -i ncat-upx.exe -o ncat-upx.scr

Take a second and open the ncat-upx.scr in whatever your favorite text editor is. As you can see, you now have a portable executable that is in printable ASCII.

Upload nc_upx.scr to the target Windows system (either by pasting in your shell, or however you need to do it) and then reconvert your binary to an executable with the following command: debug<DEBUGSCRIPT.scr

This debug script will write a new file named #TEMP#. Simply rename this file to ncat-upx.exe and execute. Better get your ncat-fu ready, because your super over complicated, slow, ninja file upload is complete!

FYI, I didn't see it mentioned in the article, but if you browse to /pentest/windows-binaries/tools/nc.txt on the latest backtrack 4, you will find line for line how to do the above. It's basically a batch file that creates the .hex file, then compiles with debug. You can just copy/paste into a CLI. Pretty sweet stuff.

2. Although he selected ncat.exe as the binary, I think it wasn't a very good choice. ncat.exe has quite a lot of dependencies including the Microsoft Visual C++ Redistributable Package (http://nmap.org/download.html) and I'd love to see how you can use it in a penetration test given its dependencies. Any ideas?

That is a very useful way to copy files. After some research I found another way that this can be done without needed to use debug. You also do not have a file size limit. I have full detailed directions on my blog, however, here is a simple summary of what happens:

Identify a executable that you wish to transferCreate the VBScript to encode the executable to Base64Transfer the ASCII text output to your victim computerCreate a VBScript on the victim computer to decode the ASCII text