Beispiel #1
0
    def test_wiwo_info_response_frame_fail(self):
        """
        Getting the iface info of the Wiwo Info Response frame shouldn't return the same info that was defined on the
        info dictionary.
        """
        info = {"iface": "wlan0",
                "protocol": "IEEE 802.11g",
                "channels": "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e",
                "channel": "\x01"}

        frame_buffer = "\x00\x11\x22\x33\x44\x55" \
                       "\x00\xde\xad\xbe\xef\x00" \
                       "\xfa\xfa" \
                       + chr(WiwoInfoResponseFrame.frametype) \
                       + "%s%s" % (struct.pack("B", len(info["iface"])), info["iface"]) \
                       + "%s%s" % (struct.pack("B", len(info["protocol"])), info["protocol"]) \
                       + "%s%s" % (struct.pack("B", len(info["channels"])), info["channels"]) \
                       + "%s" % info["channel"]
        eth = Ethernet(frame_buffer)
        data = frame_buffer[eth.get_header_size():]
        wf = WiwoFrame(data)
        if wf.get_type() == WiwoInfoResponseFrame.frametype:
            wirf = WiwoInfoResponseFrame(wf.get_body_as_string())
            ifaces = wirf.get_interfaces()
            for iface in ifaces:
                self.assertNotEqual(0, iface.get_iface_len())
                self.assertNotEqual("wlan1", iface.get_iface_as_string())
                self.assertNotEqual(0, iface.get_protocol_len())
                self.assertNotEqual("IEEE 802.3", iface.get_protocol_as_string())
                self.assertNotEqual(0, iface.get_channels_count())
                self.assertNotEqual(array.array("b", "\x00\x01"), iface.get_channels())
                self.assertNotEqual(14, iface.get_channel())
Beispiel #2
0
    def test_wiwo_info_response_multiple_interfaces_frame_success(self):
        """
        Getting the iface info of the Wiwo Info Response frame should return the same info that was defined on the info
        dictionary.
        """
        info_1 = {
            "iface": "wlan1",
            "protocol": "IEEE 802.11an",
            "channels": "\x24\x28\x2c\x30\x34\x38\x3c\x40\x95\x99\x9d\xa1\xa5",
            "channel": "\x24"
        }
        info_2 = {
            "iface": "wlan0",
            "protocol": "IEEE 802.11g",
            "channels":
            "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e",
            "channel": "\x01"
        }

        frame_buffer = "\x00\x11\x22\x33\x44\x55" \
                       "\x00\xde\xad\xbe\xef\x00" \
                       "\xfa\xfa" \
                       + chr(WiwoInfoResponseFrame.frametype) \
                       + "%s%s" % (struct.pack("B", len(info_1["iface"])), info_1["iface"]) \
                       + "%s%s" % (struct.pack("B", len(info_1["protocol"])), info_1["protocol"]) \
                       + "%s%s" % (struct.pack("B", len(info_1["channels"])), info_1["channels"]) \
                       + "%s" % info_1["channel"] \
                       + "%s%s" % (struct.pack("B", len(info_2["iface"])), info_2["iface"]) \
                       + "%s%s" % (struct.pack("B", len(info_2["protocol"])), info_2["protocol"]) \
                       + "%s%s" % (struct.pack("B", len(info_2["channels"])), info_2["channels"]) \
                       + "%s" % info_2["channel"]
        eth = Ethernet(frame_buffer)
        data = frame_buffer[eth.get_header_size():]
        wf = WiwoFrame(data)
        if wf.get_type() == WiwoInfoResponseFrame.frametype:
            wirf = WiwoInfoResponseFrame(wf.get_body_as_string())
            ifaces = wirf.get_interfaces()
            self.assertEqual(len(info_1["iface"]), ifaces[0].get_iface_len())
            self.assertEqual(info_1["iface"], ifaces[0].get_iface_as_string())
            self.assertEqual(len(info_1["protocol"]),
                             ifaces[0].get_protocol_len())
            self.assertEqual(info_1["protocol"],
                             ifaces[0].get_protocol_as_string())
            self.assertEqual(len(info_1["channels"]),
                             ifaces[0].get_channels_count())
            self.assertEqual(array.array("B", info_1["channels"]),
                             ifaces[0].get_channels())
            self.assertEqual(len(info_2["iface"]), ifaces[1].get_iface_len())
            self.assertEqual(info_2["iface"], ifaces[1].get_iface_as_string())
            self.assertEqual(len(info_2["protocol"]),
                             ifaces[1].get_protocol_len())
            self.assertEqual(info_2["protocol"],
                             ifaces[1].get_protocol_as_string())
            self.assertEqual(len(info_2["channels"]),
                             ifaces[1].get_channels_count())
            self.assertEqual(array.array("B", info_2["channels"]),
                             ifaces[1].get_channels())
