From: "M. Edward (Ed) Borasky" Date: 2007-12-10T23:33:33+09:00 Subject: Re: Emulating Netcat and connecting to bind shells Eduardo Tongson wrote: > Hello folks, > > I am creating some exploits written in Ruby. Most of my payloads are > TCP bind shells, Netcat works well for connecting to those bind > shells. But I thought, why not connect to the shell directly from Ruby > immediately after sending the payload. Currently I use this snippet > from a Ruby standard library sample I found somewhere: > > """ > s = TCPsocket.open(host,port) > STDOUT.flush > while gets( ) > s.write($_) > print(s.readline) > end > s.close > """ > > Works, but is very limited compared to Netcat. Return only one line > (for example after an "ls"). One strange thing is that it hangs when I > send "cd /". No output and subsequent commands are not processed. "/" > and "cd" are OK. Metasploit has its own library for this kind of > stuff. I think it is called Metasploit Rex. Looking at the sources I > see some references to Rex::IO::Stream. I find it complex and I would > like to avoid something that needs external libraries. > > Can the above snippet be improved? Is there a better way of emulating > Netcat? Is it possible to use Net::Telnet? Thanks everyone. > > Eduardo Tongson > > I'm not at all familiar with "netcat", but if it's like most open-source utilities, it probably has an internal library that you could interface directly to Ruby.