diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 159afb0877..47d8953f45 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -26,8 +26,6 @@ jobs: sudo apt-get install python3 python3-dev python-is-python3 sudo apt-get install build-essential clang systemtap-sdt-dev sudo apt-get install libfuzzy-dev graphviz libgraphviz-dev tesseract-ocr unrar xfonts-base xfonts-75dpi - wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_amd64.deb - sudo dpkg -i wkhtmltox_0.12.6-1.bionic_amd64.deb - name: STEP 4. Install libemu run: | diff --git a/docs/source/logging.rst b/docs/source/logging.rst index 53aa81c298..a59961c9a8 100644 --- a/docs/source/logging.rst +++ b/docs/source/logging.rst @@ -340,7 +340,7 @@ type is PE). screenshots ^^^^^^^^^^^ -The collection *screenshots* is used to store base-64 encoded screenshots (JPG format) +The collection *screenshots* is used to store base-64 encoded screenshots (PDF format) of the analyzed page. .. code-block:: sh diff --git a/pyproject.toml b/pyproject.toml index 472e33d329..f977ad99ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -81,8 +81,8 @@ exploitgraph = [ ] image = [ - "imgkit==1.1.0", "pytesseract", + "weasyprint", ] shellcode = [ diff --git a/thug/Analysis/screenshot/Screenshot.py b/thug/Analysis/screenshot/Screenshot.py index 98cc02d8fa..7d59a62e34 100644 --- a/thug/Analysis/screenshot/Screenshot.py +++ b/thug/Analysis/screenshot/Screenshot.py @@ -1,13 +1,13 @@ -import sys +import io import logging import bs4 try: - import imgkit + import weasyprint - IMGKIT_MODULE = True + WEASYPRINT_MODULE = True except ImportError: # pragma: no cover - IMGKIT_MODULE = False + WEASYPRINT_MODULE = False log = logging.getLogger("Thug") @@ -16,7 +16,7 @@ class Screenshot: content_types = ("text/html",) def __init__(self): - self.enable = IMGKIT_MODULE + self.enable = WEASYPRINT_MODULE def run(self, window, url, response, ctype): if not self.enable or not log.ThugOpts.screenshot: @@ -37,13 +37,14 @@ def run(self, window, url, response, ctype): img["src"] = norm_src content = soup.prettify(formatter=None) - options = {"quiet": ""} - - if sys.platform in ("linux",): - options["xvfb"] = "" try: - screenshot = imgkit.from_string(content, False, options=options) - log.ThugLogging.log_screenshot(url, screenshot) + html = weasyprint.HTML(string=content) + document = html.render() + + with io.BytesIO() as screenshot: + document.write_pdf(screenshot) + screenshot.seek(0) + log.ThugLogging.log_screenshot(url, screenshot.read()) except Exception as e: # pragma: no cover,pylint:disable=broad-except log.warning("[SCREENSHOT] Error: %s", str(e)) diff --git a/thug/Logging/ThugLogging.py b/thug/Logging/ThugLogging.py index 47df992a73..6a05081cee 100644 --- a/thug/Logging/ThugLogging.py +++ b/thug/Logging/ThugLogging.py @@ -453,7 +453,7 @@ def log_screenshot(self, url, screenshot): @screenshot Screenshot """ dirname = os.path.join(self.baseDir, "analysis", "screenshots") - filename = f"{hashlib.sha256(screenshot).hexdigest()}.jpg" + filename = f"{hashlib.sha256(screenshot).hexdigest()}.pdf" self.store_content(dirname, filename, screenshot) for m in self.resolve_method("log_screenshot"): # pragma: no cover