netget-tool 0.3.4

Network protocol stubbing toolkit: ~280 protocol servers and clients whose responses come from an LLM, a script, a static rule or a person.
Documentation
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
//! SOCKS5 protocol actions implementation

use crate::llm::actions::{
    protocol_trait::{ActionResult, Protocol, Server},
    ActionDefinition, Parameter,
};
use crate::protocol::log_template::LogTemplate;
use crate::protocol::EventType;
use crate::state::app_state::AppState;
use anyhow::{Context, Result};
use serde_json::json;
use std::sync::LazyLock;
use tracing::debug;

/// SOCKS5 protocol action handler
pub struct Socks5Protocol {}

impl Socks5Protocol {
    pub fn new() -> Self {
        Self {}
    }
}

// Implement Protocol trait (common functionality)
impl Protocol for Socks5Protocol {
    fn get_async_actions(&self, _state: &AppState) -> Vec<ActionDefinition> {
        // Future: Could add actions like:
        // - close_socks5_connection(connection_id)
        // - set_socks5_filter(patterns)
        // - list_socks5_connections()
        Vec::new()
    }
    fn get_sync_actions(&self) -> Vec<ActionDefinition> {
        vec![
            allow_socks5_connect_action(),
            deny_socks5_connect_action(),
            allow_socks5_auth_action(),
            deny_socks5_auth_action(),
            forward_socks5_data_action(),
            modify_socks5_data_action(),
            close_connection_action(),
        ]
    }
    fn protocol_name(&self) -> &'static str {
        "SOCKS5"
    }
    fn get_event_types(&self) -> Vec<EventType> {
        get_socks5_event_types()
    }
    fn stack_name(&self) -> &'static str {
        "ETH>IP>TCP>SOCKS5"
    }
    fn keywords(&self) -> Vec<&'static str> {
        vec!["socks", "socks5"]
    }
    fn metadata(&self) -> crate::protocol::metadata::ProtocolMetadataV2 {
        use crate::protocol::metadata::{DevelopmentState, ProtocolMetadataV2};

        ProtocolMetadataV2::builder()
            .state(DevelopmentState::Experimental)
            .well_known_port(1080)
            .implementation("Manual SOCKS5 protocol (RFC 1928)")
            .llm_control("Auth allow/deny, connection allow/deny, MITM data forward/modify/close")
            // Not "curl --socks5", which this claimed and which no test does. The peer in
            // tests/server/socks5/e2e_test.rs is a SOCKS5 client hand-written inside the test
            // over a raw TcpStream -- an independent reading of RFC 1928, not an independent
            // implementation, so it does not clear the bar for Beta.
            .e2e_testing(
                "A SOCKS5 client hand-written in tests/server/socks5/e2e_test.rs (raw TcpStream, \
                 RFC 1928/1929 by hand): no-auth and username/password handshakes, CONNECT by \
                 IPv4 and by domain, a refusal, and an HTTP exchange through a MITM tunnel. No \
                 third-party SOCKS5 client has been run against it.",
            )
            .notes(
                "OPEN RELAY BY DESIGN, AND UNRESTRICTED: the destination of every connection is \
                 chosen by the peer, and there is no allow-list, deny-list or network \
                 restriction of any kind. Loopback, link-local (including 169.254.169.254, the \
                 cloud instance-metadata endpoint), and every RFC 1918 range are all reachable, \
                 so anyone who can reach this port can reach whatever this host can -- an SSRF \
                 pivot into the operator's private network, and a relay someone else's traffic \
                 can be laundered through. The only gate is the model: `filter_mode` decides \
                 whether it is consulted at all, and `allow_all` or a `selective` filter whose \
                 patterns miss (with `default_action: allow`) connects with no consultation \
                 whatsoever. `target_host_patterns` and `target_port_ranges` select what the \
                 model is ASKED about; they do not restrict anything on their own. Do not \
                 expose this to an untrusted network. \
                 CONNECT only (no BIND/UDP ASSOCIATE); a connect/auth event with no explicit \
                 allow action is denied; MITM inspection costs one LLM call per data chunk in \
                 each direction; the handshake reads time out after 30s but the number of \
                 concurrent connections is unbounded.",
            )
            .build()
    }
    fn description(&self) -> &'static str {
        "SOCKS5 proxy server"
    }
    fn example_prompt(&self) -> &'static str {
        "Start a SOCKS5 proxy on port 1080 that asks before connecting"
    }
    fn get_startup_parameters(&self) -> Vec<crate::llm::actions::ParameterDefinition> {
        use crate::llm::actions::ParameterDefinition;
        vec![
                ParameterDefinition {
                    name: "auth_methods".to_string(),
                    type_hint: "array".to_string(),
                    description: "Array of allowed authentication methods: 'none' (no auth) or 'username_password' (RFC 1929)".to_string(),
                    required: false,
                    example: json!(["none", "username_password"]),
                    default: None,
                },
                ParameterDefinition {
                    name: "default_action".to_string(),
                    type_hint: "string".to_string(),
                    description: "Default action when no filter matches: 'allow' or 'deny'".to_string(),
                    required: false,
                    example: json!("allow"),
                    default: None,
                },
                ParameterDefinition {
                    name: "filter_mode".to_string(),
                    type_hint: "string".to_string(),
                    description: "Filter mode: 'allow_all', 'deny_all', 'ask_llm', or 'selective'".to_string(),
                    required: false,
                    example: json!("selective"),
                    default: None,
                },
                ParameterDefinition {
                    name: "filter".to_string(),
                    type_hint: "object".to_string(),
                    description: "Filter configuration object with 'target_host_patterns' (array of regex) and 'target_port_ranges' (array of [start, end])".to_string(),
                    required: false,
                    example: json!({
                        "target_host_patterns": [".*\\.example\\.com"],
                        "target_port_ranges": [[80, 80], [443, 443]]
                    }),
                    default: None,
                },
                ParameterDefinition {
                    name: "mitm_by_default".to_string(),
                    type_hint: "boolean".to_string(),
                    description: "Enable Man-in-the-Middle inspection for all allowed connections by default".to_string(),
                    required: false,
                    example: json!(false),
                    default: None,
                },
                ParameterDefinition {
                    name: "idle_timeout_secs".to_string(),
                    type_hint: "number".to_string(),
                    description: "Seconds an established tunnel may move no data in either \
                                  direction before the proxy closes it (default 3600). Traffic \
                                  either way keeps it open. Raise it for long-idle protocols \
                                  such as SSH without keepalives."
                        .to_string(),
                    required: false,
                    example: json!(3600),
                    default: Some(serde_json::json!(super::RELAY_IDLE_TIMEOUT.as_secs())),
                },
            ]
    }
    fn group_name(&self) -> &'static str {
        "Proxy & Network"
    }

    fn get_startup_examples(&self) -> crate::llm::actions::StartupExamples {
        use crate::llm::actions::StartupExamples;

        // Deterministic: allow every auth attempt and every CONNECT (no MITM),
        // no LLM call. One script handles both events.
        let script = r#"import json, sys
data = json.load(sys.stdin)
event = data["event"]
et = data["event_type_id"]
if et == "socks5_connect_request":
    actions = [{"type": "allow_socks5_connect", "mitm": False}]
elif et == "socks5_auth_request":
    actions = [{"type": "allow_socks5_auth"}]
else:
    actions = []
print(json.dumps({"actions": actions}))"#;

        StartupExamples::new(
            // LLM mode
            json!({
                "type": "open_server",
                "port": 1080,
                "base_stack": "socks5",
                "instruction": "SOCKS5 proxy server. Accept all connections without authentication. Allow all CONNECT requests to pass through."
            }),
            // Script mode
            json!({
                "type": "open_server",
                "port": 1080,
                "base_stack": "socks5",
                "event_handlers": [{
                    "event_pattern": "socks5_connect_request",
                    "handler": {
                        "type": "script",
                        "language": "python",
                        "code": script
                    }
                }, {
                    "event_pattern": "socks5_auth_request",
                    "handler": {
                        "type": "script",
                        "language": "python",
                        "code": script
                    }
                }]
            }),
            // Static mode
            json!({
                "type": "open_server",
                "port": 1080,
                "base_stack": "socks5",
                "event_handlers": [{
                    "event_pattern": "socks5_connect_request",
                    "handler": {
                        "type": "static",
                        "actions": [{
                            "type": "allow_socks5_connect",
                            "mitm": false
                        }]
                    }
                }]
            }),
        )
    }
}

