Is TCP Communication a two way communication?

This is really a newbie question regarding TCP connectivity.

Is there a TCP connection with bidirectional communication?

Let me give you a scenario: One program listens on a TCP port, say, port 25. An external program connects to the first IP address of the program (port 25) with a random outgoing port, for example, port 45000

Since the first program is just listening, does this mean that

  • The first program can only receive data and not send any data through port 25?
  • If it can send data, what protects the second computer outgoing port 45000 from malicious attacks from the first program through port 25? As I know correctly, firewalls are only for incoming ports.

Any answers are much appreciated

+4
source share
1 answer

TCP always works in two directions. In UDP there is no "send and forget". The first program will have to open the server socket. This means that it is listening on port 25 for TCP SYN (flag A, which signals that the connection is opening). If your second program connects to port 25 (from port 45000), this connection is identified by 4 values, the IP of your host, the port of your host, the IP of the remote host, and the port of the remote host. At this point, when a three-way handshake is performed (SYN, SYN ACK, ACK), the first program receives the client socket from the returned server socket, which is connected to your second program. So yes, as soon as the connection is established, it is a two-way communication, and you are vulnerable.

Firewalls basically block incoming traffic. If your first program was behind the firewall and did not configure the firewall correctly, the firewall will clear the SYN packets from the second program. There will be no connection. The firewall can also check outgoing connections if they are configured correctly.

As I already said. As soon as you connect to the remote program, the remote program will receive a client socket, just like your local program through which all communication takes place.

+6
source

Source: https://habr.com/ru/post/1380311/


All Articles