Quote:
Originally Posted by lloydie-t
Thanks Jschiwal. The machine I am trying to send to is a windows machine listening on a port 4515. Am I correct is assuming that /dev/tcp/<host1>/port is the machine I am trying to send to?
|
Yes. The abs-guide has this example:
Code:
#!/bin/bash
# dev−tcp.sh: /dev/tcp redirection to check Internet connection.
# Script by Troy Engel.
# Used with permission.
TCP_HOST=www.dns−diy.com # A known spam−friendly ISP.
TCP_PORT=80 # Port 80 is http.
# Try to connect. (Somewhat similar to a 'ping' . . .)
echo "HEAD / HTTP/1.0" >/dev/tcp/${TCP_HOST}/${TCP_PORT}
MYEXIT=$?
: <<EXPLANATION
If bash was compiled with −−enable−net−redirections, it has the capability of
using a special character device for both TCP and UDP redirections. These
redirections are used identically as STDIN/STDOUT/STDERR. The device entries
are 30,36 for /dev/tcp:
mknod /dev/tcp c 30 36
I did this between two Linux machines:
A laptop and a desktop. I'm at the laptop and ssh'd into the desktop because I was too lazy to walk over there!
desktop:
netcat -l -p 8080
laptop:
sudo tail -f /var/log/messages >/dev/tcp/hpmedia/8080
root's password:
Result at Desktop:
May 14 12:35:10 hpamd64 SuSEfirewall2: batch committing...
May 14 12:35:10 hpamd64 SuSEfirewall2: Firewall rules successfully set
May 14 12:42:33 hpamd64 syslog-ng[2762]: STATS: dropped 0
May 14 12:46:08 hpamd64 sudo: jschiwal : TTY=pts/2 ; PWD=/home/jschiwal ; USER=root ; COMMAND=/usr/bin/tail -f /var/log/messages
May 14 12:49:06 hpamd64 sudo: jschiwal : TTY=pts/2 ; PWD=/home/jschiwal ; USER=root ; COMMAND=/sbin/rcSuSEfirewall2 status
You need the target to be listening or you will get:
echo "This is a test" >/dev/tcp/hpamd64/8080
-bash: connect: Connection refused
-bash: /dev/tcp/hpamd64/8080: Connection refused
So Connection refused could just mean that there isn't a listener to complete the handshake, and isn't necessarily a firewall problem.