Commits

Joshua Bonsink committed a04e38b

Improved ddos flooding in all modes

Comments (0)

Files changed (8)

         except ValueError:
             print 'Pickle error'  
             return
-                
-        self.logger.debug('event_name will be triggered: ' + unpickled.event)        
+        
         self.trigger(unpickled.event, sock, unpickled)
 
     def install(self, node):

core/nodes/client.py

         return self.desc.server_port
 
     def request_connect(self):
-        """Request a connection to the server."""
+        """Request a connection to the server."""        
         sock = self.node.create_sock({'type':'server', 'proto':'tcp'})
         self.sock = sock
         if self.node.NODE_TYPE.startswith('real'):

core/nodes/server.py

         self.srv_sock = self.node.create_sock({'type':'server', 'proto':'tcp'})
         self.node.bind(self.srv_sock, (self.addr, self.port))
         self.node.listen(self.srv_sock, 5)
-
+                
         if self.node.NODE_TYPE.startswith('real'):
             while True:
-                client_sock, address = self.node.accept(self.srv_sock)
+                client_sock, address = self.node.accept(self.srv_sock)                
                 self.trigger('recv_request_conn', client_sock, address)
         elif self.node.NODE_TYPE.startswith('sim'):
             self.sim_node_init()
             self.node.send(client_sock, jsonpickle.encode(new_data))
     
     def forward_to_bots(self, sock, data):
-        """Forward data to all the bots"""
+        """Forward data to all the bots"""        
         self.logger.info('start to echo_bots' )
         new_data = copy.deepcopy(data)
         new_data.event = data.bot_event
         del new_data.bot_event
+        
         for client_sock in self.node.client_socks:            
             self.node.send(client_sock, jsonpickle.encode(new_data))
             

core/ns3/experiment/experiment.py

         scenario_ops = get_availabe_scenarios()
         parser.add_option('-s', '--scenario', dest="scenario",
                 default='ddos_ping_flooding',
-                help='specify the scenario you want to execute. Scenearios availiable are: %s'%(scenario_ops),
+                help='specify the scenario you want to execute. Scenarios available are: %s'%(scenario_ops),
                 )
 
     def _init(self): pass
         BOTMASTER_DESC = scen.config.Botmaster()
         SERVER_DESC = scen.config.Server()
         CLIENT_DESC = scen.config.Client()
+        
+        #When in netns3 mode set a node in the network as the target of the attack        
+        if self.target_id is not None:
+            if self.get_node(self.target_id).NODE_TYPE == 'sim_ns3':
+                target_ip = self.get_node(self.target_id).GetObject(ns3.TypeId.LookupByName("ns3::Ipv4")).GetAddress(1, 0).GetLocal()            
+                BOTMASTER_DESC.command.hostname = str(target_ip)
+            elif self.get_node(self.target_id).NODE_TYPE == 'real_ns3':
+                BOTMASTER_DESC.command.hostname = BOTMASTER_DESC.server_address
+        
         if srv_addr is not None:
             BOTMASTER_DESC.server_address = srv_addr
             SERVER_DESC.server_address = srv_addr
-            CLIENT_DESC.server_address = srv_addr
-        
+            CLIENT_DESC.server_address = srv_addr     
+         
+        print BOTMASTER_DESC.command.hostname
+               
         for i in xrange(self.node_num):
             if i in self.botmaster_id_set:
                 cmd = scen.BotMaster(BOTMASTER_DESC)
     def get_server_addr(self):
         """The all the server address"""
         addr_set = []
-        # print 'self.server_id_set', self.server_id_set
-        # for i in [0, 1, 2, 3, 4, 5]:
-            # ipv4Addr = self.get_node(i).GetObject(ns3.TypeId.LookupByName("ns3::Ipv4")).GetAddress(1, 0)
-            # print str(ipv4Addr.GetLocal())
-
         for i in self.server_id_set:
             ipv4Addr = self.get_node(i).GetObject(ns3.TypeId.LookupByName("ns3::Ipv4")).GetAddress(1, 0)
             addr_set.append(ipv4Addr)

