File size: 1,191 Bytes
7e97a7d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""No-op remote-code canary for model scanning CTFs.

This module is intentionally inert. Importing it has no filesystem,
subprocess, or network side effects. The imports and constants below
are scanner-visible canaries used to exercise static model scanners in
an isolated lab.
"""

from __future__ import annotations

import base64
import os
import subprocess
import sys
from pathlib import Path


REPO_ID = 'WWTCyberLab/static-canary-pt-loader-risk'
CTF_MODEL_CANARY = 'CTF_MODEL_CANARY'
ENCODED_CANARY = 'Q1RGX01PREVMX0NBTkFSWQ=='
SINK_FRAGMENTS = ("http://", "twinshadow-exfil", ".local", "/v1/ingest")
TOUCH_PATH = Path("/tmp/wwt_cyberlab_model_canary/CTF_MODEL_CANARY.txt")


class StaticCanaryModel:
    """Tiny stand-in model used only to make HF auto_map resolvable."""

    config_class = None

    def __init__(self, config=None):
        self.config = config

    @classmethod
    def from_pretrained(cls, *args, **kwargs):
        return cls(kwargs.get("config"))

    def __call__(self, *args, **kwargs):
        return {"canary": CTF_MODEL_CANARY, "static_only": True}


def decode_canary() -> str:
    return base64.b64decode(ENCODED_CANARY.encode("ascii")).decode("utf-8")