@push.rocks/smartproxy 25.17.9 → 26.0.0
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.
- package/changelog.md +16 -0
- package/dist_rust/rustproxy_linux_amd64 +0 -0
- package/dist_rust/rustproxy_linux_arm64 +0 -0
- package/dist_ts/00_commitinfo_data.js +2 -2
- package/dist_ts/core/index.d.ts +0 -1
- package/dist_ts/core/index.js +1 -2
- package/dist_ts/core/models/index.d.ts +0 -1
- package/dist_ts/core/models/index.js +1 -2
- package/dist_ts/core/utils/index.d.ts +0 -12
- package/dist_ts/core/utils/index.js +1 -13
- package/dist_ts/index.d.ts +0 -3
- package/dist_ts/index.js +2 -7
- package/dist_ts/protocols/http/index.d.ts +0 -1
- package/dist_ts/protocols/http/index.js +1 -2
- package/dist_ts/protocols/index.d.ts +0 -7
- package/dist_ts/protocols/index.js +1 -8
- package/dist_ts/proxies/smart-proxy/socket-handler-server.js +6 -1
- package/dist_ts/proxies/smart-proxy/utils/route-helpers/socket-handlers.d.ts +0 -7
- package/dist_ts/proxies/smart-proxy/utils/route-helpers/socket-handlers.js +50 -51
- package/dist_ts/routing/index.d.ts +0 -1
- package/dist_ts/routing/index.js +1 -3
- package/package.json +1 -1
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/core/index.ts +0 -1
- package/ts/core/models/index.ts +0 -1
- package/ts/core/utils/index.ts +0 -12
- package/ts/index.ts +1 -7
- package/ts/protocols/http/index.ts +1 -2
- package/ts/protocols/index.ts +0 -7
- package/ts/proxies/smart-proxy/socket-handler-server.ts +6 -0
- package/ts/proxies/smart-proxy/utils/route-helpers/socket-handlers.ts +60 -59
- package/ts/routing/index.ts +0 -3
- package/dist_ts/core/events/index.d.ts +0 -4
- package/dist_ts/core/events/index.js +0 -5
- package/dist_ts/core/models/socket-augmentation.d.ts +0 -15
- package/dist_ts/core/models/socket-augmentation.js +0 -18
- package/dist_ts/core/utils/async-utils.d.ts +0 -81
- package/dist_ts/core/utils/async-utils.js +0 -216
- package/dist_ts/core/utils/binary-heap.d.ts +0 -73
- package/dist_ts/core/utils/binary-heap.js +0 -193
- package/dist_ts/core/utils/enhanced-connection-pool.d.ts +0 -110
- package/dist_ts/core/utils/enhanced-connection-pool.js +0 -325
- package/dist_ts/core/utils/fs-utils.d.ts +0 -144
- package/dist_ts/core/utils/fs-utils.js +0 -252
- package/dist_ts/core/utils/ip-utils.d.ts +0 -69
- package/dist_ts/core/utils/ip-utils.js +0 -270
- package/dist_ts/core/utils/lifecycle-component.d.ts +0 -59
- package/dist_ts/core/utils/lifecycle-component.js +0 -211
- package/dist_ts/core/utils/log-deduplicator.d.ts +0 -39
- package/dist_ts/core/utils/log-deduplicator.js +0 -305
- package/dist_ts/core/utils/security-utils.d.ts +0 -111
- package/dist_ts/core/utils/security-utils.js +0 -212
- package/dist_ts/core/utils/shared-security-manager.d.ts +0 -128
- package/dist_ts/core/utils/shared-security-manager.js +0 -362
- package/dist_ts/core/utils/socket-utils.d.ts +0 -63
- package/dist_ts/core/utils/socket-utils.js +0 -249
- package/dist_ts/core/utils/template-utils.d.ts +0 -37
- package/dist_ts/core/utils/template-utils.js +0 -104
- package/dist_ts/core/utils/validation-utils.d.ts +0 -61
- package/dist_ts/core/utils/validation-utils.js +0 -149
- package/dist_ts/core/utils/websocket-utils.d.ts +0 -22
- package/dist_ts/core/utils/websocket-utils.js +0 -30
- package/dist_ts/detection/detectors/http-detector.d.ts +0 -33
- package/dist_ts/detection/detectors/http-detector.js +0 -101
- package/dist_ts/detection/detectors/quick-detector.d.ts +0 -28
- package/dist_ts/detection/detectors/quick-detector.js +0 -131
- package/dist_ts/detection/detectors/routing-extractor.d.ts +0 -28
- package/dist_ts/detection/detectors/routing-extractor.js +0 -122
- package/dist_ts/detection/detectors/tls-detector.d.ts +0 -47
- package/dist_ts/detection/detectors/tls-detector.js +0 -183
- package/dist_ts/detection/index.d.ts +0 -17
- package/dist_ts/detection/index.js +0 -22
- package/dist_ts/detection/models/detection-types.d.ts +0 -87
- package/dist_ts/detection/models/detection-types.js +0 -5
- package/dist_ts/detection/models/interfaces.d.ts +0 -97
- package/dist_ts/detection/models/interfaces.js +0 -5
- package/dist_ts/detection/protocol-detector.d.ts +0 -79
- package/dist_ts/detection/protocol-detector.js +0 -253
- package/dist_ts/detection/utils/buffer-utils.d.ts +0 -61
- package/dist_ts/detection/utils/buffer-utils.js +0 -127
- package/dist_ts/detection/utils/fragment-manager.d.ts +0 -31
- package/dist_ts/detection/utils/fragment-manager.js +0 -53
- package/dist_ts/detection/utils/parser-utils.d.ts +0 -42
- package/dist_ts/detection/utils/parser-utils.js +0 -63
- package/dist_ts/protocols/common/fragment-handler.d.ts +0 -73
- package/dist_ts/protocols/common/fragment-handler.js +0 -121
- package/dist_ts/protocols/common/index.d.ts +0 -7
- package/dist_ts/protocols/common/index.js +0 -8
- package/dist_ts/protocols/common/types.d.ts +0 -68
- package/dist_ts/protocols/common/types.js +0 -7
- package/dist_ts/protocols/http/parser.d.ts +0 -58
- package/dist_ts/protocols/http/parser.js +0 -184
- package/dist_ts/protocols/proxy/index.d.ts +0 -5
- package/dist_ts/protocols/proxy/index.js +0 -6
- package/dist_ts/protocols/proxy/types.d.ts +0 -47
- package/dist_ts/protocols/proxy/types.js +0 -6
- package/dist_ts/protocols/tls/alerts/index.d.ts +0 -4
- package/dist_ts/protocols/tls/alerts/index.js +0 -5
- package/dist_ts/protocols/tls/alerts/tls-alert.d.ts +0 -150
- package/dist_ts/protocols/tls/alerts/tls-alert.js +0 -226
- package/dist_ts/protocols/tls/index.d.ts +0 -12
- package/dist_ts/protocols/tls/index.js +0 -27
- package/dist_ts/protocols/tls/sni/client-hello-parser.d.ts +0 -100
- package/dist_ts/protocols/tls/sni/client-hello-parser.js +0 -463
- package/dist_ts/protocols/tls/sni/index.d.ts +0 -5
- package/dist_ts/protocols/tls/sni/index.js +0 -6
- package/dist_ts/protocols/tls/sni/sni-extraction.d.ts +0 -58
- package/dist_ts/protocols/tls/sni/sni-extraction.js +0 -275
- package/dist_ts/protocols/tls/utils/index.d.ts +0 -4
- package/dist_ts/protocols/tls/utils/index.js +0 -5
- package/dist_ts/protocols/tls/utils/tls-utils.d.ts +0 -158
- package/dist_ts/protocols/tls/utils/tls-utils.js +0 -187
- package/dist_ts/protocols/websocket/constants.d.ts +0 -55
- package/dist_ts/protocols/websocket/constants.js +0 -58
- package/dist_ts/protocols/websocket/index.d.ts +0 -7
- package/dist_ts/protocols/websocket/index.js +0 -8
- package/dist_ts/protocols/websocket/types.d.ts +0 -47
- package/dist_ts/protocols/websocket/types.js +0 -5
- package/dist_ts/protocols/websocket/utils.d.ts +0 -25
- package/dist_ts/protocols/websocket/utils.js +0 -103
- package/dist_ts/routing/router/http-router.d.ts +0 -89
- package/dist_ts/routing/router/http-router.js +0 -205
- package/dist_ts/routing/router/index.d.ts +0 -5
- package/dist_ts/routing/router/index.js +0 -6
- package/dist_ts/tls/index.d.ts +0 -16
- package/dist_ts/tls/index.js +0 -24
- package/dist_ts/tls/sni/index.d.ts +0 -4
- package/dist_ts/tls/sni/index.js +0 -5
- package/dist_ts/tls/sni/sni-handler.d.ts +0 -154
- package/dist_ts/tls/sni/sni-handler.js +0 -191
- package/ts/core/events/index.ts +0 -3
- package/ts/core/models/socket-augmentation.ts +0 -38
- package/ts/core/utils/async-utils.ts +0 -275
- package/ts/core/utils/binary-heap.ts +0 -225
- package/ts/core/utils/enhanced-connection-pool.ts +0 -425
- package/ts/core/utils/fs-utils.ts +0 -270
- package/ts/core/utils/ip-utils.ts +0 -303
- package/ts/core/utils/lifecycle-component.ts +0 -251
- package/ts/core/utils/log-deduplicator.ts +0 -370
- package/ts/core/utils/security-utils.ts +0 -305
- package/ts/core/utils/shared-security-manager.ts +0 -470
- package/ts/core/utils/socket-utils.ts +0 -322
- package/ts/core/utils/template-utils.ts +0 -124
- package/ts/core/utils/validation-utils.ts +0 -177
- package/ts/core/utils/websocket-utils.ts +0 -33
- package/ts/detection/detectors/http-detector.ts +0 -127
- package/ts/detection/detectors/quick-detector.ts +0 -148
- package/ts/detection/detectors/routing-extractor.ts +0 -147
- package/ts/detection/detectors/tls-detector.ts +0 -223
- package/ts/detection/index.ts +0 -25
- package/ts/detection/models/detection-types.ts +0 -102
- package/ts/detection/models/interfaces.ts +0 -115
- package/ts/detection/protocol-detector.ts +0 -319
- package/ts/detection/utils/buffer-utils.ts +0 -141
- package/ts/detection/utils/fragment-manager.ts +0 -64
- package/ts/detection/utils/parser-utils.ts +0 -77
- package/ts/protocols/common/fragment-handler.ts +0 -167
- package/ts/protocols/common/index.ts +0 -8
- package/ts/protocols/common/types.ts +0 -76
- package/ts/protocols/http/parser.ts +0 -219
- package/ts/protocols/proxy/index.ts +0 -6
- package/ts/protocols/proxy/types.ts +0 -53
- package/ts/protocols/tls/alerts/index.ts +0 -3
- package/ts/protocols/tls/alerts/tls-alert.ts +0 -259
- package/ts/protocols/tls/index.ts +0 -37
- package/ts/protocols/tls/sni/client-hello-parser.ts +0 -629
- package/ts/protocols/tls/sni/index.ts +0 -6
- package/ts/protocols/tls/sni/sni-extraction.ts +0 -353
- package/ts/protocols/tls/utils/index.ts +0 -3
- package/ts/protocols/tls/utils/tls-utils.ts +0 -201
- package/ts/protocols/websocket/constants.ts +0 -60
- package/ts/protocols/websocket/index.ts +0 -8
- package/ts/protocols/websocket/types.ts +0 -53
- package/ts/protocols/websocket/utils.ts +0 -98
- package/ts/routing/router/http-router.ts +0 -266
- package/ts/routing/router/index.ts +0 -7
- package/ts/tls/index.ts +0 -29
- package/ts/tls/sni/index.ts +0 -3
- package/ts/tls/sni/sni-handler.ts +0 -264
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTTP Protocol Detector
|
|
3
|
-
*
|
|
4
|
-
* Simplified HTTP detection using the new architecture
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { IProtocolDetector } from '../models/interfaces.js';
|
|
8
|
-
import type { IDetectionResult, IDetectionOptions } from '../models/detection-types.js';
|
|
9
|
-
import type { IProtocolDetectionResult, IConnectionContext } from '../../protocols/common/types.js';
|
|
10
|
-
import type { THttpMethod } from '../../protocols/http/index.js';
|
|
11
|
-
import { QuickProtocolDetector } from './quick-detector.js';
|
|
12
|
-
import { RoutingExtractor } from './routing-extractor.js';
|
|
13
|
-
import { DetectionFragmentManager } from '../utils/fragment-manager.js';
|
|
14
|
-
import { HttpParser } from '../../protocols/http/parser.js';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Simplified HTTP detector
|
|
18
|
-
*/
|
|
19
|
-
export class HttpDetector implements IProtocolDetector {
|
|
20
|
-
private quickDetector = new QuickProtocolDetector();
|
|
21
|
-
private fragmentManager: DetectionFragmentManager;
|
|
22
|
-
|
|
23
|
-
constructor(fragmentManager?: DetectionFragmentManager) {
|
|
24
|
-
this.fragmentManager = fragmentManager || new DetectionFragmentManager();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Check if buffer can be handled by this detector
|
|
29
|
-
*/
|
|
30
|
-
canHandle(buffer: Buffer): boolean {
|
|
31
|
-
const result = this.quickDetector.quickDetect(buffer);
|
|
32
|
-
return result.protocol === 'http' && result.confidence > 50;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Get minimum bytes needed for detection
|
|
37
|
-
*/
|
|
38
|
-
getMinimumBytes(): number {
|
|
39
|
-
return 4; // "GET " minimum
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Detect HTTP protocol from buffer
|
|
44
|
-
*/
|
|
45
|
-
detect(buffer: Buffer, options?: IDetectionOptions): IDetectionResult | null {
|
|
46
|
-
// Quick detection first
|
|
47
|
-
const quickResult = this.quickDetector.quickDetect(buffer);
|
|
48
|
-
|
|
49
|
-
if (quickResult.protocol !== 'http' || quickResult.confidence < 50) {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Check if we have complete headers first
|
|
54
|
-
const headersEnd = buffer.indexOf('\r\n\r\n');
|
|
55
|
-
const isComplete = headersEnd !== -1;
|
|
56
|
-
|
|
57
|
-
// Extract routing information
|
|
58
|
-
const routing = RoutingExtractor.extract(buffer, 'http');
|
|
59
|
-
|
|
60
|
-
// Extract headers if requested and we have complete headers
|
|
61
|
-
let headers: Record<string, string> | undefined;
|
|
62
|
-
if (options?.extractFullHeaders && isComplete) {
|
|
63
|
-
const headerSection = buffer.slice(0, headersEnd).toString();
|
|
64
|
-
const lines = headerSection.split('\r\n');
|
|
65
|
-
if (lines.length > 1) {
|
|
66
|
-
// Skip the request line and parse headers
|
|
67
|
-
headers = HttpParser.parseHeaders(lines.slice(1));
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// If we don't need full headers and we have complete headers, we can return early
|
|
72
|
-
if (quickResult.confidence >= 95 && !options?.extractFullHeaders && isComplete) {
|
|
73
|
-
return {
|
|
74
|
-
protocol: 'http',
|
|
75
|
-
connectionInfo: {
|
|
76
|
-
protocol: 'http',
|
|
77
|
-
method: quickResult.metadata?.method as THttpMethod,
|
|
78
|
-
domain: routing?.domain,
|
|
79
|
-
path: routing?.path
|
|
80
|
-
},
|
|
81
|
-
isComplete: true
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
protocol: 'http',
|
|
87
|
-
connectionInfo: {
|
|
88
|
-
protocol: 'http',
|
|
89
|
-
domain: routing?.domain,
|
|
90
|
-
path: routing?.path,
|
|
91
|
-
method: quickResult.metadata?.method as THttpMethod,
|
|
92
|
-
headers: headers
|
|
93
|
-
},
|
|
94
|
-
isComplete,
|
|
95
|
-
bytesNeeded: isComplete ? undefined : buffer.length + 512 // Need more for headers
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Handle fragmented detection
|
|
101
|
-
*/
|
|
102
|
-
detectWithContext(
|
|
103
|
-
buffer: Buffer,
|
|
104
|
-
context: IConnectionContext,
|
|
105
|
-
options?: IDetectionOptions
|
|
106
|
-
): IDetectionResult | null {
|
|
107
|
-
const handler = this.fragmentManager.getHandler('http');
|
|
108
|
-
const connectionId = DetectionFragmentManager.createConnectionId(context);
|
|
109
|
-
|
|
110
|
-
// Add fragment
|
|
111
|
-
const result = handler.addFragment(connectionId, buffer);
|
|
112
|
-
|
|
113
|
-
if (result.error) {
|
|
114
|
-
handler.complete(connectionId);
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Try detection on accumulated buffer
|
|
119
|
-
const detectResult = this.detect(result.buffer!, options);
|
|
120
|
-
|
|
121
|
-
if (detectResult && detectResult.isComplete) {
|
|
122
|
-
handler.complete(connectionId);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return detectResult;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Quick Protocol Detector
|
|
3
|
-
*
|
|
4
|
-
* Lightweight protocol identification based on minimal bytes
|
|
5
|
-
* No parsing, just identification
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import type { IProtocolDetector, IProtocolDetectionResult } from '../../protocols/common/types.js';
|
|
9
|
-
import { TlsRecordType } from '../../protocols/tls/index.js';
|
|
10
|
-
import { HttpParser } from '../../protocols/http/index.js';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Quick protocol detector for fast identification
|
|
14
|
-
*/
|
|
15
|
-
export class QuickProtocolDetector implements IProtocolDetector {
|
|
16
|
-
/**
|
|
17
|
-
* Check if this detector can handle the data
|
|
18
|
-
*/
|
|
19
|
-
canHandle(data: Buffer): boolean {
|
|
20
|
-
return data.length >= 1;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Perform quick detection based on first few bytes
|
|
25
|
-
*/
|
|
26
|
-
quickDetect(data: Buffer): IProtocolDetectionResult {
|
|
27
|
-
if (data.length === 0) {
|
|
28
|
-
return {
|
|
29
|
-
protocol: 'unknown',
|
|
30
|
-
confidence: 0,
|
|
31
|
-
requiresMoreData: true
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Check for TLS
|
|
36
|
-
const tlsResult = this.checkTls(data);
|
|
37
|
-
if (tlsResult.confidence > 80) {
|
|
38
|
-
return tlsResult;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Check for HTTP
|
|
42
|
-
const httpResult = this.checkHttp(data);
|
|
43
|
-
if (httpResult.confidence > 80) {
|
|
44
|
-
return httpResult;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Need more data or unknown
|
|
48
|
-
return {
|
|
49
|
-
protocol: 'unknown',
|
|
50
|
-
confidence: 0,
|
|
51
|
-
requiresMoreData: data.length < 20
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Check if data looks like TLS
|
|
57
|
-
*/
|
|
58
|
-
private checkTls(data: Buffer): IProtocolDetectionResult {
|
|
59
|
-
if (data.length < 3) {
|
|
60
|
-
return {
|
|
61
|
-
protocol: 'tls',
|
|
62
|
-
confidence: 0,
|
|
63
|
-
requiresMoreData: true
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const firstByte = data[0];
|
|
68
|
-
const secondByte = data[1];
|
|
69
|
-
|
|
70
|
-
// Check for valid TLS record type
|
|
71
|
-
const validRecordTypes = [
|
|
72
|
-
TlsRecordType.CHANGE_CIPHER_SPEC,
|
|
73
|
-
TlsRecordType.ALERT,
|
|
74
|
-
TlsRecordType.HANDSHAKE,
|
|
75
|
-
TlsRecordType.APPLICATION_DATA,
|
|
76
|
-
TlsRecordType.HEARTBEAT
|
|
77
|
-
];
|
|
78
|
-
|
|
79
|
-
if (!validRecordTypes.includes(firstByte)) {
|
|
80
|
-
return {
|
|
81
|
-
protocol: 'tls',
|
|
82
|
-
confidence: 0
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Check TLS version byte (0x03 for all TLS/SSL versions)
|
|
87
|
-
if (secondByte !== 0x03) {
|
|
88
|
-
return {
|
|
89
|
-
protocol: 'tls',
|
|
90
|
-
confidence: 0
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// High confidence it's TLS
|
|
95
|
-
return {
|
|
96
|
-
protocol: 'tls',
|
|
97
|
-
confidence: 95,
|
|
98
|
-
metadata: {
|
|
99
|
-
recordType: firstByte
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Check if data looks like HTTP
|
|
106
|
-
*/
|
|
107
|
-
private checkHttp(data: Buffer): IProtocolDetectionResult {
|
|
108
|
-
if (data.length < 3) {
|
|
109
|
-
return {
|
|
110
|
-
protocol: 'http',
|
|
111
|
-
confidence: 0,
|
|
112
|
-
requiresMoreData: true
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Quick check for HTTP methods
|
|
117
|
-
const start = data.subarray(0, Math.min(10, data.length)).toString('ascii');
|
|
118
|
-
|
|
119
|
-
// Check common HTTP methods
|
|
120
|
-
const httpMethods = ['GET ', 'POST ', 'PUT ', 'DELETE ', 'HEAD ', 'OPTIONS', 'PATCH ', 'CONNECT', 'TRACE '];
|
|
121
|
-
for (const method of httpMethods) {
|
|
122
|
-
if (start.startsWith(method)) {
|
|
123
|
-
return {
|
|
124
|
-
protocol: 'http',
|
|
125
|
-
confidence: 95,
|
|
126
|
-
metadata: {
|
|
127
|
-
method: method.trim()
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Check if it might be HTTP but need more data
|
|
134
|
-
if (HttpParser.isPrintableAscii(data, Math.min(20, data.length))) {
|
|
135
|
-
// Could be HTTP, but not sure
|
|
136
|
-
return {
|
|
137
|
-
protocol: 'http',
|
|
138
|
-
confidence: 30,
|
|
139
|
-
requiresMoreData: data.length < 20
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return {
|
|
144
|
-
protocol: 'http',
|
|
145
|
-
confidence: 0
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
}
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Routing Information Extractor
|
|
3
|
-
*
|
|
4
|
-
* Extracts minimal routing information from protocols
|
|
5
|
-
* without full parsing
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import type { IRoutingInfo, IConnectionContext, TProtocolType } from '../../protocols/common/types.js';
|
|
9
|
-
import { SniExtraction } from '../../protocols/tls/sni/sni-extraction.js';
|
|
10
|
-
import { HttpParser } from '../../protocols/http/index.js';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Extracts routing information from protocol data
|
|
14
|
-
*/
|
|
15
|
-
export class RoutingExtractor {
|
|
16
|
-
/**
|
|
17
|
-
* Extract routing info based on protocol type
|
|
18
|
-
*/
|
|
19
|
-
static extract(
|
|
20
|
-
data: Buffer,
|
|
21
|
-
protocol: TProtocolType,
|
|
22
|
-
context?: IConnectionContext
|
|
23
|
-
): IRoutingInfo | null {
|
|
24
|
-
switch (protocol) {
|
|
25
|
-
case 'tls':
|
|
26
|
-
case 'https':
|
|
27
|
-
return this.extractTlsRouting(data, context);
|
|
28
|
-
|
|
29
|
-
case 'http':
|
|
30
|
-
return this.extractHttpRouting(data);
|
|
31
|
-
|
|
32
|
-
default:
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Extract routing from TLS ClientHello (SNI)
|
|
39
|
-
*/
|
|
40
|
-
private static extractTlsRouting(
|
|
41
|
-
data: Buffer,
|
|
42
|
-
context?: IConnectionContext
|
|
43
|
-
): IRoutingInfo | null {
|
|
44
|
-
try {
|
|
45
|
-
// Quick SNI extraction without full parsing
|
|
46
|
-
const sni = SniExtraction.extractSNI(data);
|
|
47
|
-
|
|
48
|
-
if (sni) {
|
|
49
|
-
return {
|
|
50
|
-
domain: sni,
|
|
51
|
-
protocol: 'tls',
|
|
52
|
-
port: 443 // Default HTTPS port
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return null;
|
|
57
|
-
} catch (error) {
|
|
58
|
-
// Extraction failed, return null
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Extract routing from HTTP headers (Host header)
|
|
65
|
-
*/
|
|
66
|
-
private static extractHttpRouting(data: Buffer): IRoutingInfo | null {
|
|
67
|
-
try {
|
|
68
|
-
// Look for first line
|
|
69
|
-
const firstLineEnd = data.indexOf('\n');
|
|
70
|
-
if (firstLineEnd === -1) {
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Parse request line
|
|
75
|
-
const firstLine = data.subarray(0, firstLineEnd).toString('ascii').trim();
|
|
76
|
-
const requestLine = HttpParser.parseRequestLine(firstLine);
|
|
77
|
-
|
|
78
|
-
if (!requestLine) {
|
|
79
|
-
return null;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Look for Host header
|
|
83
|
-
let pos = firstLineEnd + 1;
|
|
84
|
-
const maxSearch = Math.min(data.length, 4096); // Don't search too far
|
|
85
|
-
|
|
86
|
-
while (pos < maxSearch) {
|
|
87
|
-
const lineEnd = data.indexOf('\n', pos);
|
|
88
|
-
if (lineEnd === -1) break;
|
|
89
|
-
|
|
90
|
-
const line = data.subarray(pos, lineEnd).toString('ascii').trim();
|
|
91
|
-
|
|
92
|
-
// Empty line means end of headers
|
|
93
|
-
if (line.length === 0) break;
|
|
94
|
-
|
|
95
|
-
// Check for Host header
|
|
96
|
-
if (line.toLowerCase().startsWith('host:')) {
|
|
97
|
-
const hostValue = line.substring(5).trim();
|
|
98
|
-
const domain = HttpParser.extractDomainFromHost(hostValue);
|
|
99
|
-
|
|
100
|
-
return {
|
|
101
|
-
domain,
|
|
102
|
-
path: requestLine.path,
|
|
103
|
-
protocol: 'http',
|
|
104
|
-
port: 80 // Default HTTP port
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
pos = lineEnd + 1;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// No Host header found, but we have the path
|
|
112
|
-
return {
|
|
113
|
-
path: requestLine.path,
|
|
114
|
-
protocol: 'http',
|
|
115
|
-
port: 80
|
|
116
|
-
};
|
|
117
|
-
} catch (error) {
|
|
118
|
-
// Extraction failed
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Try to extract domain from any protocol
|
|
125
|
-
*/
|
|
126
|
-
static extractDomain(data: Buffer, hint?: TProtocolType): string | null {
|
|
127
|
-
// If we have a hint, use it
|
|
128
|
-
if (hint) {
|
|
129
|
-
const routing = this.extract(data, hint);
|
|
130
|
-
return routing?.domain || null;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Try TLS first (more specific)
|
|
134
|
-
const tlsRouting = this.extractTlsRouting(data);
|
|
135
|
-
if (tlsRouting?.domain) {
|
|
136
|
-
return tlsRouting.domain;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Try HTTP
|
|
140
|
-
const httpRouting = this.extractHttpRouting(data);
|
|
141
|
-
if (httpRouting?.domain) {
|
|
142
|
-
return httpRouting.domain;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return null;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TLS protocol detector
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
// TLS detector doesn't need plugins imports
|
|
6
|
-
import type { IProtocolDetector } from '../models/interfaces.js';
|
|
7
|
-
import type { IDetectionResult, IDetectionOptions, IConnectionInfo } from '../models/detection-types.js';
|
|
8
|
-
import { readUInt16BE } from '../utils/buffer-utils.js';
|
|
9
|
-
import { tlsVersionToString } from '../utils/parser-utils.js';
|
|
10
|
-
|
|
11
|
-
// Import from protocols
|
|
12
|
-
import { TlsRecordType, TlsHandshakeType, TlsExtensionType } from '../../protocols/tls/index.js';
|
|
13
|
-
|
|
14
|
-
// Import TLS utilities for SNI extraction from protocols
|
|
15
|
-
import { SniExtraction } from '../../protocols/tls/sni/sni-extraction.js';
|
|
16
|
-
import { ClientHelloParser } from '../../protocols/tls/sni/client-hello-parser.js';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* TLS detector implementation
|
|
20
|
-
*/
|
|
21
|
-
export class TlsDetector implements IProtocolDetector {
|
|
22
|
-
/**
|
|
23
|
-
* Minimum bytes needed to identify TLS (record header)
|
|
24
|
-
*/
|
|
25
|
-
private static readonly MIN_TLS_HEADER_SIZE = 5;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Detect TLS protocol from buffer
|
|
30
|
-
*/
|
|
31
|
-
detect(buffer: Buffer, options?: IDetectionOptions): IDetectionResult | null {
|
|
32
|
-
// Check if buffer is too small
|
|
33
|
-
if (buffer.length < TlsDetector.MIN_TLS_HEADER_SIZE) {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Check if this is a TLS record
|
|
38
|
-
if (!this.isTlsRecord(buffer)) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Extract basic TLS info
|
|
43
|
-
const recordType = buffer[0];
|
|
44
|
-
const tlsMajor = buffer[1];
|
|
45
|
-
const tlsMinor = buffer[2];
|
|
46
|
-
const recordLength = readUInt16BE(buffer, 3);
|
|
47
|
-
|
|
48
|
-
// Initialize connection info
|
|
49
|
-
const connectionInfo: IConnectionInfo = {
|
|
50
|
-
protocol: 'tls',
|
|
51
|
-
tlsVersion: tlsVersionToString(tlsMajor, tlsMinor) || undefined
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// If it's a handshake, try to extract more info
|
|
55
|
-
if (recordType === TlsRecordType.HANDSHAKE && buffer.length >= 6) {
|
|
56
|
-
const handshakeType = buffer[5];
|
|
57
|
-
|
|
58
|
-
// For ClientHello, extract SNI and other info
|
|
59
|
-
if (handshakeType === TlsHandshakeType.CLIENT_HELLO) {
|
|
60
|
-
// Check if we have the complete handshake
|
|
61
|
-
const totalRecordLength = recordLength + 5; // Including TLS header
|
|
62
|
-
if (buffer.length >= totalRecordLength) {
|
|
63
|
-
// Extract SNI using existing logic
|
|
64
|
-
const sni = SniExtraction.extractSNI(buffer);
|
|
65
|
-
if (sni) {
|
|
66
|
-
connectionInfo.domain = sni;
|
|
67
|
-
connectionInfo.sni = sni;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Parse ClientHello for additional info
|
|
71
|
-
const parseResult = ClientHelloParser.parseClientHello(buffer);
|
|
72
|
-
if (parseResult.isValid) {
|
|
73
|
-
// Extract ALPN if present
|
|
74
|
-
const alpnExtension = parseResult.extensions.find(
|
|
75
|
-
ext => ext.type === TlsExtensionType.APPLICATION_LAYER_PROTOCOL_NEGOTIATION
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
if (alpnExtension) {
|
|
79
|
-
connectionInfo.alpn = this.parseAlpnExtension(alpnExtension.data);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Store cipher suites if needed
|
|
83
|
-
if (parseResult.cipherSuites && options?.extractFullHeaders) {
|
|
84
|
-
connectionInfo.cipherSuites = this.parseCipherSuites(parseResult.cipherSuites);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Return complete result
|
|
89
|
-
return {
|
|
90
|
-
protocol: 'tls',
|
|
91
|
-
connectionInfo,
|
|
92
|
-
remainingBuffer: buffer.length > totalRecordLength
|
|
93
|
-
? buffer.subarray(totalRecordLength)
|
|
94
|
-
: undefined,
|
|
95
|
-
isComplete: true
|
|
96
|
-
};
|
|
97
|
-
} else {
|
|
98
|
-
// Incomplete handshake
|
|
99
|
-
return {
|
|
100
|
-
protocol: 'tls',
|
|
101
|
-
connectionInfo,
|
|
102
|
-
isComplete: false,
|
|
103
|
-
bytesNeeded: totalRecordLength
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// For other TLS record types, just return basic info
|
|
110
|
-
return {
|
|
111
|
-
protocol: 'tls',
|
|
112
|
-
connectionInfo,
|
|
113
|
-
isComplete: true,
|
|
114
|
-
remainingBuffer: buffer.length > recordLength + 5
|
|
115
|
-
? buffer.subarray(recordLength + 5)
|
|
116
|
-
: undefined
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Check if buffer can be handled by this detector
|
|
122
|
-
*/
|
|
123
|
-
canHandle(buffer: Buffer): boolean {
|
|
124
|
-
return buffer.length >= TlsDetector.MIN_TLS_HEADER_SIZE &&
|
|
125
|
-
this.isTlsRecord(buffer);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Get minimum bytes needed for detection
|
|
130
|
-
*/
|
|
131
|
-
getMinimumBytes(): number {
|
|
132
|
-
return TlsDetector.MIN_TLS_HEADER_SIZE;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Check if buffer contains a valid TLS record
|
|
137
|
-
*/
|
|
138
|
-
private isTlsRecord(buffer: Buffer): boolean {
|
|
139
|
-
const recordType = buffer[0];
|
|
140
|
-
|
|
141
|
-
// Check for valid record type
|
|
142
|
-
const validTypes = [
|
|
143
|
-
TlsRecordType.CHANGE_CIPHER_SPEC,
|
|
144
|
-
TlsRecordType.ALERT,
|
|
145
|
-
TlsRecordType.HANDSHAKE,
|
|
146
|
-
TlsRecordType.APPLICATION_DATA,
|
|
147
|
-
TlsRecordType.HEARTBEAT
|
|
148
|
-
];
|
|
149
|
-
|
|
150
|
-
if (!validTypes.includes(recordType)) {
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// Check TLS version bytes (should be 0x03 0x0X)
|
|
155
|
-
if (buffer[1] !== 0x03) {
|
|
156
|
-
return false;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Check record length is reasonable
|
|
160
|
-
const recordLength = readUInt16BE(buffer, 3);
|
|
161
|
-
if (recordLength > 16384) { // Max TLS record size
|
|
162
|
-
return false;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return true;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Parse ALPN extension data
|
|
170
|
-
*/
|
|
171
|
-
private parseAlpnExtension(data: Buffer): string[] {
|
|
172
|
-
const protocols: string[] = [];
|
|
173
|
-
|
|
174
|
-
if (data.length < 2) {
|
|
175
|
-
return protocols;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
const listLength = readUInt16BE(data, 0);
|
|
179
|
-
let offset = 2;
|
|
180
|
-
|
|
181
|
-
while (offset < Math.min(2 + listLength, data.length)) {
|
|
182
|
-
const protoLength = data[offset];
|
|
183
|
-
offset++;
|
|
184
|
-
|
|
185
|
-
if (offset + protoLength <= data.length) {
|
|
186
|
-
const protocol = data.subarray(offset, offset + protoLength).toString('ascii');
|
|
187
|
-
protocols.push(protocol);
|
|
188
|
-
offset += protoLength;
|
|
189
|
-
} else {
|
|
190
|
-
break;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return protocols;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Parse cipher suites
|
|
199
|
-
*/
|
|
200
|
-
private parseCipherSuites(cipherData: Buffer): number[] {
|
|
201
|
-
const suites: number[] = [];
|
|
202
|
-
|
|
203
|
-
for (let i = 0; i < cipherData.length - 1; i += 2) {
|
|
204
|
-
const suite = readUInt16BE(cipherData, i);
|
|
205
|
-
suites.push(suite);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
return suites;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Detect with context for fragmented data
|
|
213
|
-
*/
|
|
214
|
-
detectWithContext(
|
|
215
|
-
buffer: Buffer,
|
|
216
|
-
_context: { sourceIp?: string; sourcePort?: number; destIp?: string; destPort?: number },
|
|
217
|
-
options?: IDetectionOptions
|
|
218
|
-
): IDetectionResult | null {
|
|
219
|
-
// This method is deprecated - TLS detection should use the fragment manager
|
|
220
|
-
// from the parent detector system, not maintain its own fragments
|
|
221
|
-
return this.detect(buffer, options);
|
|
222
|
-
}
|
|
223
|
-
}
|
package/ts/detection/index.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Centralized Protocol Detection Module
|
|
3
|
-
*
|
|
4
|
-
* This module provides unified protocol detection capabilities for
|
|
5
|
-
* both TLS and HTTP protocols, extracting connection information
|
|
6
|
-
* without consuming the data stream.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
// Main detector
|
|
10
|
-
export * from './protocol-detector.js';
|
|
11
|
-
|
|
12
|
-
// Models
|
|
13
|
-
export * from './models/detection-types.js';
|
|
14
|
-
export * from './models/interfaces.js';
|
|
15
|
-
|
|
16
|
-
// Individual detectors
|
|
17
|
-
export * from './detectors/tls-detector.js';
|
|
18
|
-
export * from './detectors/http-detector.js';
|
|
19
|
-
export * from './detectors/quick-detector.js';
|
|
20
|
-
export * from './detectors/routing-extractor.js';
|
|
21
|
-
|
|
22
|
-
// Utilities
|
|
23
|
-
export * from './utils/buffer-utils.js';
|
|
24
|
-
export * from './utils/parser-utils.js';
|
|
25
|
-
export * from './utils/fragment-manager.js';
|