attackmate-api-server 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- attackmate_api_server/__init__.py +0 -0
- attackmate_api_server/auth_utils.py +104 -0
- attackmate_api_server/config.py +29 -0
- attackmate_api_server/log_utils.py +149 -0
- attackmate_api_server/main.py +175 -0
- attackmate_api_server/metadata.py +19 -0
- attackmate_api_server/routers/__init__.py +0 -0
- attackmate_api_server/routers/commands.py +71 -0
- attackmate_api_server/routers/instances.py +29 -0
- attackmate_api_server/routers/playbooks.py +134 -0
- attackmate_api_server/schemas.py +35 -0
- attackmate_api_server/state.py +45 -0
- attackmate_api_server/utils.py +14 -0
- attackmate_api_server-1.1.0.dist-info/METADATA +186 -0
- attackmate_api_server-1.1.0.dist-info/RECORD +19 -0
- attackmate_api_server-1.1.0.dist-info/WHEEL +5 -0
- attackmate_api_server-1.1.0.dist-info/entry_points.txt +2 -0
- attackmate_api_server-1.1.0.dist-info/licenses/LICENSE.md +287 -0
- attackmate_api_server-1.1.0.dist-info/top_level.txt +1 -0
|
File without changes
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import secrets
|
|
3
|
+
from datetime import datetime, timedelta, timezone
|
|
4
|
+
from typing import Any, Dict, Optional
|
|
5
|
+
|
|
6
|
+
from dotenv import load_dotenv
|
|
7
|
+
from fastapi import Depends, HTTPException, status
|
|
8
|
+
from fastapi.security import APIKeyHeader
|
|
9
|
+
from argon2 import PasswordHasher
|
|
10
|
+
from argon2.exceptions import InvalidHashError, VerificationError
|
|
11
|
+
from attackmate_api_server.config import settings
|
|
12
|
+
|
|
13
|
+
load_dotenv()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
API_KEY_HEADER_NAME = 'X-Auth-Token'
|
|
17
|
+
api_key_header_scheme = APIKeyHeader(name=API_KEY_HEADER_NAME, auto_error=True)
|
|
18
|
+
password_hasher = PasswordHasher()
|
|
19
|
+
|
|
20
|
+
# In-Memory token Store
|
|
21
|
+
# token looks like this token : {"username": str, "expires": datetime}
|
|
22
|
+
# state is lost on server restart.
|
|
23
|
+
# Not inherently thread-safe for multi-worker setups without locks ?
|
|
24
|
+
ACTIVE_TOKENS: Dict[str, Dict[str, Any]] = {}
|
|
25
|
+
|
|
26
|
+
logger = logging.getLogger('attackmate_api')
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def verify_password(plain_password: str, hashed_password: str) -> bool:
|
|
30
|
+
try:
|
|
31
|
+
return bool(password_hasher.verify(hashed_password, plain_password))
|
|
32
|
+
except (VerificationError, InvalidHashError): # wrong password or malformed hash in USERS
|
|
33
|
+
return False
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def get_user_hash(username: str) -> Optional[str]:
|
|
37
|
+
"""Fetches the hashed password from the centralized settings."""
|
|
38
|
+
return settings.users.get(username.lower())
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def create_access_token(username: str) -> str:
|
|
42
|
+
"""Creates a new token, stores it, and returns the token string."""
|
|
43
|
+
token = secrets.token_urlsafe(32)
|
|
44
|
+
expires = datetime.now(timezone.utc) + timedelta(minutes=settings.token_expire_minutes)
|
|
45
|
+
# TODO locking needed for multi-threaded access, smth like with token_lock ?
|
|
46
|
+
ACTIVE_TOKENS[token] = {'username': username, 'expires': expires}
|
|
47
|
+
logger.info(f"Created new token for user '{username}' expiring at {expires}")
|
|
48
|
+
return token
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def renew_token_expiry(token: str) -> bool:
|
|
52
|
+
"""Updates the expiry time for an existing token.
|
|
53
|
+
|
|
54
|
+
Returns True if successful.
|
|
55
|
+
"""
|
|
56
|
+
token_data = ACTIVE_TOKENS.get(token)
|
|
57
|
+
if token_data:
|
|
58
|
+
token_data['expires'] = datetime.now(timezone.utc) + timedelta(minutes=settings.token_expire_minutes)
|
|
59
|
+
logger.debug(f"Renewed token expiry for user '{token_data['username']}'")
|
|
60
|
+
return True
|
|
61
|
+
return False
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def cleanup_expired_tokens() -> None:
|
|
65
|
+
"""Removes expired tokens from the store."""
|
|
66
|
+
now = datetime.now(timezone.utc)
|
|
67
|
+
expired_tokens = [token for token, data in ACTIVE_TOKENS.items() if data['expires'] < now]
|
|
68
|
+
for token in expired_tokens:
|
|
69
|
+
username = ACTIVE_TOKENS.get(token, {}).get('username', 'unknown')
|
|
70
|
+
del ACTIVE_TOKENS[token]
|
|
71
|
+
logger.info(f"Removed expired token for user '{username}'.")
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
# Authentication Dependency -> this gets passed to the routes
|
|
75
|
+
async def get_current_user(token: str = Depends(api_key_header_scheme)) -> str:
|
|
76
|
+
"""Validate token and return the username renews the token's expiration on
|
|
77
|
+
successful validation cleanup of expired tokens."""
|
|
78
|
+
cleanup_expired_tokens()
|
|
79
|
+
|
|
80
|
+
credentials_exception = HTTPException(
|
|
81
|
+
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
82
|
+
detail='Invalid authentication credentials',
|
|
83
|
+
headers={'WWW-Authenticate': 'Bearer'},
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
token_data = ACTIVE_TOKENS.get(token)
|
|
87
|
+
if not token_data:
|
|
88
|
+
logger.warning(f'Token not found: {token[:5]}...')
|
|
89
|
+
raise credentials_exception
|
|
90
|
+
|
|
91
|
+
username: str = token_data['username']
|
|
92
|
+
expires: datetime = token_data['expires']
|
|
93
|
+
|
|
94
|
+
if expires < datetime.now(timezone.utc):
|
|
95
|
+
logger.warning(f"Token expired for user '{username}'")
|
|
96
|
+
# Remove the expired token
|
|
97
|
+
if token in ACTIVE_TOKENS:
|
|
98
|
+
del ACTIVE_TOKENS[token]
|
|
99
|
+
raise credentials_exception
|
|
100
|
+
|
|
101
|
+
renew_token_expiry(token)
|
|
102
|
+
|
|
103
|
+
logger.debug(f'Token validated successfully for user: {username}')
|
|
104
|
+
return username
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
from typing import Dict, Optional
|
|
3
|
+
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
4
|
+
from pydantic import Field
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Settings(BaseSettings):
|
|
8
|
+
attackmate_config_path: Optional[str] = Field(default=None, alias="ATTACKMATE_CONFIG_PATH")
|
|
9
|
+
token_expire_minutes: int = 30
|
|
10
|
+
|
|
11
|
+
# SSL files; relative paths resolve against the working directory (like .env)
|
|
12
|
+
ssl_key_path: str = Field(default="key.pem", alias="SSL_KEY_PATH")
|
|
13
|
+
ssl_cert_path: str = Field(default="cert.pem", alias="SSL_CERT_PATH")
|
|
14
|
+
write_playbook_logs_to_disk: bool = False # Set WRITE_PLAYBOOK_LOGS_TO_DISK in .env
|
|
15
|
+
log_dir: str = "attackmate_server_logs"
|
|
16
|
+
attackmate_api_server_port: int = 8445
|
|
17
|
+
|
|
18
|
+
# User Hashes: Key is username (lowercase), Value is argon2 hash
|
|
19
|
+
# Environment Var: users='{"user1": "hash1"}'
|
|
20
|
+
users: Dict[str, str] = {}
|
|
21
|
+
|
|
22
|
+
model_config = SettingsConfigDict(
|
|
23
|
+
env_file=".env",
|
|
24
|
+
env_file_encoding="utf-8",
|
|
25
|
+
extra="ignore"
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
settings = Settings()
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
import logging
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
from collections import deque
|
|
6
|
+
from colorlog import ColoredFormatter
|
|
7
|
+
from contextlib import contextmanager
|
|
8
|
+
from typing import Any, Generator, List, Optional, Deque, Dict
|
|
9
|
+
from attackmate_api_server.config import settings
|
|
10
|
+
|
|
11
|
+
LOG_DIR = os.path.abspath(settings.log_dir)
|
|
12
|
+
TARGET_LOGGER_NAMES = ['playbook', 'output', 'json']
|
|
13
|
+
API_CONSOLE_FORMAT = ' %(asctime)s %(log_color)s%(levelname)-8s%(reset)s | API | %(log_color)s%(message)s%(reset)s'
|
|
14
|
+
DATE_FORMAT = '%Y-%m-%d %H:%M:%S'
|
|
15
|
+
|
|
16
|
+
api_logger = logging.getLogger('attackmate_api')
|
|
17
|
+
# Console handler for API logs
|
|
18
|
+
instance_log_formatter = logging.Formatter(
|
|
19
|
+
'%(asctime)s %(levelname)s - %(message)s',
|
|
20
|
+
datefmt='%Y-%m-%d %H:%M:%S'
|
|
21
|
+
)
|
|
22
|
+
json_log_formatter = logging.Formatter('%(message)s')
|
|
23
|
+
|
|
24
|
+
def initialize_api_logger(debug: bool, append_logs: bool) -> logging.Logger:
|
|
25
|
+
api_logger = logging.getLogger('attackmate_api')
|
|
26
|
+
api_logger.setLevel(logging.DEBUG if debug else logging.INFO)
|
|
27
|
+
|
|
28
|
+
if not has_stdout_handler(api_logger):
|
|
29
|
+
console_handler = logging.StreamHandler(sys.stdout)
|
|
30
|
+
formatter = ColoredFormatter(API_CONSOLE_FORMAT, datefmt=DATE_FORMAT)
|
|
31
|
+
console_handler.setFormatter(formatter)
|
|
32
|
+
api_logger.addHandler(console_handler)
|
|
33
|
+
|
|
34
|
+
api_logger.propagate = False
|
|
35
|
+
return api_logger
|
|
36
|
+
|
|
37
|
+
def has_stdout_handler(logger: logging.Logger) -> bool:
|
|
38
|
+
return any(
|
|
39
|
+
isinstance(handler, logging.StreamHandler) and handler.stream == sys.stdout
|
|
40
|
+
for handler in logger.handlers
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
class InMemoryLogHandler(logging.Handler):
|
|
44
|
+
"""
|
|
45
|
+
Captures log records into a deque for returning to the client.
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
def __init__(self, formatter: logging.Formatter):
|
|
49
|
+
super().__init__()
|
|
50
|
+
self.records: Deque[str] = deque()
|
|
51
|
+
self.setFormatter(formatter)
|
|
52
|
+
|
|
53
|
+
def emit(self, record: logging.LogRecord) -> None:
|
|
54
|
+
self.records.append(self.format(record))
|
|
55
|
+
|
|
56
|
+
def get_logs(self) -> List[str]:
|
|
57
|
+
logs = list(self.records)
|
|
58
|
+
return logs
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@contextmanager
|
|
62
|
+
def instance_logging(
|
|
63
|
+
instance_id: str,
|
|
64
|
+
write_playbook_logs_to_disk: bool,
|
|
65
|
+
log_level: int = logging.INFO
|
|
66
|
+
) -> Generator[Dict[str, Any], None, None]:
|
|
67
|
+
"""
|
|
68
|
+
Context manager for per-instance logging.
|
|
69
|
+
Always captures logs in-memory to return to the client.
|
|
70
|
+
Only writes to disk if write_playbook_logs_to_disk=True.
|
|
71
|
+
Yields a dict with keys: 'log_files' (List[Optional[str]]) and 'handlers_ref' (InMemoryLogHandler per logger).
|
|
72
|
+
|
|
73
|
+
Exceptions raised inside the `with` block propagate normally — cleanup
|
|
74
|
+
always runs via `finally`, and FastAPI's exception handlers receive the original HTTPException.
|
|
75
|
+
"""
|
|
76
|
+
file_handlers: List[logging.FileHandler] = []
|
|
77
|
+
log_files: List[Optional[str]] = [None, None, None] # [attackmate, output, json]
|
|
78
|
+
|
|
79
|
+
# In-memory handlers — always created
|
|
80
|
+
mem_map: Dict[str, InMemoryLogHandler] = {
|
|
81
|
+
'playbook': InMemoryLogHandler(instance_log_formatter),
|
|
82
|
+
'output': InMemoryLogHandler(instance_log_formatter),
|
|
83
|
+
'json': InMemoryLogHandler(json_log_formatter),
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
try:
|
|
87
|
+
file_map: Dict[str, logging.FileHandler] = {}
|
|
88
|
+
# if write_playbook_logs_to_disk=True logs will be written to disk
|
|
89
|
+
if write_playbook_logs_to_disk:
|
|
90
|
+
os.makedirs(LOG_DIR, exist_ok=True)
|
|
91
|
+
timestamp = datetime.datetime.now().strftime('%Y%m%d_%H%M%S')
|
|
92
|
+
paths = {
|
|
93
|
+
'playbook': os.path.join(LOG_DIR, f"{timestamp}_{instance_id}_attackmate.log"),
|
|
94
|
+
'output': os.path.join(LOG_DIR, f"{timestamp}_{instance_id}_output.log"),
|
|
95
|
+
'json': os.path.join(LOG_DIR, f"{timestamp}_{instance_id}_attackmate.json"),
|
|
96
|
+
}
|
|
97
|
+
formatters = {
|
|
98
|
+
'playbook': instance_log_formatter,
|
|
99
|
+
'output': instance_log_formatter,
|
|
100
|
+
'json': json_log_formatter,
|
|
101
|
+
}
|
|
102
|
+
log_files = [paths['playbook'], paths['output'], paths['json']]
|
|
103
|
+
|
|
104
|
+
for name, path in paths.items():
|
|
105
|
+
file_handler = logging.FileHandler(path, mode='a')
|
|
106
|
+
file_handler.setFormatter(formatters[name])
|
|
107
|
+
file_handler.setLevel(log_level)
|
|
108
|
+
file_map[name] = file_handler
|
|
109
|
+
file_handlers.append(file_handler)
|
|
110
|
+
|
|
111
|
+
# Attach handlers to target loggers
|
|
112
|
+
for logger_name in TARGET_LOGGER_NAMES:
|
|
113
|
+
logger = logging.getLogger(logger_name)
|
|
114
|
+
logger.setLevel(log_level)
|
|
115
|
+
logger.propagate = False
|
|
116
|
+
if mem_map[logger_name] not in logger.handlers:
|
|
117
|
+
logger.addHandler(mem_map[logger_name])
|
|
118
|
+
if write_playbook_logs_to_disk:
|
|
119
|
+
logger.addHandler(file_map[logger_name])
|
|
120
|
+
|
|
121
|
+
api_logger.info(
|
|
122
|
+
f"Instance '{instance_id}': logging set up for '{logger_name}' "
|
|
123
|
+
f"[in-memory=True, file={write_playbook_logs_to_disk}]"
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
yield {
|
|
127
|
+
'log_files': log_files, # paths or None — for response metadata
|
|
128
|
+
'mem_handlers': mem_map, # access .get_logs() after the block
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
finally:
|
|
132
|
+
for logger_name in TARGET_LOGGER_NAMES:
|
|
133
|
+
logger = logging.getLogger(logger_name)
|
|
134
|
+
|
|
135
|
+
mem_h = mem_map.get(logger_name)
|
|
136
|
+
if mem_h:
|
|
137
|
+
logger.removeHandler(mem_h)
|
|
138
|
+
|
|
139
|
+
for handler in list(logger.handlers):
|
|
140
|
+
if isinstance(handler, logging.FileHandler):
|
|
141
|
+
logger.removeHandler(handler)
|
|
142
|
+
|
|
143
|
+
for handler in file_handlers:
|
|
144
|
+
try:
|
|
145
|
+
handler.close()
|
|
146
|
+
except Exception as e:
|
|
147
|
+
api_logger.error(
|
|
148
|
+
f"Error closing file handler for '{instance_id}': {e}", exc_info=True)
|
|
149
|
+
api_logger.info(f"Instance log handlers removed for '{instance_id}'.")
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
from contextlib import asynccontextmanager
|
|
2
|
+
import sys
|
|
3
|
+
from typing import AsyncGenerator
|
|
4
|
+
import os
|
|
5
|
+
import uvicorn
|
|
6
|
+
from attackmate.execexception import ExecException
|
|
7
|
+
from fastapi import Depends, FastAPI, HTTPException, Request, status
|
|
8
|
+
from fastapi.responses import JSONResponse
|
|
9
|
+
from fastapi.security import OAuth2PasswordRequestForm
|
|
10
|
+
from attackmate.attackmate import AttackMate
|
|
11
|
+
from attackmate_api_server.log_utils import initialize_api_logger
|
|
12
|
+
from attackmate.playbook_parser import parse_config
|
|
13
|
+
|
|
14
|
+
import attackmate_api_server.state as state
|
|
15
|
+
from attackmate_api_server.routers import commands, instances, playbooks
|
|
16
|
+
from attackmate_api_server.config import settings
|
|
17
|
+
from attackmate_api_server.auth_utils import create_access_token, get_user_hash, verify_password
|
|
18
|
+
from attackmate_api_server.schemas import TokenResponse
|
|
19
|
+
from attackmate_api_server.metadata import __version__
|
|
20
|
+
|
|
21
|
+
KEY_FILE = os.path.abspath(settings.ssl_key_path)
|
|
22
|
+
CERT_FILE = os.path.abspath(settings.ssl_cert_path)
|
|
23
|
+
|
|
24
|
+
# Initialize loggers
|
|
25
|
+
logger = initialize_api_logger(debug=True, append_logs=False)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@asynccontextmanager
|
|
29
|
+
async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
|
|
30
|
+
# Code to run before the application starts accepting requests
|
|
31
|
+
logger.info('AttackMate API starting up (lifespan)...')
|
|
32
|
+
try:
|
|
33
|
+
# Load global config on startup and assign to the variable in state.py
|
|
34
|
+
config_path = settings.attackmate_config_path
|
|
35
|
+
if config_path:
|
|
36
|
+
loaded_config = parse_config(config_file=config_path, logger=logger)
|
|
37
|
+
logger.info(f'Loading AttackMate configuration from specified path: {config_path}')
|
|
38
|
+
else:
|
|
39
|
+
logger.info('No ATTACKMATE_CONFIG_PATH specified, loading default configuration.')
|
|
40
|
+
loaded_config = parse_config(config_file=None, logger=logger)
|
|
41
|
+
if loaded_config:
|
|
42
|
+
state.attackmate_config = loaded_config
|
|
43
|
+
logger.info('Global AttackMate configuration loaded.')
|
|
44
|
+
else:
|
|
45
|
+
raise RuntimeError(
|
|
46
|
+
'Failed to load essential AttackMate configuration (parse_config returned None).')
|
|
47
|
+
# Initialize the INSTANCES dict (it's already defined globally in state.py)
|
|
48
|
+
state.INSTANCES.clear()
|
|
49
|
+
# instantiate the Instance in the INSTANCES dict
|
|
50
|
+
state.INSTANCES['default_context'] = AttackMate(
|
|
51
|
+
playbook=None, config=loaded_config, varstore=None, is_api_instance=True)
|
|
52
|
+
logger.info('Instances dictionary initialized.')
|
|
53
|
+
# any other async startup tasks ?
|
|
54
|
+
|
|
55
|
+
except Exception as e:
|
|
56
|
+
logger.critical(f'Failed to initialize during startup lifespan: {e}', exc_info=True)
|
|
57
|
+
raise RuntimeError(f'Failed to initialize application state: {e}') from e
|
|
58
|
+
|
|
59
|
+
yield # Application runs here
|
|
60
|
+
|
|
61
|
+
# Code to run when the application is shutting down
|
|
62
|
+
logger.warning('AttackMate API shutting down (lifespan)... Cleaning up instances...')
|
|
63
|
+
instance_ids = list(state.INSTANCES.keys())
|
|
64
|
+
for instance_id in instance_ids:
|
|
65
|
+
instance = state.INSTANCES.pop(instance_id, None)
|
|
66
|
+
if instance:
|
|
67
|
+
logger.info(f'Cleaning up instance {instance_id}...')
|
|
68
|
+
try:
|
|
69
|
+
await instance.clean_session_stores()
|
|
70
|
+
# maybe TODO? Move process killing to a thread if it's blocking,
|
|
71
|
+
# or make the ProcessManager async-aware
|
|
72
|
+
instance.pm.kill_or_wait_processes()
|
|
73
|
+
except Exception as e:
|
|
74
|
+
logger.error(f'Error cleaning up instance {instance_id}: {e}', exc_info=True)
|
|
75
|
+
logger.info('Instance cleanup complete (lifespan).')
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
app = FastAPI(
|
|
79
|
+
title='AttackMate API',
|
|
80
|
+
description='API for remote control of AttackMate instances and playbook execution.',
|
|
81
|
+
version=__version__,
|
|
82
|
+
lifespan=lifespan)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
# Exception Handling
|
|
86
|
+
@app.exception_handler(ExecException) # type: ignore[misc]
|
|
87
|
+
async def attackmate_execution_exception_handler(request: Request, exc: ExecException) -> JSONResponse:
|
|
88
|
+
logger.error(f'AttackMate Execution Exception: {exc}')
|
|
89
|
+
return JSONResponse(
|
|
90
|
+
status_code=400,
|
|
91
|
+
content={
|
|
92
|
+
'detail': 'AttackMate command execution failed',
|
|
93
|
+
'error_message': str(exc),
|
|
94
|
+
'instance_id': None
|
|
95
|
+
},
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
@app.exception_handler(Exception) # type: ignore[misc]
|
|
100
|
+
async def generic_exception_handler(request: Request, exc: Exception) -> JSONResponse:
|
|
101
|
+
if isinstance(exc, SystemExit):
|
|
102
|
+
logger.error(f'Command triggered SystemExit with code {exc.code}')
|
|
103
|
+
return JSONResponse(
|
|
104
|
+
status_code=400, # client-side error pattern
|
|
105
|
+
content={
|
|
106
|
+
'detail': 'Command execution led to termination request',
|
|
107
|
+
'error_message': (
|
|
108
|
+
f"SystemExit triggered (likely due to error condition like 'exit_on_error'). "
|
|
109
|
+
f'Exit code: {exc.code}'
|
|
110
|
+
),
|
|
111
|
+
'instance_id': None
|
|
112
|
+
},
|
|
113
|
+
)
|
|
114
|
+
# Re-raise other exceptions for specific handling?
|
|
115
|
+
raise exc
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
# Login endpoint
|
|
119
|
+
@app.post('/login', response_model=TokenResponse, tags=['Auth']) # type: ignore[misc]
|
|
120
|
+
async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends()) -> TokenResponse:
|
|
121
|
+
"""Authenticates user and returns an access token."""
|
|
122
|
+
logger.info(f'Login attempt for user: {form_data.username}')
|
|
123
|
+
hashed_password = get_user_hash(form_data.username)
|
|
124
|
+
if not hashed_password:
|
|
125
|
+
logger.warning(f"Login failed: User '{form_data.username}' not found.")
|
|
126
|
+
raise HTTPException(
|
|
127
|
+
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
128
|
+
detail='Incorrect username or password',
|
|
129
|
+
headers={'WWW-Authenticate': 'Bearer'},
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
if not verify_password(form_data.password, hashed_password):
|
|
133
|
+
logger.warning(f"Login failed: Invalid password for user '{form_data.username}'.")
|
|
134
|
+
raise HTTPException(
|
|
135
|
+
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
136
|
+
detail='Incorrect username or password',
|
|
137
|
+
headers={'WWW-Authenticate': 'Bearer'},
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
# vlid password -> create token
|
|
141
|
+
access_token = create_access_token(username=form_data.username)
|
|
142
|
+
logger.info(f"Login successful for user '{form_data.username}'. Token created.")
|
|
143
|
+
# Return token
|
|
144
|
+
return TokenResponse(access_token=access_token, token_type='bearer') # nosec B106 (not a password)
|
|
145
|
+
|
|
146
|
+
# Include Routers
|
|
147
|
+
app.include_router(instances.router, prefix='/instances')
|
|
148
|
+
app.include_router(playbooks.router)
|
|
149
|
+
app.include_router(commands.router)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
# Root Endpoint
|
|
153
|
+
@app.get('/', include_in_schema=False) # type: ignore[misc]
|
|
154
|
+
async def root() -> dict[str, str]:
|
|
155
|
+
return {'message': 'AttackMate API is running. Use /login to authenticate. See /docs.'}
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def start() -> None:
|
|
159
|
+
if not os.path.exists(KEY_FILE):
|
|
160
|
+
logger.critical(f'SSL Error: Key file not found at {KEY_FILE}')
|
|
161
|
+
sys.exit(1)
|
|
162
|
+
if not os.path.exists(CERT_FILE):
|
|
163
|
+
logger.critical(f'SSL Error: Certificate file not found at {CERT_FILE}')
|
|
164
|
+
sys.exit(1)
|
|
165
|
+
uvicorn.run('attackmate_api_server.main:app',
|
|
166
|
+
host='0.0.0.0', # nosec B104 - remote API server, must be reachable from the network
|
|
167
|
+
port=settings.attackmate_api_server_port,
|
|
168
|
+
reload=False,
|
|
169
|
+
|
|
170
|
+
ssl_keyfile=KEY_FILE,
|
|
171
|
+
ssl_certfile=CERT_FILE)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
if __name__ == '__main__':
|
|
175
|
+
start()
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
__authors__ = ['Thorina Boenke']
|
|
2
|
+
|
|
3
|
+
__copyright__ = 'Copyright 2025, AIT Austrian Institute of Technology GmbH'
|
|
4
|
+
__date__ = '2026/11/26'
|
|
5
|
+
__license__ = 'EUPL-1.2'
|
|
6
|
+
__maintainer__ = 'Thorina Boenke, Wolfgang Hotwagner'
|
|
7
|
+
__status__ = 'Production'
|
|
8
|
+
__version__ = '1.1.0'
|
|
9
|
+
__version_string__ = (
|
|
10
|
+
f'(Austrian Institute of Technology)\t'
|
|
11
|
+
f'Version: {__version__}')
|
|
12
|
+
__all__ = [
|
|
13
|
+
'__authors__',
|
|
14
|
+
'__copyright__',
|
|
15
|
+
'__date__',
|
|
16
|
+
'__maintainer__',
|
|
17
|
+
'__status__',
|
|
18
|
+
'__version__',
|
|
19
|
+
'__version_string__']
|
|
File without changes
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
from attackmate.attackmate import AttackMate
|
|
5
|
+
from attackmate.schemas.base import BaseCommand
|
|
6
|
+
from fastapi import APIRouter, Depends, Header, HTTPException
|
|
7
|
+
from attackmate.execexception import ExecException
|
|
8
|
+
from attackmate.result import Result as AttackMateResult
|
|
9
|
+
from attackmate.schemas.command_subtypes import RemotelyExecutableCommand
|
|
10
|
+
|
|
11
|
+
from attackmate_api_server.auth_utils import API_KEY_HEADER_NAME, get_current_user
|
|
12
|
+
from attackmate_api_server.schemas import CommandResultModel, ExecutionResponseModel
|
|
13
|
+
from attackmate_api_server.utils import varstore_to_state_model
|
|
14
|
+
from attackmate_api_server.state import get_persistent_instance
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
router = APIRouter(prefix='/command', tags=['Commands'])
|
|
18
|
+
logger = logging.getLogger('attackmate_api')
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
async def run_command_on_instance(instance: AttackMate, command_data: BaseCommand) -> AttackMateResult:
|
|
22
|
+
"""Runs a command on a given AttackMate instance."""
|
|
23
|
+
try:
|
|
24
|
+
logger.info(f"Executing command type '{command_data.type}' on instance")
|
|
25
|
+
result = await instance.run_command(command_data)
|
|
26
|
+
logger.info(f'Command execution finished. RC: {result.returncode}')
|
|
27
|
+
return result
|
|
28
|
+
except (ExecException, SystemExit) as e:
|
|
29
|
+
logger.error(f'AttackMate execution error: {e}', exc_info=True)
|
|
30
|
+
raise e
|
|
31
|
+
except Exception as e:
|
|
32
|
+
logger.error(f'Unexpected error during instance.run_command: {e}', exc_info=True)
|
|
33
|
+
raise HTTPException(status_code=500, detail=f'Internal server error during command execution: {e}')
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@router.post('/execute', response_model=ExecutionResponseModel) # type: ignore[misc]
|
|
37
|
+
async def execute_unified_command(
|
|
38
|
+
command_request: RemotelyExecutableCommand,
|
|
39
|
+
instance: AttackMate = Depends(get_persistent_instance),
|
|
40
|
+
current_user: str = Depends(get_current_user),
|
|
41
|
+
x_auth_token: Optional[str] = Header(None, alias=API_KEY_HEADER_NAME)
|
|
42
|
+
) -> ExecutionResponseModel:
|
|
43
|
+
# command_request will be the correct Pydantic type based on discriminated
|
|
44
|
+
# union in RemotelyExecutableCommand
|
|
45
|
+
try:
|
|
46
|
+
attackmate_result = await run_command_on_instance(instance, command_request)
|
|
47
|
+
success = (attackmate_result.returncode == 0)
|
|
48
|
+
stdout = str(attackmate_result.stdout)
|
|
49
|
+
error_msg = None
|
|
50
|
+
return_code = attackmate_result.returncode
|
|
51
|
+
except ExecException as exc:
|
|
52
|
+
logger.error(f'Command execution failed: {exc}')
|
|
53
|
+
success = False
|
|
54
|
+
stdout = ''
|
|
55
|
+
error_msg = str(exc)
|
|
56
|
+
return_code = 1
|
|
57
|
+
|
|
58
|
+
result_model = CommandResultModel(
|
|
59
|
+
success=success,
|
|
60
|
+
stdout=stdout,
|
|
61
|
+
returncode=return_code,
|
|
62
|
+
error_message=error_msg
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
state_model = varstore_to_state_model(instance.varstore)
|
|
66
|
+
|
|
67
|
+
return ExecutionResponseModel(
|
|
68
|
+
result=result_model,
|
|
69
|
+
state=state_model,
|
|
70
|
+
instance_id='default-context',
|
|
71
|
+
)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
from fastapi import APIRouter, Depends
|
|
4
|
+
from attackmate.attackmate import AttackMate
|
|
5
|
+
|
|
6
|
+
from attackmate_api_server.auth_utils import get_current_user
|
|
7
|
+
from attackmate_api_server.schemas import VariableStoreStateModel
|
|
8
|
+
from attackmate_api_server.utils import varstore_to_state_model
|
|
9
|
+
|
|
10
|
+
from attackmate_api_server.state import get_instance_by_id, get_persistent_instance
|
|
11
|
+
|
|
12
|
+
router = APIRouter(tags=['Instances'])
|
|
13
|
+
logger = logging.getLogger('attackmate_api')
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@router.get('/{instance_id}/state', response_model=VariableStoreStateModel) # type: ignore[misc]
|
|
17
|
+
async def get_instance_state(
|
|
18
|
+
instance: AttackMate = Depends(get_instance_by_id),
|
|
19
|
+
current_user: str = Depends(get_current_user)
|
|
20
|
+
) -> VariableStoreStateModel:
|
|
21
|
+
return varstore_to_state_model(instance.varstore)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@router.get('/state', response_model=VariableStoreStateModel) # type: ignore[misc]
|
|
25
|
+
async def get_persistent_instance_state(
|
|
26
|
+
instance: AttackMate = Depends(get_persistent_instance),
|
|
27
|
+
current_user: str = Depends(get_current_user)
|
|
28
|
+
) -> VariableStoreStateModel:
|
|
29
|
+
return varstore_to_state_model(instance.varstore)
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import uuid
|
|
3
|
+
from typing import Optional
|
|
4
|
+
import yaml
|
|
5
|
+
from attackmate.schemas.playbook import Playbook
|
|
6
|
+
from fastapi import APIRouter, Body, Depends, Header, HTTPException, Query
|
|
7
|
+
from pydantic import ValidationError
|
|
8
|
+
from attackmate.attackmate import AttackMate
|
|
9
|
+
from attackmate_api_server.auth_utils import API_KEY_HEADER_NAME, get_current_user
|
|
10
|
+
from attackmate_api_server.schemas import PlaybookResponseModel
|
|
11
|
+
from attackmate_api_server.utils import varstore_to_state_model
|
|
12
|
+
from attackmate_api_server.log_utils import instance_logging
|
|
13
|
+
from attackmate_api_server.state import get_attackmate_config
|
|
14
|
+
from attackmate_api_server.config import settings
|
|
15
|
+
|
|
16
|
+
router = APIRouter(prefix='/playbooks', tags=['Playbooks'])
|
|
17
|
+
logger = logging.getLogger('attackmate_api')
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _format_validation_errors(exc: ValidationError) -> list[str]:
|
|
21
|
+
"""Convert a Pydantic ValidationError into a list of human-readable
|
|
22
|
+
strings."""
|
|
23
|
+
return [
|
|
24
|
+
f"'{' -> '.join(str(p) for p in e['loc']) or '(root)'}': {e['msg']}"
|
|
25
|
+
for e in exc.errors()
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@router.post('/execute/yaml', response_model=PlaybookResponseModel) # type: ignore[misc]
|
|
30
|
+
async def execute_playbook_from_yaml(
|
|
31
|
+
playbook_yaml: str = Body(..., media_type='application/yaml'),
|
|
32
|
+
debug: bool = Query(
|
|
33
|
+
False,
|
|
34
|
+
description=(
|
|
35
|
+
"Enable DEBUG log level for the AttackMate instance executing this playbook. "
|
|
36
|
+
"File logging on the API server is controlled by WRITE_PLAYBOOK_LOGS_TO_DISK in .env."
|
|
37
|
+
)
|
|
38
|
+
),
|
|
39
|
+
current_user: str = Depends(get_current_user),
|
|
40
|
+
x_auth_token: Optional[str] = Header(None, alias=API_KEY_HEADER_NAME)
|
|
41
|
+
) -> PlaybookResponseModel:
|
|
42
|
+
"""Executes a playbook provided as YAML content in the request body.
|
|
43
|
+
|
|
44
|
+
Uses a transient AttackMate instance.
|
|
45
|
+
|
|
46
|
+
- `debug` (query param): controls the AttackMate instance log level (DEBUG vs INFO)
|
|
47
|
+
- `WRITE_PLAYBOOK_LOGS_TO_DISK` (.env setting): instance logs saved to disk on the server
|
|
48
|
+
to LOG_DIR. (Logs are in any case captured in-memory and returned in the response.)
|
|
49
|
+
"""
|
|
50
|
+
logger.info('Received request to execute playbook from YAML content.')
|
|
51
|
+
instance_id = str(uuid.uuid4())
|
|
52
|
+
|
|
53
|
+
# debug (query param) -> AttackMate instance log level
|
|
54
|
+
instance_log_level = logging.DEBUG if debug else logging.INFO
|
|
55
|
+
write_logs_to_disk = settings.write_playbook_logs_to_disk
|
|
56
|
+
|
|
57
|
+
am_instance = None
|
|
58
|
+
return_code = 1
|
|
59
|
+
final_state = None
|
|
60
|
+
attackmate_log: Optional[str] = None
|
|
61
|
+
output_log: Optional[str] = None
|
|
62
|
+
json_log: Optional[str] = None
|
|
63
|
+
|
|
64
|
+
with instance_logging(
|
|
65
|
+
instance_id,
|
|
66
|
+
write_playbook_logs_to_disk=write_logs_to_disk,
|
|
67
|
+
log_level=instance_log_level
|
|
68
|
+
) as log_ctx:
|
|
69
|
+
try:
|
|
70
|
+
playbook_dict = yaml.safe_load(playbook_yaml)
|
|
71
|
+
if not playbook_dict:
|
|
72
|
+
raise ValueError('Received empty or invalid playbook YAML content.')
|
|
73
|
+
playbook = Playbook.model_validate(playbook_dict)
|
|
74
|
+
logger.info(f'Creating transient AttackMate instance, ID: {instance_id}')
|
|
75
|
+
am_config = get_attackmate_config()
|
|
76
|
+
am_instance = AttackMate(playbook=playbook, config=am_config,
|
|
77
|
+
varstore=None, is_api_instance=True)
|
|
78
|
+
return_code = await am_instance.main()
|
|
79
|
+
final_state = varstore_to_state_model(am_instance.varstore)
|
|
80
|
+
logger.info(f'Transient playbook execution finished. Return code: {return_code}')
|
|
81
|
+
except yaml.YAMLError as e:
|
|
82
|
+
logger.error(f'Playbook YAML parse error: {e}')
|
|
83
|
+
raise HTTPException(
|
|
84
|
+
status_code=422,
|
|
85
|
+
detail={'message': 'Invalid playbook YAML: failed to parse YAML.', 'errors': [str(e)]},
|
|
86
|
+
)
|
|
87
|
+
except ValidationError as e:
|
|
88
|
+
errors = _format_validation_errors(e)
|
|
89
|
+
logger.error(f'Playbook validation error ({len(errors)} issue(s)): ' + '; '.join(errors))
|
|
90
|
+
raise HTTPException(
|
|
91
|
+
status_code=422,
|
|
92
|
+
detail={
|
|
93
|
+
'message': f'Invalid playbook: {len(errors)} validation error(s).',
|
|
94
|
+
'errors': errors,
|
|
95
|
+
},
|
|
96
|
+
)
|
|
97
|
+
except ValueError as e:
|
|
98
|
+
logger.error(f'Playbook value error: {e}')
|
|
99
|
+
raise HTTPException(
|
|
100
|
+
status_code=422,
|
|
101
|
+
detail={'message': 'Invalid playbook YAML.', 'errors': [str(e)]},
|
|
102
|
+
)
|
|
103
|
+
except Exception as e:
|
|
104
|
+
logger.error(f'Unexpected error during playbook execution: {e}', exc_info=True)
|
|
105
|
+
raise HTTPException(status_code=500, detail=f'Server error during playbook execution: {e}')
|
|
106
|
+
finally:
|
|
107
|
+
if am_instance:
|
|
108
|
+
logger.info('Cleaning up transient playbook instance.')
|
|
109
|
+
try:
|
|
110
|
+
await am_instance.clean_session_stores()
|
|
111
|
+
am_instance.pm.kill_or_wait_processes()
|
|
112
|
+
except Exception as cleanup_e:
|
|
113
|
+
logger.error(f'Error cleaning transient instance: {cleanup_e}', exc_info=True)
|
|
114
|
+
|
|
115
|
+
# Always return logs from in-memory capture (always sent back to client)
|
|
116
|
+
mem = log_ctx['mem_handlers']
|
|
117
|
+
attackmate_log = '\n'.join(mem['playbook'].get_logs()) or None
|
|
118
|
+
output_log = '\n'.join(mem['output'].get_logs()) or None
|
|
119
|
+
json_log = '\n'.join(mem['json'].get_logs()) or None
|
|
120
|
+
|
|
121
|
+
# Optionally include file paths in logs if written to disk
|
|
122
|
+
if write_logs_to_disk:
|
|
123
|
+
log_files = log_ctx['log_files']
|
|
124
|
+
logger.info(f'Instance logs written to disk: {log_files}')
|
|
125
|
+
|
|
126
|
+
return PlaybookResponseModel(
|
|
127
|
+
success=(return_code == 0),
|
|
128
|
+
message='Playbook execution finished.',
|
|
129
|
+
final_state=final_state,
|
|
130
|
+
instance_id=instance_id,
|
|
131
|
+
attackmate_log=attackmate_log,
|
|
132
|
+
output_log=output_log,
|
|
133
|
+
json_log=json_log,
|
|
134
|
+
)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from typing import Any, Dict, Optional
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, Field
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class VariableStoreStateModel(BaseModel):
|
|
7
|
+
variables: Dict[str, Any] = {}
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class CommandResultModel(BaseModel):
|
|
11
|
+
success: bool
|
|
12
|
+
stdout: Optional[str] = None
|
|
13
|
+
returncode: Optional[int] = None
|
|
14
|
+
error_message: Optional[str] = None
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ExecutionResponseModel(BaseModel):
|
|
18
|
+
result: CommandResultModel
|
|
19
|
+
state: VariableStoreStateModel
|
|
20
|
+
instance_id: Optional[str] = None
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class PlaybookResponseModel(BaseModel):
|
|
24
|
+
success: bool
|
|
25
|
+
message: str
|
|
26
|
+
final_state: Optional[VariableStoreStateModel] = None
|
|
27
|
+
instance_id: Optional[str] = None
|
|
28
|
+
attackmate_log: Optional[str] = Field(None, description='Content of the attackmate.log for this run.')
|
|
29
|
+
output_log: Optional[str] = Field(None, description='Content of the output.log for this run.')
|
|
30
|
+
json_log: Optional[str] = Field(None, description='Content of the attackmate.json for this run.')
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class TokenResponse(BaseModel):
|
|
34
|
+
access_token: str
|
|
35
|
+
token_type: str = 'bearer'
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from typing import Dict, Optional
|
|
2
|
+
|
|
3
|
+
from fastapi import Depends, HTTPException, Path
|
|
4
|
+
from attackmate.attackmate import AttackMate
|
|
5
|
+
from attackmate.schemas.config import Config
|
|
6
|
+
|
|
7
|
+
# Define shared state variables here
|
|
8
|
+
INSTANCES: Dict[str, AttackMate] = {}
|
|
9
|
+
attackmate_config: Optional[Config] = None
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def get_instances_dict() -> Dict[str, AttackMate]:
|
|
13
|
+
"""Dependency to get the shared INSTANCES dictionary."""
|
|
14
|
+
# returns the global dict reference
|
|
15
|
+
return INSTANCES
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def get_attackmate_config() -> Config:
|
|
19
|
+
"""Dependency to get the shared AttackMate configuration."""
|
|
20
|
+
if attackmate_config is None:
|
|
21
|
+
raise RuntimeError('Server configuration is not available.')
|
|
22
|
+
return attackmate_config
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def get_instance_by_id(
|
|
26
|
+
instance_id: str = Path(...),
|
|
27
|
+
instances: Dict[str, AttackMate] = Depends(get_instances_dict)
|
|
28
|
+
) -> AttackMate:
|
|
29
|
+
"""Dependency to get a specific AttackMate instance, raising 404 if not
|
|
30
|
+
found."""
|
|
31
|
+
instance = instances.get(instance_id)
|
|
32
|
+
if not instance:
|
|
33
|
+
raise HTTPException(status_code=404, detail=f"AttackMate instance '{instance_id}' not found.")
|
|
34
|
+
return instance
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def get_persistent_instance(
|
|
38
|
+
instances: Dict[str, AttackMate] = Depends(get_instances_dict)
|
|
39
|
+
) -> AttackMate:
|
|
40
|
+
"""Dependency to get the default context persistent AttackMate instance,
|
|
41
|
+
raising 404 if not found."""
|
|
42
|
+
instance = instances.get('default_context')
|
|
43
|
+
if not instance:
|
|
44
|
+
raise HTTPException(status_code=404, detail='Persistent AttackMate instance not found.')
|
|
45
|
+
return instance
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from typing import Any, Dict
|
|
2
|
+
|
|
3
|
+
from attackmate.variablestore import VariableStore
|
|
4
|
+
|
|
5
|
+
from attackmate_api_server.schemas import VariableStoreStateModel
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def varstore_to_state_model(varstore: VariableStore) -> VariableStoreStateModel:
|
|
9
|
+
"""Converts AttackMate VariableStore to Pydantic
|
|
10
|
+
VariableStoreStateModel."""
|
|
11
|
+
combined_vars: Dict[str, Any] = {}
|
|
12
|
+
combined_vars.update(varstore.variables)
|
|
13
|
+
combined_vars.update(varstore.lists)
|
|
14
|
+
return VariableStoreStateModel(variables=combined_vars)
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: attackmate-api-server
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: API server for remote control and execution of AttackMate instances.
|
|
5
|
+
Author-email: Thorina Boenke <aecid@ait.ac.at>
|
|
6
|
+
Maintainer: Wolfgang Hotwagner
|
|
7
|
+
Maintainer-email: Thorina Boenke <aecid@ait.ac.at>
|
|
8
|
+
License-Expression: EUPL-1.2
|
|
9
|
+
Project-URL: Homepage, https://github.com/ait-testbed/attackmate-api-server
|
|
10
|
+
Project-URL: Repository, https://github.com/ait-testbed/attackmate-api-server
|
|
11
|
+
Project-URL: Issues, https://github.com/ait-testbed/attackmate-api-server/issues
|
|
12
|
+
Project-URL: Changelog, https://github.com/ait-testbed/attackmate-api-server/releases
|
|
13
|
+
Keywords: attackmate,fastapi,security,penetration-testing
|
|
14
|
+
Requires-Python: >=3.11
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE.md
|
|
17
|
+
Requires-Dist: fastapi
|
|
18
|
+
Requires-Dist: uvicorn[standard]
|
|
19
|
+
Requires-Dist: colorlog
|
|
20
|
+
Requires-Dist: pydantic
|
|
21
|
+
Requires-Dist: python-multipart
|
|
22
|
+
Requires-Dist: argon2-cffi
|
|
23
|
+
Requires-Dist: python-dotenv
|
|
24
|
+
Requires-Dist: pyyaml
|
|
25
|
+
Requires-Dist: attackmate>=1.0.2
|
|
26
|
+
Requires-Dist: pydantic-settings>=2.13.1
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# AttackMate API Server
|
|
30
|
+
|
|
31
|
+
**AttackMate API Server** is a RESTful API built with FastAPI for remotely controlling AttackMate instances and executing attack playbooks. It provides secure endpoints to orchestrate attack chains, execute commands, and run attack playbook.
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
## Features
|
|
35
|
+
|
|
36
|
+
- Execute AttackMate commands or playbooks remotely
|
|
37
|
+
- Automatic logging for requests, command execution, and playbooks.
|
|
38
|
+
- Supports SSL/TLS for secure communication.
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## Requirements
|
|
42
|
+
|
|
43
|
+
- Python 3.11+
|
|
44
|
+
- [uv](https://docs.astral.sh/uv/)
|
|
45
|
+
- openssl
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
48
|
+
|
|
49
|
+
From PyPI:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
uv tool install attackmate-api-server
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
This installs the `attackmate-api` command on your PATH. Configuration (`.env`, `key.pem`, `cert.pem`) is read
|
|
56
|
+
from the directory you start it in.
|
|
57
|
+
|
|
58
|
+
From source:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
git clone https://github.com/ait-testbed/attackmate-api-server.git
|
|
62
|
+
cd attackmate-api-server
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
uv sync
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Developer setup
|
|
69
|
+
|
|
70
|
+
If you plan to contribute to the development of this package, follow these steps to set up the dev environment and install pre-commit hooks (using [prek](https://github.com/j178/prek))
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
uv sync --dev
|
|
74
|
+
uv run --dev prek install
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Run the tests:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
uv run --dev pytest -q
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Run the tests with coverage (add `--cov-report=html` to generate an HTML report):
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
uv run --dev pytest --cov=. --cov-report=term-missing
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Certificate generation
|
|
90
|
+
with open ssl
|
|
91
|
+
```bash
|
|
92
|
+
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Common Name: server IP adress
|
|
96
|
+
|
|
97
|
+
Clients receive the cert.pem SSL certificate
|
|
98
|
+
|
|
99
|
+
By default the server looks for `key.pem` and `cert.pem` in the directory you start it from
|
|
100
|
+
(the same directory as `.env`). Set `SSL_KEY_PATH` and `SSL_CERT_PATH` to use files elsewhere.
|
|
101
|
+
|
|
102
|
+
## Environment Configuration
|
|
103
|
+
Create an .env file in the project root with the following variables:
|
|
104
|
+
```env
|
|
105
|
+
USERS='{"username": "<argon2_hash>", ...}'
|
|
106
|
+
ATTACKMATE_CONFIG_PATH="/path/to/attackmate.yml"
|
|
107
|
+
WRITE_PLAYBOOK_LOGS_TO_DISK="False"
|
|
108
|
+
LOG_DIR="/path/to/logs"
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
| Variable | Description |
|
|
112
|
+
|---|---|
|
|
113
|
+
| `USERS` | JSON object mapping usernames to Argon2-hashed passwords |
|
|
114
|
+
| `ATTACKMATE_CONFIG_PATH` | Absolute path to the AttackMate config YAML |
|
|
115
|
+
| `WRITE_PLAYBOOK_LOGS_TO_DISK` | Whether to persist playbook logs to disk (`True`/`False`) |
|
|
116
|
+
| `LOG_DIR` | Directory for log output |
|
|
117
|
+
| `ATTACKMATE_API_SERVER_PORT` | The port on which the server listens for incoming REST API requests. |
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
To generate a password hash for `USERS`, run this and type the password when asked:
|
|
121
|
+
```bash
|
|
122
|
+
uv run --with argon2-cffi python -c "import getpass; from argon2 import PasswordHasher; print(PasswordHasher().hash(getpass.getpass()))"
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Put the printed hash into your .env file, keeping the outer single quotes (the hash contains `$`):
|
|
126
|
+
```env
|
|
127
|
+
USERS='{"alice": "$argon2id$v=19$m=65536,t=3,p=4$..."}'
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
## Running the application
|
|
132
|
+
```bash
|
|
133
|
+
attackmate-api # installed with uv tool install
|
|
134
|
+
uv run attackmate-api # from a source checkout
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
The server will run on https://0.0.0.0:8445 by default.
|
|
138
|
+
|
|
139
|
+
Can be changed via ATTACKMATE_API_SERVER_PORT in the .env file
|
|
140
|
+
|
|
141
|
+
Swagger UI: https://<host>:8445/docs – interactive API documentation.
|
|
142
|
+
|
|
143
|
+
## Authentication
|
|
144
|
+
The API uses token-based authentication.
|
|
145
|
+
|
|
146
|
+
Endpoint: `POST /login`
|
|
147
|
+
|
|
148
|
+
Request:
|
|
149
|
+
```json
|
|
150
|
+
{
|
|
151
|
+
"username": "your_username",
|
|
152
|
+
"password": "your_password"
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Response:
|
|
157
|
+
```json
|
|
158
|
+
{
|
|
159
|
+
"access_token": "<TOKEN>",
|
|
160
|
+
"token_type": "bearer"
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Use the token in the Authorization header for all protected endpoints
|
|
165
|
+
|
|
166
|
+
## API Endpoints
|
|
167
|
+
`POST /playbooks/execute/yaml` – Execute a playbook provided as YAML content on an AttackMate instantiated for the duration of playbook execution.
|
|
168
|
+
|
|
169
|
+
`POST /command/execute` – Execute a command on a persistent AttackMate instance.
|
|
170
|
+
Request body must follow the RemotelyExecutableCommand schema
|
|
171
|
+
|
|
172
|
+
## Client Usage
|
|
173
|
+
The recommended way to interact with the API is via the [AttackMate Client](https://github.com/ait-testbed/attackmate-client), which provides a convenient interface for authentication, playbook submission, and result retrieval.
|
|
174
|
+
|
|
175
|
+
## Security Notes
|
|
176
|
+
**Use strong passwords.** Anyone who can log in can run commands on the server.
|
|
177
|
+
**Never commit `.env` to version control.** Ensure `.env` is listed in `.gitignore`.
|
|
178
|
+
**Use CA-signed certificates in production.** Self-signed certificates should only be used for local testing.
|
|
179
|
+
**Restrict network access** to the API server to trusted hosts where possible.
|
|
180
|
+
|
|
181
|
+
## Related Projects
|
|
182
|
+
[AttackMate](https://github.com/ait-testbed/attackmate) – the underlying attack orchestration engine
|
|
183
|
+
[AttackMate Client](https://github.com/ait-testbed/attackmate-client) – recommended client for interacting with this API
|
|
184
|
+
|
|
185
|
+
## License
|
|
186
|
+
This project is licensed under [EUPL-1.2](LICENSE)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
attackmate_api_server/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
attackmate_api_server/auth_utils.py,sha256=pk5zuuE5nrowQQFHEqD1HLDVGkDYi0nnhkyNgPDD2bk,3801
|
|
3
|
+
attackmate_api_server/config.py,sha256=vXGiiBscx7D3wU6EIql4zUCEtL3Yd20SI53WbWX99O4,996
|
|
4
|
+
attackmate_api_server/log_utils.py,sha256=mKHt_vjkL4kGPWKCrYhkLHQPS_LeLVRjKP44_oNi46U,5829
|
|
5
|
+
attackmate_api_server/main.py,sha256=yOK01woq4N_kECzhmK69P1sN_RYpEx4rurWQ7161UrA,7350
|
|
6
|
+
attackmate_api_server/metadata.py,sha256=TQ3V_lQRAFixqqQ1b1AjWpn0TnWkz32ANCRTREKzcf4,512
|
|
7
|
+
attackmate_api_server/schemas.py,sha256=wkiw7PbioG5UFy53g9cVoMzfprG8d1FbXYlITE-cKEc,1039
|
|
8
|
+
attackmate_api_server/state.py,sha256=jMRmDBCDoI-aSdQBxh6APRZCVEuC2rGtwAk_z2jbX60,1537
|
|
9
|
+
attackmate_api_server/utils.py,sha256=FPJNNuMqgpTYgEFVyh6P9oV30_RMn-0QAza4OZwqEwI,501
|
|
10
|
+
attackmate_api_server/routers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
+
attackmate_api_server/routers/commands.py,sha256=fIodGE9JzoQkHswKvQIOrArD6UFKZuMdXXzWZGi1kMc,2870
|
|
12
|
+
attackmate_api_server/routers/instances.py,sha256=i7_dEB9pyc_DqQv7JSbgV3HM8zBjtnKTIevcGybdZDU,1105
|
|
13
|
+
attackmate_api_server/routers/playbooks.py,sha256=mRTCBi8Krc-Bkdm_2TTFDcO76YvIOmZvxAtVvqIz5CI,5872
|
|
14
|
+
attackmate_api_server-1.1.0.dist-info/licenses/LICENSE.md,sha256=b8nnCcy_4Nd_v_okJ6mDKCvi64jkexzbSfIag7TR5mU,13827
|
|
15
|
+
attackmate_api_server-1.1.0.dist-info/METADATA,sha256=aCu4FkBAgCx44z1rTVl3keotDnuQDXPFNMApWSqAsM8,5825
|
|
16
|
+
attackmate_api_server-1.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
17
|
+
attackmate_api_server-1.1.0.dist-info/entry_points.txt,sha256=56Grj6a-46IZH0FStHRZpbe_kRBs9Mb-mopdPdt-AHM,68
|
|
18
|
+
attackmate_api_server-1.1.0.dist-info/top_level.txt,sha256=lRgmv19apEtt6bGv25Wc13tWte3oxmO2ZKIxf6IRyJ8,22
|
|
19
|
+
attackmate_api_server-1.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
EUROPEAN UNION PUBLIC LICENCE v. 1.2
|
|
2
|
+
EUPL © the European Union 2007, 2016
|
|
3
|
+
|
|
4
|
+
This European Union Public Licence (the ‘EUPL’) applies to the Work (as defined
|
|
5
|
+
below) which is provided under the terms of this Licence. Any use of the Work,
|
|
6
|
+
other than as authorised under this Licence is prohibited (to the extent such
|
|
7
|
+
use is covered by a right of the copyright holder of the Work).
|
|
8
|
+
|
|
9
|
+
The Work is provided under the terms of this Licence when the Licensor (as
|
|
10
|
+
defined below) has placed the following notice immediately following the
|
|
11
|
+
copyright notice for the Work:
|
|
12
|
+
|
|
13
|
+
Licensed under the EUPL
|
|
14
|
+
|
|
15
|
+
or has expressed by any other means his willingness to license under the EUPL.
|
|
16
|
+
|
|
17
|
+
1. Definitions
|
|
18
|
+
|
|
19
|
+
In this Licence, the following terms have the following meaning:
|
|
20
|
+
|
|
21
|
+
- ‘The Licence’: this Licence.
|
|
22
|
+
|
|
23
|
+
- ‘The Original Work’: the work or software distributed or communicated by the
|
|
24
|
+
Licensor under this Licence, available as Source Code and also as Executable
|
|
25
|
+
Code as the case may be.
|
|
26
|
+
|
|
27
|
+
- ‘Derivative Works’: the works or software that could be created by the
|
|
28
|
+
Licensee, based upon the Original Work or modifications thereof. This Licence
|
|
29
|
+
does not define the extent of modification or dependence on the Original Work
|
|
30
|
+
required in order to classify a work as a Derivative Work; this extent is
|
|
31
|
+
determined by copyright law applicable in the country mentioned in Article 15.
|
|
32
|
+
|
|
33
|
+
- ‘The Work’: the Original Work or its Derivative Works.
|
|
34
|
+
|
|
35
|
+
- ‘The Source Code’: the human-readable form of the Work which is the most
|
|
36
|
+
convenient for people to study and modify.
|
|
37
|
+
|
|
38
|
+
- ‘The Executable Code’: any code which has generally been compiled and which is
|
|
39
|
+
meant to be interpreted by a computer as a program.
|
|
40
|
+
|
|
41
|
+
- ‘The Licensor’: the natural or legal person that distributes or communicates
|
|
42
|
+
the Work under the Licence.
|
|
43
|
+
|
|
44
|
+
- ‘Contributor(s)’: any natural or legal person who modifies the Work under the
|
|
45
|
+
Licence, or otherwise contributes to the creation of a Derivative Work.
|
|
46
|
+
|
|
47
|
+
- ‘The Licensee’ or ‘You’: any natural or legal person who makes any usage of
|
|
48
|
+
the Work under the terms of the Licence.
|
|
49
|
+
|
|
50
|
+
- ‘Distribution’ or ‘Communication’: any act of selling, giving, lending,
|
|
51
|
+
renting, distributing, communicating, transmitting, or otherwise making
|
|
52
|
+
available, online or offline, copies of the Work or providing access to its
|
|
53
|
+
essential functionalities at the disposal of any other natural or legal
|
|
54
|
+
person.
|
|
55
|
+
|
|
56
|
+
2. Scope of the rights granted by the Licence
|
|
57
|
+
|
|
58
|
+
The Licensor hereby grants You a worldwide, royalty-free, non-exclusive,
|
|
59
|
+
sublicensable licence to do the following, for the duration of copyright vested
|
|
60
|
+
in the Original Work:
|
|
61
|
+
|
|
62
|
+
- use the Work in any circumstance and for all usage,
|
|
63
|
+
- reproduce the Work,
|
|
64
|
+
- modify the Work, and make Derivative Works based upon the Work,
|
|
65
|
+
- communicate to the public, including the right to make available or display
|
|
66
|
+
the Work or copies thereof to the public and perform publicly, as the case may
|
|
67
|
+
be, the Work,
|
|
68
|
+
- distribute the Work or copies thereof,
|
|
69
|
+
- lend and rent the Work or copies thereof,
|
|
70
|
+
- sublicense rights in the Work or copies thereof.
|
|
71
|
+
|
|
72
|
+
Those rights can be exercised on any media, supports and formats, whether now
|
|
73
|
+
known or later invented, as far as the applicable law permits so.
|
|
74
|
+
|
|
75
|
+
In the countries where moral rights apply, the Licensor waives his right to
|
|
76
|
+
exercise his moral right to the extent allowed by law in order to make effective
|
|
77
|
+
the licence of the economic rights here above listed.
|
|
78
|
+
|
|
79
|
+
The Licensor grants to the Licensee royalty-free, non-exclusive usage rights to
|
|
80
|
+
any patents held by the Licensor, to the extent necessary to make use of the
|
|
81
|
+
rights granted on the Work under this Licence.
|
|
82
|
+
|
|
83
|
+
3. Communication of the Source Code
|
|
84
|
+
|
|
85
|
+
The Licensor may provide the Work either in its Source Code form, or as
|
|
86
|
+
Executable Code. If the Work is provided as Executable Code, the Licensor
|
|
87
|
+
provides in addition a machine-readable copy of the Source Code of the Work
|
|
88
|
+
along with each copy of the Work that the Licensor distributes or indicates, in
|
|
89
|
+
a notice following the copyright notice attached to the Work, a repository where
|
|
90
|
+
the Source Code is easily and freely accessible for as long as the Licensor
|
|
91
|
+
continues to distribute or communicate the Work.
|
|
92
|
+
|
|
93
|
+
4. Limitations on copyright
|
|
94
|
+
|
|
95
|
+
Nothing in this Licence is intended to deprive the Licensee of the benefits from
|
|
96
|
+
any exception or limitation to the exclusive rights of the rights owners in the
|
|
97
|
+
Work, of the exhaustion of those rights or of other applicable limitations
|
|
98
|
+
thereto.
|
|
99
|
+
|
|
100
|
+
5. Obligations of the Licensee
|
|
101
|
+
|
|
102
|
+
The grant of the rights mentioned above is subject to some restrictions and
|
|
103
|
+
obligations imposed on the Licensee. Those obligations are the following:
|
|
104
|
+
|
|
105
|
+
Attribution right: The Licensee shall keep intact all copyright, patent or
|
|
106
|
+
trademarks notices and all notices that refer to the Licence and to the
|
|
107
|
+
disclaimer of warranties. The Licensee must include a copy of such notices and a
|
|
108
|
+
copy of the Licence with every copy of the Work he/she distributes or
|
|
109
|
+
communicates. The Licensee must cause any Derivative Work to carry prominent
|
|
110
|
+
notices stating that the Work has been modified and the date of modification.
|
|
111
|
+
|
|
112
|
+
Copyleft clause: If the Licensee distributes or communicates copies of the
|
|
113
|
+
Original Works or Derivative Works, this Distribution or Communication will be
|
|
114
|
+
done under the terms of this Licence or of a later version of this Licence
|
|
115
|
+
unless the Original Work is expressly distributed only under this version of the
|
|
116
|
+
Licence — for example by communicating ‘EUPL v. 1.2 only’. The Licensee
|
|
117
|
+
(becoming Licensor) cannot offer or impose any additional terms or conditions on
|
|
118
|
+
the Work or Derivative Work that alter or restrict the terms of the Licence.
|
|
119
|
+
|
|
120
|
+
Compatibility clause: If the Licensee Distributes or Communicates Derivative
|
|
121
|
+
Works or copies thereof based upon both the Work and another work licensed under
|
|
122
|
+
a Compatible Licence, this Distribution or Communication can be done under the
|
|
123
|
+
terms of this Compatible Licence. For the sake of this clause, ‘Compatible
|
|
124
|
+
Licence’ refers to the licences listed in the appendix attached to this Licence.
|
|
125
|
+
Should the Licensee's obligations under the Compatible Licence conflict with
|
|
126
|
+
his/her obligations under this Licence, the obligations of the Compatible
|
|
127
|
+
Licence shall prevail.
|
|
128
|
+
|
|
129
|
+
Provision of Source Code: When distributing or communicating copies of the Work,
|
|
130
|
+
the Licensee will provide a machine-readable copy of the Source Code or indicate
|
|
131
|
+
a repository where this Source will be easily and freely available for as long
|
|
132
|
+
as the Licensee continues to distribute or communicate the Work.
|
|
133
|
+
|
|
134
|
+
Legal Protection: This Licence does not grant permission to use the trade names,
|
|
135
|
+
trademarks, service marks, or names of the Licensor, except as required for
|
|
136
|
+
reasonable and customary use in describing the origin of the Work and
|
|
137
|
+
reproducing the content of the copyright notice.
|
|
138
|
+
|
|
139
|
+
6. Chain of Authorship
|
|
140
|
+
|
|
141
|
+
The original Licensor warrants that the copyright in the Original Work granted
|
|
142
|
+
hereunder is owned by him/her or licensed to him/her and that he/she has the
|
|
143
|
+
power and authority to grant the Licence.
|
|
144
|
+
|
|
145
|
+
Each Contributor warrants that the copyright in the modifications he/she brings
|
|
146
|
+
to the Work are owned by him/her or licensed to him/her and that he/she has the
|
|
147
|
+
power and authority to grant the Licence.
|
|
148
|
+
|
|
149
|
+
Each time You accept the Licence, the original Licensor and subsequent
|
|
150
|
+
Contributors grant You a licence to their contributions to the Work, under the
|
|
151
|
+
terms of this Licence.
|
|
152
|
+
|
|
153
|
+
7. Disclaimer of Warranty
|
|
154
|
+
|
|
155
|
+
The Work is a work in progress, which is continuously improved by numerous
|
|
156
|
+
Contributors. It is not a finished work and may therefore contain defects or
|
|
157
|
+
‘bugs’ inherent to this type of development.
|
|
158
|
+
|
|
159
|
+
For the above reason, the Work is provided under the Licence on an ‘as is’ basis
|
|
160
|
+
and without warranties of any kind concerning the Work, including without
|
|
161
|
+
limitation merchantability, fitness for a particular purpose, absence of defects
|
|
162
|
+
or errors, accuracy, non-infringement of intellectual property rights other than
|
|
163
|
+
copyright as stated in Article 6 of this Licence.
|
|
164
|
+
|
|
165
|
+
This disclaimer of warranty is an essential part of the Licence and a condition
|
|
166
|
+
for the grant of any rights to the Work.
|
|
167
|
+
|
|
168
|
+
8. Disclaimer of Liability
|
|
169
|
+
|
|
170
|
+
Except in the cases of wilful misconduct or damages directly caused to natural
|
|
171
|
+
persons, the Licensor will in no event be liable for any direct or indirect,
|
|
172
|
+
material or moral, damages of any kind, arising out of the Licence or of the use
|
|
173
|
+
of the Work, including without limitation, damages for loss of goodwill, work
|
|
174
|
+
stoppage, computer failure or malfunction, loss of data or any commercial
|
|
175
|
+
damage, even if the Licensor has been advised of the possibility of such damage.
|
|
176
|
+
However, the Licensor will be liable under statutory product liability laws as
|
|
177
|
+
far such laws apply to the Work.
|
|
178
|
+
|
|
179
|
+
9. Additional agreements
|
|
180
|
+
|
|
181
|
+
While distributing the Work, You may choose to conclude an additional agreement,
|
|
182
|
+
defining obligations or services consistent with this Licence. However, if
|
|
183
|
+
accepting obligations, You may act only on your own behalf and on your sole
|
|
184
|
+
responsibility, not on behalf of the original Licensor or any other Contributor,
|
|
185
|
+
and only if You agree to indemnify, defend, and hold each Contributor harmless
|
|
186
|
+
for any liability incurred by, or claims asserted against such Contributor by
|
|
187
|
+
the fact You have accepted any warranty or additional liability.
|
|
188
|
+
|
|
189
|
+
10. Acceptance of the Licence
|
|
190
|
+
|
|
191
|
+
The provisions of this Licence can be accepted by clicking on an icon ‘I agree’
|
|
192
|
+
placed under the bottom of a window displaying the text of this Licence or by
|
|
193
|
+
affirming consent in any other similar way, in accordance with the rules of
|
|
194
|
+
applicable law. Clicking on that icon indicates your clear and irrevocable
|
|
195
|
+
acceptance of this Licence and all of its terms and conditions.
|
|
196
|
+
|
|
197
|
+
Similarly, you irrevocably accept this Licence and all of its terms and
|
|
198
|
+
conditions by exercising any rights granted to You by Article 2 of this Licence,
|
|
199
|
+
such as the use of the Work, the creation by You of a Derivative Work or the
|
|
200
|
+
Distribution or Communication by You of the Work or copies thereof.
|
|
201
|
+
|
|
202
|
+
11. Information to the public
|
|
203
|
+
|
|
204
|
+
In case of any Distribution or Communication of the Work by means of electronic
|
|
205
|
+
communication by You (for example, by offering to download the Work from a
|
|
206
|
+
remote location) the distribution channel or media (for example, a website) must
|
|
207
|
+
at least provide to the public the information requested by the applicable law
|
|
208
|
+
regarding the Licensor, the Licence and the way it may be accessible, concluded,
|
|
209
|
+
stored and reproduced by the Licensee.
|
|
210
|
+
|
|
211
|
+
12. Termination of the Licence
|
|
212
|
+
|
|
213
|
+
The Licence and the rights granted hereunder will terminate automatically upon
|
|
214
|
+
any breach by the Licensee of the terms of the Licence.
|
|
215
|
+
|
|
216
|
+
Such a termination will not terminate the licences of any person who has
|
|
217
|
+
received the Work from the Licensee under the Licence, provided such persons
|
|
218
|
+
remain in full compliance with the Licence.
|
|
219
|
+
|
|
220
|
+
13. Miscellaneous
|
|
221
|
+
|
|
222
|
+
Without prejudice of Article 9 above, the Licence represents the complete
|
|
223
|
+
agreement between the Parties as to the Work.
|
|
224
|
+
|
|
225
|
+
If any provision of the Licence is invalid or unenforceable under applicable
|
|
226
|
+
law, this will not affect the validity or enforceability of the Licence as a
|
|
227
|
+
whole. Such provision will be construed or reformed so as necessary to make it
|
|
228
|
+
valid and enforceable.
|
|
229
|
+
|
|
230
|
+
The European Commission may publish other linguistic versions or new versions of
|
|
231
|
+
this Licence or updated versions of the Appendix, so far this is required and
|
|
232
|
+
reasonable, without reducing the scope of the rights granted by the Licence. New
|
|
233
|
+
versions of the Licence will be published with a unique version number.
|
|
234
|
+
|
|
235
|
+
All linguistic versions of this Licence, approved by the European Commission,
|
|
236
|
+
have identical value. Parties can take advantage of the linguistic version of
|
|
237
|
+
their choice.
|
|
238
|
+
|
|
239
|
+
14. Jurisdiction
|
|
240
|
+
|
|
241
|
+
Without prejudice to specific agreement between parties,
|
|
242
|
+
|
|
243
|
+
- any litigation resulting from the interpretation of this License, arising
|
|
244
|
+
between the European Union institutions, bodies, offices or agencies, as a
|
|
245
|
+
Licensor, and any Licensee, will be subject to the jurisdiction of the Court
|
|
246
|
+
of Justice of the European Union, as laid down in article 272 of the Treaty on
|
|
247
|
+
the Functioning of the European Union,
|
|
248
|
+
|
|
249
|
+
- any litigation arising between other parties and resulting from the
|
|
250
|
+
interpretation of this License, will be subject to the exclusive jurisdiction
|
|
251
|
+
of the competent court where the Licensor resides or conducts its primary
|
|
252
|
+
business.
|
|
253
|
+
|
|
254
|
+
15. Applicable Law
|
|
255
|
+
|
|
256
|
+
Without prejudice to specific agreement between parties,
|
|
257
|
+
|
|
258
|
+
- this Licence shall be governed by the law of the European Union Member State
|
|
259
|
+
where the Licensor has his seat, resides or has his registered office,
|
|
260
|
+
|
|
261
|
+
- this licence shall be governed by Belgian law if the Licensor has no seat,
|
|
262
|
+
residence or registered office inside a European Union Member State.
|
|
263
|
+
|
|
264
|
+
Appendix
|
|
265
|
+
|
|
266
|
+
‘Compatible Licences’ according to Article 5 EUPL are:
|
|
267
|
+
|
|
268
|
+
- GNU General Public License (GPL) v. 2, v. 3
|
|
269
|
+
- GNU Affero General Public License (AGPL) v. 3
|
|
270
|
+
- Open Software License (OSL) v. 2.1, v. 3.0
|
|
271
|
+
- Eclipse Public License (EPL) v. 1.0
|
|
272
|
+
- CeCILL v. 2.0, v. 2.1
|
|
273
|
+
- Mozilla Public Licence (MPL) v. 2
|
|
274
|
+
- GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3
|
|
275
|
+
- Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for
|
|
276
|
+
works other than software
|
|
277
|
+
- European Union Public Licence (EUPL) v. 1.1, v. 1.2
|
|
278
|
+
- Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or Strong
|
|
279
|
+
Reciprocity (LiLiQ-R+).
|
|
280
|
+
|
|
281
|
+
The European Commission may update this Appendix to later versions of the above
|
|
282
|
+
licences without producing a new version of the EUPL, as long as they provide
|
|
283
|
+
the rights granted in Article 2 of this Licence and protect the covered Source
|
|
284
|
+
Code from exclusive appropriation.
|
|
285
|
+
|
|
286
|
+
All other changes or additions to this Appendix require the production of a new
|
|
287
|
+
EUPL version.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
attackmate_api_server
|