Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion docs/source/logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ exploitgraph = [
]

image = [
"imgkit==1.1.0",
"pytesseract",
"weasyprint",
]

shellcode = [
Expand Down
23 changes: 12 additions & 11 deletions thug/Analysis/screenshot/Screenshot.py
Original file line number Diff line number Diff line change
@@ -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")

Expand All @@ -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:
Expand All @@ -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))
2 changes: 1 addition & 1 deletion thug/Logging/ThugLogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading