Example #1
0
    def test_revports_udp(self):
        # use queue to communicate between threads
        # py.test doesn't catch assertions from threads by itself
        queue = Queue.Queue()

        th = SendPacket(umit.umpa.Packet(IP(), UDP(srcport=80, dstport=0)))
        th.start()
        
        th2 = RevPortsUDPThread("host 127.0.0.1 and port 80", "lo", queue)
        th2.start()
        models.react(1, filter="host 127.0.0.1 and port 80", device="lo",
                    revports=True)
        th.join()
        th2.join()
        if not queue.empty():
            err = queue.get()
            raise AssertionError(err)
        queue.join()
Example #2
0
    def test_revhosts(self):
        # use queue to communicate between threads
        # py.test doesn't catch assertions from threads by itself
        queue = Queue.Queue()

        th = SendPacket(umit.umpa.Packet(IP(src="67.205.14.183",
                                            dst="127.0.0.1")))
        th.start()
        
        th2 = RevHostsThread("host 67.205.14.183", "any", queue)
        th2.start()
        models.react(1, filter="host 67.205.14.183", device="any",
                    revhosts=True)
        th.join()
        th2.join()
        if not queue.empty():
            err = queue.get()
            raise AssertionError(err)
        queue.join()
Example #3
0
    def test_forward(self):
        # use queue to communicate between threads
        # py.test doesn't catch assertions from threads by itself
        queue = Queue.Queue()

        th = SendPacket(umit.umpa.Packet(IP(src="127.0.0.1", 
                        dst="67.205.14.183"), TCP(srcport=888)))
        th.start()
        
        th2 = ForwardThread(
                "host 127.0.0.1 and port 888 and tcp[tcpflags] == 0x0",
                "any", queue)
        th2.start()
        models.react(1,
            filter="host 67.205.14.183 and port 888 and tcp[tcpflags] == 0x0",
            device="any", forward="127.0.0.1")
        th.join()
        th2.join()
        if not queue.empty():
            err = queue.get()
            raise AssertionError(err)
        queue.join()
Example #4
0
        def _func(ttl, decrement):
            # use queue to communicate between threads
            # py.test doesn't catch assertions from threads by itself
            queue = Queue.Queue()

            th = SendPacket(umit.umpa.Packet(IP(src="127.0.0.1", dst="127.0.0.1", ttl=ttl),
                            TCP(srcport=888)))
            th.start()
            
            th2 = TTLThread(
                    "host 127.0.0.1 and port 888 and tcp[tcpflags] == 0x0",
                    "any", queue, begin=ttl, decrement=decrement)
            th2.start()
            models.react(1,
                filter="host 127.0.0.1 and port 888 and tcp[tcpflags] == 0x0",
                device="any",
                ttl=decrement)
            th.join()
            th2.join()
            if not queue.empty():
                err = queue.get()
                raise AssertionError(err)
            queue.join()
Example #5
0
    def __init__(self, packet, amount=1):
        super(SendPacket, self).__init__()
        self._packet = packet
        self._amount = amount

    def run(self):
        s = umit.umpa.Socket()
        for i in xrange(self._amount):
            time.sleep(2)
            s.send(self._packet)


packet = umit.umpa.Packet(IP(src="1.2.3.4", dst="127.0.0.1"), TCP(srcport=99), Payload(data="sniff me"))

# run thread and send 2 packets
th = SendPacket(packet, 2)
th.start()

# capture 2 packets and resend them with reverse src/dst ports
models.react(2, filter="host 1.2.3.4 and port 99", device="any", revports=True)

# collect terminated thread
th.join()


# do the same but resend it to a new destination
th = SendPacket(packet, 2)
th.start()
models.react(2, filter="host 1.2.3.4 and port 99", device="any", revports=True, forward="67.205.14.183")
th.join()
Example #6
0
    def run(self):
        s = umit.umpa.Socket()
        for i in xrange(self._amount):
            time.sleep(2)
            s.send(self._packet)


packet = umit.umpa.Packet(IP(src="1.2.3.4", dst="127.0.0.1"), TCP(srcport=99),
                          Payload(data="sniff me"))

# run thread and send 2 packets
th = SendPacket(packet, 2)
th.start()

# capture 2 packets and resend them with reverse src/dst ports
models.react(2, filter="host 1.2.3.4 and port 99", device="any", revports=True)

# collect terminated thread
th.join()

# do the same but resend it to a new destination
th = SendPacket(packet, 2)
th.start()
models.react(2,
             filter="host 1.2.3.4 and port 99",
             device="any",
             revports=True,
             forward="67.205.14.183")
th.join()