/dev/tcp and /dev/udp
If we look inside the /dev
directory, we find lots of files that physical that can be hardware or not. These device files can represent partitions; loopback is used to access plain files as if they were block devices. ISO files, for example, can be mounted as if they were CD-ROMs. Some of this device files are quite unusual, but we have already heard of them, for instance,/dev/null
,/dev/zero
,/dev/urandom
,/dev/tcp
, and/dev/tcp
.
These are called pseudo-devices, and they represent and provide access to some facilities. For instance, all this is moved or redirected to the /dev/null
fall in a black hole and disappears, whereas /dev/urandom
is a good way to get a random string when needed:
cat /dev/urandom | head -c 25 | base64 HwUmcXt0zr6a7puLtO1xyKMrAdZrRqIrgw==
With /dev/tcp
or /dev/udp
, we get access to a socket through which we can communicate to network services locally or remotely. For our examples, we will focus on TCP sockets, since they are more interesting to use...