Exemple #1
0
 def test_blank_header_creation(self):
     """Verifies it generates the correct header (no checksum) given packet data"""
     packet = icmp.ICMP(icmp.Types.EchoRequest, payload='random text goes here', identifier=16)
     self.assertEqual(packet._header(), b'\x08\x00\x00\x00\x00\x10\x00\x01',
                      'Blank header creation failed (without checksum)')
     packet = icmp.ICMP(icmp.Types.EchoReply, payload='foo', identifier=11)
     self.assertEqual(packet._header(), b'\x00\x00\x00\x00\x00\x0b\x00\x01',
                      'Blank header creation failed (without checksum)')
 def test_checksum_creation(self):
     """Verifies it generates the correct checksum, given packet data"""
     packet = icmp.ICMP(icmp.Types.EchoRequest,
                        payload='random text goes here',
                        identifier=16)
     self.assertEqual(packet.expected_checksum, 485,
                      'Checksum creation failed')
     packet = icmp.ICMP(icmp.Types.EchoReply,
                        payload='foobar',
                        identifier=11)
     self.assertEqual(packet.expected_checksum, 48060,
                      'Checksum creation failed')
Exemple #3
0
    def craft_response_of_type(response_type):
        """Generates an executor.Response from an icmp.Types

        :param response_type: Type of response
        :type response_type: Union[icmp.Type, tuple]
        :return: The crafted response
        :rtype: executor.Response"""
        return executor.Response(executor.Message('', icmp.ICMP(response_type), '127.0.0.1'), 0.1)
Exemple #4
0
 def test_pack(self):
     """Verifies that creates the correct pack"""
     self.assertEqual(
         icmp.ICMP(icmp.Types.EchoReply, payload='banana', identifier=19700).packet,
         b'\x00\x00s\xe6L\xf4\x00\x01banana',
         "Fail to pack ICMP structure to packet"
     )
     self.assertEqual(
         icmp.ICMP(icmp.Types.EchoReply, payload='random text goes here', identifier=12436).packet,
         b'\x00\x00\xcdl0\x94\x00\x01random text goes here',
         "Fail to pack ICMP structure to packet"
     )
     self.assertEqual(
         icmp.ICMP(icmp.Types.EchoRequest, payload='random text goes here', identifier=18676).packet,
         b'\x08\x00\xad\x0cH\xf4\x00\x01random text goes here',
         "Fail to unpack ICMP structure to packet"
     )
 def test_pack(self):
     """Verifies that creates the correct pack"""
     self.assertEqual(
         icmp.ICMP(icmp.Types.EchoReply, payload='banana',
                   identifier=19700).packet,
         b'\x00\x00\xcb\x8e\xf4L\x01\x00banana',
         "Fail to pack ICMP structure to packet")
     self.assertEqual(
         icmp.ICMP(icmp.Types.EchoReply,
                   payload='random text goes here',
                   identifier=12436).packet,
         b'\x00\x00h\xd1\x940\x01\x00random text goes here',
         "Fail to pack ICMP structure to packet")
     self.assertEqual(
         icmp.ICMP(icmp.Types.EchoRequest,
                   payload='random text goes here',
                   identifier=18676).packet,
         b'\x08\x00\x00\xb9\xf4H\x01\x00random text goes here',
         "Fail to unpack ICMP structure to packet")