def __init__(self): """ Creates a new instance of the SMBScanAttack. This Attack injects TCP Syn Requests to the port 445 of several ips and related response into the output pcap file. If port 445 is open, it will simulate and inject the SMB Protocol Negotiation too. """ # Initialize attack super(SMBScanAttack, self).__init__("SmbScan Attack", "Injects an SMB scan", "Scanning/Probing") self.host_os = Util.get_rnd_os() # Define allowed parameters and their type self.supported_params.update({ atkParam.Parameter.IP_SOURCE: atkParam.ParameterTypes.TYPE_IP_ADDRESS, atkParam.Parameter.IP_DESTINATION: atkParam.ParameterTypes.TYPE_IP_ADDRESS, atkParam.Parameter.TARGET_COUNT: atkParam.ParameterTypes.TYPE_INTEGER_POSITIVE, atkParam.Parameter.HOSTING_PERCENTAGE: atkParam.ParameterTypes.TYPE_PERCENTAGE, atkParam.Parameter.PORT_SOURCE: atkParam.ParameterTypes.TYPE_PORT, atkParam.Parameter.MAC_SOURCE: atkParam.ParameterTypes.TYPE_MAC_ADDRESS, atkParam.Parameter.INJECT_AT_TIMESTAMP: atkParam.ParameterTypes.TYPE_FLOAT, atkParam.Parameter.INJECT_AFTER_PACKET: atkParam.ParameterTypes.TYPE_PACKET_POSITION, atkParam.Parameter.IP_SOURCE_RANDOMIZE: atkParam.ParameterTypes.TYPE_BOOLEAN, atkParam.Parameter.PACKETS_PER_SECOND: atkParam.ParameterTypes.TYPE_FLOAT, atkParam.Parameter.INJECT_PPS: atkParam.ParameterTypes.TYPE_FLOAT, atkParam.Parameter.PORT_SOURCE_RANDOMIZE: atkParam.ParameterTypes.TYPE_BOOLEAN, atkParam.Parameter.HOSTING_IP: atkParam.ParameterTypes.TYPE_IP_ADDRESS, atkParam.Parameter.HOSTING_VERSION: atkParam.ParameterTypes.TYPE_STRING, atkParam.Parameter.SOURCE_PLATFORM: atkParam.ParameterTypes.TYPE_STRING, atkParam.Parameter.PROTOCOL_VERSION: atkParam.ParameterTypes.TYPE_STRING })
def init_params(self): """ Initialize the parameters of this attack using the user supplied command line parameters. Use the provided statistics to calculate default parameters and to process user supplied queries. """ # PARAMETERS: initialize with default values # (values are overwritten if user specifies them) most_used_ip_address = self.statistics.get_most_used_ip_address() self.add_param_value(atkParam.Parameter.IP_SOURCE, most_used_ip_address) self.add_param_value(atkParam.Parameter.IP_SOURCE_RANDOMIZE, 'False') self.add_param_value( atkParam.Parameter.MAC_SOURCE, self.statistics.get_mac_address(most_used_ip_address)) self.add_param_value(atkParam.Parameter.TARGET_COUNT, 200) self.add_param_value(atkParam.Parameter.IP_DESTINATION, "1.1.1.1") self.add_param_value(atkParam.Parameter.PORT_SOURCE, rnd.randint(1024, 65535)) self.add_param_value(atkParam.Parameter.PORT_SOURCE_RANDOMIZE, 'True') self.add_param_value( atkParam.Parameter.PACKETS_PER_SECOND, (self.statistics.get_pps_sent(most_used_ip_address) + self.statistics.get_pps_received(most_used_ip_address)) / 2) self.add_param_value( atkParam.Parameter.INJECT_AFTER_PACKET, rnd.randint(0, self.statistics.get_packet_count())) start = Util.get_timestamp_from_datetime_str( self.statistics.get_pcap_timestamp_start()) end = Util.get_timestamp_from_datetime_str( self.statistics.get_pcap_timestamp_end()) self.add_param_value(atkParam.Parameter.INJECT_AT_TIMESTAMP, (start + end) / 2) self.add_param_value(atkParam.Parameter.INJECT_PPS, 0) self.add_param_value(atkParam.Parameter.HOSTING_PERCENTAGE, 0.5) self.add_param_value(atkParam.Parameter.HOSTING_IP, "1.1.1.1") self.add_param_value(atkParam.Parameter.HOSTING_VERSION, SMBLib.get_smb_version(platform=self.host_os)) self.add_param_value(atkParam.Parameter.SOURCE_PLATFORM, Util.get_rnd_os()) self.add_param_value(atkParam.Parameter.PROTOCOL_VERSION, "1")
def test_get_rnd_os(self): self.assertIn(Utility.get_rnd_os(), Utility.platforms)