Thứ Sáu, 11 tháng 9, 2020

[Basic Python for Pentesting]#1 Create TCPclient and TCPserver SOCKET

 Hello guys ! 

With all my effort to learning about pentesting ,  I decide to learn Python in "pentester's way"

This is a powerful script language which can make everything easier and faster . 

Today, I will introduce about Socket and furthermore , create a TCP socket client and server , by Python . 

Firstly , what is socket ?

Sockets allow communication between two different processes on the same or different machines. To be more precise, it's a way to talk to other computers using standard Unix file descriptors. In Unix, every I/O action is done by writing or reading a file descriptor. A file descriptor is just an integer associated with an open file and it can be a network connection, a text file, a terminal, or something else.

A Unix Socket is used in a client-server application framework. A server is a process that performs some functions on request from a client. Most of the application-level protocols like FTP, SMTP, and POP3 make use of sockets to establish connection between client and server and then for exchanging data.

So , It seems very clearly. With socket , we can establish a connection between 2 computer or system. 

Programmers have a number of third-party tools to create networked server and client in Python, but the core module for those tools is socket.  This module expose all of the necessary pieces to quickly write TCP and UDP servers and clients, use raw sockets, and so forth.

So, this is my very first piece of code in Python to create TCP Client

It's pretty simple, but the one you'll write more often. For more explanation, first we create a socket object with socket.AF_INET( saying we use standard IPv4) and socket.SOCK_STREAM(use the TCP protocol) . Then, we connect() the client with host and port of target we focus. Next step , we send() some data to the host. and finally we receive the response from host. 

And next stuff is TCP server which you might want to use when writing command shells or crafting a proxy 

Here we go !

It's a simple Server which can receive data from clients and response back to them .

If we do it correcly, those TCP client and server above can completely connect when both of them running . Let's test this.

Firsly, we compile and run TCP server

Then, we run TCP client

This is the response of the server to the client. So , they connected successfully!

And this is the log in server-side

We can continue testing this connection via Netcat. Opening netcat and connect to the server via host and port we have described (


That's it!

Good bye and see you guys in next #



1 nhận xét:

  1. From the method, we can to} see the usual deviation is proportional to the sq. root of the variety of rounds performed, while the anticipated loss is proportional to the variety of rounds 점보카지노 performed. As the variety of rounds increases, the anticipated loss increases at a a lot faster rate. This is why it is inconceivable for a gambler to win in lengthy term|the lengthy run}. It is the excessive ratio of short-term standard deviation to anticipated loss that fools gamblers into pondering that they can win. The calculation of the roulette home edge is a trivial train; for different video games, this isn't normally the case. Combinatorial analysis and/or laptop simulation is necessary to complete the duty.

    Trả lờiXóa

Phổ Biến