Beispiel #3
0
 def test_wiwo_info_request_frame_type_success(self):
     """
     Getting the type of a Wiwo Info Request frame should return a Wiwo Info Request frame type.
     """
     frame_buffer = "\x00\x11\x22\x33\x44\x55" \
                    "\x00\xde\xad\xbe\xef\x00" \
                    "\xfa\xfa" \
                    + chr(WiwoInfoRequestFrame.frametype)
     eth = Ethernet(frame_buffer)
     data = frame_buffer[eth.get_header_size():]
     wf = WiwoFrame(data)
     self.assertEqual(WiwoInfoRequestFrame.frametype, wf.get_type())
Beispiel #4
0
 def test_wiwo_frame_get_type_fail(self):
     """
     Getting the type of a Wiwo ACK frame shouldn't return a Wiwo Error frame type.
     """
     frame_buffer = "\x00\x11\x22\x33\x44\x55" \
                    "\x00\xde\xad\xbe\xef\x00" \
                    "\xfa\xfa" \
                    + chr(WiwoAckFrame.frametype)
     eth = Ethernet(frame_buffer)
     data = frame_buffer[eth.get_header_size():]
     wf = WiwoFrame(data)
     self.assertNotEqual(WiwoErrorFrame.frametype, wf.get_type())
Beispiel #5
0
 def test_wiwo_info_request_frame_type_success(self):
     """
     Getting the type of a Wiwo Info Request frame should return a Wiwo Info Request frame type.
     """
     frame_buffer = "\x00\x11\x22\x33\x44\x55" \
                    "\x00\xde\xad\xbe\xef\x00" \
                    "\xfa\xfa" \
                    + chr(WiwoInfoRequestFrame.frametype)
     eth = Ethernet(frame_buffer)
     data = frame_buffer[eth.get_header_size():]
     wf = WiwoFrame(data)
     self.assertEqual(WiwoInfoRequestFrame.frametype, wf.get_type())
Beispiel #6
0
 def test_wiwo_frame_get_type_fail(self):
     """
     Getting the type of a Wiwo ACK frame shouldn't return a Wiwo Error frame type.
     """
     frame_buffer = "\x00\x11\x22\x33\x44\x55" \
                    "\x00\xde\xad\xbe\xef\x00" \
                    "\xfa\xfa" \
                    + chr(WiwoAckFrame.frametype)
     eth = Ethernet(frame_buffer)
     data = frame_buffer[eth.get_header_size():]
     wf = WiwoFrame(data)
     self.assertNotEqual(WiwoErrorFrame.frametype, wf.get_type())
Beispiel #7
0
 def test_wiwo_error_frame_fail(self):
     """
     Getting the message of the Wiwo Error frame shouldn't return the same message that was defined on error_msg.
     """
     error_msg = "Error message."
     frame_buffer = "\x00\x11\x22\x33\x44\x55" \
                    "\x00\xde\xad\xbe\xef\x00" \
                    "\xfa\xfa" \
                    + chr(WiwoErrorFrame.frametype) \
                    + error_msg
     eth = Ethernet(frame_buffer)
     data = frame_buffer[eth.get_header_size():]
     wf = WiwoFrame(data)
     if wf.get_type() == WiwoErrorFrame.frametype:
         wef = WiwoErrorFrame(wf.get_body_as_string())
         self.assertNotEqual("fafa", wef.get_msg_as_string())
