数据融合

用 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

我们如何用这些数据构造有标签样本?

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...