예제 #1
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
예제 #2
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
예제 #3
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