Skip to content

Commit fd7edd4

Browse files
committed
bugfix + fraction of attack by bytes
1 parent 6e235bc commit fd7edd4

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

fingerprint_format.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ The datatype `Map<?, Float>` refers to a map of values to their corresponding fr
4747
|---------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------|
4848
| `service` | Name of the service used in this attack vector, determined by the source port and protocol. e.g. UDP port 53 -> DNS. Or: "Unknown service" or "Fragmented IP packets" for the vector of packet fragments that cannot be assigned to another vector | String |
4949
| `protocol` | IP protocol, e.g. TCP, UDP, ICMP | String |
50-
| `fraction_of_attack` | The fraction of the entire DDoS attack that this attack vector makes up \[0, 1\], not taking into account the vector of packet fragments (null) | Float or null |
50+
| `fraction_of_attack` | The fraction of the entire DDoS attack that this attack vector makes up \[0, 1\], calculated from total bytes, not taking into account the vector of packet fragments (null) | Float or null |
5151
| `source_port` | Source port of this attack vector if the source port in combination with protocol is associated with a specific service (e.g. UDP/53 -> DNS), if not - see `destiantion_ports` | Integer or "random" |
5252
| `destination_ports` | List of outlier destination ports (if any) with the corresponding fraction of the traffic, or "random". e.g. {"443": 0.65, "80": 0.35}. (The keys are strings because of the JSON format) | Map<String, Float> or "random" |
5353
| `tcp_flags` | List of outlier TCP flags (if any) with the corresponding fraction of the traffic,. e.g. {"...A....": 0.987}. null if the protocol is not TCP, or there are no outliers | null or Map<String, Float> |

src/analysis.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,14 @@ def combine_outliers(port_protocol_tuples: list[tuple[str, int]]) -> list[tuple[
169169
# Compute the fraction of all traffic for each attack vector, discard vectors with less than 5% of traffic
170170
LOGGER.debug("Computing the fraction of traffic each attack vector contributes.")
171171
while True:
172-
total_packets = sum([v.packets for v in attack_vectors])
172+
total_bytes = sum([v.bytes for v in attack_vectors])
173173
for vector in attack_vectors:
174-
vector.fraction_of_attack = round(vector.packets / total_packets, 3)
174+
vector.fraction_of_attack = round(vector.bytes / total_bytes, 3)
175175
if vector.fraction_of_attack < 0.05:
176176
break
177177
else:
178178
break
179+
LOGGER.debug(f'removing {vector} ({vector.fraction_of_attack * 100}% of traffic)')
179180
attack_vectors.remove(vector)
180181

181182
# Create attack vector(s) with fragmented packets

src/attack.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def __init__(self, data: pd.DataFrame, source_port: int, protocol: str, filetype
6060
self.source_ips: list[IPAddress] = data.source_address.unique()
6161
self.fraction_of_attack = 0
6262
try:
63-
if self.protocol == 'UDP':
63+
if self.protocol == 'UDP' and source_port != -1:
6464
self.service = (AMPLIFICATION_SERVICES.get(self.source_port, None) or
6565
socket.getservbyport(source_port, protocol.lower()).upper())
6666
elif self.protocol == 'TCP':
@@ -109,7 +109,7 @@ def __init__(self, data: pd.DataFrame, source_port: int, protocol: str, filetype
109109
return_others=True)) or 'random'
110110

111111
def __str__(self):
112-
return f"[AttackVector] {self.service} on port {self.source_port}, protocol {self.protocol}"
112+
return f"[AttackVector ({self.fraction_of_attack * 100}% of traffic) {self.protocol}, service: {self.service}]"
113113

114114
def __repr__(self):
115115
return self.__str__()

0 commit comments

Comments
 (0)