Beispiel #8
0
 def test_wiwo_data_frame_fail(self):
     """
     Getting the data of the Wiwo Data frame shouldn't return the same data that was defined on frame_data.
     """
     frame_data = "\x00\x01\x02\x03\x04\x05"
     frame_buffer = "\x00\x11\x22\x33\x44\x55" \
                    "\x00\xde\xad\xbe\xef\x00" \
                    "\xfa\xfa" \
                    + chr(WiwoDataFrame.frametype) \
                    + frame_data
     eth = Ethernet(frame_buffer)
     data = frame_buffer[eth.get_header_size():]
     wf = WiwoFrame(data)
     if wf.get_type() == WiwoDataFrame.frametype:
         wdf = WiwoDataFrame(wf.get_body_as_string())
         self.assertNotEqual("\x00\x02\x05\x06", wdf.get_data_as_string())
Beispiel #9
0
 def test_wiwo_error_frame_fail(self):
     """
     Getting the message of the Wiwo Error frame shouldn't return the same message that was defined on error_msg.
     """
     error_msg = "Error message."
     frame_buffer = "\x00\x11\x22\x33\x44\x55" \
                    "\x00\xde\xad\xbe\xef\x00" \
                    "\xfa\xfa" \
                    + chr(WiwoErrorFrame.frametype) \
                    + error_msg
     eth = Ethernet(frame_buffer)
     data = frame_buffer[eth.get_header_size():]
     wf = WiwoFrame(data)
     if wf.get_type() == WiwoErrorFrame.frametype:
         wef = WiwoErrorFrame(wf.get_body_as_string())
         self.assertNotEqual("fafa", wef.get_msg_as_string())
Beispiel #10
0
 def test_wiwo_data_frame_fail(self):
     """
     Getting the data of the Wiwo Data frame shouldn't return the same data that was defined on frame_data.
     """
     frame_data = "\x00\x01\x02\x03\x04\x05"
     frame_buffer = "\x00\x11\x22\x33\x44\x55" \
                    "\x00\xde\xad\xbe\xef\x00" \
                    "\xfa\xfa" \
                    + chr(WiwoDataFrame.frametype) \
                    + frame_data
     eth = Ethernet(frame_buffer)
     data = frame_buffer[eth.get_header_size():]
     wf = WiwoFrame(data)
     if wf.get_type() == WiwoDataFrame.frametype:
         wdf = WiwoDataFrame(wf.get_body_as_string())
         self.assertNotEqual("\x00\x02\x05\x06", wdf.get_data_as_string())
Beispiel #11
0
    def test_wiwo_info_response_multiple_interfaces_frame_success(self):
        """
        Getting the iface info of the Wiwo Info Response frame should return the same info that was defined on the info
        dictionary.
        """
        info_1 = {"iface": "wlan1",
                  "protocol": "IEEE 802.11an",
                  "channels": "\x24\x28\x2c\x30\x34\x38\x3c\x40\x95\x99\x9d\xa1\xa5",
                  "channel": "\x24"}
        info_2 = {"iface": "wlan0",
                  "protocol": "IEEE 802.11g",
                  "channels": "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e",
                  "channel": "\x01"}

        frame_buffer = "\x00\x11\x22\x33\x44\x55" \
                       "\x00\xde\xad\xbe\xef\x00" \
                       "\xfa\xfa" \
                       + chr(WiwoInfoResponseFrame.frametype) \
                       + "%s%s" % (struct.pack("B", len(info_1["iface"])), info_1["iface"]) \
                       + "%s%s" % (struct.pack("B", len(info_1["protocol"])), info_1["protocol"]) \
                       + "%s%s" % (struct.pack("B", len(info_1["channels"])), info_1["channels"]) \
                       + "%s" % info_1["channel"] \
                       + "%s%s" % (struct.pack("B", len(info_2["iface"])), info_2["iface"]) \
                       + "%s%s" % (struct.pack("B", len(info_2["protocol"])), info_2["protocol"]) \
                       + "%s%s" % (struct.pack("B", len(info_2["channels"])), info_2["channels"]) \
                       + "%s" % info_2["channel"]
        eth = Ethernet(frame_buffer)
        data = frame_buffer[eth.get_header_size():]
        wf = WiwoFrame(data)
        if wf.get_type() == WiwoInfoResponseFrame.frametype:
            wirf = WiwoInfoResponseFrame(wf.get_body_as_string())
            ifaces = wirf.get_interfaces()
            self.assertEqual(len(info_1["iface"]), ifaces[0].get_iface_len())
            self.assertEqual(info_1["iface"], ifaces[0].get_iface_as_string())
            self.assertEqual(len(info_1["protocol"]), ifaces[0].get_protocol_len())
            self.assertEqual(info_1["protocol"], ifaces[0].get_protocol_as_string())
            self.assertEqual(len(info_1["channels"]), ifaces[0].get_channels_count())
            self.assertEqual(array.array("B", info_1["channels"]), ifaces[0].get_channels())
            self.assertEqual(len(info_2["iface"]), ifaces[1].get_iface_len())
            self.assertEqual(info_2["iface"], ifaces[1].get_iface_as_string())
            self.assertEqual(len(info_2["protocol"]), ifaces[1].get_protocol_len())
            self.assertEqual(info_2["protocol"], ifaces[1].get_protocol_as_string())
            self.assertEqual(len(info_2["channels"]), ifaces[1].get_channels_count())
            self.assertEqual(array.array("B", info_2["channels"]), ifaces[1].get_channels())
