Home page logo

nmap-dev logo Nmap Development mailing list archives

Re: Using ncat to read TCP stream --> send HTTP GET request
From: David Fifield <david () bamsoftware com>
Date: Sat, 21 May 2011 00:15:02 -0700

On Mon, May 16, 2011 at 12:12:08PM +0000, Elias Home wrote:


I'm attempting to get two devices to communicate with each other on my network.  The first device (sender) is able to 
send plain text via TCP to an IPAddress:Port when an event occurs.  The second device (receiver) is triggered by 
receiving an HTTP GET request; it then closes the socket as it should.  The problem is that the transmitter does not 
expect the socket to be closed after the string is sent - it is designed to send to a simple "open TCP port" that 
just monitors for TCP plain text traffic and doesn't respond (and certainly doesn't close the socket). 

I am able to send the following from the transmitter via TCP:  GET /rest/programs/0071/runThe n 
HTTP/1.1[CRLF]Authorizatio n: Basic xxxxxxxxxx[CRLF][CRLF] 

This works perfectly, however the HTTP server (receiver) replies with a 200 and then closes the socket.  The 
transmitter doesn't know how to hand this, and nothing works until I reset the socket connection. 

So, here's what I'm looking to accomplish: 

1.  Open a port on a Windows PC and listen for TCP plain text data; socket connections should NOT be closed on this 
port after data is received 

2.  When a particular plain text string is received over this port, an HTTP GET command must be issued to a different 
IP address:port.  It should be expected that this socket will be closed by the HTTP server. 

3.  The utility performing this task must be able to run in the background and be available to repeat this process 
for an indefinite number of triggers 

Is this possible with ncat?  Any help with an appropriate syntax (or other ideas on how to accomplish this) would be 
greatly appreciated. 

You can try the --sh-exec function and execute a script that reads from
the socket and looks for the magic string. For example, maybe something
like this in server.pl:

#!/usr/bin/perl -w
while (<STDIN>) {
        if (/^GET/) {
                # Do HTTP request.
        } else {
                # Do something else with $_.

Then run

        ncat -lk --sh-exec "./server.py" port

David Fifield
Sent through the nmap-dev mailing list
Archived at http://seclists.org/nmap-dev/

  By Date           By Thread  

Current thread:
[ Nmap | Sec Tools | Mailing Lists | Site News | About/Contact | Advertising | Privacy ]