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 5 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_S = decouple.config(
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: _S -> _SECOND

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 all occurrences

"WHATVPN_TIMEOUT_S",
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 pip install requests
Copy link
Member

Choose a reason for hiding this comment

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

requests is already in the artemis image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

RUN pip3 install https://github.com/dlenski/what-vpn/archive/master.zip
Copy link
Member

Choose a reason for hiding this comment

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

pin versions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pinned latest hash on master branch


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

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

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):
"""
Runs what-vpn -> SSL VPN identifier
"""

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

@kazet kazet Sep 1, 2024

Choose a reason for hiding this comment

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

hmmm, if you want a service on a port, use TaskType.SERVICE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll stay with IP task type as profit from scanning all discovered ports is debatable while increase number of sent requests is noticeable.
Might change in the future based on observations.

]

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

error_messages = ["error", "timeout", "no match"]
if any(msg in output for msg in error_messages):
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.append(output.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