// Implement Server trait (server-specific functionality)
impl Server for Socks5Protocol {
    fn spawn(
        &self,
        ctx: crate::protocol::SpawnContext,
    ) -> std::pin::Pin<
        Box<dyn std::future::Future<Output = anyhow::Result<std::net::SocketAddr>> + Send>,
    > {
        Box::pin(async move {
            use crate::server::socks5::Socks5Server;
            Socks5Server::spawn_with_llm_actions(
                ctx.legacy_listen_addr(),
                ctx.llm_client,
                ctx.state,
                ctx.status_tx,
                ctx.server_id,
                ctx.startup_params,
            )
            .await
        })
    }
    fn execute_action(&self, action: serde_json::Value) -> Result<ActionResult> {
        let action_type = action
            .get("type")
            .and_then(|v| v.as_str())
            .context("Missing 'type' field in action")?;

        match action_type {
            "allow_socks5_connect" => self.execute_allow_connect(action),
            "deny_socks5_connect" => self.execute_deny_connect(action),
            "allow_socks5_auth" => self.execute_allow_auth(action),
            "deny_socks5_auth" => self.execute_deny_auth(action),
            "forward_socks5_data" => self.execute_forward_data(action),
            "modify_socks5_data" => self.execute_modify_data(action),
            "close_connection" => self.execute_close_connection(action),
            _ => Err(anyhow::anyhow!("Unknown SOCKS5 action: {}", action_type)),
        }
    }
}

