1. 前言
如果只需要研究Linux的tcp協議棧行為,只需要使用packetdrill就能夠滿足我的所有需求。packetdrill才是讓我隨心所欲地撩tcp協議棧。packetdrill的簡單使用手冊。
然而悲劇的是,除了要研究Linux的TCP協議棧行為,還需要研究Windows的tcp協議棧的行為,Windows不開源,感覺里面應該有挺多未知的坑。
為了能夠重現Windows的tcp協議棧的一些網絡行為,這里使用python的scapy進行包構造撩撩Windows的tcp協議棧。scapy在tcp數據報文注入會有一點的時延,這個工具在要求時延嚴格的場景無法使用(還是packetdrill好用,囧)。針對目前遇到的場景,勉強能用,再則已經擼慣了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)
在大部分時候,如果看到不明白的地方,請用help。其次是官方的參考手冊
基本語法ip/tcp/http數據包操縱
>>> 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" 數據部分可以直接使用字符串<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 [email protected] 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"
新聞熱點
疑難解答