How to Reverse Shell Using Python « Null Byte :: WonderHowTo

Hi Folks. This is my first post. I will teach how to create a server and client python reverse shell using sockets and python language. The script i'll post here is going to be very simple, and from here you'll have the possibility to adapt to your own purpose. For example, my original script can download files, upload files, make changes to registry, create user accounts and more. I'm sure you could do it on your own too.PROS: No AV detectionCONS: A bit more complicated to make it work efficiently than using metasploit.First things first, we'll need to set up a server.Step 1: How It WILL WorkOkay, I'll describe how things are going to work. I'm using kali OS at my server-side script. And the client (victim) side MUST be a Windows. So IT WON'T WORK if you test at your UNIX environment.Attacker OS: Kali LinuxVictim OS: Windows 8How the script should work: It will send commands that will be interpreted at the targeted machine running the client script. Then, it will send the output back to the attacker machine.Step 2: Setting Up Server Script (Kali)The script will use three socket functions, Create, Bind and Accept to listen for the client connection. Code:When it detects a incoming connection, it'll receive a hostname from client (the client's code is below) and prompt for an input.This is the last function - main - responsible for executing the functions.Step 3: Setting Up Client (Victim)The client code: You need to set the port for the value you've set at server script. The host could be your local IP on LAN or your WAN IP, or even a DNS Host. I've commented the code for the DNS host.And that should do it.Step 4: ClientImage viaimgur.comStep 5: ServerImage viaimgur.comAfter connecting, a prompt will appear with "IP@Hostname> ' so you can send some commands.To work you'll need to send like this way:shell ipconfigorshell verorshell net userYou'll have to type SHELL before the respective DOS command.That's it. It should be noted that not all commands would work without multi threading the script. RMDIR, MKDIR, DEL, START, and some other commands will require to start another thread. I recommend googling for 'threads python' for more info.IMPORTANT FINAL NOTETo use in pratical scenarios, you could use py2exe to turn the client into windows executable and run in any machine that don't have python installed.So, that's it. Good hacking and remember, everything is possible, the impossible is merely something you don't know how to do it, yet.Want to start making money as a white hat hacker?Jump-start your hacking career with our2020 Premium Ethical Hacking Certification Training Bundlefrom the newNull Byte Shopand get over 60 hours of training from cybersecurity professionals.Buy Now (90% off) >Other worthwhile deals to check out:97% off The Ultimate 2021 White Hat Hacker Certification Bundle99% off The 2021 All-in-One Data Scientist Mega Bundle98% off The 2021 Premium Learn To Code Certification Bundle62% off MindMaster Mind Mapping Software: Perpetual LicenseRelatedHow To:Bypass Antivirus Software by Obfuscating Your Payloads with GraffitiHow To:Convert Python Script to ExeNews:And the Winner of the White Hat Award for Technical Excellence Is...How To:Find & Exploit SUID Binaries with SUID3NUMHow To:Use One-Lin3r to Quickly Generate Reverse Shells, Privesc Commands & MoreHow To:Create a Bind Shell in PythonHow To:Upload a Shell to a Web Server and Get Root (RFI): Part 2How To:Use Meterpeter on OS XHow To:Hack UnrealIRCd Using Python Socket ProgrammingHow To:The Novice Guide to Teaching Yourself How to Program (Learning Resources Included)How To:Create a Reverse Shell to Remotely Execute Root Commands Over Any Open Port Using NetCat or BASHNews:Null Byte Is Calling for Contributors!News:Change from BASH to zshWeekend Homework:How to Become a Null Byte ContributorHow To:Push and Pull Remote Files Securely Over SSH with PipesNews:Learning Python 3.x as I go (Last Updated 6/72012)Hack Like a Pro:Hacking Samba on Ubuntu and Installing the Meterpreter