Gentoo Archives: gentoo-user

From: Hilco Wijbenga <hilco.wijbenga@×××××.com>
To: Gentoo User <gentoo-user@l.g.o>
Subject: [gentoo-user] Bash & Server Sockets
Date: Fri, 16 Jan 2009 05:53:34
Message-Id: e95b15950901152153i32ee25c7k62b35603b11ce55b@mail.gmail.com
1 Hi all,
2
3 In Bash /dev/tcp/host/port can be used to write to a TCP socket. This
4 works nicely so I was very curious whether it would work the other way
5 too: is it possible to have a Bash script listen on a particular port
6 as if it were a server? I couldn't find anything in the Bash manual
7 about it. Google does find a few examples but they all use nc. But
8 that's cheating! ;-) Is it possible with just Bash, no extra tools?
9 (If yes, please enlighten me as to how, obviously I could not get it
10 to work.)
11
12 On a related note, I read some comments about Debian having /dev/tcp
13 disabled in Bash because of security concerns. Would someone
14 knowledgeable about security be able to comment on that? It doesn't
15 make much sense to me. I mean, any Perl, Python, Ruby, etcetera script
16 can write to a socket. Even Debian (with every option deselected)
17 comes installed with Perl. (Yes, I installed Debian just to find out!)
18 :-) So why should /dev/tcp in Bash be deemed such a security risk?
19
20 Cheers,
21 Hilco
22
23 P.S. For the curious:
24 #!/bin/bash
25 exec 3<>/dev/tcp/www.google.ca/80
26 echo -ne "GET / HTTP/1.1\r\n">&3
27 echo -ne "Host: www.google.ca\r\n">&3
28 echo -ne "Connection: close\r\n">&3
29 echo -ne "\r\n">&3
30 cat <&3

Replies

Subject Author
Re: [gentoo-user] Bash & Server Sockets Albert Hopkins <marduk@×××××××××××.org>