impl Socks5Protocol {
    fn execute_allow_connect(&self, action: serde_json::Value) -> Result<ActionResult> {
        let _mitm = action
            .get("mitm")
            .and_then(|v| v.as_bool())
            .unwrap_or(false);

        debug!("SOCKS5 allowing connection (MITM: {})", _mitm);

        // Return NoAction to signal connection should proceed
        Ok(ActionResult::NoAction)
    }

    fn execute_deny_connect(&self, action: serde_json::Value) -> Result<ActionResult> {
        let reason = action
            .get("reason")
            .and_then(|v| v.as_str())
            .unwrap_or("Connection denied by policy");

        debug!("SOCKS5 denying connection: {}", reason);

        // Return CloseConnection to deny
        Ok(ActionResult::CloseConnection)
    }

    fn execute_allow_auth(&self, _action: serde_json::Value) -> Result<ActionResult> {
        debug!("SOCKS5 allowing authentication");
        Ok(ActionResult::NoAction)
    }

    fn execute_deny_auth(&self, action: serde_json::Value) -> Result<ActionResult> {
        let reason = action
            .get("reason")
            .and_then(|v| v.as_str())
            .unwrap_or("Authentication failed");

        debug!("SOCKS5 denying authentication: {}", reason);
        Ok(ActionResult::CloseConnection)
    }

    fn execute_forward_data(&self, _action: serde_json::Value) -> Result<ActionResult> {
        debug!("SOCKS5 forwarding data as-is");
        // Return NoAction to signal data should be forwarded unchanged
        Ok(ActionResult::NoAction)
    }

    fn execute_modify_data(&self, action: serde_json::Value) -> Result<ActionResult> {
        let modified_data = action
            .get("data")
            .and_then(|v| v.as_str())
            .context("Missing 'data' field for modify_socks5_data action")?;

        // The `data` field used to be documented as "base64 or UTF-8" while the
        // executor only ever took `.as_bytes()`, so a base64 payload was relayed
        // as its literal base64 text. Encoding is now explicit and honoured.
        let bytes = decode_outbound_data(modified_data, &action)?;

        debug!("SOCKS5 modifying data (new length: {} bytes)", bytes.len());

        // Return Output with the modified data
        Ok(ActionResult::Output(bytes))
    }

