To start in the world of cybersecurity, to become an expert, you must take the right path. The Infosecaddicts courses will help you advance much faster and easier.
In other publications, I have named many tools that you should know so that you can perform your tests in a very simple way.
In this publication, we will know the sockets. Something that I have also mentioned a lot is that python is one of the best programming languages for hackers, the reasons for it? It’s high level and very easy to learn.
What is socket?
Socket: is an internal endpoint for sending or receiving data within a node on a computer network. Concretely, it is a representation of this endpoint in networking software (protocol stack), such as an entry in a table (listing communication protocol, destination, status, etc.), and is a form of system resource.
Client: make the request
Server: receive and manage the request
How to use?
We will perform a simple test to see how the sockets work. Initially, we open a Linux terminal and type the following command.
ncat -l -v -p 1234
Now using any text editor copy and paste the following script.
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # we create a STREAM INET socket
s.connect((‘localhost’, 1234)) # instantiate
s.send(‘Hello World’.encode()) # we send a message
data = s.recv(1024)
s.close() # we close the connection
print (‘Received’, data) # we show the received data
The moment we execute our previous script we will get the message “hello word” in the console where we are listening.
If we write anything on our console and press enter we will have the following result.
The time that appears of 13 seconds is due to the time it takes me to write “infosecaddicts” in console, they do not correspond to the response time of the socket.
Sockets are used almost anywhere, but they are one of the worst understood technologies.
This is something widely used by developers, they are much more efficient than requests, it is necessary that every hacker fully understands the functioning of the sockets.