+-+-+ +-+ +-+-+-+-+
|G|O| |4| |H|I|V|E|
+-+-+ +-+ +-+-+-+-+

 --- A GOPHER-LIKE INTERFACE FOR HIVE BLOCKCHAIN ---

pcap parsing using dpkt

BY: @ss5h | CREATED: Feb. 13, 2018, 7:02 a.m. | VOTES: 1 | PAYOUT: $0.00 | [ VOTE ]

어쩌다 pcap에서 http 통신을 하는 패킷을 찾아내고 Request에 들어가는 값들을 파싱해야하는 일이 생겼다.

그래서 사용한게 dpkt 라이브러리이다.

사용법은 엄청 간단하다. pcap파일을 rb모드로 open하고 dpkt.pcap.Reader라는 함수에 넣어주면 기초 작업은 끝이다.

f = open(sys.argv[1],'rb')
pcap = dpkt.pcap.Reader(f)

그 후엔 다음과 같이 사용할 수 있다.

for ts, buf in pcap:
            eth = dpkt.ethernet.Ethernet(buf)
            ip = eth.data
            tcp = ip.data
            try:
                    if (tcp.dport == 80 or tcp.dport == 443) and len(tcp.data) > 0:
                            request = dpkt.http.Request(tcp.data)
            except:
                    pass

그래서 request에서 많은 정보들을 뽑아 올 수 있다.
ex) request.body, request.header, request.header['user-agent']

TAGS: [ #network ] [ #pcap ] [ #dpkt ] [ #python ]

Replies

@steemitboard | Jan. 29, 2019, 10:14 a.m. | Votes: 0 | [ VOTE ]

Congratulations @ss5h! You received a personal award!

https://steemitimages.com/70x70/http://steemitboard.com/@ss5h/birthday1.pngHappy Birthday! - You are on the Steem blockchain for 1 year!

Click here to view your Board

> Support SteemitBoard's project! Vote for its witness and get one more award!

@steemitboard | Jan. 29, 2020, 8:53 a.m. | Votes: 0 | [ VOTE ]

Congratulations @ss5h! You received a personal award!

https://steemitimages.com/70x70/http://steemitboard.com/@ss5h/birthday2.pngHappy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!
[ BACK TO TRENDING ] [ BACK TO MENU ]
CMD>