LoginSignup
0
1

More than 5 years have passed since last update.

Jupyterでpcap分析

Posted at

pcapファイルを解析したかったらWiresharkなどが定番だと思うが、やることが決まってる場合はPythonのdpktで自動処理できれば楽だ。

まずはdpktをインストール。Azure Notebookでも問題なくインストールできた。

!pip install dpkt

pcapファイルはksnctfのものを使ってみる。

!curl http://ksnctf.sweetduet.info/q/8/q8.pcap

あとはサンプルファイルを参考にコーディング。ksnctfの問題はBasic認証に関するものなので、HTTPリクエストからAuthenticationヘッダのみ取り出し、base64デコード。

import dpkt,socket
import base64

filename = 'ksnctf_8_basic_is_secure.pcap'
pcap = dpkt.pcap.Reader(open(filename,'rb'))
for timestamp, buf in pcap:
    try:
        eth = dpkt.ethernet.Ethernet(buf)
        ip = eth.data
        tcp = ip.data
        re = dpkt.http.Request(tcp.data)
        if re["headers"]["authorization"]:
            auth = re["headers"]["authorization"]
            passwd = base64.b64decode(auth.replace("Basic ",""))
            print(passwd)
    except:
        pass

特定のヘッダのみ追っかけて処理したい場合などに応用できそう。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1