예제 #1
0
    def run(self):
        """Run screenshotting.
        @return: operation status.
        """
        if not Screenshot().have_pil():
            log.warning("Python Image Library is not installed, screenshots are disabled")
            return False

        img_counter = 0
        img_last = None

        while self.do_run:
            img_current = Screenshot().take()

            if img_last:
                if Screenshot().equal(img_last, img_current):
                    time.sleep(SHOT_DELAY)
                    continue

            img_counter += 1
            save_at = os.path.join(self.save_path, "%s.jpg" % str(img_counter).rjust(4, '0'))
            img_current.save(save_at)

            img_last = img_current
            time.sleep(SHOT_DELAY)

        return True
예제 #2
0
    def run(self):
        """Run screenshotting.
        @return: operation status.
        """
        if "screenshots" in self.options:
            shot_delay = int(self.options["screenshots"])
            if shot_delay == 0: self.do_run = False
        else:
            shot_delay = 1

        if not Screenshot().have_pil():
            log.warning("Python Image Library is not installed, "
                        "screenshots are disabled")
            return False

        img_counter = 0
        img_last = None

        while self.do_run:
            time.sleep(shot_delay)

            try:
                img_current = Screenshot().take()
            except IOError as e:
                log.error("Cannot take screenshot: %s", e)
                continue

            if img_last:
                if Screenshot().equal(img_last, img_current, SKIP_AREA):
                    continue

            img_counter += 1

            # workaround as PIL can't write to the socket file object :(
            tmpio = StringIO.StringIO()
            img_current.save(tmpio, format="JPEG")
            tmpio.seek(0)

            # now upload to host from the StringIO
            nf = NetlogFile()
            nf.init("shots/%s.jpg" % str(img_counter).rjust(4, "0"))

            for chunk in tmpio:
                nf.sock.sendall(chunk)

            nf.close()

            img_last = img_current

        return True
예제 #3
0
    def run(self):
        """Run screenshotting.
        @return: operation status.
        """
        img_counter = 0
        img_last = None

        while self.do_run:
            time.sleep(SHOT_DELAY)

            try:
                filename = "screenshot%s.jpg" % str(img_counter)
                img_current = take_screenshot(filename)
                if img_last:
                    if Screenshot().equal(img_last, img_current):
                        continue

                file = open(img_current, 'r')
                tmpio = StringIO.StringIO(file.read())
                # now upload to host from the StringIO
                nf = NetlogFile("shots/%s.jpg" % str(img_counter).rjust(4, "0"))

                for chunk in tmpio:
                    nf.sock.sendall(chunk)

                nf.close()
                file.close()
                img_counter += 1
                img_last = img_current

            except IOError as e:
                log.error("Cannot take screenshot: %s", e)
                continue

        return True
예제 #4
0
    def run(self):
        """Run screenshotting.
        @return: operation status.
        """
        scr = Screenshot()

        img_count = 0
        img_last = None
        img_current = tempfile.mktemp()

        while self.do_run:
            time.sleep(SHOT_DELAY)

            try:
                scr.take(img_current)
            except CuckooScreenshotError as e:
                log.error("Error taking screenshot: %s", e)
                continue

            if img_last and scr.equal(img_last, img_current):
                continue

            # The screencap tool doesn't support jpeg as output format, which
            # is what the cuckoo backend expects. We hack around this by
            # uploading the shots with a jpeg extension.
            # Obviously, this is a nasty hack, but will have to do for now.
            upload_to_host(img_current, "shots/%s.jpg" % img_count)
            if img_last:
                os.unlink(img_last)

            img_count += 1
            img_last = img_current
            img_current = tempfile.mktemp()

        return True