    fn execute_close_connection(&self, action: serde_json::Value) -> Result<ActionResult> {
        let reason = action
            .get("reason")
            .and_then(|v| v.as_str())
            .unwrap_or("Connection closed by policy");

        debug!("SOCKS5 closing connection: {}", reason);
        Ok(ActionResult::CloseConnection)
    }
}

/// Turn the `data` field of a MITM action into the exact bytes to relay,
/// honouring the action's optional `encoding` field.
///
/// - `encoding` absent or `"utf8"`: the string's UTF-8 bytes are relayed verbatim.
/// - `encoding` = `"hex"`: `data` is decoded as hex.
///
/// There is deliberately no auto-detection: `"48656c6c6f"` is both valid text and
/// valid hex, so the caller must say which it means.
fn decode_outbound_data(data: &str, action: &serde_json::Value) -> Result<Vec<u8>> {
    let encoding = action
        .get("encoding")
        .and_then(|v| v.as_str())
        .unwrap_or("utf8");

    match encoding {
        "utf8" => Ok(data.as_bytes().to_vec()),
        "hex" => {
            let cleaned: String = data
                .chars()
                .filter(|c| !c.is_ascii_whitespace() && *c != ':')
                .collect();
            let cleaned = cleaned.strip_prefix("0x").unwrap_or(&cleaned);

            if cleaned.len() % 2 != 0 {
                return Err(anyhow::anyhow!(
                    "Invalid hex in 'data': expected an even number of hex digits, got {} \
                     ({data:?}). Each byte is two hex digits, e.g. \"48656c6c6f\" = \"Hello\".",
                    cleaned.len()
                ));
            }

            hex::decode(cleaned).map_err(|e| {
                anyhow::anyhow!(
                    "Invalid hex in 'data' ({data:?}): {e}. Use only 0-9/a-f, two digits per \
                     byte. To relay this string as literal text instead, omit 'encoding' or \
                     set it to \"utf8\"."
                )
            })
        }
        other => Err(anyhow::anyhow!(
            "Unknown 'encoding' value {other:?}. Valid values are \"utf8\" (default) and \"hex\"."
        )),
    }
}

// ============================================================================
// SOCKS5 Action Definitions
// ============================================================================

fn allow_socks5_connect_action() -> ActionDefinition {
    ActionDefinition {
        name: "allow_socks5_connect".to_string(),
        description: "Allow SOCKS5 CONNECT request to proceed".to_string(),
        parameters: vec![Parameter {
            name: "mitm".to_string(),
            type_hint: "boolean".to_string(),
            description: "Enable MITM inspection for this connection (default: false)".to_string(),
            required: false,
        }],
        example: json!({
            "type": "allow_socks5_connect",
            "mitm": false
        }),
        log_template: Some(
            LogTemplate::new()
                .with_info("-> SOCKS5 allow (MITM={mitm})")
                .with_debug("SOCKS5 allow_socks5_connect: mitm={mitm}"),
        ),
    }
}

fn deny_socks5_connect_action() -> ActionDefinition {
    ActionDefinition {
        name: "deny_socks5_connect".to_string(),
        description: "Deny SOCKS5 CONNECT request".to_string(),
        parameters: vec![Parameter {
            name: "reason".to_string(),
            type_hint: "string".to_string(),
            description: "Reason for denial (for logging)".to_string(),
            required: false,
        }],
        example: json!({
            "type": "deny_socks5_connect",
            "reason": "Blocked by security policy"
        }),
        log_template: Some(
            LogTemplate::new()
                .with_info("-> SOCKS5 deny: {reason}")
                .with_debug("SOCKS5 deny_socks5_connect: reason={reason}"),
        ),
    }
}

