当前位置:首页 » 编程语言 » pcapypython

pcapypython

发布时间: 2023-01-04 21:00:07

‘壹’ python 解析数据包用哪个库好 主要解析http的数据包

用urllib, urllib2, httplib, httplib2,都看一下吧,有这四个,你要的功能应该都差不多能实现了。

‘贰’ libpcap库基本使用教程(python、C语言)

[TOC]

// 待补充

返回第一个适合的网络接口名称,没有找到的话返回-1。

返回所有的网络接口名称。

打开监听的设备, 返回一个可供操作的捕获句柄。

将捕获句柄设置为“非阻塞”或者“阻塞”模式,具体取决于nonblock参数为非零或零。另外pcap_getnonblock(p, errbuf)函数可用于获取当前模式状态。

获取设备的网络掩码。

用于将字符串str编译为过滤器程序。

设置过滤器程序。

一次只抓取一个包。

‘叁’ Python渗透测试工具都有哪些

网络

Scapy, Scapy3k: 发送,嗅探,分析和伪造网络数据包。可用作交互式包处理程序或单独作为一个库

pypcap, Pcapy, pylibpcap: 几个不同 libpcap 捆绑的python库

libdnet: 低级网络路由,包括端口查看和以太网帧的转发

dpkt: 快速,轻量数据包创建和分析,面向基本的 TCP/IP 协议

Impacket: 伪造和解码网络数据包,支持高级协议如 NMB 和 SMB

pynids: libnids 封装提供网络嗅探,IP 包碎片重组,TCP 流重组和端口扫描侦查

Dirtbags py-pcap: 无需 libpcap 库支持读取 pcap 文件

flowgrep: 通过正则表达式查找数据包中的 Payloads

Knock Subdomain Scan: 通过字典枚举目标子域名

SubBrute: 快速的子域名枚举工具

Mallory: 可扩展的 TCP/UDP 中间人代理工具,可以实时修改非标准协议

Pytbull: 灵活的 IDS/IPS 测试框架(附带超过300个测试样例)

调试和逆向工程

Paimei: 逆向工程框架,包含PyDBG, PIDA , pGRAPH

Immunity Debugger: 脚本 GUI 和命令行调试器

mona.py: Immunity Debugger 中的扩展,用于代替 pvefindaddr

IDAPython: IDA pro 中的插件,集成 Python 编程语言,允许脚本在 IDA Pro 中执行

PyEMU: 全脚本实现的英特尔32位仿真器,用于恶意软件分析

pefile: 读取并处理 PE 文件

pydasm: Python 封装的libdasm

PyDbgEng: Python 封装的微软 Windows 调试引擎

uhooker: 截获 DLL 或内存中任意地址可执行文件的 API 调用

diStorm: AMD64 下的反汇编库

python-ptrace: Python 写的使用 ptrace 的调试器

vdb/vtrace: vtrace 是用 Python 实现的跨平台调试 API, vdb 是使用它的调试器

Androguard: 安卓应用程序的逆向分析工具

Capstone: 一个轻量级的多平台多架构支持的反汇编框架。支持包括ARM,ARM64,MIPS和x86/x64平台

PyBFD: GNU 二进制文件描述(BFD)库的 Python 接口

Fuzzing

Sulley: 一个模糊器开发和模糊测试的框架,由多个可扩展的构件组成的

Peach Fuzzing Platform: 可扩展的模糊测试框架(v2版本 是用 Python 语言编写的)

antiparser: 模糊测试和故障注入的 API

TAOF: (The Art of Fuzzing, 模糊的艺术)包含 ProxyFuzz, 一个中间人网络模糊测试工具

untidy: 针对 XML 模糊测试工具

Powerfuzzer: 高度自动化和可完全定制的 Web 模糊测试工具

SMUDGE: 纯 Python 实现的网络协议模糊测试

Mistress: 基于预设模式,侦测实时文件格式和侦测畸形数据中的协议

Fuzzbox: 媒体多编码器的模糊测试

Forensic Fuzzing Tools: 通过生成模糊测试用的文件,文件系统和包含模糊测试文件的文件系统,来测试取证工具的鲁棒性

Windows IPC Fuzzing Tools: 使用 Windows 进程间通信机制进行模糊测试的工具

WSBang: 基于 Web 服务自动化测试 SOAP 安全性

Construct: 用于解析和构建数据格式(二进制或文本)的库

