ai-remote 0.4.2 → 0.4.4
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/dist/index.js +1 -6
- package/dist/{protocols/index.d.ts → protocols.d.ts} +2 -0
- package/dist/protocols.js +24 -0
- package/package.json +15 -10
- package/dist/protocols/index.js +0 -34
- package/dist/protocols/rdp/buffer.d.ts +0 -38
- package/dist/protocols/rdp/buffer.js +0 -169
- package/dist/protocols/rdp/caps.d.ts +0 -49
- package/dist/protocols/rdp/caps.js +0 -259
- package/dist/protocols/rdp/cert.d.ts +0 -18
- package/dist/protocols/rdp/cert.js +0 -134
- package/dist/protocols/rdp/client.d.ts +0 -56
- package/dist/protocols/rdp/client.js +0 -1069
- package/dist/protocols/rdp/cliprdr.d.ts +0 -27
- package/dist/protocols/rdp/cliprdr.js +0 -239
- package/dist/protocols/rdp/credssp.d.ts +0 -34
- package/dist/protocols/rdp/credssp.js +0 -253
- package/dist/protocols/rdp/crypto.d.ts +0 -63
- package/dist/protocols/rdp/crypto.js +0 -368
- package/dist/protocols/rdp/display.d.ts +0 -38
- package/dist/protocols/rdp/display.js +0 -588
- package/dist/protocols/rdp/gcc.d.ts +0 -23
- package/dist/protocols/rdp/gcc.js +0 -131
- package/dist/protocols/rdp/keymap.d.ts +0 -9
- package/dist/protocols/rdp/keymap.js +0 -131
- package/dist/protocols/rdp/mcs.d.ts +0 -40
- package/dist/protocols/rdp/mcs.js +0 -222
- package/dist/protocols/rdp/ntlm.d.ts +0 -61
- package/dist/protocols/rdp/ntlm.js +0 -304
- package/dist/protocols/rdp/pdu.d.ts +0 -155
- package/dist/protocols/rdp/pdu.js +0 -443
- package/dist/protocols/rdp/rail.d.ts +0 -119
- package/dist/protocols/rdp/rail.js +0 -382
- package/dist/protocols/rdp/rle.d.ts +0 -13
- package/dist/protocols/rdp/rle.js +0 -275
- package/dist/protocols/rdp/sec.d.ts +0 -59
- package/dist/protocols/rdp/sec.js +0 -155
- package/dist/protocols/rdp/session.d.ts +0 -62
- package/dist/protocols/rdp/session.js +0 -306
- package/dist/protocols/rdp/tls.d.ts +0 -18
- package/dist/protocols/rdp/tls.js +0 -353
- package/dist/protocols/rdp/vchannel.d.ts +0 -28
- package/dist/protocols/rdp/vchannel.js +0 -58
- package/dist/protocols/rdp/x224.d.ts +0 -40
- package/dist/protocols/rdp/x224.js +0 -109
- package/dist/protocols/ssh/kex.d.ts +0 -97
- package/dist/protocols/ssh/kex.js +0 -176
- package/dist/protocols/ssh/messages.d.ts +0 -50
- package/dist/protocols/ssh/messages.js +0 -54
- package/dist/protocols/ssh/session.d.ts +0 -66
- package/dist/protocols/ssh/session.js +0 -608
- package/dist/protocols/ssh/terminal.d.ts +0 -46
- package/dist/protocols/ssh/terminal.js +0 -190
- package/dist/protocols/ssh/transport.d.ts +0 -62
- package/dist/protocols/ssh/transport.js +0 -612
- package/dist/protocols/ssh/wire.d.ts +0 -52
- package/dist/protocols/ssh/wire.js +0 -188
- package/dist/protocols/types.d.ts +0 -127
- package/dist/protocols/types.js +0 -0
- package/dist/protocols/vnc/input.d.ts +0 -5
- package/dist/protocols/vnc/input.js +0 -15
- package/dist/protocols/vnc/session.d.ts +0 -12
- package/dist/protocols/vnc/session.js +0 -258
- package/dist/shared/connection.d.ts +0 -81
- package/dist/shared/connection.js +0 -113
- package/dist/shared/device.d.ts +0 -26
- package/dist/shared/device.js +0 -0
- package/dist/shared/hosts.d.ts +0 -63
- package/dist/shared/hosts.js +0 -132
- package/dist/shared/icons.d.ts +0 -46
- package/dist/shared/icons.js +0 -41
- package/dist/shared/protocol.d.ts +0 -28
- package/dist/shared/protocol.js +0 -39
- package/dist/shared/signals.d.ts +0 -37
- package/dist/shared/signals.js +0 -41
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { Reader, Writer, concatBytes } from "./buffer.js";
|
|
2
|
-
import { parseServerCertificate } from "./cert.js";
|
|
3
|
-
const CS_CORE = 49153;
|
|
4
|
-
const CS_SECURITY = 49154;
|
|
5
|
-
const CS_NET = 49155;
|
|
6
|
-
const CS_CLUSTER = 49156;
|
|
7
|
-
const SC_CORE = 3073;
|
|
8
|
-
const SC_SECURITY = 3074;
|
|
9
|
-
const SC_NET = 3075;
|
|
10
|
-
const RDP_VERSION_5_PLUS = 524292;
|
|
11
|
-
const COLOR_16BPP = 51715;
|
|
12
|
-
const RNS_UD_SAS_DEL = 43523;
|
|
13
|
-
const SUPPORT_ERRINFO_PDU = 1;
|
|
14
|
-
const ENCRYPTION_LEVEL = {
|
|
15
|
-
NONE: 0,
|
|
16
|
-
LOW: 1,
|
|
17
|
-
CLIENT_COMPATIBLE: 2,
|
|
18
|
-
HIGH: 3,
|
|
19
|
-
FIPS: 4
|
|
20
|
-
};
|
|
21
|
-
function userDataBlock(type, body) {
|
|
22
|
-
const writer = new Writer(body.length + 4);
|
|
23
|
-
writer.u16le(type).u16le(body.length + 4).raw(body);
|
|
24
|
-
return writer.take();
|
|
25
|
-
}
|
|
26
|
-
function clientCoreData({ width, height, clientName, keyboardLayout, selectedProtocol }) {
|
|
27
|
-
const writer = new Writer(256);
|
|
28
|
-
writer.u32le(RDP_VERSION_5_PLUS);
|
|
29
|
-
writer.u16le(width);
|
|
30
|
-
writer.u16le(height);
|
|
31
|
-
writer.u16le(COLOR_16BPP);
|
|
32
|
-
writer.u16le(RNS_UD_SAS_DEL);
|
|
33
|
-
writer.u32le(keyboardLayout);
|
|
34
|
-
writer.u32le(2600);
|
|
35
|
-
writer.utf16le(clientName, 32);
|
|
36
|
-
writer.u32le(4);
|
|
37
|
-
writer.u32le(0);
|
|
38
|
-
writer.u32le(12);
|
|
39
|
-
writer.zeros(64);
|
|
40
|
-
writer.u16le(COLOR_16BPP);
|
|
41
|
-
writer.u16le(1);
|
|
42
|
-
writer.u32le(0);
|
|
43
|
-
writer.u16le(16);
|
|
44
|
-
writer.u16le(7);
|
|
45
|
-
writer.u16le(SUPPORT_ERRINFO_PDU);
|
|
46
|
-
writer.zeros(64);
|
|
47
|
-
writer.u8(0);
|
|
48
|
-
writer.u8(0);
|
|
49
|
-
writer.u32le(selectedProtocol);
|
|
50
|
-
return userDataBlock(CS_CORE, writer.take());
|
|
51
|
-
}
|
|
52
|
-
function clientSecurityData(encryptionMethods) {
|
|
53
|
-
const writer = new Writer(8);
|
|
54
|
-
writer.u32le(encryptionMethods);
|
|
55
|
-
writer.u32le(0);
|
|
56
|
-
return userDataBlock(CS_SECURITY, writer.take());
|
|
57
|
-
}
|
|
58
|
-
function clientClusterData() {
|
|
59
|
-
const writer = new Writer(8);
|
|
60
|
-
writer.u32le(13);
|
|
61
|
-
writer.u32le(0);
|
|
62
|
-
return userDataBlock(CS_CLUSTER, writer.take());
|
|
63
|
-
}
|
|
64
|
-
function clientNetworkData(channels) {
|
|
65
|
-
if (channels.length === 0) return new Uint8Array(0);
|
|
66
|
-
const writer = new Writer(4 + channels.length * 12);
|
|
67
|
-
writer.u32le(channels.length);
|
|
68
|
-
for (const channel of channels) {
|
|
69
|
-
const name = new Uint8Array(8);
|
|
70
|
-
for (let i = 0; i < Math.min(7, channel.name.length); i++) name[i] = channel.name.charCodeAt(i);
|
|
71
|
-
writer.raw(name);
|
|
72
|
-
writer.u32le(channel.options >>> 0);
|
|
73
|
-
}
|
|
74
|
-
return userDataBlock(CS_NET, writer.take());
|
|
75
|
-
}
|
|
76
|
-
function clientData(options) {
|
|
77
|
-
return concatBytes(
|
|
78
|
-
clientCoreData(options),
|
|
79
|
-
clientClusterData(),
|
|
80
|
-
clientSecurityData(options.encryptionMethods),
|
|
81
|
-
clientNetworkData(options.channels || [])
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
function parseServerData(blocks) {
|
|
85
|
-
const reader = new Reader(blocks);
|
|
86
|
-
const result = {
|
|
87
|
-
version: null,
|
|
88
|
-
encryptionMethod: 0,
|
|
89
|
-
encryptionLevel: ENCRYPTION_LEVEL.NONE,
|
|
90
|
-
serverRandom: null,
|
|
91
|
-
publicKey: null,
|
|
92
|
-
ioChannelId: 1003,
|
|
93
|
-
channelIds: []
|
|
94
|
-
};
|
|
95
|
-
while (reader.remaining >= 4) {
|
|
96
|
-
const type = reader.u16le();
|
|
97
|
-
const length = reader.u16le();
|
|
98
|
-
if (length < 4 || length - 4 > reader.remaining) break;
|
|
99
|
-
const body = new Reader(reader.raw(length - 4));
|
|
100
|
-
if (type === SC_CORE) {
|
|
101
|
-
result.version = body.remaining >= 4 ? body.u32le() : null;
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
if (type === SC_NET) {
|
|
105
|
-
result.ioChannelId = body.u16le();
|
|
106
|
-
const channelCount = body.u16le();
|
|
107
|
-
for (let i = 0; i < channelCount && body.remaining >= 2; i++) {
|
|
108
|
-
result.channelIds.push(body.u16le());
|
|
109
|
-
}
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
if (type === SC_SECURITY) {
|
|
113
|
-
result.encryptionMethod = body.u32le();
|
|
114
|
-
result.encryptionLevel = body.u32le();
|
|
115
|
-
if (result.encryptionMethod === 0 && result.encryptionLevel === 0) continue;
|
|
116
|
-
if (body.remaining < 8) continue;
|
|
117
|
-
const serverRandomLength = body.u32le();
|
|
118
|
-
const serverCertLength = body.u32le();
|
|
119
|
-
result.serverRandom = body.raw(serverRandomLength).slice();
|
|
120
|
-
result.publicKey = parseServerCertificate(body.raw(serverCertLength));
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return result;
|
|
125
|
-
}
|
|
126
|
-
export {
|
|
127
|
-
ENCRYPTION_LEVEL,
|
|
128
|
-
RDP_VERSION_5_PLUS,
|
|
129
|
-
clientData,
|
|
130
|
-
parseServerData
|
|
131
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/** Returns { scancode, extended } or null when the key has no RDP equivalent. */
|
|
2
|
-
export declare function lookupScancode(code: string): {
|
|
3
|
-
scancode: any;
|
|
4
|
-
extended: boolean;
|
|
5
|
-
};
|
|
6
|
-
export declare const CTRL_ALT_DEL: {
|
|
7
|
-
code: string;
|
|
8
|
-
pressed: boolean;
|
|
9
|
-
}[];
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
const SCANCODES = {
|
|
2
|
-
Escape: 1,
|
|
3
|
-
Digit1: 2,
|
|
4
|
-
Digit2: 3,
|
|
5
|
-
Digit3: 4,
|
|
6
|
-
Digit4: 5,
|
|
7
|
-
Digit5: 6,
|
|
8
|
-
Digit6: 7,
|
|
9
|
-
Digit7: 8,
|
|
10
|
-
Digit8: 9,
|
|
11
|
-
Digit9: 10,
|
|
12
|
-
Digit0: 11,
|
|
13
|
-
Minus: 12,
|
|
14
|
-
Equal: 13,
|
|
15
|
-
Backspace: 14,
|
|
16
|
-
Tab: 15,
|
|
17
|
-
KeyQ: 16,
|
|
18
|
-
KeyW: 17,
|
|
19
|
-
KeyE: 18,
|
|
20
|
-
KeyR: 19,
|
|
21
|
-
KeyT: 20,
|
|
22
|
-
KeyY: 21,
|
|
23
|
-
KeyU: 22,
|
|
24
|
-
KeyI: 23,
|
|
25
|
-
KeyO: 24,
|
|
26
|
-
KeyP: 25,
|
|
27
|
-
BracketLeft: 26,
|
|
28
|
-
BracketRight: 27,
|
|
29
|
-
Enter: 28,
|
|
30
|
-
ControlLeft: 29,
|
|
31
|
-
KeyA: 30,
|
|
32
|
-
KeyS: 31,
|
|
33
|
-
KeyD: 32,
|
|
34
|
-
KeyF: 33,
|
|
35
|
-
KeyG: 34,
|
|
36
|
-
KeyH: 35,
|
|
37
|
-
KeyJ: 36,
|
|
38
|
-
KeyK: 37,
|
|
39
|
-
KeyL: 38,
|
|
40
|
-
Semicolon: 39,
|
|
41
|
-
Quote: 40,
|
|
42
|
-
Backquote: 41,
|
|
43
|
-
ShiftLeft: 42,
|
|
44
|
-
Backslash: 43,
|
|
45
|
-
KeyZ: 44,
|
|
46
|
-
KeyX: 45,
|
|
47
|
-
KeyC: 46,
|
|
48
|
-
KeyV: 47,
|
|
49
|
-
KeyB: 48,
|
|
50
|
-
KeyN: 49,
|
|
51
|
-
KeyM: 50,
|
|
52
|
-
Comma: 51,
|
|
53
|
-
Period: 52,
|
|
54
|
-
Slash: 53,
|
|
55
|
-
ShiftRight: 54,
|
|
56
|
-
NumpadMultiply: 55,
|
|
57
|
-
AltLeft: 56,
|
|
58
|
-
Space: 57,
|
|
59
|
-
CapsLock: 58,
|
|
60
|
-
F1: 59,
|
|
61
|
-
F2: 60,
|
|
62
|
-
F3: 61,
|
|
63
|
-
F4: 62,
|
|
64
|
-
F5: 63,
|
|
65
|
-
F6: 64,
|
|
66
|
-
F7: 65,
|
|
67
|
-
F8: 66,
|
|
68
|
-
F9: 67,
|
|
69
|
-
F10: 68,
|
|
70
|
-
NumLock: 69,
|
|
71
|
-
ScrollLock: 70,
|
|
72
|
-
Numpad7: 71,
|
|
73
|
-
Numpad8: 72,
|
|
74
|
-
Numpad9: 73,
|
|
75
|
-
NumpadSubtract: 74,
|
|
76
|
-
Numpad4: 75,
|
|
77
|
-
Numpad5: 76,
|
|
78
|
-
Numpad6: 77,
|
|
79
|
-
NumpadAdd: 78,
|
|
80
|
-
Numpad1: 79,
|
|
81
|
-
Numpad2: 80,
|
|
82
|
-
Numpad3: 81,
|
|
83
|
-
Numpad0: 82,
|
|
84
|
-
NumpadDecimal: 83,
|
|
85
|
-
IntlBackslash: 86,
|
|
86
|
-
F11: 87,
|
|
87
|
-
F12: 88,
|
|
88
|
-
IntlRo: 115,
|
|
89
|
-
IntlYen: 125
|
|
90
|
-
};
|
|
91
|
-
const EXTENDED_SCANCODES = {
|
|
92
|
-
NumpadEnter: 28,
|
|
93
|
-
ControlRight: 29,
|
|
94
|
-
NumpadDivide: 53,
|
|
95
|
-
PrintScreen: 55,
|
|
96
|
-
AltRight: 56,
|
|
97
|
-
Home: 71,
|
|
98
|
-
ArrowUp: 72,
|
|
99
|
-
PageUp: 73,
|
|
100
|
-
ArrowLeft: 75,
|
|
101
|
-
ArrowRight: 77,
|
|
102
|
-
End: 79,
|
|
103
|
-
ArrowDown: 80,
|
|
104
|
-
PageDown: 81,
|
|
105
|
-
Insert: 82,
|
|
106
|
-
Delete: 83,
|
|
107
|
-
MetaLeft: 91,
|
|
108
|
-
MetaRight: 92,
|
|
109
|
-
ContextMenu: 93
|
|
110
|
-
};
|
|
111
|
-
function lookupScancode(code) {
|
|
112
|
-
if (Object.prototype.hasOwnProperty.call(SCANCODES, code)) {
|
|
113
|
-
return { scancode: SCANCODES[code], extended: false };
|
|
114
|
-
}
|
|
115
|
-
if (Object.prototype.hasOwnProperty.call(EXTENDED_SCANCODES, code)) {
|
|
116
|
-
return { scancode: EXTENDED_SCANCODES[code], extended: true };
|
|
117
|
-
}
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
const CTRL_ALT_DEL = [
|
|
121
|
-
{ code: "ControlLeft", pressed: true },
|
|
122
|
-
{ code: "AltLeft", pressed: true },
|
|
123
|
-
{ code: "Delete", pressed: true },
|
|
124
|
-
{ code: "Delete", pressed: false },
|
|
125
|
-
{ code: "AltLeft", pressed: false },
|
|
126
|
-
{ code: "ControlLeft", pressed: false }
|
|
127
|
-
];
|
|
128
|
-
export {
|
|
129
|
-
CTRL_ALT_DEL,
|
|
130
|
-
lookupScancode
|
|
131
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export declare const MCS_BASE_CHANNEL_ID = 1001;
|
|
2
|
-
export declare const MCS_GLOBAL_CHANNEL_ID = 1003;
|
|
3
|
-
export declare function connectInitial(clientData: Uint8Array): Uint8Array<ArrayBufferLike>;
|
|
4
|
-
export declare function parseConnectResponse(frame: Uint8Array): Uint8Array<ArrayBufferLike>;
|
|
5
|
-
export declare function erectDomainRequest(): Uint8Array<ArrayBufferLike>;
|
|
6
|
-
export declare function attachUserRequest(): Uint8Array<ArrayBufferLike>;
|
|
7
|
-
export declare function parseAttachUserConfirm(frame: Uint8Array): {
|
|
8
|
-
userId: number;
|
|
9
|
-
};
|
|
10
|
-
export declare function channelJoinRequest(userId: number, channelId: number): Uint8Array<ArrayBufferLike>;
|
|
11
|
-
export declare function parseChannelJoinConfirm(frame: Uint8Array): {
|
|
12
|
-
channelId: number;
|
|
13
|
-
};
|
|
14
|
-
export declare function sendDataRequest(userId: number, channelId: number, payload: Uint8Array): Uint8Array<ArrayBufferLike>;
|
|
15
|
-
/**
|
|
16
|
-
* Classify an inbound X.224 data frame. Everything the server sends after the
|
|
17
|
-
* connect sequence arrives as a send-data indication on some channel.
|
|
18
|
-
*/
|
|
19
|
-
export declare function parseDomainPdu(frame: Uint8Array): {
|
|
20
|
-
type: string;
|
|
21
|
-
channelId: number;
|
|
22
|
-
payload: Uint8Array<ArrayBufferLike>;
|
|
23
|
-
reason?: undefined;
|
|
24
|
-
message?: undefined;
|
|
25
|
-
mcsPduType?: undefined;
|
|
26
|
-
} | {
|
|
27
|
-
channelId?: undefined;
|
|
28
|
-
payload?: undefined;
|
|
29
|
-
type: string;
|
|
30
|
-
reason: number;
|
|
31
|
-
message: any;
|
|
32
|
-
mcsPduType?: undefined;
|
|
33
|
-
} | {
|
|
34
|
-
channelId?: undefined;
|
|
35
|
-
payload?: undefined;
|
|
36
|
-
reason?: undefined;
|
|
37
|
-
message?: undefined;
|
|
38
|
-
type: string;
|
|
39
|
-
mcsPduType: number;
|
|
40
|
-
};
|
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
import { Reader, Writer, concatBytes } from "./buffer.js";
|
|
2
|
-
import { dataFrame, dataPayload } from "./x224.js";
|
|
3
|
-
const MCS_BASE_CHANNEL_ID = 1001;
|
|
4
|
-
const MCS_GLOBAL_CHANNEL_ID = 1003;
|
|
5
|
-
const DOMAIN_MCSPDU = {
|
|
6
|
-
ERECT_DOMAIN_REQUEST: 1,
|
|
7
|
-
DISCONNECT_PROVIDER_ULTIMATUM: 8,
|
|
8
|
-
ATTACH_USER_REQUEST: 10,
|
|
9
|
-
ATTACH_USER_CONFIRM: 11,
|
|
10
|
-
CHANNEL_JOIN_REQUEST: 14,
|
|
11
|
-
CHANNEL_JOIN_CONFIRM: 15,
|
|
12
|
-
SEND_DATA_REQUEST: 25,
|
|
13
|
-
SEND_DATA_INDICATION: 26
|
|
14
|
-
};
|
|
15
|
-
const DISCONNECT_REASONS = {
|
|
16
|
-
0: "The host closed the RDP session (domain disconnected).",
|
|
17
|
-
1: "The host closed the RDP session (provider initiated).",
|
|
18
|
-
2: "The host closed the RDP session (token purged).",
|
|
19
|
-
3: "The host closed the RDP session (user requested).",
|
|
20
|
-
4: "The host closed the RDP session (channel purged)."
|
|
21
|
-
};
|
|
22
|
-
function berLength(length) {
|
|
23
|
-
if (length > 255) return new Uint8Array([130, length >> 8 & 255, length & 255]);
|
|
24
|
-
if (length > 127) return new Uint8Array([129, length]);
|
|
25
|
-
return new Uint8Array([length]);
|
|
26
|
-
}
|
|
27
|
-
function berTlv(tag, content) {
|
|
28
|
-
return concatBytes(new Uint8Array(tag), berLength(content.length), content);
|
|
29
|
-
}
|
|
30
|
-
function berInteger(value) {
|
|
31
|
-
let body;
|
|
32
|
-
if (value < 128) body = new Uint8Array([value]);
|
|
33
|
-
else if (value < 32768) body = new Uint8Array([value >> 8, value & 255]);
|
|
34
|
-
else if (value < 8388608) body = new Uint8Array([value >> 16, value >> 8 & 255, value & 255]);
|
|
35
|
-
else body = new Uint8Array([value >>> 24, value >> 16 & 255, value >> 8 & 255, value & 255]);
|
|
36
|
-
return berTlv([2], body);
|
|
37
|
-
}
|
|
38
|
-
const berOctetString = (bytes) => berTlv([4], bytes);
|
|
39
|
-
const berBoolean = (value) => berTlv([1], new Uint8Array([value ? 255 : 0]));
|
|
40
|
-
function berDomainParameters(values) {
|
|
41
|
-
return berTlv([48], concatBytes(...values.map(berInteger)));
|
|
42
|
-
}
|
|
43
|
-
function perLength(writer, length) {
|
|
44
|
-
if (length > 127) writer.u16be(32768 | length);
|
|
45
|
-
else writer.u8(length);
|
|
46
|
-
return writer;
|
|
47
|
-
}
|
|
48
|
-
function perReadLength(reader) {
|
|
49
|
-
const first = reader.u8();
|
|
50
|
-
return first & 128 ? (first & 127) << 8 | reader.u8() : first;
|
|
51
|
-
}
|
|
52
|
-
const T124_OBJECT_IDENTIFIER = new Uint8Array([5, 0, 20, 124, 0, 1]);
|
|
53
|
-
const H221_CLIENT_KEY = new Uint8Array([68, 117, 99, 97]);
|
|
54
|
-
const H221_SERVER_KEY = new Uint8Array([77, 99, 68, 110]);
|
|
55
|
-
function gccConferenceCreateRequest(clientData) {
|
|
56
|
-
const writer = new Writer(clientData.length + 32);
|
|
57
|
-
writer.u8(0);
|
|
58
|
-
writer.raw(T124_OBJECT_IDENTIFIER);
|
|
59
|
-
perLength(writer, clientData.length + 14);
|
|
60
|
-
writer.u8(0);
|
|
61
|
-
writer.u8(8);
|
|
62
|
-
writer.u8(0);
|
|
63
|
-
writer.u8(16);
|
|
64
|
-
writer.u8(0);
|
|
65
|
-
writer.u8(1);
|
|
66
|
-
writer.u8(192);
|
|
67
|
-
writer.u8(0);
|
|
68
|
-
writer.raw(H221_CLIENT_KEY);
|
|
69
|
-
perLength(writer, clientData.length);
|
|
70
|
-
writer.raw(clientData);
|
|
71
|
-
return writer.take();
|
|
72
|
-
}
|
|
73
|
-
function gccServerDataBlocks(userData) {
|
|
74
|
-
for (let i = 0; i + 4 <= userData.length; i++) {
|
|
75
|
-
if (userData[i] === H221_SERVER_KEY[0] && userData[i + 1] === H221_SERVER_KEY[1] && userData[i + 2] === H221_SERVER_KEY[2] && userData[i + 3] === H221_SERVER_KEY[3]) {
|
|
76
|
-
const reader = new Reader(userData, i + 4);
|
|
77
|
-
const length = perReadLength(reader);
|
|
78
|
-
const blocks = reader.rest();
|
|
79
|
-
return blocks.subarray(0, Math.min(length, blocks.length));
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
throw new Error("RDP: the host response contained no GCC server data");
|
|
83
|
-
}
|
|
84
|
-
const DOMAIN_TARGET = [34, 2, 0, 1, 0, 1, 65535, 2];
|
|
85
|
-
const DOMAIN_MINIMUM = [1, 1, 1, 1, 0, 1, 1056, 2];
|
|
86
|
-
const DOMAIN_MAXIMUM = [65535, 64535, 65535, 1, 0, 1, 65535, 2];
|
|
87
|
-
function connectInitial(clientData) {
|
|
88
|
-
const userData = gccConferenceCreateRequest(clientData);
|
|
89
|
-
const content = concatBytes(
|
|
90
|
-
berOctetString(new Uint8Array([1])),
|
|
91
|
-
// callingDomainSelector
|
|
92
|
-
berOctetString(new Uint8Array([1])),
|
|
93
|
-
// calledDomainSelector
|
|
94
|
-
berBoolean(true),
|
|
95
|
-
// upwardFlag
|
|
96
|
-
berDomainParameters(DOMAIN_TARGET),
|
|
97
|
-
berDomainParameters(DOMAIN_MINIMUM),
|
|
98
|
-
berDomainParameters(DOMAIN_MAXIMUM),
|
|
99
|
-
berOctetString(userData)
|
|
100
|
-
);
|
|
101
|
-
return dataFrame(berTlv([127, 101], content));
|
|
102
|
-
}
|
|
103
|
-
function readBerTlv(reader) {
|
|
104
|
-
let tag = reader.u8();
|
|
105
|
-
if ((tag & 31) === 31) tag = tag << 8 | reader.u8();
|
|
106
|
-
let length = reader.u8();
|
|
107
|
-
if (length & 128) {
|
|
108
|
-
const byteCount = length & 127;
|
|
109
|
-
length = 0;
|
|
110
|
-
for (let i = 0; i < byteCount; i++) length = length << 8 | reader.u8();
|
|
111
|
-
}
|
|
112
|
-
return { tag, value: reader.raw(length) };
|
|
113
|
-
}
|
|
114
|
-
function parseConnectResponse(frame) {
|
|
115
|
-
const reader = new Reader(dataPayload(frame));
|
|
116
|
-
const outer = readBerTlv(reader);
|
|
117
|
-
if (outer.tag !== 32614) {
|
|
118
|
-
throw new Error(`RDP: expected an MCS connect response, got BER tag 0x${outer.tag.toString(16)}`);
|
|
119
|
-
}
|
|
120
|
-
const inner = new Reader(outer.value);
|
|
121
|
-
const result = readBerTlv(inner);
|
|
122
|
-
readBerTlv(inner);
|
|
123
|
-
readBerTlv(inner);
|
|
124
|
-
const userData = readBerTlv(inner);
|
|
125
|
-
if (result.value[0] !== 0) {
|
|
126
|
-
throw new Error(`RDP: the host rejected the MCS connection (result ${result.value[0]})`);
|
|
127
|
-
}
|
|
128
|
-
return gccServerDataBlocks(userData.value);
|
|
129
|
-
}
|
|
130
|
-
const domainHeader = (pdu) => pdu << 2;
|
|
131
|
-
function erectDomainRequest() {
|
|
132
|
-
const writer = new Writer(8);
|
|
133
|
-
writer.u8(domainHeader(DOMAIN_MCSPDU.ERECT_DOMAIN_REQUEST));
|
|
134
|
-
writer.u8(1).u8(0);
|
|
135
|
-
writer.u8(1).u8(0);
|
|
136
|
-
return dataFrame(writer.take());
|
|
137
|
-
}
|
|
138
|
-
function attachUserRequest() {
|
|
139
|
-
return dataFrame(new Uint8Array([domainHeader(DOMAIN_MCSPDU.ATTACH_USER_REQUEST)]));
|
|
140
|
-
}
|
|
141
|
-
function parseAttachUserConfirm(frame) {
|
|
142
|
-
const reader = new Reader(dataPayload(frame));
|
|
143
|
-
const header = reader.u8();
|
|
144
|
-
if (header >> 2 !== DOMAIN_MCSPDU.ATTACH_USER_CONFIRM) {
|
|
145
|
-
throw new Error(`RDP: expected an MCS attach-user confirm, got PDU ${header >> 2}`);
|
|
146
|
-
}
|
|
147
|
-
const result = reader.u8();
|
|
148
|
-
if (result !== 0) throw new Error(`RDP: the host refused to attach a user (result ${result})`);
|
|
149
|
-
const userId = header & 2 ? reader.u16be() + MCS_BASE_CHANNEL_ID : MCS_BASE_CHANNEL_ID;
|
|
150
|
-
return { userId };
|
|
151
|
-
}
|
|
152
|
-
function channelJoinRequest(userId, channelId) {
|
|
153
|
-
const writer = new Writer(8);
|
|
154
|
-
writer.u8(domainHeader(DOMAIN_MCSPDU.CHANNEL_JOIN_REQUEST));
|
|
155
|
-
writer.u16be(userId - MCS_BASE_CHANNEL_ID);
|
|
156
|
-
writer.u16be(channelId);
|
|
157
|
-
return dataFrame(writer.take());
|
|
158
|
-
}
|
|
159
|
-
function parseChannelJoinConfirm(frame) {
|
|
160
|
-
const reader = new Reader(dataPayload(frame));
|
|
161
|
-
const header = reader.u8();
|
|
162
|
-
if (header >> 2 !== DOMAIN_MCSPDU.CHANNEL_JOIN_CONFIRM) {
|
|
163
|
-
throw new Error(`RDP: expected an MCS channel-join confirm, got PDU ${header >> 2}`);
|
|
164
|
-
}
|
|
165
|
-
const result = reader.u8();
|
|
166
|
-
reader.u16be();
|
|
167
|
-
const requested = reader.u16be();
|
|
168
|
-
if (result !== 0) {
|
|
169
|
-
throw new Error(`RDP: the host refused to join channel ${requested} (result ${result})`);
|
|
170
|
-
}
|
|
171
|
-
const channelId = reader.remaining >= 2 ? reader.u16be() : requested;
|
|
172
|
-
return { channelId: channelId || requested };
|
|
173
|
-
}
|
|
174
|
-
function sendDataRequest(userId, channelId, payload) {
|
|
175
|
-
const writer = new Writer(payload.length + 16);
|
|
176
|
-
writer.u8(domainHeader(DOMAIN_MCSPDU.SEND_DATA_REQUEST));
|
|
177
|
-
writer.u16be(userId - MCS_BASE_CHANNEL_ID);
|
|
178
|
-
writer.u16be(channelId);
|
|
179
|
-
writer.u8(112);
|
|
180
|
-
perLength(writer, payload.length);
|
|
181
|
-
writer.raw(payload);
|
|
182
|
-
return dataFrame(writer.take());
|
|
183
|
-
}
|
|
184
|
-
function parseDomainPdu(frame) {
|
|
185
|
-
const reader = new Reader(dataPayload(frame));
|
|
186
|
-
const header = reader.u8();
|
|
187
|
-
const type = header >> 2;
|
|
188
|
-
if (type === DOMAIN_MCSPDU.SEND_DATA_INDICATION) {
|
|
189
|
-
reader.u16be();
|
|
190
|
-
const channelId = reader.u16be();
|
|
191
|
-
reader.u8();
|
|
192
|
-
const length = perReadLength(reader);
|
|
193
|
-
const payload = reader.rest();
|
|
194
|
-
return {
|
|
195
|
-
type: "send-data",
|
|
196
|
-
channelId,
|
|
197
|
-
payload: payload.subarray(0, Math.min(length, payload.length))
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
if (type === DOMAIN_MCSPDU.DISCONNECT_PROVIDER_ULTIMATUM) {
|
|
201
|
-
const reason = (header & 1) << 1 | (reader.remaining > 0 ? reader.u8() >> 7 : 0);
|
|
202
|
-
return {
|
|
203
|
-
type: "disconnect",
|
|
204
|
-
reason,
|
|
205
|
-
message: DISCONNECT_REASONS[reason] || `The host closed the RDP session (reason ${reason}).`
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
return { type: "other", mcsPduType: type };
|
|
209
|
-
}
|
|
210
|
-
export {
|
|
211
|
-
MCS_BASE_CHANNEL_ID,
|
|
212
|
-
MCS_GLOBAL_CHANNEL_ID,
|
|
213
|
-
attachUserRequest,
|
|
214
|
-
channelJoinRequest,
|
|
215
|
-
connectInitial,
|
|
216
|
-
erectDomainRequest,
|
|
217
|
-
parseAttachUserConfirm,
|
|
218
|
-
parseChannelJoinConfirm,
|
|
219
|
-
parseConnectResponse,
|
|
220
|
-
parseDomainPdu,
|
|
221
|
-
sendDataRequest
|
|
222
|
-
};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
export declare function md4(message: string): Uint8Array<ArrayBuffer>;
|
|
2
|
-
/** HMAC-MD5. WebCrypto has no MD5, so it is built from the MD5 here. */
|
|
3
|
-
export declare function hmacMd5(key: Uint8Array, message: string): Uint8Array<ArrayBuffer>;
|
|
4
|
-
export declare const NTLM_FLAG: {
|
|
5
|
-
UNICODE: number;
|
|
6
|
-
REQUEST_TARGET: number;
|
|
7
|
-
SIGN: number;
|
|
8
|
-
SEAL: number;
|
|
9
|
-
NTLM: number;
|
|
10
|
-
ALWAYS_SIGN: number;
|
|
11
|
-
EXTENDED_SESSION_SECURITY: number;
|
|
12
|
-
TARGET_INFO: number;
|
|
13
|
-
VERSION: number;
|
|
14
|
-
KEY_128: number;
|
|
15
|
-
KEY_EXCH: number;
|
|
16
|
-
KEY_56: number;
|
|
17
|
-
};
|
|
18
|
-
export declare function negotiateMessage(): Uint8Array<ArrayBufferLike>;
|
|
19
|
-
export declare function parseChallengeMessage(bytes: Uint8Array): {
|
|
20
|
-
flags: number;
|
|
21
|
-
serverChallenge: Uint8Array<ArrayBuffer>;
|
|
22
|
-
targetName: Uint8Array<ArrayBuffer>;
|
|
23
|
-
targetInfo: Uint8Array<ArrayBuffer>;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Build the AUTHENTICATE message plus every key CredSSP needs afterwards.
|
|
27
|
-
*
|
|
28
|
-
* The MIC is always sent: a current Windows host expects one, and sending it
|
|
29
|
-
* obliges the client to flag it in the AV pair list, which in turn feeds the
|
|
30
|
-
* NTProofStr -- so the modified list has to be the one that goes on the wire.
|
|
31
|
-
*/
|
|
32
|
-
export declare function authenticateMessage({ username, domain, password, challenge, negotiateBytes, challengeBytes }: {
|
|
33
|
-
challenge: any;
|
|
34
|
-
challengeBytes: any;
|
|
35
|
-
domain: any;
|
|
36
|
-
negotiateBytes: any;
|
|
37
|
-
password: any;
|
|
38
|
-
username: any;
|
|
39
|
-
}): {
|
|
40
|
-
message: Uint8Array<ArrayBufferLike>;
|
|
41
|
-
exportedSessionKey: Uint8Array<ArrayBuffer>;
|
|
42
|
-
keys: {
|
|
43
|
-
clientSigningKey: Uint8Array<ArrayBuffer>;
|
|
44
|
-
serverSigningKey: Uint8Array<ArrayBuffer>;
|
|
45
|
-
clientSealing: import("./crypto").Rc4State;
|
|
46
|
-
serverSealing: import("./crypto").Rc4State;
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* NTLM message confidentiality (MS-NLMP 3.4.3). The signature covers the
|
|
51
|
-
* plaintext, and both the payload and the checksum draw from the same RC4
|
|
52
|
-
* stream -- payload first.
|
|
53
|
-
*/
|
|
54
|
-
export declare class NtlmSealer {
|
|
55
|
-
private readonly keys;
|
|
56
|
-
private sendSequence;
|
|
57
|
-
private receiveSequence;
|
|
58
|
-
constructor(keys: any);
|
|
59
|
-
seal(plaintext: Uint8Array): Uint8Array<ArrayBufferLike>;
|
|
60
|
-
unseal(bytes: Uint8Array): Uint8Array<ArrayBuffer>;
|
|
61
|
-
}
|