|
@@ -9,6 +9,8 @@ class Sample:
|
|
|
TIME_FMT = '%Y-%m-%d %H:%M:%S.%f'
|
|
TIME_FMT = '%Y-%m-%d %H:%M:%S.%f'
|
|
|
FILTER = "tcp.flags.push == 1 && tcp.dstport == 22" # len % 8 == 6
|
|
FILTER = "tcp.flags.push == 1 && tcp.dstport == 22" # len % 8 == 6
|
|
|
EPSIOLON = 0.0000000000001
|
|
EPSIOLON = 0.0000000000001
|
|
|
|
|
+ BASE_PACKET_SIZE = 102
|
|
|
|
|
+ BLOCK_SIZE = 8
|
|
|
|
|
|
|
|
def make_samples(keylog: typing.TextIO,
|
|
def make_samples(keylog: typing.TextIO,
|
|
|
pcap: typing.BinaryIO,
|
|
pcap: typing.BinaryIO,
|
|
@@ -33,6 +35,15 @@ class Sample:
|
|
|
Sample.high_act_threshold = upper_bound
|
|
Sample.high_act_threshold = upper_bound
|
|
|
Sample.low_act_threshold = lower_bound
|
|
Sample.low_act_threshold = lower_bound
|
|
|
Sample.lookback = lookback
|
|
Sample.lookback = lookback
|
|
|
|
|
+
|
|
|
|
|
+ # Boundaries measured in packets/second
|
|
|
|
|
+ def set_copypaste_thresholds(lower_bound: float, upper_bound: float):
|
|
|
|
|
+ assert(lower_bound < upper_bound)
|
|
|
|
|
+ assert(lower_bound >= 1)
|
|
|
|
|
+ Sample.small_paste_threshold = Sample.BLOCK_SIZE*lower_bound + \
|
|
|
|
|
+ Sample.BASE_PACKET_SIZE
|
|
|
|
|
+ Sample.large_paste_threshold = Sample.BLOCK_SIZE*upper_bound + \
|
|
|
|
|
+ Sample.BASE_PACKET_SIZE
|
|
|
|
|
|
|
|
def __packet_time(p):
|
|
def __packet_time(p):
|
|
|
return (datetime.strptime(p.time, Sample.TIME_FMT) - Sample.EPOCH) \
|
|
return (datetime.strptime(p.time, Sample.TIME_FMT) - Sample.EPOCH) \
|
|
@@ -43,6 +54,7 @@ class Sample:
|
|
|
self.__extract_tag(keylog)
|
|
self.__extract_tag(keylog)
|
|
|
self.__extract_activity_stats(packets)
|
|
self.__extract_activity_stats(packets)
|
|
|
self.__extract_time_stats(packets)
|
|
self.__extract_time_stats(packets)
|
|
|
|
|
+ self.__extract_paste_stats(packets)
|
|
|
|
|
|
|
|
def __extract_tag(self, keylog: typing.TextIO):
|
|
def __extract_tag(self, keylog: typing.TextIO):
|
|
|
import os
|
|
import os
|
|
@@ -131,6 +143,13 @@ class Sample:
|
|
|
end = Sample.__packet_time(pcap[-1])
|
|
end = Sample.__packet_time(pcap[-1])
|
|
|
self["total_time"] = end - start
|
|
self["total_time"] = end - start
|
|
|
self["average_iat"] = (end - start) / len(pcap)
|
|
self["average_iat"] = (end - start) / len(pcap)
|
|
|
|
|
+
|
|
|
|
|
+ def __extract_paste_stats(self, pcaps):
|
|
|
|
|
+ self["total_pastes"] = sum(p.length > Sample.small_paste_threshold
|
|
|
|
|
+ for p in pcaps)
|
|
|
|
|
+ self["large_pastes"] = sum(p.length > Sample.large_paste_threshold
|
|
|
|
|
+ for p in pcaps)
|
|
|
|
|
+ self["small_pastes"] = self["total_pastes"] - self["large_pastes"]
|
|
|
|
|
|
|
|
def __is_valid_prefix(pre):
|
|
def __is_valid_prefix(pre):
|
|
|
return pre in ["high", "mid", "low"]
|
|
return pre in ["high", "mid", "low"]
|