Beispiel #12
0
 def test_wiwo_data_fragment_frame_fail(self):
     """
     Getting the data of the Wiwo Data frame shouldn't return the same data that was defined on frame_data.
     """
     frame_data = "\x00\x01\x02" + ("\xff" * 1400)
     frame_buffer = "\x00\x11\x22\x33\x44\x55" \
                    "\x00\xde\xad\xbe\xef\x00" \
                    "\xfa\xfa" \
                    + chr(WiwoDataFragmentFrame.frametype) \
                    + "\x82" \
                    + frame_data
     eth = Ethernet(frame_buffer)
     data = frame_buffer[eth.get_header_size():]
     wf = WiwoFrame(data)
     if wf.get_type() == WiwoDataFragmentFrame.frametype:
         wdff = WiwoDataFragmentFrame(wf.get_body_as_string())
         self.assertNotEqual(1, wdff.get_sequence_number())
         self.assertNotEqual(False, wdff.is_last_fragment())
         self.assertNotEqual("\x00" * 1400, wdff.get_data_as_string())
Beispiel #13
0
 def test_wiwo_data_fragment_frame_fail(self):
     """
     Getting the data of the Wiwo Data frame shouldn't return the same data that was defined on frame_data.
     """
     frame_data = "\x00\x01\x02" + ("\xff" * 1400)
     frame_buffer = "\x00\x11\x22\x33\x44\x55" \
                    "\x00\xde\xad\xbe\xef\x00" \
                    "\xfa\xfa" \
                    + chr(WiwoDataFragmentFrame.frametype) \
                    + "\x82" \
                    + frame_data
     eth = Ethernet(frame_buffer)
     data = frame_buffer[eth.get_header_size():]
     wf = WiwoFrame(data)
     if wf.get_type() == WiwoDataFragmentFrame.frametype:
         wdff = WiwoDataFragmentFrame(wf.get_body_as_string())
         self.assertNotEqual(1, wdff.get_sequence_number())
         self.assertNotEqual(False, wdff.is_last_fragment())
         self.assertNotEqual("\x00" * 1400, wdff.get_data_as_string())
Beispiel #14
0
 def test_wiwo_data_fragment_frame_fail(self):
     """
     Getting the data of the Wiwo Data Inject frame shouldn't return the same data that was defined on frame_data.
     """
     iface = "wlan0"
     frame_data = "\xff" * 1400
     frame_buffer = "\x00\x11\x22\x33\x44\x55" \
                    "\x00\xde\xad\xbe\xef\x00" \
                    "\xfa\xfa" \
                    + chr(WiwoDataInjectFrame.frametype) \
                    + "%s%s" % (struct.pack("B", len(iface)), iface) \
                    + frame_data
     eth = Ethernet(frame_buffer)
     data = frame_buffer[eth.get_header_size():]
     wf = WiwoFrame(data)
     if wf.get_type() == WiwoDataInjectFrame.frametype:
         wdif = WiwoDataInjectFrame(wf.get_body_as_string())
         self.assertNotEqual(0, wdif.get_iface_len())
         self.assertNotEqual("wlan1", wdif.get_iface_as_string())
         self.assertNotEqual("\x00" * 1400, wdif.get_data_as_string())
