NFStreamのセットアップ(WSL+OracleLinux9+Python3.12)

概要

通信解析用のフレームワーク「NFStream」をPython 3.12とWSL2環境に対してインストールします。


目次


環境

WSL2にインストールしたOracle Linux 9.1を使用します。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ cat /etc/os-release
NAME="Oracle Linux Server"
VERSION="9.1"
ID="ol"
ID_LIKE="fedora"
VARIANT="Server"
VARIANT_ID="server"
VERSION_ID="9.1"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Oracle Linux Server 9.1"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:oracle:linux:9:1:server"
HOME_URL="https://linux.oracle.com/"
BUG_REPORT_URL="https://github.com/oracle/oracle-linux"

ORACLE_BUGZILLA_PRODUCT="Oracle Linux 9"
ORACLE_BUGZILLA_PRODUCT_VERSION=9.1
ORACLE_SUPPORT_PRODUCT="Oracle Linux"
ORACLE_SUPPORT_PRODUCT_VERSION=9.1

セットアップ

前提パッケージの導入

WSLに導入したばかりのOracleLinuxには基本的なコマンドや開発ツールが無いため、
以下のコマンドで必要なパッケージをインストールします。

1
2
3
sudo dnf group install "Minimal Install"
sudo dnf group install "Development Tools"
sudo dnf install libpcap libpcap-devel --enablerepo=ol9_codeready_builder

Pythonのインストール

以下のコマンドでPython3.12を導入し、デフォルトのPythonパッケージに指定します。

1
2
sudo dnf install python3.12 python3.12-devel python3.12-libs python3.12-libs python3.12-pip
sudo alternatives --install /usr/bin/python python /usr/bin/python3.12 1

nfstreamのインストール

NFStreamのリポジトリをクローンします。

1
2
git clone --recurse-submodules https://github.com/nfstream/nfstream.git
cd nfstream

※記事執筆時点のバージョンで固定する場合

1
git checkout a4180aa52fbc9f135b8ecfe039652845047b176b

スクリプトの誤りを修正します

1
sed 's|/tmp/nfstream_build/{usr}/lib/libndpi.a|/tmp/nfstream_build/{usr}/lib64/libndpi.a|g' -i ./nfstream/engine/engine_build.py

上記コマンド実行後、差分が次のようになっていれば成功です。

1
2
3
4
5
6
7
8
9
10
11
12
13
diff --git a/nfstream/engine/engine_build.py b/nfstream/engine/engine_build.py
index c3bf6a9..8548f6a 100644
--- a/nfstream/engine/engine_build.py
+++ b/nfstream/engine/engine_build.py
@@ -83,7 +83,7 @@ INCLUDE_DIRS = [
"{root}/tmp/nfstream_build/{usr}/include".format(root=ROOT, usr=USR_LOCAL),
]
EXTRALINK_ARGS = [
- "{root}/tmp/nfstream_build/{usr}/lib/libndpi.a".format(root=ROOT, usr=USR)
+ "{root}/tmp/nfstream_build/{usr}/lib64/libndpi.a".format(root=ROOT, usr=USR)
]

if os.name != "posix": # Windows

インストールします

1
2
3
python -m pip install --upgrade pip
python -m pip install -r dev_requirements.txt
python -m pip install .

テスト

サンプルとなるcapファイルをダウンロードします。

1
2
cd ~
wget https://wiki.wireshark.org/uploads/27707187aeb30df68e70c8fb9d614981/http.cap

以下のpythonスクリプトをnfstream_test.pyのファイル名で保存

1
2
3
4
from nfstream import NFStreamer
s = NFStreamer(source="http.cap")
for flow in s :
print(flow)

保存したnfstream_test.pyを実行

1
2
3
4
5
6
7
8
9
10
11
python nfstream_test.py

NFlow(id=0,
expiration_id=0,
src_ip=145.254.160.237,
src_mac=00:00:01:00:00:00,
src_oui=00:00:01,
src_port=3372,
dst_ip=65.208.228.223,
dst_mac=fe:ff:20:00:01:00,
(中略)
Author

fuchse-ohren

Posted on

2025-03-07

Updated on

2026-03-11

Licensed under

コメント