2008年10月13日星期一

在Windows环境下编译SendIP的问题总结

以下是SendIP的介绍,我主要是想用这个东西来发伪造的数据包,可惜在俺的D版的Windows XP SP2上还是不通。
SendIP is a tool to send completely arbitrary packets out over the network.
In conjunction with PackPrint (see
http://www.earth.li/projectpurple/progs/packprint.html), this makes an
extremely powerful debugging tool for networks.

SendIP目前支持如下协议:
Here is a list of protocols that SendIP currently understands:
* IPv4 (but see below section 7)
* TCP
* BGP
* ICMP
* UDP
* RIP
* NTP
* IPv6 (except on solaris)
* ICMPv6
* TCP
* UDP
* RIPng
* NTP?

Other protocols will be added in future versions, as and when I have time
to add them.

Of course, it is still possible to send packets using other protocols, but
you have to construct the packet data and headers entirely by hand.


因为这东西只提供了Linux和Solaris下的版本,我猜可能国外的人私人都用不起Windows……
我就在Cygwin下想将其编译看看。
结果遇到如下问题:
  1. 在编译的时候,遇到了gethostbyname2这个函数未定义……
  2. gcc的-fPic等选项不支持
第一个问题么,我知道gethostbyname是在netdb.h这个头文件中声明的,gethostbyname2不清楚。google 关键字cygwin+gethostbyname2发现,gethostbyname2也是在netdb上声明,但是从http://win6.jp/Cygwin/index.html这上面知道,现在最新版本的cygwin并没有支持IPV6,需要从这个网址上下载补丁。
下载后按照里面的README很快的就解决了第一个问题

第二个问题也简单,直接将Makefile里面相关的编译选项去掉就可以了




最后编译好了,就开始运行了……

$ ./sendip -p ipv4 -p tcp -d r99 x.x.x.x
sendto: Interrupted system call

faint!!!!
$ ls
CHANGES contrib gnugetopt1.o ipv6.so sendip.1 tcp.so
LICENSE csum.c help2man ntp.c sendip.c types.h
Makefile csum.o icmp.c ntp.h sendip.exe udp.c
README cygwin1.dll icmp.h ntp.so sendip.o udp.h
TODO dummy.c icmp.so rip.c sendip.spec udp.so
VERSION dummy.h ipv4.c rip.h sendip.spec.in
bgp.c gnugetopt.c ipv4.h rip.so sendip2.exe
bgp.so gnugetopt.h ipv4.so ripng.c sendip_module.h
compact.c gnugetopt.o ipv6.c ripng.h tcp.c
compact.o gnugetopt1.c ipv6.h ripng.so tcp.h


$ fgrep "Interrupted system call" *
Binary file cygwin1.dll matches

看来这个错误是在Cygwin下封装了。

最后想起了,MS在winXP SP2版本后就对发送raw packet进行了限制
C:\Documents and Settings\Administrator>net helpmsg 10004

一个封锁操作被对 WSACancelBlockingCall 的调用中断。
发送伪造的数据包将被WSACancelBlockingCall中断。


解决方法应该是用驱动直接发包。。。。。。


可以参考winpcap + libnet +自己的code来实现吧

郁闷,还以为有现成的工具呢,自己写的话,就是组装包比较麻烦。

可以参考参考tcpReplay-Win32或者JPcap,封装的都还挺好。

1 条评论:

Unknown 说...

我在编译SendIP时,还遇到了第三个问题

常量IPPROTO_ICMPV6和IPPROTO_NONE未定义的问题。


后来在http://www.freepascal.org/docs-html/rtl/sockets/index-2.html上找到了这些定义

分别是58和59