当前位置: 首页 > news >正文

吉林省建设厅网站周军页面访问

吉林省建设厅网站周军,页面访问,干果坚果网站建设,网站自然优化自学一、程序说明本程序有两个要点#xff0c;第一个要点是读取wireshark数据包(当然也可以从网卡直接捕获改个函数就行)#xff0c;这个使用pyshark实现。pyshark是tshark的一个python封装#xff0c;至于tshark可以认为是命令行版的wireshark#xff0c;随wireshark一起安装。…一、程序说明本程序有两个要点第一个要点是读取wireshark数据包(当然也可以从网卡直接捕获改个函数就行)这个使用pyshark实现。pyshark是tshark的一个python封装至于tshark可以认为是命令行版的wireshark随wireshark一起安装。第二个要点是追踪流追踪流在wireshark中是“tcp.stream eq 70”之类的形式但是70这类值暂是不知道具体怎么计算出来的,但从网上资料看是依据[IP address A, TCP port A, IP address B, TCP port B]四元组计算出来的只要这四个值一样那么计算出来的tcp.stream也就一样就认为是同一个流。那么反过来也就是说“tcp.stream eq 70”这种形式其实等价于ip.addr ip_a and tcp.port port_a and ip.addr ip_b and tcp.port port_b的形式我们这里就是用这种形式来追踪telnet流。至于为什么一再强调是追踪telnet流而不是追踪流是因为感觉各应用层协议没有统一获取应用层协议内容的方法比如这里通过tmp_packet[highest_layer_name].get_field(data)形式读取telnet数据的但http则得用tmp_packet[http].file_data读取ftp等其他协议又要通过其他不同属性来获取。另外还要说明的一点是数据包的每次过滤主要是借助写display_filter重新读取数据包文件而不是将所有数据包读入后自己写代码进行过滤(就实际来看这种方法比借助写display_filter重新读取数据包文件要复杂且运行速度要慢)或者写display_filter进行二次过滤(tshark本身就不支持二次过滤就观察来看wireshark自己也没有二次过滤这种东西在执行过滤器表达式时都是重新读取数据包文件)运行效果如下二、程序源代码importpysharkclasswireshark_analysis_script():#此函数的作用是封装一下pyshark.FileCapturedefread_packets_from_file(self,packets_file_path,tshark_path,display_filter):packets_file_obj pyshark.FileCapture(input_filepackets_file_path,tshark_pathtshark_path,display_filterdisplay_filter)returnpackets_file_obj#此函数的作用是从传送过来的所有数据包中抽取并返回{ip_server,ip_client,port_server,port_client}四元组defget_target_client_ip_port(self,packets_file_obj):for tmp_packet inpackets_file_obj:ip_servertmp_packet.ip.srcport_servertmp_packet.tcp.srcportip_clienttmp_packet.ip.dstport_clienttmp_packet.tcp.dstportyield {ip_server:ip_server,port_server:port_server,ip_client:ip_client, port_client:port_client}#此函数的作用是读取传过来的所有数据包应用层的数据并打印deffollow_tcp_stream(self,packets_file_obj,ip,port):for tmp_packet inpackets_file_obj:highest_layer_nametmp_packet.highest_layerif ((tmp_packet.ip.dst ip) and (tmp_packet.tcp.dstport port)):print(server(%s:%s)-client(%s:%s): %s % (tmp_packet.ip.src, tmp_packet.tcp.srcport, tmp_packet.ip.dst, tmp_packet.tcp.dstport, tmp_packet[highest_layer_name].get_field(data)))elif ((tmp_packet.ip.src ip) and (tmp_packet.tcp.srcport port)):print(client(%s:%s)-server(%s:%s): %s % (tmp_packet.ip.src, tmp_packet.tcp.srcport, tmp_packet.ip.dst, tmp_packet.tcp.dstport, tmp_packet[highest_layer_name].get_field(data)))if __name__ __main__:#要读取的wireshark数据包的所在的路径packets_file_path F:\\PycharmProjects\\telnet\\pyshark_pack#tshark程序所在的路径tshark随wireshark安装tshark_path D:\\tools\\Wireshark\\tshark.exe#过滤器表达式与在wireshark中使用时的写法完全相同first_step_filter telnet contains HiLinux#用于存放要追踪流的ip和端口target_client_ip_port []#实例化类wireshark_analysis_script_instance wireshark_analysis_script()#使用first_step_filter过滤器表达式过滤出要追踪流的数据包first_step_obj wireshark_analysis_script_instance.read_packets_from_file(packets_file_path, tshark_path, first_step_filter)#从要追踪流的数据包中抽取出ip和端口target_client_ip_port wireshark_analysis_script_instance.get_target_client_ip_port(first_step_obj)first_step_obj.close()#遍历要追踪流的ip端口组合for target_client_ip_port_temp intarget_client_ip_port:ip_server target_client_ip_port_temp[ip_server]port_server target_client_ip_port_temp[port_server]ip_client target_client_ip_port_temp[ip_client]port_client target_client_ip_port_temp[port_client]#这里是追踪流的关键所有数据包中如果数据包中{ip_server,ip_client,port_server,port_client}四元组相同那么就认为是同一个流#当然追踪流一般都是追踪应用层的数据流所以加上应用层协议运行过滤去掉三次握手四次挥手等没有应用层数据的数据包我这里要追踪telnet数据流所以除四元组外还加了telnet做过滤second_step_filter telnet and ip.addr %s and ip.addr %s and tcp.port %s and tcp.port %s %(ip_server,ip_client,port_server,port_client)second_step_objwireshark_analysis_script_instance.read_packets_from_file(packets_file_path, tshark_path, second_step_filter)print([%s:%s] %(ip_client, port_client))#调用follow_tcp_stream将认为是同一个流的所有数据包的应用层数据打印wireshark_analysis_script_instance.follow_tcp_stream(second_step_obj, ip_client, port_client)second_step_obj.close()三、使用与wireshark一致的形式【20180929更新】在前边的解决方案中我们使用ip.addr ip_a and tcp.port port_a and ip.addr ip_b and tcp.port port_b等价代替wireshark中“tcp.stream eq 70”的形式来实现追踪流当时的想法是不知道某个流的70这种值如何计算。现在发现这种值pyshark在tcp.stream属性直接给出了所以我们完全可以使用和wireshark的“tcp.stream eq 70”一致的形式来追踪流。第二大节程序可等介修改如下。(当然因为是等价形式所以输出结果还是一样的都是要重新解析数据包文件所以效率也就差不多主要是为了说追流可以使用和wireshark一样的形式)importpysharkclasswireshark_analysis_script():#此函数的作用是封装一下pyshark.FileCapturedefread_packets_from_file(self, packets_file_path, tshark_path, display_filter):packets_file_obj pyshark.FileCapture(input_filepackets_file_path, tshark_pathtshark_path, display_filterdisplay_filter)returnpackets_file_obj#此函数的作用是从传送过来的所有数据包中抽取并返回{ip_server,ip_client,port_server,port_client}四元组defget_target_client_ip_port(self, packets_file_obj):for tmp_packet inpackets_file_obj:ip_servertmp_packet.ip.srcport_servertmp_packet.tcp.srcportip_clienttmp_packet.ip.dstport_clienttmp_packet.tcp.dstportstream_valuetmp_packet.tcp.streamyield {ip_server: ip_server, port_server: port_server, ip_client: ip_client, port_client: port_client,stream_value:stream_value}#此函数的作用是读取传过来的所有数据包应用层的数据并打印deffollow_tcp_stream(self, packets_file_obj, ip, port):for tmp_packet inpackets_file_obj:highest_layer_nametmp_packet.highest_layer#追踪流时会有握手挥手tcp将其排除if highest_layer_name ! TCP:if ((tmp_packet.ip.dst ip) and (tmp_packet.tcp.dstport port)):print(server(%s:%s)-client(%s:%s): %s % (tmp_packet.ip.src, tmp_packet.tcp.srcport, tmp_packet.ip.dst, tmp_packet.tcp.dstport, tmp_packet[highest_layer_name].get_field(data)))elif ((tmp_packet.ip.src ip) and (tmp_packet.tcp.srcport port)):print(client(%s:%s)-server(%s:%s): %s % (tmp_packet.ip.src, tmp_packet.tcp.srcport, tmp_packet.ip.dst, tmp_packet.tcp.dstport, tmp_packet[highest_layer_name].get_field(data)))if __name__ __main__:#要读取的wireshark数据包的所在的路径packets_file_path F:\\PycharmProjects\\telnet\\pyshark_pack#tshark程序所在的路径tshark随wireshark安装tshark_path D:\\tools\\Wireshark\\tshark.exe#过滤器表达式与在wireshark中使用时的写法完全相同first_step_filter telnet contains HiLinux#用于存放要追踪流的ip和端口target_client_ip_port []#实例化类wireshark_analysis_script_instance wireshark_analysis_script()#使用first_step_filter过滤器表达式过滤出要追踪流的数据包first_step_obj wireshark_analysis_script_instance.read_packets_from_file(packets_file_path, tshark_path, first_step_filter)#从要追踪流的数据包中抽取出ip和端口target_client_ip_port wireshark_analysis_script_instance.get_target_client_ip_port(first_step_obj)first_step_obj.close()#遍历要追踪流的ip端口组合for target_client_ip_port_temp intarget_client_ip_port:#stream的值stream_value target_client_ip_port_temp[stream_value]ip_client target_client_ip_port_temp[ip_client]port_client target_client_ip_port_temp[port_client]#tcp.stream eq 70形式。为了排除tcp其实可以再直接加上and telnetsecond_step_filter tcp.stream eq %s %(stream_value)second_step_objwireshark_analysis_script_instance.read_packets_from_file(packets_file_path, tshark_path, second_step_filter)print([%s:%s] %(ip_client, port_client))#调用follow_tcp_stream将认为是同一个流的所有数据包的应用层数据打印wireshark_analysis_script_instance.follow_tcp_stream(second_step_obj, ip_client, port_client)second_step_obj.close()View Code参考
http://www.pierceye.com/news/29137/

