● Notice //GitHub (@shehzade) is temporarily suspended pending an automated false-positive review. All tools are hosted on this Code Mirror and available on request (contact); GitHub links will return once reinstated.
PUBLIC MIRRORGo v1.0

Multi-protocol network egress assessment and DLP verification framework featuring automated L4 sweeps, corporate proxy traversal, and covert protocol smuggling across 20+ channels.

$ git clone https://shehzade.io/repos/contraband.git Copy
Source ZIP (1.93 MB)
Code 174 Commits 1
contraband / pkg / common / errors.go
← Back to directory
104 lines · 4.0 KB
Raw
1package common
2
3import (
4 "context"
5 "errors"
6 "io"
7 "net"
8 "os"
9 "strings"
10 "syscall"
11)
12
13// ClassifyError classifies any network, transport, application, or system error
14// into the authoritative Verdict taxonomy:
15// - BLOCKED_L4: Network-layer drops, timeouts, connection refused, unroutable paths, closed ports, EOF socket drops.
16// - BLOCKED_L7: Protocol inspection drops, TLS handshake resets, HTTP 401/403/407, application rejections.
17// - BLOCKED_DLP: Payload tampering, mid-stream truncation, or SHA-256 hash mismatch.
18// - SUCCESS: nil error.
19func ClassifyError(err error) Verdict {
20 if err == nil {
21 return VerdictSuccess
22 }
23
24 errStr := strings.ToLower(err.Error())
25
26 // 1. Layer 4 Network / Port / Packet Filter Blocks, dial failures,
27 // timeouts, and premature socket drops (including EOF, connection reset, unroutable paths).
28 // Layer 4 transport drops MUST take precedence over higher-level protocol
29 // handshake wrappers (e.g. uTLS, WebSocket handshake, SSH handshake, TLS timeouts)
30 // which embed strings like "handshake" alongside EOF or timeout errors.
31 var netErr net.Error
32 if (errors.As(err, &netErr) && netErr.Timeout()) ||
33 errors.Is(err, io.EOF) ||
34 errors.Is(err, io.ErrUnexpectedEOF) ||
35 strings.Contains(errStr, "eof") ||
36 errors.Is(err, context.DeadlineExceeded) ||
37 errors.Is(err, context.Canceled) ||
38 errors.Is(err, os.ErrDeadlineExceeded) ||
39 errors.Is(err, syscall.ETIMEDOUT) ||
40 strings.Contains(errStr, "timeout") ||
41 strings.Contains(errStr, "timed out") ||
42 strings.Contains(errStr, "deadline exceeded") ||
43 strings.Contains(errStr, "i/o timeout") ||
44 errors.Is(err, syscall.ECONNREFUSED) ||
45 strings.Contains(errStr, "connection refused") ||
46 errors.Is(err, syscall.ECONNRESET) ||
47 strings.Contains(errStr, "connection reset") ||
48 strings.Contains(errStr, "reset by peer") ||
49 errors.Is(err, syscall.EPIPE) ||
50 strings.Contains(errStr, "broken pipe") ||
51 errors.Is(err, net.ErrClosed) ||
52 strings.Contains(errStr, "closed network connection") ||
53 strings.Contains(errStr, "use of closed network connection") ||
54 strings.Contains(errStr, "connection closed") ||
55 strings.Contains(errStr, "connection was closed") ||
56 strings.Contains(errStr, "server closed") ||
57 strings.Contains(errStr, "transport connection broken") ||
58 strings.Contains(errStr, "connection broken") ||
59 errors.Is(err, syscall.ENETUNREACH) ||
60 strings.Contains(errStr, "network is unreachable") ||
61 errors.Is(err, syscall.EHOSTUNREACH) ||
62 strings.Contains(errStr, "no route to host") ||
63 strings.Contains(errStr, "no such host") ||
64 errors.Is(err, syscall.EPERM) ||
65 strings.Contains(errStr, "operation not permitted") {
66 return VerdictBlockedL4
67 }
68
69 // 2. DLP interception or cryptographic tampering
70 if strings.Contains(errStr, "hash mismatch") ||
71 strings.Contains(errStr, "dlp") ||
72 strings.Contains(errStr, "tampering") ||
73 strings.Contains(errStr, "content inspection") ||
74 strings.Contains(errStr, "hash corruption") ||
75 strings.Contains(errStr, "dpi") ||
76 strings.Contains(errStr, "pattern drop") ||
77 strings.Contains(errStr, "does not match expected hash") ||
78 strings.Contains(errStr, "hash does not match") {
79 return VerdictBlockedDLP
80 }
81
82 // 3. TLS protocol / certificate errors are Layer 7 protocol blocks
83 // (Reached only if not an underlying Layer 4 transport drop/timeout)
84 if strings.Contains(errStr, "tls:") ||
85 strings.Contains(errStr, "x509:") ||
86 strings.Contains(errStr, "handshake") ||
87 strings.Contains(errStr, "bad certificate") ||
88 strings.Contains(errStr, "certificate signed by unknown authority") {
89 return VerdictBlockedL7
90 }
91
92 // 4. Explicit Layer 7 Application & Proxy Rejections
93 if strings.Contains(errStr, "403 forbidden") ||
94 strings.Contains(errStr, "407 proxy") ||
95 strings.Contains(errStr, "401 unauthorized") ||
96 strings.Contains(errStr, "forbidden") ||
97 strings.Contains(errStr, "unauthorized") ||
98 strings.Contains(errStr, "proxy auth") {
99 return VerdictBlockedL7
100 }
101
102 // 5. Default fallback for application/payload level errors
103 return VerdictBlockedL7
104}