Beispiel #15
0
 def test_wiwo_set_channel_frame_fail(self):
     """
     Getting the iface and channel of the Wiwo Set Channel frame shouldn't return the same info that was defined on
     the frame buffer.
     """
     info = {"iface": "wlan0", "channel": 1}
     frame_buffer = "\x00\x11\x22\x33\x44\x55" \
                    "\x00\xde\xad\xbe\xef\x00" \
                    "\xfa\xfa" \
                    + chr(WiwoSetChannelFrame.frametype) \
                    + "%s%s" % (struct.pack("B", len(info["iface"])), info["iface"]) \
                    + "%s" % struct.pack("B", info["channel"])
     eth = Ethernet(frame_buffer)
     data = frame_buffer[eth.get_header_size():]
     wf = WiwoFrame(data)
     if wf.get_type() == WiwoSetChannelFrame.frametype:
         wscf = WiwoSetChannelFrame(wf.get_body_as_string())
         self.assertNotEqual(0, wscf.get_iface_len())
         self.assertNotEqual("wlan1", wscf.get_iface_as_string())
         self.assertNotEqual(14, wscf.get_channel())
Beispiel #16
0
 def test_wiwo_set_channel_frame_fail(self):
     """
     Getting the iface and channel of the Wiwo Set Channel frame shouldn't return the same info that was defined on
     the frame buffer.
     """
     info = {"iface": "wlan0", "channel": 1}
     frame_buffer = "\x00\x11\x22\x33\x44\x55" \
                    "\x00\xde\xad\xbe\xef\x00" \
                    "\xfa\xfa" \
                    + chr(WiwoSetChannelFrame.frametype) \
                    + "%s%s" % (struct.pack("B", len(info["iface"])), info["iface"]) \
                    + "%s" % struct.pack("B", info["channel"])
     eth = Ethernet(frame_buffer)
     data = frame_buffer[eth.get_header_size():]
     wf = WiwoFrame(data)
     if wf.get_type() == WiwoSetChannelFrame.frametype:
         wscf = WiwoSetChannelFrame(wf.get_body_as_string())
         self.assertNotEqual(0, wscf.get_iface_len())
         self.assertNotEqual("wlan1", wscf.get_iface_as_string())
         self.assertNotEqual(14, wscf.get_channel())
Beispiel #17
0
 def test_wiwo_data_fragment_frame_fail(self):
     """
     Getting the data of the Wiwo Data Inject frame shouldn't return the same data that was defined on frame_data.
     """
     iface = "wlan0"
     frame_data = "\xff" * 1400
     frame_buffer = "\x00\x11\x22\x33\x44\x55" \
                    "\x00\xde\xad\xbe\xef\x00" \
                    "\xfa\xfa" \
                    + chr(WiwoDataInjectFrame.frametype) \
                    + "%s%s" % (struct.pack("B", len(iface)), iface) \
                    + frame_data
     eth = Ethernet(frame_buffer)
     data = frame_buffer[eth.get_header_size():]
     wf = WiwoFrame(data)
     if wf.get_type() == WiwoDataInjectFrame.frametype:
         wdif = WiwoDataInjectFrame(wf.get_body_as_string())
         self.assertNotEqual(0, wdif.get_iface_len())
         self.assertNotEqual("wlan1", wdif.get_iface_as_string())
         self.assertNotEqual("\x00" * 1400, wdif.get_data_as_string())