fn allow_socks5_auth_action() -> ActionDefinition {
    ActionDefinition {
        name: "allow_socks5_auth".to_string(),
        description: "Allow SOCKS5 username/password authentication".to_string(),
        parameters: vec![],
        example: json!({
            "type": "allow_socks5_auth"
        }),
        log_template: Some(
            LogTemplate::new()
                .with_info("-> SOCKS5 auth allowed")
                .with_debug("SOCKS5 allow_socks5_auth"),
        ),
    }
}

fn deny_socks5_auth_action() -> ActionDefinition {
    ActionDefinition {
        name: "deny_socks5_auth".to_string(),
        description: "Deny SOCKS5 authentication".to_string(),
        parameters: vec![Parameter {
            name: "reason".to_string(),
            type_hint: "string".to_string(),
            description: "Reason for denial (for logging)".to_string(),
            required: false,
        }],
        example: json!({
            "type": "deny_socks5_auth",
            "reason": "Invalid credentials"
        }),
        log_template: Some(
            LogTemplate::new()
                .with_info("-> SOCKS5 auth denied: {reason}")
                .with_debug("SOCKS5 deny_socks5_auth: reason={reason}"),
        ),
    }
}

fn forward_socks5_data_action() -> ActionDefinition {
    ActionDefinition {
        name: "forward_socks5_data".to_string(),
        description: "Forward SOCKS5 data without modification (MITM mode)".to_string(),
        parameters: vec![],
        example: json!({
            "type": "forward_socks5_data"
        }),
        log_template: Some(
            LogTemplate::new()
                .with_info("-> SOCKS5 forward")
                .with_debug("SOCKS5 forward_socks5_data"),
        ),
    }
}

fn modify_socks5_data_action() -> ActionDefinition {
    ActionDefinition {
        name: "modify_socks5_data".to_string(),
        description: "Modify SOCKS5 data before forwarding (MITM mode)".to_string(),
        parameters: vec![
            Parameter {
                name: "data".to_string(),
                type_hint: "string".to_string(),
                description: "Replacement payload. Interpreted according to 'encoding'.".to_string(),
                required: true,
            },
            Parameter {
                name: "encoding".to_string(),
                type_hint: "string".to_string(),
                description: "How to interpret 'data': \"utf8\" (default) relays the string's bytes verbatim; \"hex\" decodes it as hex first. Match the 'encoding' reported on the event to round-trip binary payloads.".to_string(),
                required: false,
            },
        ],
        example: json!({
            "type": "modify_socks5_data",
            "data": "Modified payload"
        }),
        log_template: Some(
            LogTemplate::new()
                .with_info("-> SOCKS5 modify data")
                .with_debug("SOCKS5 modify_socks5_data"),
        ),
    }
}

fn close_connection_action() -> ActionDefinition {
    ActionDefinition {
        name: "close_connection".to_string(),
        description: "Close the SOCKS5 connection (MITM mode)".to_string(),
        parameters: vec![Parameter {
            name: "reason".to_string(),
            type_hint: "string".to_string(),
            description: "Reason for closing (for logging)".to_string(),
            required: false,
        }],
        example: json!({
            "type": "close_connection",
            "reason": "Suspicious data detected"
        }),
        log_template: Some(
            LogTemplate::new()
                .with_info("-> SOCKS5 close: {reason}")
                .with_debug("SOCKS5 close_connection: reason={reason}"),
        ),
    }
}

// ============================================================================
// SOCKS5 Event Type Constants
// ============================================================================

pub static SOCKS5_AUTH_REQUEST_EVENT: LazyLock<EventType> = LazyLock::new(|| {
    EventType::new(
        "socks5_auth_request",
        "SOCKS5 client authentication request (username/password)",
        json!({
            "type": "allow_socks5_auth"
        }),
    )
    .with_parameters(vec![
        Parameter {
            name: "username".to_string(),
            type_hint: "string".to_string(),
            description: "Username provided by client".to_string(),
            required: true,
        },
        Parameter {
            name: "password".to_string(),
            type_hint: "string".to_string(),
            description: "Password provided by client".to_string(),
            required: true,
        },
    ])
    .with_actions(vec![allow_socks5_auth_action(), deny_socks5_auth_action()])
});

