Sendip是一個linux平台的命令行發數據包工具,目前(2018年2月)支持的協議有ipv4、ipv6、icmp、tcp、udp、bgp、rip、ntp,作者表示其他協議將會后面支持,當他有空寫的時候。Sendip很強大,它支持自定義頭部和數據(也就是IP層以上的整個包),沒有過多的限制,所以連源IP都可以隨意寫,而且里面也提供了一些默認的選項,可以擇需而發,非常方便。又因為它是命令行的,還支持從文件中直接讀取整個packet發送,所以適合用腳本批量測試。它只是個發包工具,對於發出去的包,收到了什么樣的回復,Sendip是不知道的,所以要得到回復的包就只能用抓包工具了。它的源碼也很簡單,沒有過多平台相關的代碼,如果不理解也可以看源碼。
其實這個工具已經滿足了我的要求,之前下載的PackETH是GUI版的,連數據鏈路層(link layer)都支持,也要求必須提供這一層的相關信息才能發包,這一層一般不太關心,它又不提供自動封裝,總的來說不太適合用。
Sendip簡單使用
常見協議報頭可參考常見協議TCP、UDP、IP圖
通用選項:
-d 要攜帶的數據。rN隨機產生N個字節,0x之后帶十六進制,0之后帶8進制。
-f 從文件中讀取要攜帶的數據。
-p 加載協議模塊,只有加載了才能使用。
-v 打印整個發出的包。
ipv4模塊:
-iv x 版本 Default: 4
-ih x 首部長度 Default: Correct
-iy x 區分服務 Default: 0
-il x 總長度 Default: Correct
----------------------------------------------32bit
-ii x 標識 Default: Random
-ifr x 標志 Default: 0 (options are 0,1,r)
-if x 片偏移 Default: 0
----------------------------------------------32bit
-it x 生存時間 Default: 255
-ip x 協議 Default: 0, or set by underlying protocol
-ic x 首部檢驗和 Default: Correct
----------------------------------------------32bit
-is x 源地址 Default: 127.0.0.1
----------------------------------------------32bit
-id x 目的地址 Default: Correct
----------------------------------------------32bit
下面全是可選字段(比較少用,不譯):
-ifd x IP don't fragment flag (see README)
Default: 0 (options are 0,1,r)
-ifm x IP more fragments flag (see README)
Default: 0 (options are 0,1,r)
-ionum x
IP option as string of hex bytes (length is always correct)
Default: (no options)
-ioeol IP option: end of list
-ionop IP option: no-op
-iorr x
IP option: record route. Format: pointer:addr1:addr2:...
-iots x
IP option: timestamp. Format: pointer:overflow:flag:(ip1:)ts1:(ip2:)ts2:...
-iolsr x
IP option: loose source route. Format: pointer:addr1:addr2:...
-iosid x
IP option: stream identifier
-iossr x
IP option: strict source route. Format: pointer:addr1:addr2:...
tcp模塊:
-ts x 源端口 Default: 0
-td x 目的端口 Default: 0
----------------------------------------------32bit
-tn x 序號 Default: Random
----------------------------------------------32bit
-ta x 確認號 Default: 0
----------------------------------------------32bit
-tt x 數據偏移 Default: Correct
-tr x 保留(ECN、CWR看rfc2481) Default: 0
-tfu x URG Default: 0, or 1 if -tu specified (options are 0,1,r)
-tfa x ACK Default: 0, or 1 if -ta specified (options are 0,1,r)
-tfp x PSH Default: 0 (options are 0,1,r)
-tfr x RST Default: 0 (options are 0,1,r)
-tfs x SYN Default: 1 (options are 0,1,r)
-tff x FIN Default: 0 (options are 0,1,r)
-tw x 窗口 Default: 65535
----------------------------------------------32bit
-tc x 檢驗和 Default: Correct
-tu x 緊急指針 Default: 0
----------------------------------------------32bit
下面全是可選字段(比較少用,不譯):
-tonum x TCP option as string of hex bytes (length is always correct)
Default: (no options)
-toeol TCP option: end of list
-tonop TCP option: no op
-tomss x
TCP option: maximum segment size
-towscale x
TCP option: window scale (rfc1323)
-tosackok
TCP option: allow selective ack (rfc2018)
-tosack x
TCP option: selective ack (rfc2018), format is l_edge1:r_edge1,l_edge2:r_edge2...
-tots x
TCP option: timestamp (rfc1323), format is tsval:tsecr
udp模塊:
-us x 源端口 Default: 0
-ud x 目的端口 Default: 0
-ul x 長度 Default: Correct
-uc x 檢驗和 Default: Correct
要注意,按照從左到右的順序依次封裝報文,所以ip報文必須寫在其他報文之前。如果協議中需要檢驗和之類的就按默認的就行了,省去計算的痛苦。下面有幾個例子:
sendip -v -p ipv4 -id 14.215.177.39 -p udp -f test www.baidu.comsendip -p ipv4 -is 192.168.1.2 -id 192.168.1.1 -p icmp -d 0x89ABCDEF www.google.com
其中主要的結構是sendip 網絡層 上一層 數據 domain,domain是目的主機,可以是www.baidu.com或192.168.1.1之類的。如果出現什么錯誤就會打印出幫助信息,里面有一行是提示錯誤原因,別漏看了。至於能不能發不規則的包(如數據與報文長度不符合、校驗和亂寫之類的),實際會不會發出去就沒進行測試了。
