Exemple #1
0
    def write_req(self, handle, value):
        if self.receiver.isConnected():
            if utils.isHexadecimal(handle) and utils.isHexadecimal(value):
                self.emitter.sendp(
                    ble.BLEWriteRequest(handle=int(handle, 16),
                                        value=bytes.fromhex(value)))
                io.info("Write Request : handle = " + handle + " / value = " +
                        value)

                response = self.receiver.next(timeout=3)
                retry = 3
                while not (isinstance(response, ble.BLEWriteResponse)
                           or isinstance(response, ble.BLEErrorResponse)
                           or retry == 0):
                    response = self.receiver.next(timeout=1)
                    retry -= 1
                if isinstance(response, ble.BLEWriteResponse):
                    io.success("Response : success")
                elif isinstance(response, ble.BLEErrorResponse):
                    io.fail("Error response !")
                elif retry == 0:
                    io.fail("Timeout error !")
            else:
                io.fail(
                    "Handle or value is not correctly formatted (hexadecimal) !"
                )
        else:
            io.fail("No active connections !")
Exemple #2
0
    def run(self):
        interface = self.args["INTERFACE"]
        self.emitter = self.getEmitter(interface=interface)
        if self.checkCapabilities():
            if self.emitter.isConnected():
                self.emitter.sendp(ble.BLEDisconnect())
            while self.emitter.isConnected():
                utils.wait(seconds=0.01)
            address = (self.emitter.getAddress()
                       if self.args["ADVERTISING_ADDRESS"] == "" else
                       utils.addressArg(self.args["ADVERTISING_ADDRESS"]))
            if address != self.emitter.getAddress():
                self.emitter.setAddress(address)

            if utils.isHexadecimal(self.args["SCANNING_DATA"]):
                scanningData = bytes.fromhex(self.args["SCANNING_DATA"])
            else:
                scanningData = b""

            if utils.isHexadecimal(self.args["ADVERTISING_DATA"]):
                advertisingData = bytes.fromhex(self.args["ADVERTISING_DATA"])
            else:
                advertisingData = b""

            destAddress = ("00:00:00:00:00:00"
                           if self.args["DESTINATION_ADDRESS"] == "" else
                           utils.addressArg(self.args["DESTINATION_ADDRESS"]))

            intervalMin = utils.integerArg(self.args["INTERVAL_MIN"])
            intervalMax = utils.integerArg(self.args["INTERVAL_MAX"])

            advertisingType = self.args["ADVERTISING_TYPE"].upper()

            advertisingAddressType = "public" if self.args[
                "ADVERTISING_ADDRESS_TYPE"].lower() == "public" else "random"
            destinationAddressType = "public" if self.args[
                "DESTINATION_ADDRESS_TYPE"].lower() == "public" else "random"
            self.emitter.setScanningParameters(data=scanningData)
            self.emitter.setAdvertisingParameters(
                type=advertisingType,
                destAddr=destAddress,
                data=advertisingData,
                intervalMin=intervalMin,
                intervalMax=intervalMax,
                daType=advertisingAddressType,
                oaType=destinationAddressType)
            self.emitter.setAdvertising(
                enable=utils.booleanArg(self.args["ENABLE"]))
            time = utils.integerArg(
                self.args['TIME']) if self.args["TIME"] != "" else -1

            while time != 0:
                utils.wait(seconds=1)
                time -= 1
            return self.ok({"INTERFACE": self.args["INTERFACE"]})
        else:
            io.fail("Interface provided (" + str(self.args["INTERFACE"]) +
                    ") is not able to send advertisements.")
            return self.nok()
Exemple #3
0
	def write_cmd(self,handle,value):
		if self.receiver.isConnected():
			if utils.isHexadecimal(handle) and utils.isHexadecimal(value):
				self.emitter.sendp(ble.BLEWriteCommand(handle = int(handle,16),value=bytes.fromhex(value)))
				io.success("Write Command : handle = "+handle+" / value = "+value)
			else:
				io.fail("Handle or value is not correctly formatted (hexadecimal) !")
		else:
			io.fail("No active connections !")
Exemple #4
0
	def _getRType(self,type):
		if isinstance(type, int):
			rtype = UUID(UUID16=type)
		elif utils.isHexadecimal(type) and len(type)<=6:
			rtype = UUID(UUID16=int(type, 16))
		elif utils.isHexadecimal(type) and len(type)>6:
			rtype = UUID(UUID128=bytes.fromhex(type))
		else:
			rtype = UUID(name=type)
		return rtype