相关文章:

  • 网络营销推广的平台搜索引擎优化的策略主要有
  • 企业网站建设申请怎么写大学教学应用网站开发现状
  • 网站建设论文参考文献网站批量上传文章
  • 做网站美工要学什么网站编辑器是怎么做的
  • 一 网站建设的目的和目标个人网站可以做淘宝客吗
  • 留号码的广告网站经典网站源码
  • 正规网站建设价格费用注册会计师考试科目
  • 招标网站排名信用卡在哪些网站上做推广
  • 厦门维品网站建设网站布局 下载
  • 不懂见网站怎么办wordpress压缩图片
  • 网站备案 新网大连英文网站建设
  • 重庆做的好的房产网站网站建设如何描述
  • 分析海尔网站的建设特点和优势金华兰溪网站建设
  • net网站开发参考文献吉林seo排名公司
  • 建网站大概多少费用深圳公司举报网站
  • 罗庄区住房和城乡建设局网站网站接口设置
  • 南磨房做网站公司网址导航模板
  • 石家庄营销型网站建设费用护肤品网站建设的摘要
  • 谁有马和人做的网站学校网站的建设费用
  • php网站开发方案注册安全工程师考试结果查询
  • 网站开发要跑道吗建行网上银行
  • 浙江新中环建设有限公司 网站山东潍坊网站制作公司
  • html网页制作接单南宁seo按天收费
  • 陶瓷 中企动力 网站建设定制网络接口报警灯生产厂商
  • 嘉兴网站备案去哪里呼叫中心系统有哪些
  • 企业网站建设源码+微信+手机网站图片的作用
  • 站长工具域名查询自己做的网站搜索不到
  • 2h1g做视频网站980网站
  • 网站打不开 别人能打开dedecms和wordpress
  • 上海网站开发月薪多少钱wd设计视图可以做网站吗