|
@@ -12,10 +12,12 @@ class MessageType(Enum):
|
|
|
SALITY_HELLO_REPLY = 104
|
|
|
|
|
|
class Message():
|
|
|
+ INVALID_LINENO = -1
|
|
|
+
|
|
|
"""
|
|
|
Defines a compact message type that contains all necessary information.
|
|
|
"""
|
|
|
- def __init__(self, msg_id: int, src, dst, type_: MessageType, time: float, refer_msg_id: int=-1):
|
|
|
+ def __init__(self, msg_id: int, src, dst, type_: MessageType, time: float, refer_msg_id: int=-1, line_no = -1):
|
|
|
"""
|
|
|
Constructs a message with the given parameters.
|
|
|
|
|
@@ -25,6 +27,7 @@ class Message():
|
|
|
:param type_: the type of the message
|
|
|
:param time: the timestamp of the message
|
|
|
:param refer_msg_id: the ID this message is a request for or reply to. -1 if there is no related message.
|
|
|
+ :param line_no: The line number this message appeared in the original file
|
|
|
"""
|
|
|
self.msg_id = msg_id
|
|
|
self.src = src
|
|
@@ -32,6 +35,8 @@ class Message():
|
|
|
self.type = type_
|
|
|
self.time = time
|
|
|
self.refer_msg_id = refer_msg_id
|
|
|
+ # if similar fields to line_no should be added consider a separate class
|
|
|
+ self.line_no = line_no
|
|
|
|
|
|
def __str__(self):
|
|
|
str_ = "{0}. at {1}: {2}-->{3}, {4}, refer:{5}".format(self.msg_id, self.time, self.src, self.dst, self.type, self.refer_msg_id)
|
|
@@ -54,6 +59,7 @@ from ID2TLib.PcapAddressOperations import PcapAddressOperations
|
|
|
from ID2TLib.CommunicationProcessor import CommunicationProcessor
|
|
|
from ID2TLib.MacAddressGenerator import MacAddressGenerator
|
|
|
from ID2TLib.PortGenerator import gen_random_server_port
|
|
|
+from ID2TLib.Botnet.MessageMapping import MessageMapping
|
|
|
|
|
|
|
|
|
class MembersMgmtCommAttack(BaseAttack.BaseAttack):
|
|
@@ -141,7 +147,7 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
|
|
|
|
|
|
|
|
|
|
|
|
- def generate_attack_pcap(self):
|
|
|
+ def generate_attack_pcap(self, context):
|
|
|
# create the final messages that have to be sent, including all bot configurations
|
|
|
messages = self._create_messages()
|
|
|
|
|
@@ -160,6 +166,10 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
|
|
|
limit_duration = self.get_param_value(Param.ATTACK_DURATION)
|
|
|
duration = 0
|
|
|
path_attack_pcap = None
|
|
|
+
|
|
|
+ msg_packet_mapping = MessageMapping(messages)
|
|
|
+
|
|
|
+
|
|
|
# create packets to write to PCAP file
|
|
|
for msg in messages:
|
|
|
# retrieve the source and destination configurations
|
|
@@ -193,6 +203,7 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
|
|
|
|
|
|
packet.time = pcap_timestamp
|
|
|
packets.append(packet)
|
|
|
+ msg_packet_mapping.map_message(msg, packet)
|
|
|
total_pkts += 1
|
|
|
|
|
|
# Store timestamp of first packet (for attack label)
|
|
@@ -212,6 +223,9 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
|
|
|
path_attack_pcap = self.write_attack_pcap(packets, True, path_attack_pcap)
|
|
|
last_packet = packets[-1]
|
|
|
|
|
|
+ # write the mapping to a file
|
|
|
+ msg_packet_mapping.write_to(context.allocate_file("_mapping.xml"))
|
|
|
+
|
|
|
# Store timestamp of last packet
|
|
|
self.attack_end_utime = last_packet.time
|
|
|
|