コード例 #1
0
 def default(self, line):
     """Called on an input line when the command prefix is not recognized.
        In that case we execute the line as Python code.
     """
     words = line.split()
     if len(words) == 3:
         if words[1] == 'ping':
             new_line = words[0] + ' ' + words[2]
             self.do_ping(new_line)
             return
     if len(words) == 2:
         if words[1] == 'ifconfig':
             new_line = words[0]
             self.do_ifconfig(new_line)
             return
     if self.is_hostname(words[0]) and words not in self.host_IP_map.keys():
         print('Unknown host name')
         return
     elif self.is_hostname(words[0]) and words in self.host_IP_map.keys():
         cmd = ''
         for word in words:
             cmd += word + ' '
         send_mininet_cmd_to_cluster_node(self.host_to_node_map[self.host_IP_map[words[0]]],
                                           cmd, self.ssh_chan_map, quite=False)
         return
     else:
         print('Sorry, unknown command')
コード例 #2
0
 def do_setupsniffers(self, args):
     for host in self.host_IP_map.keys():
         cmd = host + ' python ' + DST_SCRIPT_FOLDER + 'port_sniffer.py ' + host + \
               '-eth0 ' + DST_SCRIPT_FOLDER + INFECTED_HOSTS_FILENAME + ' &'
         #print cmd
         send_mininet_cmd_to_cluster_node(self.host_to_node_map[self.host_IP_map[host]],
                                           cmd, self.ssh_chan_map, quite=False)
コード例 #3
0
ファイル: CLI_Director.py プロジェクト: ruacon35/nps
    def default(self, line):
        """Called on an input line when the command prefix is not recognized.
           In that case we execute the line as Python code.
        """
        words = line.split()
        if len(words) == 3:
            if words[1] == "ping":
                new_line = words[0] + " " + words[2]
                self.do_ping(new_line)
                return
        if len(words) == 2:
            if words[1] == "ifconfig":
                new_line = words[0]
                self.do_ifconfig(new_line)
                return

        src_host = self.is_host_exist(words[0])
        if src_host == None:
            print ("No such src host")
            return
        cmd = ""
        for word in words:
            cmd += word + " "
        host = self.hosts[src_host]
        node = self.nodes[host["nodeIP"]]
        send_mininet_cmd_to_cluster_node(node, cmd, quite=False)
        return
コード例 #4
0
ファイル: host_configurator.py プロジェクト: ARCCN/nps
def host_process_configurator_nodegroup(node, groups, CIDR_mask, leaves, hosts):
    '''Configurate hosts propcesses network interfaces in each nodegroup.

    Args:
        node_IP: IP address of node.
        node_groups: Group ID to Group node-list map.
        node_IP_gr_map: Node IP address to Group ID map.
        node_IP_pool_map: Cluster Node to pool of IP addresses map.
        CIDR_mask: CIRD mask of IP address for host network interface.
        leaves: List of leave-nodes in network graph.

    '''
    # curr_host = first_host
    first_host_ip = node['IP_pool']
    curr_host_ip = first_host_ip
    group = groups[node['group']]
    for vertex in group['vertexes']:
        if vertex in leaves:
            # reset config on host interface
            curr_host = 'h' + str(vertex)
            cmd = curr_host + ' ifconfig ' + curr_host + '-eth0 0'
            send_mininet_cmd_to_cluster_node(node, cmd)
            # config new IP address on host interface
            cmd = curr_host + ' ifconfig ' + curr_host + '-eth0 ' + curr_host_ip + '/' + CIDR_mask
            send_mininet_cmd_to_cluster_node(node, cmd)

            host = {}
            host['nodeIP'] = node['IP']
            host['name'] = curr_host
            host['IP'] = curr_host_ip
            hosts[curr_host] = host

            # prepare for next host
            curr_host_ip = get_next_IP(curr_host_ip)
コード例 #5
0
 def setup_generator(self, generator_list):
     for generator in generator_list:
         mal_node  = generator[0]
         victim_ip = generator[1]
         intf_name = self.host_map[mal_node.get_host_IP()] + "-eth0"
         cmd = self.host_map[mal_node.get_host_IP()] + ' python ' + DST_SCRIPT_FOLDER + 'scapy_packet_gen.py ' \
               + victim_ip + " " + intf_name
         send_mininet_cmd_to_cluster_node(mal_node.get_cluster_IP(), cmd, self.ssh_chan_map)
コード例 #6
0
 def setup_sniffer(self, sniffer_list):
     for sniffer in sniffer_list:
         victim_node = sniffer[0]
         victim_ip   = sniffer[1]
         intf_name = self.host_map[victim_ip] + "-eth0"
         cmd = self.host_map[victim_ip] + ' python ' + DST_SCRIPT_FOLDER + 'port_sniffer.py ' + victim_ip + \
               " " + intf_name
         send_mininet_cmd_to_cluster_node(victim_node.get_cluster_IP(), cmd, self.ssh_chan_map)
