open(), pipe(), dup2(), close() and watch the descriptor table update live| FD | Type | Path / Device | Mode |
|---|
Key insight (pwnable.kr input2):
To supply controlled data to a program's read(0, buf, n) (reading from stdin),
create a pipe(), then dup2(pipefd[0], 0) — this makes FD 0 point to the pipe's
read end instead of the terminal. Now anything written to pipefd[1] arrives as the process's stdin.
Afterwards close() both original pipe FDs to avoid leaking them.
The same pattern redirects stdout (dup2(fd, 1)) or stderr (dup2(fd, 2)).