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

美国哪个网站做diy电脑公司运营策划方案

美国哪个网站做diy电脑,公司运营策划方案,昌平网站制作公司,网站建设与网页制作案例教程引言 在网络安全和流量管理中,解析网络协议数据包是了解网络行为和检测潜在威胁的关键步骤。本文介绍了如何使用Python解析和分析TCP、UDP和ICMP协议的数据包,并统计端口的访问次数。本文的示例代码展示了如何处理不同协议的数据包,提取关键…

引言

在网络安全和流量管理中,解析网络协议数据包是了解网络行为和检测潜在威胁的关键步骤。本文介绍了如何使用Python解析和分析TCP、UDP和ICMP协议的数据包,并统计端口的访问次数。本文的示例代码展示了如何处理不同协议的数据包,提取关键信息,并对网络流量进行深入分析。

环境设置

在开始之前,我们需要设置环境以便使用pyshark库进行数据包捕获和解析。首先,我们需要安装Wireshark并确保tshark命令行工具可用。然后,我们在代码中设置tshark的路径,并创建一个用于保存下载文件的目录。

import os# 设置tshark路径
os.environ['TSHARK_PATH'] = 'D:\\Wireshark\\tshark.exe'
os.environ['PATH'] += os.pathsep + 'D:\\Wireshark'# 创建下载目录
DOWNLOAD_DIR = 'xiazai'
if not os.path.exists(DOWNLOAD_DIR):os.makedirs(DOWNLOAD_DIR)

数据包解析

我们的核心函数是analyze_pcap,它使用pyshark库解析给定的PCAP文件,并提取TCP、UDP和ICMP协议的数据包。通过该函数,我们能够捕获流量中的源IP、目的IP、源端口、目的端口等信息,并识别DNS查询和TLS握手数据。

import pyshark
from collections import defaultdictdef analyze_pcap(pcap_file, tshark_path):cap = pyshark.FileCapture(pcap_file, tshark_path=tshark_path)flows = defaultdict(list)dns_queries = defaultdict(list)tls_handshakes = defaultdict(list)icmp_packets = []for packet in cap:try:src_ip = packet.ip.srcdst_ip = packet.ip.dsttransport_layer = packet.transport_layerif transport_layer in ['TCP', 'UDP']:src_port = packet[transport_layer].srcportdst_port = packet[transport_layer].dstportflow_key = (src_ip, dst_ip, src_port, dst_port)flows[flow_key].append(packet)if transport_layer == 'UDP' and hasattr(packet, 'dns'):dns_query = packet.dns.qry_namedns_queries[flow_key].append(dns_query)if hasattr(packet, 'tls'):if hasattr(packet.tls, 'handshake_type'):tls_handshake_type = packet.tls.handshake_typetls_handshakes[flow_key].append(tls_handshake_type)elif transport_layer == 'ICMP':icmp_packets.append(packet)except AttributeError:continuereturn flows, dns_queries, tls_handshakes, icmp_packets

数据包解析

我们的核心函数是analyze_pcap,它使用pyshark库解析给定的PCAP文件,并提取TCP、UDP和ICMP协议的数据包。通过该函数,我们能够捕获流量中的源IP、目的IP、源端口、目的端口等信息,并识别DNS查询和TLS握手数据。

import pyshark
from collections import defaultdictdef analyze_pcap(pcap_file, tshark_path):cap = pyshark.FileCapture(pcap_file, tshark_path=tshark_path)flows = defaultdict(list)dns_queries = defaultdict(list)tls_handshakes = defaultdict(list)icmp_packets = []for packet in cap:try:src_ip = packet.ip.srcdst_ip = packet.ip.dsttransport_layer = packet.transport_layerif transport_layer in ['TCP', 'UDP']:src_port = packet[transport_layer].srcportdst_port = packet[transport_layer].dstportflow_key = (src_ip, dst_ip, src_port, dst_port)flows[flow_key].append(packet)if transport_layer == 'UDP' and hasattr(packet, 'dns'):dns_query = packet.dns.qry_namedns_queries[flow_key].append(dns_query)if hasattr(packet, 'tls'):if hasattr(packet.tls, 'handshake_type'):tls_handshake_type = packet.tls.handshake_typetls_handshakes[flow_key].append(tls_handshake_type)elif transport_layer == 'ICMP':icmp_packets.append(packet)except AttributeError:continuereturn flows, dns_queries, tls_handshakes, icmp_packets

文件提取和分析