Exemple #5
0
 def parseFilterType(self):
     filterType = self.args["FILTER"]
     if filterType == "":
         return None
     if utils.isNumber(filterType):
         return ble.UUID(UUID16=int(filterType)).data
     elif utils.isHexadecimal(filterType) and len(filterType) <= 6:
         return ble.UUID(UUID16=int(filterType, 16)).data
     elif utils.isHexadecimal(filterType) and len(filterType) > 6:
         uuid = ble.UUID(UUID128=bytes.fromhex(filterType)).data
         if uuid is None:
             return bytes.fromhex(filterType)
         else:
             return uuid
     else:
         return ble.UUID(name=filterType).data
Exemple #6
0
	def notification(self,handle,value):
		try:
			handle = int(handle,16)
			if utils.isHexadecimal(value):
				value = bytes.fromhex(value)
			else:
				value = bytes(value,"ascii")

			self.emitter.sendp(ble.BLEHandleValueNotification(handle=handle, value=value))
		except:
			io.fail("An error happened during notification emission !")
Exemple #7
0
	def __init__(self,handle=None,value=None,type=None, permissions=None):
		self.handle = handle
		self.value = value
		
		if isinstance(type,int):
			self.type = UUID(UUID16=type)
		elif isinstance(type,bytes):
			self.type = UUID(data=type)
		elif utils.isHexadecimal(type) and len(type)<=6:
			self.type = UUID(UUID16=int(type, 16))
		elif utils.isHexadecimal(type) and len(type)>6:
			self.type = UUID(UUID128=bytes.fromhex(type))
		else:
			self.type = UUID(name=type)


		if isinstance(permissions,str) and utils.isNumber(permissions):
			self.permissions = PermissionsFlag(data=struct.pack('B',permissions))
		elif isinstance(permissions,bytes):
			self.permissions = PermissionsFlag(data=permissions)
		else:
			self.permissions = PermissionsFlag(permissions=permissions)
Exemple #8
0
    def jamAdvertisements(self):
        if self.checkAdvertisementsJammingCapabilities():
            channel = utils.integerArg(self.args["CHANNEL"])
            if self.args["TARGET"] != "":
                target = utils.addressArg(self.args["TARGET"])
                pattern = bytes.fromhex(target.replace(":", ""))[::-1]
                offset = 2
            elif (utils.isNumber(self.args["OFFSET"])
                  and utils.isHexadecimal(self.args["PATTERN"])
                  and self.args["OFFSET"] != ""
                  and self.args["PATTERN"] != ""):
                pattern = bytes.fromhex(self.args["PATTERN"])
                offset = utils.integerArg(self.args["OFFSET"])
            else:
                io.fail(
                    "You must provide a dewhitened pattern and an offset, or a target to jam."
                )
                return self.nok()

            if len(self.emitters) == 1:
                self.emitters[0].jamAdvertisements(pattern=pattern,
                                                   offset=offset,
                                                   channel=channel)
            if len(self.emitters) == 2:
                self.emitters[0].jamAdvertisements(pattern=pattern,
                                                   offset=offset,
                                                   channel=channel)
                self.emitters[1].jamAdvertisements(
                    pattern=pattern,
                    offset=offset,
                    channel=(channel + 1 if channel < 39 else 37))
            if len(self.emitters) == 3:
                self.emitters[0].jamAdvertisements(pattern=pattern,
                                                   offset=offset,
                                                   channel=37)
                self.emitters[1].jamAdvertisements(pattern=pattern,
                                                   offset=offset,
                                                   channel=38)
                self.emitters[2].jamAdvertisements(pattern=pattern,
                                                   offset=offset,
                                                   channel=39)

            while True:
                utils.wait(seconds=0.01)

        else:
            io.fail("Interfaces provided are not able to jam advertisements.")
            return self.nok()
Exemple #9
0
    def applyFilter(self, attributes):
        filteredAttributes = attributes
        filterBy = self.args["FILTER_BY"].lower()
        if filterBy == "type":
            filterType = self.parseFilterType()
            if filterType is not None:
                filteredAttributes = [
                    i for i in attributes if i["type"] == filterType
                ]
        elif filterBy == "value":
            filterValue = self.args["FILTER"]
            if utils.isHexadecimal(filterValue):
                filterValue = bytes.fromhex(filterValue)
            else:
                filterValue = bytes(filterValue, "utf-8")

                filteredAttributes = [
                    i for i in attributes if filterValue in i["value"]
                ]
        return filteredAttributes
Exemple #10
0
	def read(self,handle):
		if self.receiver.isConnected():
			if utils.isHexadecimal(handle):
				self.emitter.sendp(ble.BLEReadRequest(handle = int(handle,16)))
				io.info("Read Request : handle = "+handle)

				response = self.receiver.next(timeout=3)
				retry = 3
				while not (isinstance(response,ble.BLEReadResponse)  or
					   isinstance(response,ble.BLEErrorResponse) or
					   retry == 0
					  ):
					response = self.receiver.next(timeout=1)
					retry -= 1
				if isinstance(response,ble.BLEReadResponse):
					io.success("Response : handle = "+str(handle)+" / Values (hex) = "+response.value.hex())
				elif isinstance(response, ble.BLEErrorResponse):
					io.fail("Error response")
			else:
				io.fail("Handle is not correctly formatted (hexadecimal)")
		else:
			io.fail("No active connections !")
