{"id":322371,"date":"2021-02-05T19:21:39","date_gmt":"2021-02-05T11:21:39","guid":{"rendered":"http:\/\/4563.org\/?p=322371"},"modified":"2021-02-05T19:21:39","modified_gmt":"2021-02-05T11:21:39","slug":"%e8%af%b7%e6%95%99%e4%b8%80%e4%b8%8b%e5%85%b3%e4%ba%8e%e4%bd%bf%e7%94%a8-python-%e7%9a%84-scapy-%e5%ba%93%e9%80%9a%e8%bf%87-npcap-%e9%a9%b1%e5%8a%a8%e6%8a%93%e5%8c%85%e6%97%b6%e9%81%87%e5%88%b0","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=322371","title":{"rendered":"\u8bf7\u6559\u4e00\u4e0b\u5173\u4e8e\u4f7f\u7528 Python \u7684 scapy \u5e93\u901a\u8fc7 npcap \u9a71\u52a8\u6293\u5305\u65f6\u9047\u5230\u7684\u65e0\u6cd5\u6293\u53d6\u65e0\u7ebf\u7f51\u5361\u6d41\u91cf\u7684\u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u8bf7\u6559\u4e00\u4e0b\u5173\u4e8e\u4f7f\u7528 Python \u7684 scapy \u5e93\u901a\u8fc7 npcap \u9a71\u52a8\u6293\u5305\u65f6\u9047\u5230\u7684\u65e0\u6cd5\u6293\u53d6\u65e0\u7ebf\u7f51\u5361\u6d41\u91cf\u7684\u95ee\u9898               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : EtherShark <\/span>  <span><i><\/i> 5<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u6700\u8fd1\u53c2\u7167\u7f51\u4e0a\u7684 scapy \u5e93\u7684\u4f7f\u7528\u65b9\u6cd5\u5199\u4e86\u4e00\u4e2a\u7528\u4e8e\u6293\u53d6\u6240\u6709\u6570\u636e\u5305\u7684\u811a\u672c\uff0c\u4e00\u5f00\u59cb\u4e00\u5207\u6b63\u5e38\uff0c\u4f46\u662f\u540e\u6765\u4e3a\u4e86\u6d4b\u8bd5\u6ca1\u6709\u5b89\u88c5\u9a71\u52a8\u7684\u60c5\u51b5\u4e0b\u53ef\u4ee5\u8f93\u51fa\u9700\u8981\u5b89\u88c5\u9a71\u52a8\uff0c\u800c\u4e0d\u662f\u76f4\u63a5\u62a5\u9519\uff0c\u4e8e\u662f\u628a npcap \u9a71\u52a8\u53cd\u590d\u5b89\u88c5\u5378\u8f7d\u591a\u6b21\uff0c\u5c31\u9047\u5230\u4e86\u8fd9\u4e2a\u95ee\u9898\uff1a \u7535\u8111\u5728\u8fde\u7740\u65e0\u7ebf\u7f51\u7684\u65f6\u5019\u811a\u672c\u5c31\u6293\u4e0d\u5230\u6570\u636e\u5305\uff0c\u4f46\u662f\u8fde\u7740\u6709\u7ebf\u7f51\u5c31\u53ef\u4ee5\u6293\u5230\u3002\u4e0e\u6b64\u540c\u65f6\uff0cwireshark \u5374\u4e00\u5207\u6b63\u5e38\uff0c\u65e0\u8bba\u662f\u65e0\u7ebf\u8fd8\u662f\u6709\u7ebf\u90fd\u53ef\u4ee5\u6293\u5230\u5305\u3002<br \/> \u4e4b\u540e\u5c1d\u8bd5\u4e86<\/p>\n<ol>\n<li>\u7528 ccleaner \u6e05\u7406\u6ce8\u518c\u8868\uff1b<\/li>\n<li>\u5b89\u88c5 winpcap \u9a71\u52a8\u66ff\u6362 npcap \uff1b<\/li>\n<li>\u81ea\u5df1\u53bb\u6ce8\u518c\u8868\u641c\u7d22 npcap \u5b57\u6837\u7684\u9879\uff0c\u5e76\u901a\u901a\u5220\u9664\uff1b<\/li>\n<li>\u53bb system32 \u4e0e syswow64 \u76ee\u5f55\u4e0b\u5220\u9664 Npcap \u76ee\u5f55\uff0c\u4e0e wpcap.dll \u548c packet.dll \u6587\u4ef6\uff0c\u4ee5\u53ca drivers \u76ee\u5f55\u4e0b\u7684 npcap.sys \u548c npfs.sys \u548c npf.sys \u6587\u4ef6<br \/> \u4f46\u662f\u53cd\u590d\u5378\u8f7d\u91cd\u88c5\u540e\u95ee\u9898\u4f9d\u7136\u65e0\u6cd5\u89e3\u51b3\uff0c\u53ea\u80fd\u6293\u53d6\u6709\u7ebf\u7f51\u5361\u7684\u6570\u636e\u5305\uff0c\u65e0\u6cd5\u6293\u53d6\u65e0\u7ebf\u7f51\u5361\u7684\u6570\u636e\u5305\u3002 \u4ee5\u4e0b\u662f\u4ee3\u7801\uff1a<\/li>\n<\/ol>\n<pre><code>from scapy.all import * import time  def countfun(packet):     global n      n += 1     print(n)      if not IFACES.data:     print(\"Need install npcap driver\") else:     print(\"Capturing...\")     n = 0     dpkt = sniff(prn=countfun, count=0)     capfile = time.strftime(\"%Y%m%d%H%M\", time.localtime()) + \".pcap\"     print(n,\"packets captured\")     if n != 0:         wrpcap(capfile, dpkt)         print(\"Saved in \" + capfile) <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>2<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5113831\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : disk <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u3002\u3002\u3002\u4f60\u6709\u6307\u5b9a\u54ea\u4e2a\u7f51\u7edc\u63a5\u53e3\u5417                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5113832\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : EtherShark <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @disk \u6ca1\u6709\u6307\u5b9a\u7f51\u7edc\u63a5\u53e3\uff0c\u6211\u770b scapy \u7684 sniff()\u51fd\u6570\u7684\u4ecb\u7ecd\uff0c\u5982\u679c\u4e0d\u6307\u5b9a iface \u7684\u8bdd\uff0c\u9ed8\u8ba4\u662f\u6293\u53d6\u6240\u6709\u7f51\u5361\u7684\u6570\u636e\u5305\uff0c\u800c\u4e14\u5728\u6211\u53cd\u590d\u5378\u8f7d\u4e4b\u524d\uff0c\u4e5f\u662f\u53ef\u4ee5\u6293\u5230\u6570\u636e\u5305\u7684\u3002\u5e76\u4e14\u76f8\u540c\u7684\u4ee3\u7801\uff0c\u653e\u5230\u53e6\u4e00\u53f0\u53ea\u6709\u6709\u7ebf\u7f51\u5361\u7684\u8bbe\u5907\u4e0a\uff0c\u662f\u53ef\u4ee5\u6b63\u5e38\u6355\u83b7\u6570\u636e\u5305\u7684\u3002<\/p>\n<p>\u53e6\u5916\uff0c\u6211\u4e0b\u5348\u627e\u5230\u7684\u4e00\u4e2a\u201c\u89e3\u51b3\u65b9\u6cd5\u201d\uff0c\u901a\u8fc7\u8fed\u4ee3 IFACES.data.items() \u83b7\u53d6\u5230\u6240\u6709\u7f51\u5361\u540d\u5b57\uff0c\u5e76\u653e\u5230 list \u91cc\uff0c\u4f20\u7ed9 sniff \u7684 iface \u3002<\/p>\n<p>\u76ee\u524d\u7684\u60c5\u51b5\u662f\uff0c\u53ef\u4ee5\u6293\u5230\u6570\u636e\u5305\u4e86\uff0c\u4f46\u662f\u76f8\u6bd4 wireshark \u6293\u5305\u7684\u7ed3\u679c\u770b\uff0c\u6f0f\u6293\u4e86\u6570\u91cf\u5de8\u5927\u7684\u6570\u636e\u5305\uff0c\u57fa\u672c\u4e0a\u5355\u4f4d\u65f6\u95f4\uff0c\u80fd\u5dee\u51fa\u53bb 4-6 \u500d\u7684\u6570\u636e\u5305\uff0c\u5bfc\u81f4\u6293\u5230\u7684\u7ed3\u679c\u5b8c\u5168\u4e0d\u5177\u5907\u53c2\u8003\u4ef7\u503c\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u8bf7\u6559\u4e00\u4e0b\u5173\u4e8e\u4f7f\u7528 Python \u7684&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/322371"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=322371"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/322371\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=322371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=322371"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=322371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}