2

I want to config a PC with necat or socat to execute a script when I tell the server to do this.

I have an old app cappable to send simple message UDP prefered.

The message is stored in a playlist.

enter image description here

example

Let's say I want to send a message to open a macro/script to the PC that is running netcat/socat

"C:\Users\xxx\Desktop\script.bat"   

the server needs to listen on a port. and execute the program when the command its received

how I do this? I don't know how to start I found nothing on internet.

PS. please don't mind UDP security or reliability; it's a LAN thing, and I don't need the server to tell me anything back.

0

1 Answer 1

3

This is a classic use of netcat. But this is unix.SE so my answer will be completely in unix.

Note: netcat has different names on different distros:

  • netcat: alias to nc on some distros
  • nc: GNU netcat on linux or BSD netcat on *BSD
  • ncat: Nmap netcat, consistent on most systems

Options between different versions of netcat vary, I'll point out where different version may behave differently. Moreover, I strongly recommend installing the nmap version of netcat (ncat) since its command line options are consistent across different systems.

I'll be using ncat as the netcat name thorough the answer.

TCP

To use TCP to control a machine through netcat you have two options: using a named pipe (which works with all versions of netcat) and using -e (which only exists in the linux version, or, more exactly, -e on *BSD does something completely different).

On the server side you need to perform either:

mkfifo pinkie
ncat -kl 0.0.0.0 4096 <pinkie | /bin/sh >pinkie

Where: 0.0.0.0 is the placeholder for "all interfaces", use a specific IP to limit it to a specific interface; -l is listen and -k keep open (to not terminate after a single connection).

Another option (on linux/ncat) is to use:

ncat -kl 0.0.0.0 4096 -e /bin/sh

To achieve the same result.

On the client side you can use your app or simply perform:

ncat <server ip> 4096

And you are in control of the shell on the server, and can send commands.

UDP

UDP is similar but has some limitations. You cannot use -k for the UDP protocol without -e, therefore you need to use the linux/ncat to achieve a reusable socket.

On the server side you do:

ncat -ukl 0.0.0.0 4096 -e /bin/sh

And on the client side (or from your app):

ncat -u <server ip> 4096

And once again you have a working shell.

2
  • thank you I finnaly learn what a shell is ive got it worked with nc -L -v -p 4096 -e cmd.exe -k option is not available on windows the UDP mode is not working. nc -L -u -v -p 4096 -e cmd.exe any idea why? and soory i not a linux user, :( Aug 2, 2016 at 19:47
  • @MihaiPopescu - I cannot tell you on the switches for MS windows, I have not a single MS machine to test it, sorry. But ncat should be consistent even across MS windows, and should be included on nmap's bundle for MS windows
    – grochmal
    Aug 2, 2016 at 21:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .