Search code examples
windowsperlnetcat

Using windows built-ins (plus TeraTerm and perl, possibly) to emulate netcat's raw connection mode


So I'm trying to get windows to perform much like our Linux machines are able to.

Basically, we have a server set up to run a specific program on a port. From a Linux box, running the following will display the help output for the program:

echo "--help" | nc servername portnum

Is it possible to do something similar to this in Windows, using only the build-in functionality of Windows 7, TeraTerm, and Perl (this will go with code that can be run on multiple machines in a lab, thus extra software can't easily be installed).

NetCat is detected as malware (backdoor agent) by many Windows anti-virus programs, so putting it into the shared directory wouldn't work.


Solution

  • It's not hard to write a Perl script to connect to a remote host and port and print its standard input to the socket.

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    use IO::Socket;
    
    my $host = shift @ARGV;
    my $port = shift @ARGV;
    
    my $remote = IO::Socket::INET->new(
                        Proto    => "tcp",
                        PeerAddr => $host,
                        PeerPort => $port,
                    )
                  or die "cannot connect to port $port at $host";
    while (<>) { print $remote $_ }
    

    (Shamelessly adapted from the first Google hit for "simple perl client", http://www.ccsf.edu/Pub/Perl/perlipc/A_Simple_Client.html)