{"id":1102,"date":"2013-12-26T10:13:56","date_gmt":"2013-12-26T02:13:56","guid":{"rendered":"http:\/\/www.dogeye.net\/?p=1102"},"modified":"2013-12-26T10:13:56","modified_gmt":"2013-12-26T02:13:56","slug":"%e6%8a%93%e5%8c%85%e7%a8%8b%e5%ba%8f%e7%9a%84%e4%b8%80%e4%ba%9b%e5%88%86%e4%ba%ab","status":"publish","type":"post","link":"https:\/\/ykyi.net\/?p=1102","title":{"rendered":"\u6293\u5305\u7a0b\u5e8f\u7684\u4e00\u4e9b\u5206\u4eab"},"content":{"rendered":"<p><span style=\"font-size:14px;\">\u6628\u665a\u540c\u767d\u603b\u548cadden\u63d0\u5230\u6293\u5305\u7684\u95ee\u9898\u3002\u56e0\u4e3a\u5199\u8fc7\u76f8\u5173\u7684\u4ee3\u7801\uff0c\u9047\u5230\u8fc7\u6293\u5305\u7684\u5404\u79cd\u5404\u6837\u7684\u5751\uff0c\u6b64\u6587\u5206\u4eab\u4e00\u4e9b\u76f8\u5173\u7684\u7ecf\u9a8c\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-size:14px;\"><strong>1. Linux cooked capture<\/strong><\/span><\/p>\n<p><span style=\"font-size:14px;\">\u5728\u7528tcpdump\u6216wireshark\u770b\u6570\u636e\u5305\u65f6\uff0c\u6709\u65f6\u4f1a\u770b\u5230\u6570\u636e\u94fe\u8def\u5c42\u7684\u7684\u5305\u5934\u79f0\u4e3aLinux cooked capture\u3002\u8fd9\u4e0d\u662f\u4e00\u4e2a\u771f\u5b9e\u7684\u5305\u5934\uff0c\u5f53\u7528tcpdump\u6307\u5b9a\u4ece\u6240\u6709\u7f51\u7edc\u4ecb\u8d28 -i any \u6293\u5305\u65f6\uff0c\u6240\u6709\u6293\u5230\u7684\u5305\u7684\u6570\u636e\u94fe\u8def\u5c42\u88ab\u6362\u6210\u4e86Linux cooked capture\u3002\u5728wireshark\u5b98\u65b9\u7f51\u7ad9\u5bf9Linux cooked capture\u7684\u89e3\u91ca\u4e2d: \u8fd9\u662f\u4e00\u4e2a\u5728linux\u4e0a\u88ablibpcap\u6293\u5305\u5e93\u4f7f\u7528\u7684&ldquo;\u5047\u534f\u8bae&rdquo;(pseudo-protocal)\uff0c\u5f53\u4ece&ldquo;any&rdquo;\u8bbe\u5907\u5728\u6293\u5305\uff0c\u6216\u8005\u672c\u5730\u7684\u6570\u636e\u94fe\u8def\u5c42\u5305\u5934\u65e0\u6548\u65f6\u88ab\u4f7f\u7528\u3002\u66f4\u591a\uff0c\u89c1<a href=\"http:\/\/wiki.wireshark.org\/SLL\">http:\/\/wiki.wireshark.org\/SLL<\/a><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-size:14px;\"><strong>2. IP over IP tunnel<\/strong><\/span><\/p>\n<p><span style=\"font-size:14px;\">wikipedia\u7684\u793a\u4f8b\u56fe\u663e\u793aIP tunnel\u4e0a\u7684\u5305\u7684\u7ed3\u6784\u662f\uff1a<\/span><\/p>\n<p><span style=\"font-size:14px;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" height=\"100\" src=\"http:\/\/upload.wikimedia.org\/wikipedia\/en\/thumb\/2\/2d\/IPTunnelDiagram_01-12-07.jpg\/300px-IPTunnelDiagram_01-12-07.jpg\" width=\"300\" \/><\/span><\/p>\n<p><span style=\"font-size:14px;\">\u4f46\u5b9e\u6218\u4e2d\u7528libpcap\u5e93\u4ece\u6211\u4eec\u7684\u7ebf\u4e0a\u673a\u7684IP\u96a7\u9053\u6293\u5305\u65f6\uff0cpcap_loop\u6216pcap_dispatch\u6216pcap_next\u51fd\u6570\u8fd4\u56de\u7684\u6570\u636e\u5305\u53ea\u6709Inner IP header + IP payload\uff0c\u6ca1\u6709Outer IP headr\uff0c\u4e5f\u6ca1\u94fe\u8def\u5c42\u7684\u5934\u90e8\u3002\u591a\u4e48\u5e78\u8fd0\u554a\uff01<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-size:14px;\"><strong>3. \u6df7\u4e71\u7684RAW_SOCKET\uff0cPF_PACKET\u534f\u8bae\u65cf<\/strong><\/span><\/p>\n<p><span style=\"font-size:14px;\">\u8fd9\u4e0d\u662f\u5de5\u4e1a\u6807\u51c6\u5b9a\u4e49\u7684\u795e\u79d8\u9886\u57df\uff0c\u975e\u5e38\u4e4b\u6df7\u4e71\uff0c\u8c28\u614e\u8fdb\u5165\u3002\u5982\u679c\u8981\u5199\u8fd9\u65b9\u9762\u7684socket\uff0c\u53ef\u4f9b\u53c2\u8003\u3002\u4e2a\u4eba\u7ecf\u9a8c\uff0c\u7528linux\u539f\u751f\u7684socket\u6293\u5305\u65f6\uff0csocket()\u7684\u4e09\u7684\u53c2\u6570\u5982\u4e0b\u7ec4\u5408\u65f6\u7684\u795e\u5947\u6548\u679c.<\/span><\/p>\n<p><span style=\"font-size:14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/p>\n<p><span style=\"font-size:14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_recv_fd = socket(AF_PACKET, SOCK_DGRAM, htons(ETH_P_IP));<\/span><\/p>\n<p><span style=\"font-size:14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u4ece\u6b64socket\u4e2d\u8bfb\u6240\u6709\u7684IP\u5305\uff0c\u8fd4\u56de\u7684IP\u5305\u6ca1\u6709\u94fe\u8def\u5c42\u5305\u5934,\u56e0\u4e3a\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662fSOCK_DGRAM\uff0c\u94fe\u8def\u5c42\u5305\u5934\u8fd4\u56de\u65f6\u88ab\u53bb\u6389\u3002\u7b2c\u4e09\u4e2a\u53c2\u6570\u6307\u5b9a\u7684\u662fIP\u5305\u3002\u5947\u602a\u7684\u662f\uff0c\u5982\u679c\u51fa\u7ad9\u7684IP\u5305\u7684\u76ee\u7684\u5730\u5740\u4e0d\u662f\u672c\u673a\uff0c\u5219\u51fa\u7ad9\u7684IP\u5305\u4e0d\u4f1a\u88ab\u6293\u5230\u3002<\/span><\/p>\n<p><span style=\"font-size:14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/p>\n<p><span style=\"font-size:14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_recv_fd = socket(AF_PACKET , SOCK_RAW , htons(ETH_P_IP));<\/span><\/p>\n<p><span style=\"font-size:14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u548c\u4e0a\u4e00\u4e2asocket\u7684\u533a\u522b\u662f\uff0c\u8fd9\u4e2a\u4f1a\u8fd4\u56de\u94fe\u8def\u5c42\u5305\u5934\u3002\u548c\u4e0a\u4e00\u4e2asocket\u4e00\u6837\uff0c\u540c\u6837\u53ea\u80fd\u88c5\u5230\u90e8\u5206\u51fa\u7ad9\u7684\u5305\u3002<\/span><\/p>\n<p><span style=\"font-size:14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><\/p>\n<p><span style=\"font-size:14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; _recv_fd = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);<\/span><\/p>\n<p><span style=\"font-size:14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u8fd9\u884c\u4ee3\u7801\u53ea\u53ef\u4ee5\u8bfb\u5165\u7ad9\u7684\u5305\uff0c\u6293\u4e0d\u5230\u51fa\u7ad9\u7684\u5305\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-size:14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; _recv_fd = socket(AF_PACKET , SOCK_RAW , htons(ETH_P_ALL));<\/span><\/p>\n<p><span style=\"font-size:14px;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u8fd9\u884c\u4ee3\u7801\u53ef\u4ee5\u6293\u5230\u6240\u6709\u51fa\u7ad9\uff0c\u5165\u7ad9\u7684\u5305\uff0c\u6570\u636e\u94fe\u8def\u5c42\u5305\u5934\u4e5f\u88ab\u8fd4\u56de\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-size:14px;\"><strong>4. \u5916\u7f51\u8fdb\u6765\u7684IP\u5305\u6709\u53ef\u80fd\u5f88\u5927\u3002<\/strong><\/span><\/p>\n<p><span style=\"font-size:14px;\">N\u591a\u5e74\u524d\u4e00\u822c\u7684\u8def\u7531\u7684MTU\u53ea\u67091K\u591a\uff0c\u610f\u5473\u77404K\u5927\u5c0f\u7684IP\u4f1a\u88ab\u5207\u6210\u5c0fIP\u5305\u3002\u73b0\u5728\u7684\u7f51\u7edc\u73af\u5883\u4e0e\u51e0\u5e74\u524d\u786e\u5b9e\u5927\u5927\u63d0\u9ad8\u3002\u4ece\u5916\u7f51\u5165\u6765\u7684IP\u5305\u4f1a\u5927\u8fc74096\uff0c\u5f53\u65f6\u5199\u7a0b\u5e8f\u65f6\u653eIP\u5305\u7684buffer\u5927\u5c0f\u4e3a4096\uff0c\u89c9\u5f97\u5e94\u8be5\u65e0\u538b\u529b\uff0c\u7ed3\u679c\u89c2\u5bdf\u5230\u7a0b\u5e8f\u5d29\u6e83\uff0c\u540e\u5b9a\u4f4d\u5230\u662f\u653eIP\u5305\u7684\u7f13\u51b2\u533a\u6ea2\u51fa\u3002\u540e\u6765\u6539\u62108192\uff0c\u6682\u65f6\u6ca1\u95ee\u9898\u3002<\/span><\/p>\n<p><span style=\"color: rgb(0, 0, 0); font-family: Verdana, Geneva, sans-serif; font-size: 16px; line-height: 22px; background-color: rgb(244, 244, 244);\">copyright ykyi.net<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6628\u665a\u540c\u767d\u603b\u548cadden\u63d0\u5230\u6293\u5305\u7684\u95ee\u9898\u3002\u56e0\u4e3a\u5199\u8fc7\u76f8\u5173\u7684\u4ee3\u7801\uff0c\u9047\u5230\u8fc7\u6293\u5305\u7684\u5404\u79cd\u5404\u6837\u7684\u5751\uff0c\u6b64\u6587\u5206\u4eab\u4e00\u4e9b\u76f8\u5173\u7684\u7ecf\u9a8c\u3002 &nbsp; 1. Linux cooked capture \u5728\u7528tcpdump\u6216wireshark\u770b\u6570\u636e\u5305\u65f6\uff0c\u6709\u65f6\u4f1a\u770b\u5230\u6570\u636e\u94fe\u8def\u5c42\u7684\u7684\u5305\u5934\u79f0\u4e3aLinux cooked capture\u3002\u8fd9\u4e0d\u662f\u4e00\u4e2a\u771f\u5b9e\u7684\u5305\u5934\uff0c\u5f53\u7528tcpdump\u6307\u5b9a\u4ece\u6240\u6709\u7f51\u7edc\u4ecb\u8d28 -i any \u6293\u5305\u65f6\uff0c\u6240\u6709\u6293\u5230\u7684\u5305\u7684\u6570\u636e\u94fe\u8def\u5c42\u88ab\u6362\u6210\u4e86Linux cooked capture\u3002\u5728wireshark\u5b98\u65b9\u7f51\u7ad9\u5bf9Linux cooked capture\u7684\u89e3\u91ca\u4e2d: \u8fd9\u662f\u4e00\u4e2a\u5728linux\u4e0a\u88ablibpcap\u6293\u5305\u5e93\u4f7f\u7528\u7684&ldquo;\u5047\u534f\u8bae&rdquo;(pseudo-protocal)\uff0c\u5f53\u4ece&ldquo;any&rdquo;\u8bbe\u5907\u5728\u6293\u5305\uff0c\u6216\u8005\u672c\u5730\u7684\u6570\u636e\u94fe\u8def\u5c42\u5305\u5934\u65e0\u6548\u65f6\u88ab\u4f7f\u7528\u3002\u66f4\u591a\uff0c\u89c1http:\/\/wiki.wireshark.org\/SLL &nbsp; 2. IP over IP tunnel wikipedia\u7684\u793a\u4f8b\u56fe\u663e\u793aIP tunnel\u4e0a\u7684\u5305\u7684\u7ed3\u6784\u662f\uff1a \u4f46\u5b9e\u6218\u4e2d\u7528libpcap\u5e93\u4ece\u6211\u4eec\u7684\u7ebf\u4e0a\u673a\u7684IP\u96a7\u9053\u6293\u5305\u65f6\uff0cpcap_loop\u6216pcap_dispatch\u6216pcap_next\u51fd\u6570\u8fd4\u56de\u7684\u6570\u636e\u5305\u53ea\u6709Inner IP header + IP payload\uff0c\u6ca1\u6709Outer IP headr\uff0c\u4e5f\u6ca1\u94fe\u8def\u5c42\u7684\u5934\u90e8\u3002\u591a\u4e48\u5e78\u8fd0\u554a\uff01 &nbsp; 3. \u6df7\u4e71\u7684RAW_SOCKET\uff0cPF_PACKET\u534f\u8bae\u65cf \u8fd9\u4e0d\u662f\u5de5\u4e1a\u6807\u51c6\u5b9a\u4e49\u7684\u795e\u79d8\u9886\u57df\uff0c\u975e\u5e38\u4e4b\u6df7\u4e71\uff0c\u8c28\u614e\u8fdb\u5165\u3002\u5982\u679c\u8981\u5199\u8fd9\u65b9\u9762\u7684socket\uff0c\u53ef\u4f9b\u53c2\u8003\u3002\u4e2a\u4eba\u7ecf\u9a8c\uff0c\u7528linux\u539f\u751f\u7684socket\u6293\u5305\u65f6\uff0csocket()\u7684\u4e09\u7684\u53c2\u6570\u5982\u4e0b\u7ec4\u5408\u65f6\u7684\u795e\u5947\u6548\u679c. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_recv_fd = socket(AF_PACKET, SOCK_DGRAM, htons(ETH_P_IP)); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u4ece\u6b64socket\u4e2d\u8bfb\u6240\u6709\u7684IP\u5305\uff0c\u8fd4\u56de\u7684IP\u5305\u6ca1\u6709\u94fe\u8def\u5c42\u5305\u5934,\u56e0\u4e3a\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662fSOCK_DGRAM\uff0c\u94fe\u8def\u5c42\u5305\u5934\u8fd4\u56de\u65f6\u88ab\u53bb\u6389\u3002\u7b2c\u4e09\u4e2a\u53c2\u6570\u6307\u5b9a\u7684\u662fIP\u5305\u3002\u5947\u602a\u7684\u662f\uff0c\u5982\u679c\u51fa\u7ad9\u7684IP\u5305\u7684\u76ee\u7684\u5730\u5740\u4e0d\u662f\u672c\u673a\uff0c\u5219\u51fa\u7ad9\u7684IP\u5305\u4e0d\u4f1a\u88ab\u6293\u5230\u3002 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_recv_fd = socket(AF_PACKET , SOCK_RAW , htons(ETH_P_IP)); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u548c\u4e0a\u4e00\u4e2asocket\u7684\u533a\u522b\u662f\uff0c\u8fd9\u4e2a\u4f1a\u8fd4\u56de\u94fe\u8def\u5c42\u5305\u5934\u3002\u548c\u4e0a\u4e00\u4e2asocket\u4e00\u6837\uff0c\u540c\u6837\u53ea\u80fd\u88c5\u5230\u90e8\u5206\u51fa\u7ad9\u7684\u5305\u3002 &hellip; <a href=\"https:\/\/ykyi.net\/?p=1102\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;\u6293\u5305\u7a0b\u5e8f\u7684\u4e00\u4e9b\u5206\u4eab&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[50,70],"class_list":["post-1102","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-libpcap","tag-raw_socket"],"_links":{"self":[{"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/posts\/1102","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ykyi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1102"}],"version-history":[{"count":0,"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/posts\/1102\/revisions"}],"wp:attachment":[{"href":"https:\/\/ykyi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1102"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ykyi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1102"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ykyi.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1102"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}