Python으로 pcap 파일을 분석하기 위해서 dpkt 라이브러리 설치가 필요합니다.



※ 설치방법


pip install dpkt




※ 사용법 기초


Pcap에서 datetime, mac address, ip.src, ip.dst, length을 출력하는 예제


import dpkt

import datetime

import socket


def mac_addr(address):

return ':'.join('%02x' % ord(b) for b in address)


with open('pcap파일명 입력', 'rb') as f:

pcap = dpkt.pcap.Reader(f)


var = 100


for timestamp, buf in pcap:

eth = dpkt.ethernet.Ethernet(buf)

ip = eth.data

var = var - 1

if var == 0:

break


if eth.type != dpkt.ethernet.ETH_TYPE_IP:

continue

   

if ip.p != dpkt.ip.IP_PROTO_TCP:

continue

print 'Timestamp: ', timestamp

print 'Ethernet Frame: ', mac_addr(eth.src), ' -> ', mac_addr(eth.dst), eth.type

print 'IP: %s -> %s len=%d \n' % (socket.inet_ntoa(ip.src), socket.inet_ntoa(ip.dst), ip.len)



Posted by n3015m
:
BLOG main image
'네오이즘'의 보안LAB 블로그입니다........... n3oism@gmail.com by n3015m

카테고리

분류 전체보기 (228)
[ HappyDevTool ] (29)
[ HappyToolRelease ] (4)
[Book] (6)
[ Security Studies ] (0)
- CII (2)
- BigData (2)
- Web Hacking (10)
- SQL Injection (25)
- Mobile Security (9)
- Network (6)
- OperatingSystem (4)
- Malware & Reversing (4)
- Phishing (5)
- Compliance (0)
- Programming (13)
- Tools (13)
- IoT (6)
- etc (21)
[Pentration Testing] (3)
[OS X] (4)
[ Security Trends ] (16)
[ Fixing Guideline ] (7)
My Way, My Life (34)
About Me (2)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

Total :
Today : Yesterday :