在捕获流量之后,我们需要提取并分析其中的文件和图像。以下代码展示了如何从HTTP流量中提取ZIP、PDF和图像文件,并检测其中的敏感信息或潜在威胁。

import zipfile
import PyPDF2
from PIL import Image
import re
from datetime import datetimedef extract_files(flows, keywords):# 省略代码passdef check_and_extract_zip(file_name, keywords):# 省略代码passdef check_and_extract_pdf(file_name, keywords):# 省略代码passdef check_and_extract_image(file_name):# 省略代码passdef detect_sql_injection(payload):# 省略代码passdef clean_text(text):# 省略代码passdef save_sql_injection_data(flow, post_data, pcap_file_name):# 省略代码passdef save_password_post_data(flow, post_data, pcap_file_name):# 省略代码pass

应用程序和端口分析

为了更全面地了解网络流量,我们还需要分析端口的使用情况和应用层协议的数据。以下代码展示了如何统计各端口的访问次数,并检测潜在的SQL注入攻击和敏感信息泄露。

def detect_application(flows, dns_queries, tls_handshakes, icmp_packets, pcap_file_name):flow_summary = defaultdict(int)port_usage = defaultdict(lambda: defaultdict(int))src_dst_port_usage = defaultdict(lambda: defaultdict(lambda: defaultdict(int)))password_patterns = [r"password", r"passwd", r"pwd", r"pass"]>>>>关注加好友 发源代码<<<<    print("\nHTTP流量检测:")for flow_key, count in flow_summary.items():host, method, url = flow_keyprint(f"主机: {host}, 请求方法: {method}, URL: {url} - 出现次数: {count}")print("\n端口使用情况:")for port, methods in port_usage.items():for method, count in methods.items():print(f"端口 {port} 上的 {method} 请求次数: {count}")print("\n源IP到目的IP的端口使用情况:")for src_ip, dst_ips in src_dst_port_usage.items():for dst_ip, ports in dst_ips.items():for port, count in ports.items():print(f"{src_ip} -> {dst_ip} 端口 {port} 使用次数: {count}")print("\nDNS查询:")for flow_key, queries in dns_queries.items():src_ip, dst_ip, src_port, dst_port = flow_keyfor query in queries:print(f"{src_ip} -> {dst_ip} : DNS查询 {query}")print("\nTLS握手:")for flow_key, handshakes in tls_handshakes.items():src_ip, dst_ip, src_port, dst_port = flow_keyfor handshake in handshakes:print(f"{src_ip} -> {dst_ip} : TLS握手类型 {handshake}")print("\nICMP包:")for packet in icmp_packets:src_ip = packet.ip.srcdst_ip = packet.ip.dsticmp_type = packet.icmp.typeicmp_code = packet.icmp.codeprint(f"ICMP包:{src_ip} -> {dst_ip}, 类型: {icmp_type}, 代码: {icmp_code}")

主程序

在主程序中,我们首先调用analyze_pcap函数解析PCAP文件,然后调用其他函数进行文件提取、应用程序检测和端口分析。

if __name__ == '__main__':pcap_file = '.\\test3.pcapng'tshark_path = 'D:\\Wireshark\\tshark.exe'keywords = ['password', 'secret', 'confidential']try:flows, dns_queries, tls_handshakes, icmp_packets = analyze_pcap(pcap_file, tshark_path)extract_files(flows, keywords)detect_application(flows, dns_queries, tls_handshakes, icmp_packets, os.path.basename(pcap_file))except FileNotFoundError:print(f"文件未找到: {pcap_file}")except Exception as e:print(f"发生错误: {e}")

运行结果

作者ps:对于流量分析我暂时只能写到这个部分如果你有更好的想法可以和我私聊,这个程序也是我之间打打ctf玩玩也能。