예제 #5
0
    def run(self):
        """Run screenshotting.
        @return: operation status.
        """
        if "screenshots" in self.options:
            self.do_run = int(self.options["screenshots"])

        scr = Screenshot()

        # TODO We should also send the action "pillow" so that the Web
        # Interface can adequately inform the user about this missing library.
        if not scr.have_pil():
            log.info("Python Image Library (either PIL or Pillow) is not "
                     "installed, screenshots are disabled.")
            return False

        img_counter = 0
        img_last = None

        while self.do_run:
            time.sleep(SHOT_DELAY)

            try:
                img_current = scr.take()
            except IOError as e:
                log.error("Cannot take screenshot: %s", e)
                continue

            if img_last and scr.equal(img_last, img_current, SKIP_AREA):
                continue

            img_counter += 1

            # workaround as PIL can't write to the socket file object :(
            tmpio = StringIO.StringIO()
            img_current.save(tmpio, format="JPEG")
            tmpio.seek(0)

            # evan - instead of uploading it, store it in the stuff folder
            f = os.path.join(os.getcwd(), 'stuff', 'shots')
            if not os.path.exists(f):
                os.makedirs(f)

            upload_path = os.path.join(f, '{0}.jpg'.format(img_counter))
            with open(upload_path, 'wb') as fw:
                for chunk in tmpio:
                    fw.write(chunk)

            # now upload to host from the StringIO
#           nf = NetlogFile()
#           nf.init("shots/%04d.jpg" % img_counter)

#           for chunk in tmpio:
#               nf.sock.sendall(chunk)

#           nf.close()

            img_last = img_current

        return True
예제 #6
0
    def run(self):
        """Run screenshotting.
        @return: operation status.
        """
        if not Screenshot().have_pil():
            log.warning("Python Image Library is not installed, "
                        "screenshots are disabled")
            return False

        img_counter = 0
        img_last = None

        while self.do_run:
            time.sleep(SHOT_DELAY)
            try:
                img_current = Screenshot().take()
            except IOError as e:
                log.error("Cannot take screenshot: %s", e)
                continue

            if img_last:
                if Screenshot().equal(img_last, img_current):
                    continue
            img_counter += 1

            #send a return keystroke for installers
            self.sendKey(0x24)

            try:
                # workaround as PIL can't write to the socket file object :(
                tmpio = StringIO.StringIO()
                img_current.save(tmpio, format="PNG")
                tmpio.seek(0)
            except:
                log.exception("Unable to write screenshot to disk.")

            # now upload to host from the StringIO
            nf = NetlogFile("shots/%s.png" % str(img_counter).rjust(4, "0"))

            for chunk in tmpio:
                nf.sock.sendall(chunk)

            nf.close()

            img_last = img_current

        return True
예제 #7
0
    def run(self):
        """Run screenshotting.
        @return: operation status.
        """
        if not self.enabled:
            return False

        if not Screenshot().have_pil():
            log.warning(
                "Python Image Library is not installed, screenshots are disabled"
            )
            return False

        img_counter = 0
        img_last = None

        while self.do_run:
            time.sleep(SHOT_DELAY)

            try:
                img_current = Screenshot().take()
            except IOError as e:
                log.error("Cannot take screenshot: %s", e)
                continue

            if img_last:
                if Screenshot().equal(img_last, img_current, SKIP_AREA):
                    continue

            img_counter += 1
            # workaround as PIL can't write to the socket file object :(
            tmpio = BytesIO()
            img_current.save(tmpio, format="JPEG")
            tmpio.seek(0)

            # now upload to host from the StringIO
            nf = NetlogFile()
            nf.init(f"shots/{str(img_counter).rjust(4, '0')}.jpg")
            for chunk in tmpio:
                nf.sock.send(chunk)
            nf.close()
            img_last = img_current

        return True
예제 #8
0
    def run(self):
        """Run screenshotting.
        @return: operation status.
        """
        if "screenshots" in self.options:
            self.do_run = int(self.options["screenshots"])

        scr = Screenshot()

        # TODO We should also send the action "pillow" so that the Web
        # Interface can adequately inform the user about this missing library.
        if not scr.have_pil():
            log.info(
                "Python Image Library (either PIL or Pillow) is not "
                "installed, screenshots are disabled."
            )
            return False

        img_counter = 0
        img_last = None

        while self.do_run:
            time.sleep(SHOT_DELAY)

            try:
                img_current = scr.take()
            except IOError as e:
                log.error("Cannot take screenshot: %s", e)
                continue

            if img_last and scr.equal(img_last, img_current, SKIP_AREA):
                continue

            img_counter += 1

            # workaround as PIL can't write to the socket file object :(
            tmpio = StringIO.StringIO()
            img_current.save(tmpio, format="JPEG")
            tmpio.seek(0)

            # now upload to host from the StringIO
            nf = NetlogFile()
            nf.init("shots/%04d.jpg" % img_counter)

            for chunk in tmpio:
                nf.sock.sendall(chunk)

            nf.close()

            img_last = img_current

        return True