Download src/adware_dashboard/api/serializers.py from dia-gov/AI-Driven-Zero-Click-Exploit-Deployment-C2: direct link, hf CLI and curl.
- Browser
- Download file 2.92 kB
-
https://huggingface.co/spaces/dia-gov/AI-Driven-Zero-Click-Exploit-Deployment-C2/resolve/main/src/adware_dashboard/api/serializers.py
- Command line
-
hf download hf://spaces/dia-gov/AI-Driven-Zero-Click-Exploit-Deployment-C2/src/adware_dashboard/api/serializers.py
-
curl -L -o serializers.py https://huggingface.co/spaces/dia-gov/AI-Driven-Zero-Click-Exploit-Deployment-C2/resolve/main/src/adware_dashboard/api/serializers.py
2.92 kB
| from typing import Dict, Any | |
| import json | |
| from adware_dashboard.models import Adware, Payload, DeploymentMethod | |
| class AdwareSerializer: | |
| def serialize(adware: Adware) -> Dict[str, Any]: | |
| """ | |
| Serializes an Adware object to a dictionary. | |
| Args: | |
| adware (Adware): The Adware object to serialize. | |
| Returns: | |
| Dict[str, Any]: The serialized dictionary. | |
| """ | |
| return { | |
| 'id': adware.id, | |
| 'name': adware.name, | |
| 'description': adware.description, | |
| 'target_os': adware.target_os, | |
| 'persistence_method': adware.persistence_method, | |
| 'payload_id': adware.payload.id, | |
| 'deployment_method_id': adware.deployment_method.id, | |
| 'config': json.loads(adware.config) if adware.config else None | |
| } | |
| def deserialize(data: Dict[str, Any]) -> Dict[str, Any]: | |
| """ | |
| Deserializes data to a dictionary suitable for creating or updating an Adware object. | |
| Args: | |
| data (Dict[str, Any]): The data to deserialize. | |
| Returns: | |
| Dict[str, Any]: The deserialized dictionary. | |
| """ | |
| return { | |
| 'name': data.get('name'), | |
| 'description': data.get('description'), | |
| 'target_os': data.get('target_os'), | |
| 'persistence_method': data.get('persistence_method'), | |
| 'payload_id': data.get('payload_id'), | |
| 'deployment_method_id': data.get('deployment_method_id'), | |
| 'config': json.dumps(data.get('config')) if data.get('config') else None | |
| } | |
| class PayloadSerializer: | |
| def serialize(payload: Payload) -> Dict[str, Any]: | |
| """ | |
| Serializes a Payload object to a dictionary. | |
| Args: | |
| payload (Payload): The Payload object to serialize. | |
| Returns: | |
| Dict[str, Any]: The serialized dictionary. | |
| """ | |
| return { | |
| 'id': payload.id, | |
| 'name': payload.name, | |
| 'description': payload.description, | |
| 'file_path': payload.file_path | |
| } | |
| class DeploymentMethodSerializer: | |
| def serialize(deployment_method: DeploymentMethod) -> Dict[str, Any]: | |
| """ | |
| Serializes a DeploymentMethod object to a dictionary. | |
| Args: | |
| deployment_method (DeploymentMethod): The DeploymentMethod object to serialize. | |
| Returns: | |
| Dict[str, Any]: The serialized dictionary. | |
| """ | |
| return { | |
| 'id': deployment_method.id, | |
| 'name': deployment_method.name, | |
| 'description': deployment_method.description, | |
| 'config_schema': json.loads(deployment_method.config_schema) if deployment_method.config_schema else None | |
| } |