fuzzer.py(feliam): 由 Felipe Andres Manzano 编写的简单模糊测试工具

Fusil: 用于编写模糊测试程序的 Python 库

Web

Requests: 优雅,简单,人性化的 HTTP 库

HTTPie: 人性化的类似 cURL 命令行的 HTTP 客户端

ProxMon: 处理代理日志和报告发现的问题

WSMap: 寻找 Web 服务器和发现文件

Twill: 从命令行界面浏览网页。支持自动化网络测试

Ghost.py: Python 写的 WebKit Web 客户端

Windmill: Web 测试工具帮助你轻松实现自动化调试 Web 应用

FunkLoad: Web 功能和负载测试

spynner: Python 写的 Web浏览模块支持 Javascript/AJAX

python-spidermonkey: 是 Mozilla JS 引擎在 Python 上的移植,允许调用 Javascript 脚本和函数

mitmproxy: 支持 SSL 的 HTTP 代理。可以在控制台接口实时检查和编辑网络流量

pathod/pathoc: 变态的 HTTP/S 守护进程,用于测试和折磨 HTTP 客户端

‘肆’ 求教python程序调用scapy模块的问题

scapy 模块安装

今天因为要用到scapy 模块就进行安装:
windows:
pip install scapy
成功安装。
mac:

pip install scapy1

竟然提示权限问题,于是

sudo pip install scapy1

还是报错permission denied
于是上网查询,发现原来是mac 系统的sip 机制导致。
参考:参考链接

sudo pip install scapy --user -U1

安装成功。

scapy 模块使用
安装完成,进行使用。

>>python >>import scapy12

没有问题,我以为安装成功,于是开始写代码。
参考代码链接:
结果发现在导入模块的时候后出错:

from scapy.all import *1

如果遇到模块不存在的错误,只需要 pip install XX 安装对应的模块即可。
mac就遇到此类错误:

importError: No mole named pcapy1

那就安装pcapy模块,遇到同样的权限问题,使用:

pip install pcapy --user -U1

安装完之后还出现错误:

ImportError: No mole nam

‘伍’ python3.2 下的抓包库。。无论是pypcap还是scapy。貌似都没有py3的版本。。跪求一个可以python3用

有一个py3kcap是pycap的封装版本,可以用于python3版本。

给你一个使用的示例代码:

#!/usr/bin/env python3.2
import ctypes,sys
from ctypes.util import find_library
#pcap = ctypes.cdll.LoadLibrary("libpcap.so")
pcap = None
if(find_library("libpcap") == None):
print("We are here!")
pcap = ctypes.cdll.LoadLibrary("libpcap.so")
else:
pcap = ctypes.cdll.LoadLibrary(find_library("libpcap"))
# required so we can access bpf_program->bf_insns
"""
struct bpf_program {
u_int bf_len;
struct bpf_insn *bf_insns;}
"""
class bpf_program(ctypes.Structure):
_fields_ = [("bf_len", ctypes.c_int),("bf_insns", ctypes.c_void_p)]
class sockaddr(ctypes.Structure):
_fields_=[("sa_family",ctypes.c_uint16),("sa_data",ctypes.c_char*14)]
class pcap_pkthdr(ctypes.Structure):
_fields_ = [("tv_sec", ctypes.c_long), ("tv_usec", ctypes.c_long), ("caplen", ctypes.c_uint), ("len", ctypes.c_uint)]