core/ns3/node/imalse_netns_node.py

         NetnsNode.__init__(self, *args, **kwargs)
         PhysicalNode.__init__(self)
 
-    def ping(self, sock, data, threaded=False):
-        dst = data['hostname'][0]
-        count = 3
-        cmd = ["ping", "-b", "-c", str(count), str(dst)]
+    def ping(self, sock, data, threaded):        
+        cmd = ["ping", "-b", "-c", str(data.num_packets), "-i", str(data.interval),\
+               "-l", str(data.preload), "-s", str(data.packet_size),\
+                data.hostname]
         print "%s: %s" % (self.name, " ".join(cmd))
+        
         p, stdin, stdout, stderr = self.popen(cmd)
         err = stderr.read()
         out = stdout.read()

core/ns3/node/imalse_netns_sim_node.py

+import jsonpickle
+
 from core.nodes.base_node import BaseNode
 import ns3
 
         cmd.dispatcher()
         """
         print 'dispatcher'
-#FIXME this function was not exculated in pure simulation mode
-        # if self.name == "sim_n%s" %(2):
-            # import pdb;pdb.set_trace()
-
+        
         _from = ns3.Address()
         packet = sock.RecvFrom (_from)
-        # import pdb;pdb.set_trace()
+
         try:
             msg = self.get_msg(packet)
         except:
-            self.logger.error('Probably you are not using NS3 with imalse customaization?' +
-                    ' Use deprec API will suppport only very limitted msgs')
+            self.logger.error('Probably you are not using NS3 with imalse customization?' +
+                    ' Use deprec API will support only very limited msgs')
             msg = self.get_msg_deprec(packet)
-
+                
         self.logger.debug('Node [%s] has receive message %s from sock [%s] and node [%s]'%(self.name, msg, sock, _from) )
 
         if msg == 'connect_ack':
             self.logger.debug('Node [%s] call self.recv_ack s'%(self.name) )
             self.cmd_set.recv_ack()
         else:
-            self.logger.debug('Node [%s] call cmd_set.dispatcher'%(self.name) )
+            self.logger.debug('Node [%s] call cmd_set.dispatcher'%(self.name) )       
             self.cmd_set.dispatcher(sock, msg)
-
-        # self.recv(sock, 512, self.dispatcher)
-        self.after(0.1, self.recv, sock, 512, self.dispatcher)
-        # self.after(0, self.recv, sock, 512, self.dispatcher)
+                
+        self.after(0.1, self.recv, sock, 512, self.dispatcher)        
 
     def sleep(self, t, call_back=None):
         if call_back:
             # raise Exception('node [%s] cannot connect to server'%(self.name) )
         print 'node %s connected to server'%(self.name)
 
-        # self.recv(sock, 512, self.dispatcher)
-        # x = inetAddr.GetIpv4()
-        # from inspect import getmembers
-        # for a, b in getmembers(x): print a, b
-        # print sock
-        # print ns3.InetSocketAddress.IsMatchingType(inetAddr)
-        # ns3.TcpSocketFactory.GetTypeId()
-        # import pdb;pdb.set_trace()
-        # self.after(0, sock.Connect, inetAddr)
-        # import pdb;pdb.set_trace()
-
     @staticmethod
     def get_msg(p):
         """get message from the pacetk"""
         **Interval**: Wait interval seconds between sending each packet.
         **Size**: The number of data bytes to be sent, real packet will
                 be 8 (ICMP) + 20 (IP) bytes longer.
-        """
-        # print 'ImalseNetnsSimNode.ping: this is just a stub, please finish it'
-        print 'data, ', data
-        print 'here, '
-        remote = data.get('remote')[0]
-        remote_addr = ns3.Ipv4Address(remote)
-
-        helper = ns3.V4PingHelper(remote_addr)
-
-        start_time = data.get('start_time')[0]
-        stop_time = data.get('stop_time')[0]
-        helper.SetAttribute("StartTime", ns3.TimeValue(ns3.Time(str(start_time)+'s')))
-        helper.SetAttribute("StopTime", ns3.TimeValue(ns3.Time(str(stop_time)+'s')))
-
-       # helper.SetAttribute("Remote", ns3.AddressValue(remote_inet))
-
-        # interval = data.get('Interval')
-        # helper.SetAttribute("Interval", ns3.TimeValue(str(interval) + 's'))
+        """       
+        
+        remote_addr = ns3.Ipv4Address(data.hostname)
+        
+        helper = ns3.V4PingHelper(remote_addr)                      
+        helper.SetAttribute("Interval", ns3.TimeValue(ns3.Time(str(data.interval)+'s')))
+        helper.SetAttribute("Size", ns3.UintegerValue(data.packet_size))     
+        helper.SetAttribute("Verbose", ns3.BooleanValue(data.verbose))
+               
         helper.Install(self)

core/real/jedie_python_ping/ping.py

 ICMP_ECHO = 8 # Echo request (per RFC792)
 ICMP_MAX_RECV = 2048 # Max size of incoming buffer
 
-MAX_SLEEP = 1000
-
-
 def calculate_checksum(source_string):
     """
     A port of the functionality of in_cksum() from ping.c
 
     #--------------------------------------------------------------------------
 
