跳转至

Nc: invalid option — ‘ ‘

nc反弹shell的时候出现错误

  • nc: invalid option — ‘-‘

需要安装netcat-traditional

1. enable universe repository (if not enabled)`sudo add-apt-repository universe`
2. Install the other netcat using synaptic. (To do this, the universe repository must be enabled.)`sudo apt-get install netcat-traditional`
3. type `sudo update-alternatives --config nc`
4. Select the option `/bin/nc.traditional`
5. type `nc -h`

输出:

[v1.10-41.1]

connect to somewhere: nc [-options] hostname port[s] [ports] …   
listen for inbound: nc -l -p port [-options] [hostname] [port]  
options:  
 -c shell commands as `-e’; use /bin/sh to exec [dangerous!!]  
 -e filename program to exec after connect [dangerous!!]  
 -b allow broadcasts

从中可以看到有将远程文件/命令输出到网络的参数,类似CTF中的方式:

使用说明:

Here is a full example that works:

The script:

#!/bin/bash

echo "Give me a line..."
while read ln; do
    echo "I got '$ln'"
    echo "Give me a line..."
done
Start a listener

nc -l -p 9999 -e ./zzz.sh
Connect to the script:

nc 127.0.0.1 9999
you will see

Give me a line...
type

Hello script...
and you will see two more lines

I got 'Hello script...'
Give me a line...
Check if you did not forget to chmod a+x script.sh. If nc can not execute the script you will get something like:

$ nc -l -p 9999 -e ./zzz.shs
exec: No such file or directory
Also, choose ports in the range [1025 .. 65535], [1 .. 1024] are available only to the root user.

客户端被拒绝?

(UNKNOWN) [127.0.0.1] 9999 (?) : Connection refused

nc端口错误:-p没有正确的设置

原文链接: http://droid10.com/2021/06/25/nc-invalid-option/