nc(NETCAT)

一、网猫出场

地位

nc工具能胜任全天下的跟TCP/UDP相关的一切操作

配置环境

server1:172.25.8.1
server2:172.25.8.2

安装

yum install nc -y             //客户端和服务端都要安装

注意

防火墙一定要关闭

测试

连接成功以后,在server2上写入一段文字,server1上会显示出来

  • step1:
    这里写图片描述
  • step2:
    这里写图片描述

二、端口扫描

查看帮助

[root@foundation8 Desktop]# nc --help
Ncat 6.40 ( http://nmap.org/ncat )
Usage: ncat [options] [hostname] [port]

Options taking a time assume seconds. Append 'ms' for milliseconds,
's' for seconds, 'm' for minutes, or 'h' for hours (e.g. 500ms).
  -4                         Use IPv4 only
  -6                         Use IPv6 only
  -U, --unixsock             Use Unix domain sockets only
  -C, --crlf                 Use CRLF for EOL sequence
  -c, --sh-exec <command>    Executes the given command via /bin/sh
  -e, --exec <command>       Executes the given command
      --lua-exec <filename>  Executes the given Lua script
  -g hop1[,hop2,...]         Loose source routing hop points (8 max)
  -G <n>                     Loose source routing hop pointer (4, 8, 12, ...)
  -m, --max-conns <n>        Maximum <n> simultaneous connections
  -h, --help                 Display this help screen
  -d, --delay <time>         Wait between read/writes
  -o, --output <filename>    Dump session data to a file
  -x, --hex-dump <filename>  Dump session data as hex to a file
  -i, --idle-timeout <time>  Idle read/write timeout
  -p, --source-port port     Specify source port to use
  -s, --source addr          Specify source address to use (doesn't affect -l)
  -l, --listen               Bind and listen for incoming connections
  -k, --keep-open            Accept multiple connections in listen mode
  -n, --nodns                Do not resolve hostnames via DNS
  -t, --telnet               Answer Telnet negotiations
  -u, --udp                  Use UDP instead of default TCP
      --sctp                 Use SCTP instead of default TCP
  -v, --verbose              Set verbosity level (can be used several times)
  -w, --wait <time>          Connect timeout
      --append-output        Append rather than clobber specified output files
      --send-only            Only send data, ignoring received; quit on EOF
      --recv-only            Only receive data, never send anything
      --allow                Allow only given hosts to connect to Ncat
      --allowfile            A file of hosts allowed to connect to Ncat
      --deny                 Deny given hosts from connecting to Ncat
      --denyfile             A file of hosts denied from connecting to Ncat
      --broker               Enable Ncat's connection brokering mode
      --chat                 Start a simple Ncat chat server
      --proxy <addr[:port]>  Specify address of host to proxy through
      --proxy-type <type>    Specify proxy type ("http" or "socks4")
      --proxy-auth <auth>    Authenticate with HTTP or SOCKS proxy server
      --ssl                  Connect or listen with SSL
      --ssl-cert             Specify SSL certificate file (PEM) for listening
      --ssl-key              Specify SSL private key (PEM) for listening
      --ssl-verify           Verify trust and domain name of certificates
      --ssl-trustfile        PEM file containing trusted SSL certificates
      --version              Display Ncat's version information and exit

See the ncat(1) manpage for full options, descriptions and usage examples
[root@foundation8 Desktop]# nc -v 127.0.0.1 22
Ncat: Version 6.40 ( http://nmap.org/ncat )
Ncat: Connected to 127.0.0.1:22.
SSH-2.0-OpenSSH_6.6.1
^C
[root@foundation8 Desktop]# nc -v 127.0.0.1 20
Ncat: Version 6.40 ( http://nmap.org/ncat )
Ncat: Connection refused.
[root@foundation8 Desktop]# nc -v 127.0.0.1 21
Ncat: Version 6.40 ( http://nmap.org/ncat )
Ncat: Connected to 127.0.0.1:21.
220 (vsFTPd 3.0.2)
^C

三、传输文件

在服务端启动监听端口,准备好文件,等待客户端来接受

这里写图片描述

在客户端,接收服务器端的数据,并进行重定向到文件中

这里写图片描述

在回到服务器端,可以看到下面的输出

这里写图片描述

四、传输文件夹

在服务端,将tar的输出通过管道传给nc

这里写图片描述

在客户端连接12345端口,然后将接收到的数据通过tar直接解包

这里写图片描述

  • 推出nc客户端后,通过tree命令可以进行查看

这里写图片描述

 注意:为了节省带宽,我们也可以将文件夹打成压缩包再进行传送,下面的命令是使用gzip进行压缩和解压缩。如果要使用bzip2,则将z选项改成j选项即可。

- 服务器端: tar -czvPf - /home/student/hx1 | nc -l 12345
- 客户端:nc -n 172.25.8.1 12345 | tar -xzvPf -
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值