pkthdr = pcap_pkthdr()
program = bpf_program()
# prepare args
snaplen = ctypes.c_int(1500)
#buf = ctypes.c_char_p(filter)
optimize = ctypes.c_int(1)
mask = ctypes.c_uint()
net = ctypes.c_uint()
to_ms = ctypes.c_int(100000)
promisc = ctypes.c_int(1)
filter = bytes(str("port 80"), 'ascii')
buf = ctypes.c_char_p(filter)
errbuf = ctypes.create_string_buffer(256)
pcap_close = pcap.pcap_close
pcap_lookupdev = pcap.pcap_lookupdev
pcap_lookupdev.restype = ctypes.c_char_p
#pcap_lookupnet(dev, &net, &mask, errbuf)
pcap_lookupnet = pcap.pcap_lookupnet
#pcap_t *pcap_open_live(const char *device, int snaplen,int promisc, int to_ms,
#char *errbuf
pcap_open_live = pcap.pcap_open_live
#int pcap_compile(pcap_t *p, struct bpf_program *fp,const char *str, int optimize,
#bpf_u_int32 netmask)
pcap_compile = pcap.pcap_compile
#int pcap_setfilter(pcap_t *p, struct bpf_program *fp);
pcap_setfilter = pcap.pcap_setfilter
#const u_char *pcap_next(pcap_t *p, struct pcap_pkthdr *h);
pcap_next = pcap.pcap_next
# int pcap_compile_nopcap(int snaplen, int linktype, struct bpf_program *program,
# const char *buf, int optimize, bpf_u_int32 mask);
pcap_geterr = pcap.pcap_geterr
pcap_geterr.restype = ctypes.c_char_p
#check for default lookup device
dev = pcap_lookupdev(errbuf)
#override it for now ..
dev = bytes(str("wlan0"), 'ascii')
if(dev):
print("{0} is the default interface".format(dev))
else:
print("Was not able to find default interface")

if(pcap_lookupnet(dev,ctypes.byref(net),ctypes.byref(mask),errbuf) == -1):
print("Error could not get netmask for device {0}".format(errbuf))
sys.exit(0)
else:
print("Got Required netmask")
handle = pcap_open_live(dev,snaplen,promisc,to_ms,errbuf)
if(handle is False):
print("Error unable to open session : {0}".format(errbuf.value))
sys.exit(0)
else:
print("Pcap open live worked!")
if(pcap_compile(handle,ctypes.byref(program),buf,optimize,mask) == -1):
# this requires we call pcap_geterr() to get the error
err = pcap_geterr(handle)
print("Error could not compile bpf filter because {0}".format(err))
else:
print("Filter Compiled!")
if(pcap_setfilter(handle,ctypes.byref(program)) == -1):
print("Error couldn't install filter {0}".format(errbuf.value))
sys.exit(0)
else:
print("Filter installed!")
if(pcap_next(handle,ctypes.byref(pkthdr)) == -1):
err = pcap_geterr(handle)
print("ERROR pcap_next: {0}".format(err))
print("Got {0} bytes of data".format(pkthdr.len))
pcap_close(handle)

‘陆’ winpcap在python3中的使用,求助

from ctypes import *
from winpcapy import *
import time
import sys
import string
import platform

if platform.python_version()[0] == "3":
raw_input=input
#/* prototype of the packet handler */
#void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data);
PHAND=CFUNCTYPE(None,POINTER(c_ubyte),POINTER(pcap_pkthdr),POINTER(c_ubyte))

## Callback function invoked by libpcap for every incoming packet
def _packet_handler(param,header,pkt_data):
## convert the timestamp to readable format
local_tv_sec = header.contents.ts.tv_sec
ltime=time.localtime(local_tv_sec);
timestr=time.strftime("%H:%M:%S", ltime)
print
print("%s,%.6d len:%d" % (timestr, header.contents.ts.tv_usec, header.contents.len))

packet_handler=PHAND(_packet_handler)
alldevs=POINTER(pcap_if_t)()
errbuf= create_string_buffer(PCAP_ERRBUF_SIZE)
## Retrieve the device list
if (pcap_findalldevs(byref(alldevs), errbuf) == -1):
print ("Error in pcap_findalldevs: %s\n" % errbuf.value)
sys.exit(1)
## Print the list
i=0
try:
d=alldevs.contents
except:
print ("Error in pcap_findalldevs: %s" % errbuf.value)
print ("Maybe you need admin privilege?\n")
sys.exit(1)
while d:
i=i+1
print("%d. %s" % (i, d.name))
if (d.description):
print (" (%s)\n" % (d.description))
else:
print (" (No description available)\n")
if d.next:
d=d.next.contents
else:
d=False

if (i==0):
print ("\nNo interfaces found! Make sure WinPcap is installed.\n")
sys.exit(-1)
print ("Enter the interface number (1-%d):" % (i))
inum= raw_input('--> ')
if inum in string.digits:
inum=int(inum)
else:
inum=0
if ((inum < 1) | (inum > i)):
print ("\nInterface number out of range.\n")
## Free the device list
pcap_freealldevs(alldevs)
sys.exit(-1)
## Jump to the selected adapter
d=alldevs
for i in range(0,inum-1):
d=d.contents.next
## Open the device
## Open the adapter
d=d.contents
adhandle = pcap_open_live(d.name,65536,1,1000,errbuf)
if (adhandle == None):
print("\nUnable to open the adapter. %s is not supported by Pcap-WinPcap\n" % d.contents.name)
## Free the device list
pcap_freealldevs(alldevs)
sys.exit(-1)
print("\nlistening on %s...\n" % (d.description))
## At this point, we don't need any more the device list. Free it
pcap_freealldevs(alldevs)
## start the capture (we take only 15 packets)
pcap_loop(adhandle, 15, packet_handler, None)
pcap_close(adhandle)

