資料融合

在 Python 設計機器學習工作流程

Dr. Chris Anagnostopoulos

Honorary Associate Professor

電腦、連接埠與通訊協定

電腦流量以封包形式,從來源電腦的連接埠傳送到目標電腦的另一個連接埠。

在 Python 設計機器學習工作流程

LANL 網路安全資料集

flows:在來源電腦的某個連接埠與目標電腦的某個連接埠之間,依特定通訊協定持續傳輸資料的一段工作階段。

flows.iloc[1]
time                    471692
duration                     0
source_computer          C5808
source_port              N2414
destination_computer    C26871
destination_port        N19148
protocol                     6
packet_count                 1
byte_count                  60
1 https://csr.lanl.gov/data/cyber1/
在 Python 設計機器學習工作流程

LANL 網路安全資料集

attack:安全團隊於測試中自行發動的特定攻擊資訊。

attacks.head()
     time user@domain source_computer destination_computer
0  151036   U748@DOM1          C17693                 C305
1  151648   U748@DOM1          C17693                 C728
2  151993  U6115@DOM1          C17693                C1173
3  153792   U636@DOM1          C17693                 C294
4  155219   U748@DOM1          C17693                C5693

How can we construct labeled examples from this data?

1 https://csr.lanl.gov/data/cyber1/
在 Python 設計機器學習工作流程

事件標記 vs. 電腦標記

單一事件不易標記。 來自受感染來源與某目標電腦之間的一次傳輸。

但整台電腦不是受感染就是未感染。 受感染的來源嘗試連線兩台電腦上的所有可能連接埠。

在 Python 設計機器學習工作流程

分組與特徵化

分析單位 = destination_computer

flows_grouped = flows.groupby('destination_computer')

list(flows_grouped)[0]
('C10047',         
        time  duration    ...     packet_count byte_count
2791  471694         0    ...               12       6988
2792  471694         0    ...                1        193
...
2846  471694        38    ...              157      84120
在 Python 設計機器學習工作流程

分組與特徵化

從每台電腦一個 DataFrame,轉為每台電腦一個特徵向量。

def featurize(df):
    return {
        'unique_ports': len(set(df['destination_port'])),
        'average_packet': np.mean(df['packet_count']),
        'average_duration': np.mean(df['duration'])
    }
在 Python 設計機器學習工作流程

分組與特徵化

out = flows.groupby('destination_computer').apply(featurize)
X = pd.DataFrame(list(out), index=out.index)

X.head()
                      average_duration      ...       unique_ports
destination_computer                        ...                   
C10047                        7.538462      ...                 13
C10054                        0.000000      ...                  1
C10131                       55.000000      ...                  1
...
[5 rows x 3 columns]
在 Python 設計機器學習工作流程

有標記資料集

bads = set(attacks['source_computer'].append(attacks['destination_computer']))
y = [x in bads for x in X.index]

現在的組合 (X, y) 是一個標準的有標記分類資料集。

X_train, X_test, y_train, y_test = train_test_split(X, y)
clf = AdaBoostClassifier()
accuracy_score(y_test, clf.fit(X_train, y_train).predict(X_test))
0.92
在 Python 設計機器學習工作流程

準備抓駭客了嗎?

在 Python 設計機器學習工作流程

Preparing Video For Download...