Beispiel #18
0
 def test_wiwo_start_frame_fail(self):
     """
     Getting the iface and bpf filter of the Wiwo Set Channel frame shouldn't return the same info that was defined
     on the frame buffer.
     """
     info = {"iface": "wlan0", "filter": "ip and (tcp port 80 or tcp port 443)"}
     frame_buffer = "\x00\x11\x22\x33\x44\x55" \
                    "\x00\xde\xad\xbe\xef\x00" \
                    "\xfa\xfa" \
                    + chr(WiwoStartFrame.frametype) \
                    + "%s%s" % (struct.pack("B", len(info["iface"])), info["iface"]) \
                    + "%s%s" % (struct.pack("!H", len(info["filter"])), info["filter"])
     eth = Ethernet(frame_buffer)
     data = frame_buffer[eth.get_header_size():]
     wf = WiwoFrame(data)
     if wf.get_type() == WiwoStartFrame.frametype:
         wsf = WiwoStartFrame(wf.get_body_as_string())
         self.assertNotEqual(0, wsf.get_iface_len())
         self.assertNotEqual("wlan1", wsf.get_iface_as_string())
         self.assertNotEqual(0, wsf.get_filter_len())
         self.assertNotEqual("udp port 69", wsf.get_filter_as_string())
Beispiel #19
0
    def test_wiwo_info_response_frame_fail(self):
        """
        Getting the iface info of the Wiwo Info Response frame shouldn't return the same info that was defined on the
        info dictionary.
        """
        info = {
            "iface": "wlan0",
            "protocol": "IEEE 802.11g",
            "channels":
            "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e",
            "channel": "\x01"
        }

        frame_buffer = "\x00\x11\x22\x33\x44\x55" \
                       "\x00\xde\xad\xbe\xef\x00" \
                       "\xfa\xfa" \
                       + chr(WiwoInfoResponseFrame.frametype) \
                       + "%s%s" % (struct.pack("B", len(info["iface"])), info["iface"]) \
                       + "%s%s" % (struct.pack("B", len(info["protocol"])), info["protocol"]) \
                       + "%s%s" % (struct.pack("B", len(info["channels"])), info["channels"]) \
                       + "%s" % info["channel"]
        eth = Ethernet(frame_buffer)
        data = frame_buffer[eth.get_header_size():]
        wf = WiwoFrame(data)
        if wf.get_type() == WiwoInfoResponseFrame.frametype:
            wirf = WiwoInfoResponseFrame(wf.get_body_as_string())
            ifaces = wirf.get_interfaces()
            for iface in ifaces:
                self.assertNotEqual(0, iface.get_iface_len())
                self.assertNotEqual("wlan1", iface.get_iface_as_string())
                self.assertNotEqual(0, iface.get_protocol_len())
                self.assertNotEqual("IEEE 802.3",
                                    iface.get_protocol_as_string())
                self.assertNotEqual(0, iface.get_channels_count())
                self.assertNotEqual(array.array("b", "\x00\x01"),
                                    iface.get_channels())
                self.assertNotEqual(14, iface.get_channel())
Beispiel #20
0
 def test_wiwo_start_frame_fail(self):
     """
     Getting the iface and bpf filter of the Wiwo Set Channel frame shouldn't return the same info that was defined
     on the frame buffer.
     """
     info = {
         "iface": "wlan0",
         "filter": "ip and (tcp port 80 or tcp port 443)"
     }
     frame_buffer = "\x00\x11\x22\x33\x44\x55" \
                    "\x00\xde\xad\xbe\xef\x00" \
                    "\xfa\xfa" \
                    + chr(WiwoStartFrame.frametype) \
                    + "%s%s" % (struct.pack("B", len(info["iface"])), info["iface"]) \
                    + "%s%s" % (struct.pack("!H", len(info["filter"])), info["filter"])
     eth = Ethernet(frame_buffer)
     data = frame_buffer[eth.get_header_size():]
     wf = WiwoFrame(data)
     if wf.get_type() == WiwoStartFrame.frametype:
         wsf = WiwoStartFrame(wf.get_body_as_string())
         self.assertNotEqual(0, wsf.get_iface_len())
         self.assertNotEqual("wlan1", wsf.get_iface_as_string())
         self.assertNotEqual(0, wsf.get_filter_len())
         self.assertNotEqual("udp port 69", wsf.get_filter_as_string())