コード例 #7
0
    def do_startworm(self, args):
        hosts = args.split()

        for host in hosts:
            if self.is_hostname(host):

                cmd = host + ' python ' + DST_SCRIPT_FOLDER + 'worm_instance.py ' + host + '-eth0' + ' &'
                #print cmd
                send_mininet_cmd_to_cluster_node(self.host_to_node_map[self.host_IP_map[host]],
                                                  cmd, self.ssh_chan_map, quite=False)
コード例 #8
0
ファイル: CLI_Director.py プロジェクト: ruacon35/nps
    def do_ifconfig(self, args):
        args = args.split()
        if len(args) != 1:
            print ("*** invalid number of arguments")
            return
        src = args[0]

        src = self.is_host_exist(src)
        if src == None:
            print ("No such src host")
            return
        cmd = src + " ifconfig"
        src_host = self.hosts[src]
        node = self.nodes[src_host["nodeIP"]]
        send_mininet_cmd_to_cluster_node(node, cmd, quite=False)
コード例 #9
0
ファイル: CLI_Director.py プロジェクト: ruacon35/nps
    def do_startworm(self, args):
        malware_hosts = args.split()

        for malware_host_name in malware_hosts:
            if self.is_hostname(malware_host_name):
                cmd = (
                    malware_host_name
                    + " python "
                    + DST_SCRIPT_FOLDER
                    + "worm_instance.py "
                    + malware_host_name
                    + "-eth0"
                    + " &"
                )
                # print cmd
                host = self.hosts[malware_host_name]
                node = self.nodes[host["nodeIP"]]
                send_mininet_cmd_to_cluster_node(node, cmd, quite=False)
コード例 #10
0
ファイル: CLI_Director.py プロジェクト: ruacon35/nps
    def do_setupsniffers(self, args):
        for host in self.hosts.values():
            cmd = (
                host["name"]
                + " python "
                + DST_SCRIPT_FOLDER
                + "port_sniffer.py "
                + host["name"]
                + "-eth0 "
                + DST_SCRIPT_FOLDER
                + INFECTED_HOSTS_FILENAME
                + " &"
            )
            print cmd

            # print(self.nodes)
            node = self.nodes[host["nodeIP"]]
            send_mininet_cmd_to_cluster_node(node, cmd, quite=True)
        print ("Finish setuping sniffers!")
コード例 #11
0
    def do_ifconfig(self, args):
        args = args.split()
        if len(args) != 1:
            print('*** invalid number of arguments')
            return
        src = args[0]

        if src not in self.host_IP_map.keys() and src not in self.host_IP_map.values():
            print('No such host')
            return

        if self.is_hostname(src):
            cmd = src + ' ifconfig'
        else:
            cmd = self.host_map[src] + ' ifconfig'
        if self.is_hostname(src):
            send_mininet_cmd_to_cluster_node(self.host_to_node_map[self.host_IP_map[src]], cmd,
                                             self.ssh_chan_map, quite=False)
        else:
            send_mininet_cmd_to_cluster_node(self.host_to_node_map[src], cmd, self.ssh_chan_map, quite=False)
コード例 #12
0
def host_process_configurator_nodegroup(node_IP, node_groups, node_IP_gr_map, node_IP_pool_map, CIDR_mask, leaves,
                                        host_to_node_map, host_map, host_IP_map, ssh_chan_map):
    '''Configurate hosts propcesses network interfaces in each nodegroup.

    Args:
        node_IP: IP address of node.
        node_groups: Group ID to Group node-list map.
        node_IP_gr_map: Node IP address to Group ID map.
        node_IP_pool_map: Cluster Node to pool of IP addresses map.
        CIDR_mask: CIRD mask of IP address for host network interface.
        leaves: List of leave-nodes in network graph.
        host_to_node_map: Host IP to node IP map.
        host_map: Host IP to host name map.
        host_IP_map: Host name to host IP map.
        ssh_chan_map: SSH session chan to cluster node map.
    '''
    # curr_host = first_host
    first_host_ip = node_IP_pool_map[node_IP]
    curr_host_ip = first_host_ip
    node_group = node_groups[node_IP_gr_map[node_IP]]
    for node in node_group:
        if node in leaves:
            # reset config on host interface
            curr_host = 'h' + str(node)
            cmd = curr_host + ' ifconfig ' + curr_host + '-eth0 0'
            send_mininet_cmd_to_cluster_node(node_IP, cmd, ssh_chan_map)
            # config new IP address on host interface
            cmd = curr_host + ' ifconfig ' + curr_host + '-eth0 ' + curr_host_ip + '/' + CIDR_mask
            send_mininet_cmd_to_cluster_node(node_IP, cmd, ssh_chan_map)
            host_to_node_map[curr_host_ip] = node_IP
            host_map[curr_host_ip] = curr_host
            host_IP_map[curr_host] = curr_host_ip
            if MALWARE_PROPAGATION_MODE:
                malware_list_semaphore.acquire()
                malware_director.add_malware_node(curr_host_ip, node_IP, True,
                                                  randomize_infected(MALWARE_INIT_INF_PROB))
                malware_list_semaphore.release()
            # prepare for next host
            curr_host_ip = get_next_IP(curr_host_ip)