pub static SOCKS5_CONNECT_REQUEST_EVENT: LazyLock<EventType> = LazyLock::new(|| {
    EventType::new(
        "socks5_connect_request",
        "SOCKS5 CONNECT request to target address",
        json!({
            "type": "allow_socks5_connect",
            "mitm": false
        }),
    )
    .with_parameters(vec![
        Parameter {
            name: "target".to_string(),
            type_hint: "string".to_string(),
            description: "Target address (IP or domain:port)".to_string(),
            required: true,
        },
        Parameter {
            name: "username".to_string(),
            type_hint: "string".to_string(),
            description: "Authenticated username (if any)".to_string(),
            required: false,
        },
    ])
    .with_actions(vec![
        allow_socks5_connect_action(),
        deny_socks5_connect_action(),
    ])
    .with_log_template(
        LogTemplate::new()
            .with_info("SOCKS5 {client_ip} -> {target}")
            .with_debug("SOCKS5 connection from {client_ip}:{client_port} to {target}")
            .with_trace("SOCKS5: {json_pretty(.)}"),
    )
});

pub static SOCKS5_DATA_TO_TARGET_EVENT: LazyLock<EventType> = LazyLock::new(|| {
    EventType::new(
        "socks5_data_to_target",
        "Data from client to target (MITM inspection mode)",
        json!({
            "type": "forward_socks5_data"
        }),
    )
    .with_parameters(vec![
        Parameter {
            name: "data".to_string(),
            type_hint: "string".to_string(),
            description: "Data being sent from client to target. Printable payloads arrive as text, binary arrives hex-encoded; check 'encoding'.".to_string(),
            required: true,
        },
        Parameter {
            name: "encoding".to_string(),
            type_hint: "string".to_string(),
            description: "How 'data' is encoded: \"utf8\" or \"hex\". Pass the same value to modify_socks5_data when replacing the payload.".to_string(),
            required: true,
        },
        Parameter {
            name: "target".to_string(),
            type_hint: "string".to_string(),
            description: "Target address (IP or domain:port)".to_string(),
            required: true,
        },
        Parameter {
            name: "username".to_string(),
            type_hint: "string".to_string(),
            description: "Authenticated username (if any)".to_string(),
            required: false,
        },
    ])
    .with_actions(vec![
        forward_socks5_data_action(),
        modify_socks5_data_action(),
        close_connection_action(),
    ])
});

pub static SOCKS5_DATA_FROM_TARGET_EVENT: LazyLock<EventType> = LazyLock::new(|| {
    EventType::new(
        "socks5_data_from_target",
        "Data from target to client (MITM inspection mode)",
        json!({
            "type": "forward_socks5_data"
        }),
    )
    .with_parameters(vec![
        Parameter {
            name: "data".to_string(),
            type_hint: "string".to_string(),
            description: "Data being sent from target to client. Printable payloads arrive as text, binary arrives hex-encoded; check 'encoding'.".to_string(),
            required: true,
        },
        Parameter {
            name: "encoding".to_string(),
            type_hint: "string".to_string(),
            description: "How 'data' is encoded: \"utf8\" or \"hex\". Pass the same value to modify_socks5_data when replacing the payload.".to_string(),
            required: true,
        },
        Parameter {
            name: "target".to_string(),
            type_hint: "string".to_string(),
            description: "Target address (IP or domain:port)".to_string(),
            required: true,
        },
        Parameter {
            name: "username".to_string(),
            type_hint: "string".to_string(),
            description: "Authenticated username (if any)".to_string(),
            required: false,
        },
    ])
    .with_actions(vec![
        forward_socks5_data_action(),
        modify_socks5_data_action(),
        close_connection_action(),
    ])
});

pub fn get_socks5_event_types() -> Vec<EventType> {
    vec![
        SOCKS5_AUTH_REQUEST_EVENT.clone(),
        SOCKS5_CONNECT_REQUEST_EVENT.clone(),
        SOCKS5_DATA_TO_TARGET_EVENT.clone(),
        SOCKS5_DATA_FROM_TARGET_EVENT.clone(),
    ]
}