Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New module using what-vpn #117

Merged
merged 8 commits into from
Sep 3, 2024
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ NASK is relieved of such liability to the fullest extent possible.
The module is disabled by default - to enable it, rename `docker-compose.additional.wpscan.yml.disabled` to
`docker-compose.additional.wpscan.yml` and re-run ``./scripts/start``.

### what-vpn
Uses https://github.com/dlenski/what-vpn under the hood. Identifies servers running various SSL VPNs and is licensed under GPL-3.0-or-later.

## Testing
To run the tests, run:

Expand Down
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ services:
command: "python3 -m artemis.modules.karton_ssl_checks"
profiles: [not-arm]

karton-whatvpn:
build:
context: Artemis-modules-extra
dockerfile: karton_whatvpn/Dockerfile
volumes: ["./docker/karton.ini:/etc/karton/karton.ini", "${DOCKER_COMPOSE_ADDITIONAL_SHARED_DIRECTORY:-./shared}:/shared/"]
depends_on: [karton-system]
env_file: .env
restart: always
command: "python3 -m artemis.modules.karton_whatvpn"

autoreporter:
volumes:
- ./Artemis-modules-extra/extra_modules_config.py:/opt/extra_modules_config.py
Expand Down
8 changes: 8 additions & 0 deletions extra_modules_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,13 @@ class ExtraModulesConfig:
),
)

# Timeout counted in seconds, after which the what-vpn module terminates a connection and starts using the next sniffer.
# Some of VPN gateways do not respond in any way to the HTTP(S) requests, so the timeout variable should be optimized in
# order to avoid false negatives while not blocking the task for too long.
WHATVPN_TIMEOUT_SECONDS = decouple.config(
"WHATVPN_TIMEOUT_SECONDS",
default="2",
)

# WPScan API key
WPSCAN_API_KEY = decouple.config("WPSCAN_API_KEY", default=None)
9 changes: 9 additions & 0 deletions karton_whatvpn/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM certpl/artemis:latest

RUN apk add git
RUN pip3 install https://github.com/dlenski/what-vpn/archive/607c351037acb1fae06ba98760f462a3aa61b359.zip
# Last release v0.7 is from 2022, but current master branch contains significant improvements

WORKDIR /opt/
COPY karton_whatvpn/karton_whatvpn.py ./artemis/modules
COPY extra_modules_config.py .
62 changes: 62 additions & 0 deletions karton_whatvpn/karton_whatvpn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import subprocess

from artemis import load_risk_class, utils
from artemis.binds import TaskStatus, TaskType
from artemis.module_base import ArtemisBase
from artemis.task_utils import get_target_host
from karton.core import Task

from extra_modules_config import ExtraModulesConfig

logger = utils.build_logger(__name__)


@load_risk_class.load_risk_class(load_risk_class.LoadRiskClass.LOW)
class WhatVPN(ArtemisBase): # type: ignore
"""
Runs what-vpn -> SSL VPN identifier
"""

identity = "what-vpn"
filters = [{"type": TaskType.IP.value}]

def _process(self, current_task: Task, host: str) -> None:
output = subprocess.run(
["what-vpn", "--keep-going-after-exception", "--timeout", ExtraModulesConfig.WHATVPN_TIMEOUT_SECONDS, host],
capture_output=True,
)
output_str = output.stdout.decode("utf-8")
detected_vpn = None

error_messages = ["error", "timeout"]
if any(msg in output_str for msg in error_messages):
status = TaskStatus.ERROR
status_reason = "Error or timeout occurred"
elif "no match" in output_str:
status = TaskStatus.OK
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TaskStatus.ERROR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed the logic to return separate OK and ERROR statuses

status_reason = "Could not identify a VPN gateway"
else:
# Format of what-vpn output:
# scanned_host: identified_VPN [VPN_version]
detected_vpn = output_str.split(" ", 1)[1]
status = TaskStatus.INTERESTING
status_reason = f"Detected {detected_vpn}"

# Save the task result to the database
self.db.save_task_result(
task=current_task,
status=status,
status_reason=status_reason,
data=detected_vpn,
)

def run(self, current_task: Task) -> None:
target_host = get_target_host(current_task)

self.log.info("Requested to check if %s is a VPN gateway", target_host)

self._process(current_task, target_host)


if __name__ == "__main__":
WhatVPN().loop()
Loading