PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Bash TCP Rediretion Hat das schon mal we hinbekommen?



linuxhanz
01.02.03, 10:27
In man bash


findet sich im Abschnitt REDIRECTION auch etwas der Art:




`/dev/tcp/HOST/PORT'
If HOST is a valid hostname or Internet address, and PORT is an
integer port number, Bash attempts to open a TCP connection to the
corresponding socket.

`/dev/udp/HOST/PORT'
If HOST is a valid hostname or Internet address, and PORT is an
integer port number, Bash attempts to open a UDP connection to the
corresponding socket.

A failure to open or create a file causes the redirection to fail.




Habe das mal versucht, allerdings Permission denied.

Hat das schonmall jemand eingesetzt und koennte mal wer ein BSP posten.
Wäre sau-cool!

linuxhanz
01.02.03, 14:56
Ok in einer ILUG Liste steht folgendes





Stephen Shirley wrote:
> On Tue, Nov 05, 2002 at 10:43:42AM +0000, John P. Looney wrote:
>
>> There is some way of binding filedescriptors in bash to network sockets.
>>never got it to work myself, but that will be the easiest way of doing it.
>>
>> Stuff like:
>>
>> # cat < /dev/tcp/$i/$port > $results_directory/$i$port$date
>>
>> etc. is *supposed* to work. Never seen it happen. Docs could be lying.
>
> It's a compile-time option that i've never seen turned on yet.

No it works fine (only hapens on redirection)
at least on (2.05a.0(1)-release) (RH7.3).
For e.g. this gets the homepage on my machine:

(echo "GET" 1>&3 & cat 0<&3) 3</dev/tcp/localhost/80

Pįdraig.



Vielleicht sollte das in die FAQ an BASH-MANUAL angehängt werden.
Also ich mache jetzt Wochenende
:)

aus bash2.05 redir.c

#define RF_DEVTCP 5
#define RF_DEVUDP 6


Hier ein Paar Versuche:



linux:/tmp # echo "GET" 1>&3 & cat 0<&3 3< /dev/tcp/localhost/80
bash: 3: Bad file descriptor
[1] 2293
bash: 3: Bad file descriptor
[1]+ Exit 1 echo "GET" 1>&3
linux:/tmp #
linux:/tmp # echo "GET" 1>&2 && cat 0<&2 2</dev/tcp/localhost/80
GET
linux:~ # (echo "EHLO localhost" 1>&3 & cat 0<&3) 3</dev/tcp/localhost/25
220 linux.local ESMTP Sendmail 8.12.2/8.12.2/SuSE Linux 0.6; Mon, 3 Feb 2003 10:14:26 +0100
250-linux.local Hello localhost [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-DELIVERBY
250 HELP
linux:~ # (echo "route show" 1>&3 & cat 0<&3) 3</dev/tcp/localhost/2604

Hello, this is zebra (version 0.92a).
Copyright 1996-2001 Kunihiro Ishiguro.


User Access Verification

’ū’ū’ž"’żPassword:
Password:
linux:~ # (echo "LIST" 1>&3 & cat 0<&3) 3</dev/tcp/192.168.10.74/21
220 ready, dude (vsFTPd 1.0.1: beat me, break me)
530 Please login with USER and PASS.
l
inux:~ # (echo "AAAAAAAAAAAAA%)(/%(//////////////" 1>&3 & cat 0<&3) 3</dev/tcp/192.168.10.74/22
SSH-1.99-OpenSSH_3.0.2p1
Protocol mismatch.



Mist:


linux:~ # cat < /dev/rawip > out.raw
Segmentation fault
linux:~ # Feb 3 10:31:37 linux kernel: Unable to handle kernel NULL pointer dereference at virtual address 00000008
Feb 3 10:31:37 linux kernel: *pde = 00000000