-    def run(self, count=None, deadline=None):
+    def run(self, count=None, interval=1000, deadline=None):
         """
         send and receive pings in a loop. Stop if count or until deadline.
         """
                 delay = 0
 
             # Pause for the remainder of the MAX_SLEEP period (if applicable)
-            if (MAX_SLEEP > delay):
-                time.sleep((MAX_SLEEP - delay) / 1000.0)
+            if (interval > delay):
+                time.sleep((interval - delay) / 1000.0)
 
         self.print_exit()
 
             if timeout <= 0:
                 return None, 0, 0, 0, 0
 
-
-def verbose_ping(hostname, timeout=1000, count=3, packet_size=55):
+def verbose_ping(hostname, timeout=1000, packet_size=55, interval=1000, count = 0):    
     p = Ping(hostname, timeout, packet_size)
-    p.run(count)
-
-
+    p.run(count = count, interval = interval)
+    
 if __name__ == '__main__':
     # FIXME: Add a real CLI
     if len(sys.argv) == 1:

core/real/node.py

     def run(self):
         """Ping hosts based on the given parameters."""        
         verbose_ping(self.data.hostname, self.data.timeout,\
-                      self.data.num_pings, self.data.packet_size)
+                      self.data.packet_size, self.data.interval,\
+                      self.data.num_packets)
 
 class PhysicalNode(object):
     
         desc -- the address and port it tries to connect to and the type of 
                 the connection.
         
-        """
+        """       
         sock = socket.socket(socket.AF_INET, self.proto_map[desc['proto']])
         sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
         self.sockets[sock] = desc
     def accept(self, sock):
         """Accept a connection and add the socket to the 'client_sock" map."""
         assert( self.sockets[sock]['type'] == 'server')
-        client_sock, address = sock.accept()
+        client_sock, address = sock.accept()        
         self.sockets[client_sock] = {
                 'addr': address,
                 'type':'client'
         Send data to the socket. The destination socket is specified
         by the address.
         
-        """
+        """        
         sock.sendto(data, (addr, port))
 
     def close_socks(self, socket_ids):
             self.pings[sock] = ping_th
             ping_th.run()
         else:            
-            verbose_ping(data.hostname, data.timeout, data.num_pings, data.packet_size)
+            verbose_ping(data.hostname, data.timeout, data.packet_size, data.interval, data.num_packets)
 
     def ftp_upload(self, data, host, user, password):
         """Upload data to a ftp sever"""