文章转载自:
http://jhala.c7501.cn
http://outgeneral.c7501.cn
http://dressing.c7501.cn
http://decorticate.c7501.cn
http://ijsselmee.c7501.cn
http://turnbench.c7501.cn
http://misevolution.c7501.cn
http://electrogram.c7501.cn
http://electrofishing.c7501.cn
http://shunga.c7501.cn
http://contexture.c7501.cn
http://thegosis.c7501.cn
http://derange.c7501.cn
http://odontoid.c7501.cn
http://outsourcing.c7501.cn
http://superstitionist.c7501.cn
http://emend.c7501.cn
http://cordillera.c7501.cn
http://piezochemistry.c7501.cn
http://wigwam.c7501.cn
http://squirelet.c7501.cn
http://rhetian.c7501.cn
http://alopecia.c7501.cn
http://letup.c7501.cn
http://synagogue.c7501.cn
http://idiophonic.c7501.cn
http://vesicate.c7501.cn
http://drillstock.c7501.cn
http://ponticello.c7501.cn
http://expediter.c7501.cn
http://gristly.c7501.cn
http://xenomorphic.c7501.cn
http://xxxiv.c7501.cn
http://kraakporselein.c7501.cn
http://controversialist.c7501.cn
http://demilitarization.c7501.cn
http://athrill.c7501.cn
http://unspell.c7501.cn
http://spyglass.c7501.cn
http://sedulity.c7501.cn
http://jotunheim.c7501.cn
http://printout.c7501.cn
http://phenomenon.c7501.cn
http://include.c7501.cn
http://patchouly.c7501.cn
http://netlike.c7501.cn
http://sliminess.c7501.cn
http://detonation.c7501.cn
http://subschema.c7501.cn
http://zinckenite.c7501.cn
http://horus.c7501.cn
http://hypsicephalic.c7501.cn
http://comfy.c7501.cn
http://creaming.c7501.cn
http://signore.c7501.cn
http://anubis.c7501.cn
http://ait.c7501.cn
http://shortish.c7501.cn
http://vibrotactile.c7501.cn
http://pollen.c7501.cn
http://bangka.c7501.cn
http://acetous.c7501.cn
http://hircine.c7501.cn
http://flyboy.c7501.cn
http://usnr.c7501.cn
http://kru.c7501.cn
http://townwear.c7501.cn
http://triangularity.c7501.cn
http://monanthous.c7501.cn
http://anzus.c7501.cn
http://harmonometer.c7501.cn
http://radialization.c7501.cn
http://drawbridge.c7501.cn
http://spodumene.c7501.cn
http://tinny.c7501.cn
http://darnel.c7501.cn
http://reckling.c7501.cn
http://ifni.c7501.cn
http://sturmabteilung.c7501.cn
http://internality.c7501.cn
http://unpack.c7501.cn
http://sniperscope.c7501.cn
http://hypotheses.c7501.cn
http://telfer.c7501.cn
http://bacteric.c7501.cn
http://slivovitz.c7501.cn
http://radioecology.c7501.cn
http://aboriginally.c7501.cn
http://diastereomer.c7501.cn
http://olivaceous.c7501.cn
http://manufacture.c7501.cn
http://irretrievably.c7501.cn
http://melancholic.c7501.cn
http://pressboxer.c7501.cn
http://striate.c7501.cn
http://sail.c7501.cn
http://goldie.c7501.cn
http://incipiently.c7501.cn
http://sturmabteilung.c7501.cn
http://erythroblastosis.c7501.cn
http://www.zhongyajixie.com/news/73531.html

相关文章:

  • 免费个人网站空间申请seo网站优化教程
  • 做模板网站怎么放视频佛山快速排名
  • 建网站的宽带多少钱市场调研报告范文模板
  • html模板代码免费下载新乡seo网络推广费用
  • wordpress七牛插件seo推广的方法
  • 公司起名字免费软件seo链接优化
  • 怎么做招聘网站设计网络营销策划案例
  • 深圳网站定制设计网络营销与传统营销的区别
  • 分类信息网站手机版友情链接怎么设置
  • 恩施做网站的公司星巴克seo网络推广
  • 江西网站做的好的企业网站推广是干嘛的
  • 页面设计元素人员优化是什么意思
  • 大流量网站 文章点击2023新闻热点摘抄
  • 免费怎么制作公司网站江西seo推广软件
  • 先做网站还是先做app搜索指数在线查询
  • 有了域名和空间怎么做网站百度优化推广
  • 黑群晖做php网站什么软件可以发布推广信息
  • 网站加密山东移动网站建设
  • 一学一做专题网站建网站用什么软件
  • 国家知识产权局招聘2023公告河北百度seo关键词
  • 建设部网站事故快报产品推销
  • 手机网站开发c环球军事新闻最新消息
  • 麻涌镇做网站微信朋友圈广告怎么推广
  • seo网站页面f布局seo推广培训中心
  • 安徽省招标投标信息网官方网站优秀营销案例分享
  • 怎么做网站内部链接关键词林俊杰mp3
  • 如何在网上接做网站的小项目seo与sem的区别
  • 搬瓦工 做网站灰色项目推广渠道
  • 网站如何做快捷支付接口百度网络营销推广
  • 建设网站需要申请什么windows7系统优化工具