Skip to main content

Python Sockets Bind vs Connect

Python Sockets Bind vs Connect

R. Eric Kiser

A fellow nerd buddy of mine once told me how much he wanted to “know” his new lady friend. I laughed and responded with some simple advice. Teddy, before you can make a connection you have to offer her a binding agreement. (Like if you get this)

I have created several successful python connections for penetration testing in my career. However, I still get asked to create a “trojan” or “backdoor” by would be scrip kiddies. I shrug my shoulders as each person has their method for obtaining information and this is a rather simple task if by reading some Python documentation. Still building out tool in different ways is a fun task. The key to a good “backdoor” is knowing how to use the socket module in Python. The interesting thing is this usually is allowed on most networks as it is a legitimate way of connecting two systems. However, it get tricky if you are connecting outside the network. I find a HTTP request module to a form is best for collecting data.

In this article I want to quickly break down (mostly for a linked reference for those who ask me) the difference between the server socket bind and the client socket connect.

In Python, the module provides low-level core networking services. It allows you to create network sockets and work with them in a manner similar to the Berkeley sockets API.

is used to bind a socket to a specific address and port. This is typically used for servers, where the socket needs to be bound to a specific address and port so that clients can connect to it.

is used to bind the socket to a specific address and port on the host machine. This is done so that the socket can listen for incoming connection requests on that specific address and port. For example, in a server application, the socket can be bound to the localhost address (127.0.0.1) and port 8000. This means that the server is listening for incoming connection requests on the localhost address and port 8000.

On the other hand is used by a client to initiate a connection to a server. After a connection has been established, the client can send data to the server using method and the server can receive data from the client using method.

So in summary, is used to bind a socket to a specific address and port, making the socket listen for incoming connection requests on that address and port, while is used by a client to initiate a connection to a server.

 

Comments

Popular posts from this blog

  Python Script to search for YouTube Data trends R. Eric Kiser As a subject matter expert, I wanted to gain insight into the topics that my readers and students are interested in. Given the increasing popularity of video platforms such as YouTube, I decided to use a Python script to pull data from Google Trends on a specific topic of interest, “hacking.” This script allows me to understand the current trends and popular search queries in the field, and tailor my content to align with the needs and interests of my audience. Below is the simple script that I created. I tend to do more with the project but that is for another day. import requests from pytrends.request import TrendReq # create a new instance of the pytrends class pytrend = TrendReq() # prompt for keyword keyword = input ( "Enter a keyword to search for data trends: " ) # set the parameters for the trend search kw_list = [keyword] timeframe = "today 1-m" # get the trends pytrend.build_payloa...
  Cyber Incident Response Workflow Diagraming Tools R. Eric Kiser There are several diagram drawing tools available on the market today that can be explored. Two very common drawing tools, Microsoft Visio and Draw.io tend to dominate the arena. Draw.io is a free, web-based diagramming software that allows users to create a variety of diagrams, including flowcharts, mind maps, network diagrams, and more. It is web application or as a standalone desktop application for multiple operating systems. Draw.io provides a range of templates and shapes to help users create professional-looking diagrams quickly and easily. It also has a range of collaboration features, including the ability to share diagrams and work on them with others in real-time. Draw.io supports a number of file formats, including .png, .svg, .pdf, and .xml, and can be integrated with other applications through its API. Microsoft Visio is very similar to Draw.io but is the proprietary and a part of the Micr...
  Vulnerability Identification Techniques R. Eric Kiser Vulnerability detection can often be automated through the use of tools such as vulnerability scanners. While these tools can be useful, it is important for organizations not to rely solely on automated techniques and to also incorporate more comprehensive methods in their vulnerability detection efforts. Failing to do so could result in the organization missing vulnerabilities that could potentially lead to data breaches. There are a number of methods that can be employed to identify vulnerabilities in target systems Penetration Tests A penetration test, also known as a pen test, is a simulated cyber attack on a computer system, network, or web application to test its defenses and identify vulnerabilities that an attacker could exploit. This is much more than just a scan as the pen tester intends to find a method of getting foothold on your internal network or sensitive data by acting as a real attacker would. T...