Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
kazet committed Jul 17, 2024
1 parent 7ba6cc3 commit b652481
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
19 changes: 18 additions & 1 deletion artemis/reporting/export/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pathlib import Path
from typing import Dict, Optional

import bs4
import termcolor
import typer
from jinja2 import BaseLoader, Environment, StrictUndefined, Template
Expand Down Expand Up @@ -39,6 +40,22 @@
HOST_ROOT_PATH = "/host-root/"


def unwrap(html: str) -> str:
"""Uwraps html if it's wrapped in a single tag (e.g. <div>)."""
html = html.strip()
soup = bs4.BeautifulSoup(html)
while len(list(soup.children)) == 1:
only_child = list(soup.children)[0]

if only_child.name: # type: ignore
only_child.unwrap()
soup = bs4.BeautifulSoup(soup.renderContents().strip())
else:
break

return soup.renderContents().decode("utf-8", "ignore")


def _build_message_template_and_print_path(output_dir: Path, silent: bool) -> Template:
output_message_template_file_name = output_dir / "advanced" / "message_template.jinja2"

Expand Down Expand Up @@ -103,7 +120,7 @@ def _build_messages_and_print_path(
}
message_data["custom_template_arguments"]["skip_html_and_body_tags"] = True # type: ignore
message_data["custom_template_arguments"]["skip_header_and_footer_text"] = True # type: ignore
report.html = message_template.render({"data": message_data})
report.html = unwrap(message_template.render({"data": message_data}))

if not silent:
print()
Expand Down
1 change: 0 additions & 1 deletion artemis/reporting/severity.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class Severity(str, Enum):

SEVERITY_MAP = {
ReportType("forti_vuln"): Severity.HIGH,
ReportType("globalprotect_vuln"): Severity.HIGH,
ReportType("insecure_wordpress"): Severity.HIGH,
ReportType("nuclei_vulnerability"): Severity.HIGH,
ReportType("script_unregistered_domain"): Severity.HIGH,
Expand Down
23 changes: 23 additions & 0 deletions test/e2e/test_exporting.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import re
import tempfile
import time
Expand Down Expand Up @@ -106,6 +107,28 @@ def test_exporting_gui(self) -> None:
).encode("ascii"),
)

with export.open("advanced/output.json", "r") as f:
output_data = json.loads(f.read().decode("ascii"))
self.assertEqual(
output_data["messages"]["test-smtp-server.artemis"]["reports"][0]["html"],
"\n".join(
[
"The following domains don't have properly configured e-mail sender verification mechanisms: <ul>",
" <li>",
" test-smtp-server.artemis:",
"",
" Valid DMARC record not found. We recommend using all three mechanisms: SPF, DKIM and DMARC to decrease the possibility of successful e-mail message spoofing.",
" ",
" </li>",
" </ul>",
" <p>",
" These mechanisms greatly increase the chance that the recipient server will reject a spoofed message.",
" Even if a domain is not used to send e-mails, SPF and DMARC records are needed to reduce the possibility to spoof e-mails.",
" </p>",
]
),
)

def test_exporting_api(self) -> None:
self.submit_tasks_with_modules_enabled(
["test-smtp-server.artemis"], "exporting-api", ["mail_dns_scanner", "classifier"]
Expand Down

0 comments on commit b652481

Please sign in to comment.