Fusione dei dati

Progettare workflow di Machine Learning in Python

Dr. Chris Anagnostopoulos

Honorary Associate Professor

Computer, porte e protocolli

Il traffico passa in pacchetti da una porta del computer sorgente a una porta del computer di destinazione.

Progettare workflow di Machine Learning in Python

Il dataset LANL cyber

flows: sessioni di trasferimento dati continuo tra una porta del computer sorgente e una del computer di destinazione, secondo un certo protocollo.

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/
Progettare workflow di Machine Learning in Python

Il dataset LANL cyber

attack: info su alcuni attacchi eseguiti dal team di sicurezza durante un test.

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

Come creiamo esempi etichettati da questi dati?

1 https://csr.lanl.gov/data/cyber1/
Progettare workflow di Machine Learning in Python

Etichettare eventi vs etichettare computer

Un singolo evento non si etichetta facilmente. Una singola transazione tra una sorgente infetta e un computer di destinazione.

Ma un intero computer è infetto o no. Una sorgente infetta tenta di comunicare con tutte le porte possibili in due computer diversi.

Progettare workflow di Machine Learning in Python

Raggruppa e crea feature

Unità di analisi = 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
Progettare workflow di Machine Learning in Python

Raggruppa e crea feature

Da un DataFrame per computer a un vettore di feature per computer.

def featurize(df):
    return {
        'unique_ports': len(set(df['destination_port'])),
        'average_packet': np.mean(df['packet_count']),
        'average_duration': np.mean(df['duration'])
    }
Progettare workflow di Machine Learning in Python

Raggruppa e crea feature

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 righe x 3 colonne]
Progettare workflow di Machine Learning in Python

Dataset etichettato

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

La coppia (X, y) ora è un classico dataset etichettato per classificazione.

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
Progettare workflow di Machine Learning in Python

Pronti a beccare un hacker?

Progettare workflow di Machine Learning in Python

Preparing Video For Download...