I have a small program that first outputs a string to the user and then takes an input. I instead want the program to work by sending and receiving from a port. To try to realize this I ran the command socat TCP4-LISTEN:1337,reuseaddr,fork EXEC:./program
. From this command, I wanted to be able to run nc 127.0.0.1 1337
and expected the program to:
- Recieve the message from the program
- Be able to provide input
- Lost connetion
However, when running the program using socat
it goes like this
- Give input
- Message received from the program
- Give another input
- Lost connection
I don't understand why this happens. Is there any fault on my part using the socat
command? And if it is, please tell me what is missing/wrong.
Here is the program.
#include <stdio.h>
void vuln(void) {
printf("Input\n");
char buffer[256];
gets(buffer); // potential buffer overflow
}
int main(void) {
vuln();
return 0;
}
pty
? – Kamil Maciorowski Dec 06 '21 at 17:56