Dash and stdin/stdout
On 2017/09/03 at 01:40
When playing CTF, it is often to use a dash character to get an interactable shell after pwning a binary.
cat payload - | ./binary
# is the same as
cat payload /dev/stdin | ./binary
Other commands such as wget
also use dash to represent stdout.
wget fatminmin.com -O -
# is the same as
wget fatminmin.com -O /dev/stdout
Another example is socat
.
# stream TCP-LISTEN:5566 to ./a.out binary
socat TCP-LISTEN:5566,fork EXEC:./a.out
# - is used to stream input/output from TCP-LISTEN:5566 to stdin/stdout
socat TCP-LISTEN:5566,fork -
I used to think it is a convention supported by shells such as bash
and zsh
. However, I recently found out that it is a convention supported by individual UNIX programs not by the shells as stated in the following links.
Reference: