1. 前言
如果只需要研究Linux的tcp協(xié)議棧行為,只需要使用packetdrill就能夠滿足我的所有需求。packetdrill才是讓我隨心所欲地撩tcp協(xié)議棧。packetdrill的簡(jiǎn)單使用手冊(cè)。
然而悲劇的是,除了要研究Linux的TCP協(xié)議棧行為,還需要研究Windows的tcp協(xié)議棧的行為,Windows不開源,感覺里面應(yīng)該有挺多未知的坑。
為了能夠重現(xiàn)Windows的tcp協(xié)議棧的一些網(wǎng)絡(luò)行為,這里使用python的scapy進(jìn)行包構(gòu)造撩撩Windows的tcp協(xié)議棧。scapy在tcp數(shù)據(jù)報(bào)文注入會(huì)有一點(diǎn)的時(shí)延,這個(gè)工具在要求時(shí)延嚴(yán)格的場(chǎng)景無法使用(還是packetdrill好用,囧)。針對(duì)目前遇到的場(chǎng)景,勉強(qiáng)能用,再則已經(jīng)擼慣了python,上手起來比較容易。
2. 基本語法
安裝scapy在Centos 7.2中直接使用yum install 來安裝。
yum install scapy.noarchhelp 能解決大部分問題
[root@localhost ~]# scapyINFO: Can't import python gnuplot wrapper . Won't be able to plot.INFO: Can't import PyX. Won't be able to use psdump() or pdfdump().WARNING: No route found for IPv6 destination :: (no default route?)Welcome to Scapy (2.2.0)>>> help(send)
在大部分時(shí)候,如果看到不明白的地方,請(qǐng)用help。其次是官方的參考手冊(cè)
基本語法ip/tcp/http數(shù)據(jù)包操縱
>>> IP()<IP |>>>>> IP()/TCP()<IP frag=0 proto=tcp |<TCP |>>>>>> IP(proto=55)/TCP()<IP frag=0 proto=55 |<TCP >> >>>> Ether()/IP()/TCP()<Ether type=IPv4 |<IP frag=0 proto=tcp |<TCP |>>>>>>> IP()/TCP()/"GET /HTTP/1.0/r/n/r/n" 數(shù)據(jù)部分可以直接使用字符串<IP frag=0 proto=tcp |<TCP |<Raw load='GET /HTTP/1.0/r/n/r/n' |>>> >>>> Ether()/IP()/UDP()<Ether type=IPv4 |<IP frag=0 proto=udp |<UDP |>>>>>>> Ether()/IP()/IP()/UDP()<Ether type=IPv4 |<IP frag=0 proto=ipencap |<IP frag=0 proto=udp |<UDP |>>>>>>> str(IP())'E/x00/x00/x14/x00/x01/x00/x00@/x00|/xe7/x7f/x00/x00/x01/x7f/x00/x00/x01'>>> IP(_)<IP version=4L ihl=5L tos=0x0 len=20 id=1 flags= frag=0L ttl=64 proto=hopopt chksum=0x7ce7 src=127.0.0.1 dst=127.0.0.1 |>>>> a=Ether()/IP(dst="www.baidu.com")/TCP()/"GET /index.html HTTP/1.0 /n/n">>> hexdump(a)0000 00 03 0F 19 6A 49 08 00 27 FE D8 12 08 00 45 00 ....jI..'.....E.0010 00 43 00 01 00 00 40 06 70 78 C0 A8 73 C6 B4 61 .C....@.px..s..a0020 21 6C 00 14 00 50 00 00 00 00 00 00 00 00 50 02 !l...P........P.0030 20 00 B3 75 00 00 47 45 54 20 2F 69 6E 64 65 78 ..u..GET /index0040 2E 68 74 6D 6C 20 48 54 54 50 2F 31 2E 30 20 0A .html HTTP/1.0 .0050 0A .>>> b=str(a)>>> b"/x00/x03/x0f/x19jI/x08/x00'/xfe/xd8/x12/x08/x00E/x00/x00C/x00/x01/x00/x00@/x06px/xc0/xa8s/xc6/xb4a!l/x00/x14/x00P/x00/x00/x00/x00/x00/x00/x00/x00P/x02 /x00/xb3u/x00/x00GET /index.html HTTP/1.0 /n/n"
新聞熱點(diǎn)
疑難解答
圖片精選