데이터 융합

Python으로 설계하는 Machine Learning 워크플로

Dr. Chris Anagnostopoulos

Honorary Associate Professor

컴퓨터, 포트, 프로토콜

컴퓨터 트래픽은 소스 컴퓨터의 포트에서 대상 컴퓨터의 다른 포트로, 특정 프로토콜을 따라 패킷으로 전송됩니다.

Python으로 설계하는 Machine Learning 워크플로

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으로 설계하는 Machine Learning 워크플로

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으로 설계하는 Machine Learning 워크플로

이벤트 라벨링 vs. 컴퓨터 라벨링

단일 이벤트에는 라벨을 붙이기 어렵습니다. 감염된 소스와 대상 컴퓨터 간의 단일 트랜잭션.

하지만 컴퓨터 전체는 감염 여부가 명확합니다. 감염된 소스가 두 대의 컴퓨터에서 가능한 모든 포트와 통신을 시도합니다.

Python으로 설계하는 Machine Learning 워크플로

그룹화와 특징 추출

분석 단위 = 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으로 설계하는 Machine Learning 워크플로

그룹화와 특징 추출

컴퓨터별 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으로 설계하는 Machine Learning 워크플로

그룹화와 특징 추출

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으로 설계하는 Machine Learning 워크플로

라벨된 데이터셋

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으로 설계하는 Machine Learning 워크플로

이제 해커를 잡아볼까요?

Python으로 설계하는 Machine Learning 워크플로

Preparing Video For Download...