Rotate a simple program on the server using netcat

One interesting feature netcatis how it can turn any command line program into a server. For example, on Unix systems, we can make a simple date server by passing the binary code dateto netcatso that it stdoutgoes through the socket:

netcat -l -p 2020 -e date

Then we can call this service from another machine by simply issuing the command:

netcat <ip-address> 2020

Even a shell can be connected ( /bin/sh), although I know that this is very unjustified and has great security implications.

Similarly, I tried to make my own simple C program that reads and writes from stdinand stdout:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char const *argv[])
{
    char buffer[20];
    printf("Please enter your name:\n");
    fgets(buffer, 20, stdin);
    printf("Hello there, %s\n", buffer);
    return 0;
}

, , ; . :

user@computer:~$ netcat localhost 2020
User
Please enter your name:
Hello there, User

, , , ( , )?

, (, , ) , netcat .

+4
1

stdout . fflush(stdout) printf.

+3

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


All Articles