这是WINPCAPY自带的例子。

‘柒’ python怎样读取pcap文件

程序如下:

#!/usr/bin/env python
#coding=utf-8
#读取pcap文件,解析相应的信息,为了在记事本中显示的方便,把二进制的信息
import struct
fpcap = open('test.pcap','rb')
ftxt = open('result.txt','w')
string_data = fpcap.read()
#pcap文件包头解析
pcap_header = {}
pcap_header['magic_number'] = string_data[0:4]
pcap_header['version_major'] = string_data[4:6]
pcap_header['version_minor'] = string_data[6:8]
pcap_header['thiszone'] = string_data[8:12]
pcap_header['sigfigs'] = string_data[12:16]
pcap_header['snaplen'] = string_data[16:20]
pcap_header['linktype'] = string_data[20:24]
#把pacp文件头信息写入result.txt
ftxt.write("Pcap文件的包头内容如下: \n")
for key in ['magic_number','version_major','version_minor','thiszone',
'sigfigs','snaplen','linktype']:
ftxt.write(key+ " : " + repr(pcap_header[key])+'\n')

#pcap文件的数据包解析
step = 0
packet_num = 0
packet_data = []
pcap_packet_header = {}
i =24
while(i<len(string_data)):

#数据包头各个字段
pcap_packet_header['GMTtime'] = string_data[i:i+4]
pcap_packet_header['MicroTime'] = string_data[i+4:i+8]
pcap_packet_header['caplen'] = string_data[i+8:i+12]
pcap_packet_header['len'] = string_data[i+12:i+16]
#求出此包的包长len
packet_len = struct.unpack('I',pcap_packet_header['len'])[0]
#写入此包数据
packet_data.append(string_data[i+16:i+16+packet_len])
i = i+ packet_len+16
packet_num+=1

#把pacp文件里的数据包信息写入result.txt
for i in range(packet_num):
#先写每一包的包头
ftxt.write("这是第"+str(i)+"包数据的包头和数据:"+'\n')
for key in ['GMTtime','MicroTime','caplen','len']:
ftxt.write(key+' : '+repr(pcap_packet_header[key])+'\n')
#再写数据部分
ftxt.write('此包的数据内容'+repr(packet_data[i])+'\n')
ftxt.write('一共有'+str(packet_num)+"包数据"+'\n')

ftxt.close()
fpcap.close()

最终得到的result文件如下所示:字段显示的都是十六进制,其中的数据部分和wireshark打开,显示的十六进制窗口一样。

‘捌’ 哪里可以下载到支持python2.7的pcapy呢望山下载的都是支持python2.5的。跪求支持python2.7的pcapy。

1.用google搜:
Pcapy - Corelabs site
可以找到该网页。
2.去下载里面的zip的源码包,比如
pcapy-0.10.8.zip
3.然后解压,运行cmd,手动执行:
setup.py install
4。如果不会安装,那么参考:
【总结】Python安装第三方的库、package的方法

(此处不给贴地址,请自己用google搜帖子标题,即可找到帖子地址)

热点内容
随机启动脚本 发布:2025-07-05 16:10:30 浏览:516
微博数据库设计 发布:2025-07-05 15:30:55 浏览:19
linux485 发布:2025-07-05 14:38:28 浏览:299
php用的软件 发布:2025-07-05 14:06:22 浏览:751
没有权限访问计算机 发布:2025-07-05 13:29:11 浏览:425
javaweb开发教程视频教程 发布:2025-07-05 13:24:41 浏览:688
康师傅控流脚本破解 发布:2025-07-05 13:17:27 浏览:234
java的开发流程 发布:2025-07-05 12:45:11 浏览:680
怎么看内存卡配置 发布:2025-07-05 12:29:19 浏览:277
访问学者英文个人简历 发布:2025-07-05 12:29:17 浏览:828