Exemple #11
0
    def run(self):
        self.emitter = self.getEmitter(interface=self.args["INTERFACE"])
        if self.checkCapabilities():
            frequency = self.emitter.getFrequency()
            if frequency != utils.integerArg(self.args["FREQUENCY"]):
                self.emitter.setFrequency(
                    utils.integerArg(self.args["FREQUENCY"]))

            if self.args["CODE"] != "" and utils.isHexadecimal(
                    self.args["CODE"]):
                code = self.args["CODE"]
                if "0x" == self.args["CODE"][:2]:
                    code = self.args["CODE"][2:]
                code = bytes.fromhex(code)
                if self.args["PROTOCOL"].upper() == "NEC":
                    packet = ir.IRNECPacket(code=code,
                                            size=utils.integerArg(
                                                self.args["CODE_SIZE"]))
                elif self.args["PROTOCOL"].upper() == "SONY":
                    packet = ir.IRSonyPacket(code=code,
                                             size=utils.integerArg(
                                                 self.args["CODE_SIZE"]))
                elif self.args["PROTOCOL"].upper() == "RC5":
                    packet = ir.IRRC5Packet(code=code,
                                            size=utils.integerArg(
                                                self.args["CODE_SIZE"]))
                elif self.args["PROTOCOL"].upper() == "RC6":
                    packet = ir.IRRC6Packet(code=code,
                                            size=utils.integerArg(
                                                self.args["CODE_SIZE"]))
                elif self.args["PROTOCOL"].upper() == "DISH":
                    packet = ir.IRDishPacket(code=code,
                                             size=utils.integerArg(
                                                 self.args["CODE_SIZE"]))
                elif self.args["PROTOCOL"].upper() == "SHARP":
                    packet = ir.IRSharpPacket(code=code,
                                              size=utils.integerArg(
                                                  self.args["CODE_SIZE"]))
                elif self.args["PROTOCOL"].upper() == "JVC":
                    packet = ir.IRJVCPacket(code=code,
                                            size=utils.integerArg(
                                                self.args["CODE_SIZE"]))
                elif self.args["PROTOCOL"].upper() == "SANYO":
                    packet = ir.IRSanyoPacket(code=code,
                                              size=utils.integerArg(
                                                  self.args["CODE_SIZE"]))
                elif self.args["PROTOCOL"].upper() == "MITSUBISHI":
                    packet = ir.IRMitsubishiPacket(code=code,
                                                   size=utils.integerArg(
                                                       self.args["CODE_SIZE"]))
                elif self.args["PROTOCOL"].upper() == "SAMSUNG":
                    packet = ir.IRSamsungPacket(code=code,
                                                size=utils.integerArg(
                                                    self.args["CODE_SIZE"]))
                elif self.args["PROTOCOL"].upper() == "LG":
                    packet = ir.IRLGPacket(code=code,
                                           size=utils.integerArg(
                                               self.args["CODE_SIZE"]))
                elif self.args["PROTOCOL"].upper() == "WHYNTER":
                    packet = ir.IRWhynterPacket(code=code,
                                                size=utils.integerArg(
                                                    self.args["CODE_SIZE"]))
                elif self.args["PROTOCOL"].upper() == "AIWA":
                    packet = ir.IRAiwaPacket(code=code,
                                             size=utils.integerArg(
                                                 self.args["CODE_SIZE"]))
                elif self.args["PROTOCOL"].upper() == "PANASONIC":
                    packet = ir.IRPanasonicPacket(code=code,
                                                  size=utils.integerArg(
                                                      self.args["CODE_SIZE"]))
                elif self.args["PROTOCOL"].upper() == "DENON":
                    packet = ir.IRDenonPacket(code=code,
                                              size=utils.integerArg(
                                                  self.args["CODE_SIZE"]))
                else:
                    io.fail("Unknown protocol !")
                    return self.nok()
                io.info("Injecting ...")
                self.emitter.sendp(packet)
                utils.wait(seconds=1)
                io.success("Injection done !")
                return self.ok()

            elif self.args["DATA"] != "":
                data = [int(i) for i in utils.listArg(self.args["DATA"])]
                packet = ir.IRPacket(data=data)

                io.info("Injecting ...")
                self.emitter.sendp(packet)
                utils.wait(seconds=1)
                io.success("Injection done !")
                return self.ok()

            else:
                io.fail("Incorrect parameters !")
                return self.nok()
        else:
            io.fail("Interface provided (" + str(self.args["INTERFACE"]) +
                    ") is not able to inject IR signals.")
            return self.nok()