public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
From: Hilco Wijbenga <hilco.wijbenga@gmail.com>
To: Gentoo User <gentoo-user@lists.gentoo.org>
Subject: [gentoo-user] Bash & Server Sockets
Date: Thu, 15 Jan 2009 21:53:16 -0800	[thread overview]
Message-ID: <e95b15950901152153i32ee25c7k62b35603b11ce55b@mail.gmail.com> (raw)

Hi all,

In Bash /dev/tcp/host/port can be used to write to a TCP socket. This
works nicely so I was very curious whether it would work the other way
too: is it possible to have a Bash script listen on a particular port
as if it were a server? I couldn't find anything in the Bash manual
about it. Google does find a few examples but they all use nc. But
that's cheating! ;-) Is it possible with just Bash, no extra tools?
(If yes, please enlighten me as to how, obviously I could not get it
to work.)

On a related note, I read some comments about Debian having /dev/tcp
disabled in Bash because of security concerns. Would someone
knowledgeable about security be able to comment on that? It doesn't
make much sense to me. I mean, any Perl, Python, Ruby, etcetera script
can write to a socket. Even Debian (with every option deselected)
comes installed with Perl. (Yes, I installed Debian just to find out!)
:-) So why should /dev/tcp in Bash be deemed such a security risk?

Cheers,
Hilco

P.S. For the curious:
#!/bin/bash
exec 3<>/dev/tcp/www.google.ca/80
echo -ne "GET / HTTP/1.1\r\n">&3
echo -ne "Host: www.google.ca\r\n">&3
echo -ne "Connection: close\r\n">&3
echo -ne "\r\n">&3
cat <&3



             reply	other threads:[~2009-01-16  5:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-16  5:53 Hilco Wijbenga [this message]
2009-01-16 15:17 ` [gentoo-user] Bash & Server Sockets Albert Hopkins
2009-01-19 20:14   ` Eric Martin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e95b15950901152153i32ee25c7k62b35603b11ce55b@mail.gmail.com \
    --to=hilco.wijbenga@gmail.com \
    --cc=gentoo-user@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox