@pyrokine/mcp-ssh 3.1.0 → 3.2.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/README.md +328 -104
- package/README_zh.md +173 -37
- package/dist/command-risk.js +5 -2
- package/dist/directory-verification.d.ts +10 -5
- package/dist/directory-verification.js +153 -66
- package/dist/file-mode.js +25 -13
- package/dist/file-ops.d.ts +13 -6
- package/dist/file-ops.js +477 -208
- package/dist/forward-manager.js +6 -1
- package/dist/known-hosts.d.ts +22 -0
- package/dist/known-hosts.js +553 -0
- package/dist/openssh.js +51 -26
- package/dist/operation-manager.js +13 -4
- package/dist/pty-manager.d.ts +2 -1
- package/dist/pty-manager.js +81 -19
- package/dist/remote-platform.d.ts +1 -1
- package/dist/remote-platform.js +82 -50
- package/dist/security.d.ts +2 -0
- package/dist/security.js +39 -3
- package/dist/session-manager.d.ts +22 -2
- package/dist/session-manager.js +231 -48
- package/dist/sftp-timeout.d.ts +16 -1
- package/dist/sftp-timeout.js +104 -12
- package/dist/ssh-config.js +1 -1
- package/dist/tools/connection.js +17 -3
- package/dist/tools/exec.js +83 -38
- package/dist/tools/file.js +250 -135
- package/dist/tools/operation.js +7 -5
- package/dist/tools/pty.js +16 -13
- package/dist/tools/utils.d.ts +1 -1
- package/dist/tools/utils.js +2 -2
- package/dist/types.d.ts +20 -3
- package/dist/types.js +1 -0
- package/dist/utf8.d.ts +1 -1
- package/dist/utf8.js +2 -2
- package/dist/windows-acl.d.ts +1 -0
- package/dist/windows-acl.js +167 -80
- package/package.json +5 -5
package/dist/tools/operation.js
CHANGED
|
@@ -110,10 +110,11 @@ async function handleOperationList(args) {
|
|
|
110
110
|
}
|
|
111
111
|
export function registerOperationTools(server) {
|
|
112
112
|
server.registerTool('ssh_operation_start', {
|
|
113
|
-
description:
|
|
114
|
-
|
|
115
|
-
返回不可预测的 operationId。channel 建立受 startTimeoutMs 限制,等待期间 record 可通过 list
|
|
116
|
-
|
|
113
|
+
description: '启动可跟踪的长时间远端命令\n' +
|
|
114
|
+
'\n' +
|
|
115
|
+
'返回不可预测的 operationId。channel 建立受 startTimeoutMs 限制,等待期间 record 可通过 list ' +
|
|
116
|
+
'查询;超时 details 返回 operationId。\n' +
|
|
117
|
+
'输出保存在有硬上限的内存缓冲区中,完成后按 retentionMs 自动过期。普通 ssh_exec 的同步和 timeout 行为不变。',
|
|
117
118
|
inputSchema: operationStartSchema,
|
|
118
119
|
}, (args) => handleOperationStart(args));
|
|
119
120
|
server.registerTool('ssh_operation_status', {
|
|
@@ -125,7 +126,8 @@ export function registerOperationTools(server) {
|
|
|
125
126
|
inputSchema: operationReadSchema,
|
|
126
127
|
}, (args) => handleOperationRead(args));
|
|
127
128
|
server.registerTool('ssh_operation_cancel', {
|
|
128
|
-
description: '校验远端 operation marker 和进程身份后执行取消;POSIX 发送 TERM,Windows 在 PID、创建时间和
|
|
129
|
+
description: '校验远端 operation marker 和进程身份后执行取消;POSIX 发送 TERM,Windows 在 PID、创建时间和 ' +
|
|
130
|
+
'marker 验证后执行 taskkill /T /F;无法证明身份时拒绝取消',
|
|
129
131
|
inputSchema: operationIdSchema,
|
|
130
132
|
}, (args) => handleOperationCancel(args));
|
|
131
133
|
server.registerTool('ssh_operation_list', {
|
package/dist/tools/pty.js
CHANGED
|
@@ -74,7 +74,7 @@ async function handlePtyWrite(args) {
|
|
|
74
74
|
}
|
|
75
75
|
async function handlePtyRead(args) {
|
|
76
76
|
try {
|
|
77
|
-
const readResult = sessionManager.ptyRead(args.ptyId, {
|
|
77
|
+
const readResult = await sessionManager.ptyRead(args.ptyId, {
|
|
78
78
|
mode: args.mode ?? 'screen',
|
|
79
79
|
clear: args.clear !== false,
|
|
80
80
|
});
|
|
@@ -159,17 +159,19 @@ write 返回 accepted=true 表示数据已被本地 stream 接收。backpressure
|
|
|
159
159
|
inputSchema: ptyWriteSchema,
|
|
160
160
|
}, (args) => handlePtyWrite(args));
|
|
161
161
|
server.registerTool('ssh_pty_read', {
|
|
162
|
-
description:
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
- screen(默认):返回当前屏幕内容(解析后的纯文本,适合 top/btop/htop
|
|
166
|
-
- raw:data 为 UTF-8 文本预览,dataBase64 为原始 ANSI/二进制字节的无损 base64
|
|
167
|
-
|
|
168
|
-
bufferSize、unreadRawBytes 和 rawBufferLimit
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
162
|
+
description: '读取 PTY 输出\n' +
|
|
163
|
+
'\n' +
|
|
164
|
+
'两种模式:\n' +
|
|
165
|
+
'- screen(默认):返回当前屏幕内容(解析后的纯文本,适合 top/btop/htop 等全屏刷新工具)\n' +
|
|
166
|
+
'- raw:data 为 UTF-8 文本预览,dataBase64 为原始 ANSI/二进制字节的无损 base64\n' +
|
|
167
|
+
'\n' +
|
|
168
|
+
'bufferSize、unreadRawBytes 和 rawBufferLimit ' +
|
|
169
|
+
'均按原始字节计数。rawBufferTruncated=true 表示本次 clear 之后已有更早的 raw 输出因上限被丢弃;raw ' +
|
|
170
|
+
'读取使用默认 clear=true 时,响应返回清理前的计数和标志,然后重置缓冲区。\n' +
|
|
171
|
+
'\n' +
|
|
172
|
+
'示例:\n' +
|
|
173
|
+
'- 获取 top 当前画面: ssh_pty_read(ptyId="xxx")\n' +
|
|
174
|
+
'- 获取原始输出: ssh_pty_read(ptyId="xxx", mode="raw")',
|
|
173
175
|
inputSchema: ptyReadSchema,
|
|
174
176
|
}, (args) => handlePtyRead(args));
|
|
175
177
|
server.registerTool('ssh_pty_resize', {
|
|
@@ -181,7 +183,8 @@ bufferSize、unreadRawBytes 和 rawBufferLimit 均按原始字节计数。rawBuf
|
|
|
181
183
|
inputSchema: ptyCloseSchema,
|
|
182
184
|
}, (args) => handlePtyClose(args));
|
|
183
185
|
server.registerTool('ssh_pty_list', {
|
|
184
|
-
description: '列出所有 PTY 会话。bufferSize、unreadRawBytes 和 rawBufferLimit
|
|
186
|
+
description: '列出所有 PTY 会话。bufferSize、unreadRawBytes 和 rawBufferLimit ' +
|
|
187
|
+
'使用原始字节,rawBufferTruncated 表示更早的 raw 输出已因缓冲区上限被丢弃。',
|
|
185
188
|
inputSchema: ptyListSchema,
|
|
186
189
|
}, () => handlePtyList());
|
|
187
190
|
}
|
package/dist/tools/utils.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare function formatResult(data: unknown): {
|
|
|
19
19
|
/**
|
|
20
20
|
* 格式化错误响应
|
|
21
21
|
*/
|
|
22
|
-
export declare function formatError(error: unknown): {
|
|
22
|
+
export declare function formatError(error: unknown, context?: Record<string, unknown>): {
|
|
23
23
|
content: {
|
|
24
24
|
type: 'text';
|
|
25
25
|
text: string;
|
package/dist/tools/utils.js
CHANGED
|
@@ -28,7 +28,7 @@ export function formatResult(data) {
|
|
|
28
28
|
/**
|
|
29
29
|
* 格式化错误响应
|
|
30
30
|
*/
|
|
31
|
-
export function formatError(error) {
|
|
31
|
+
export function formatError(error, context = {}) {
|
|
32
32
|
const message = error instanceof Error ? error.message : String(error);
|
|
33
33
|
const details = typeof error === 'object' && error !== null && 'details' in error
|
|
34
34
|
? error.details
|
|
@@ -37,7 +37,7 @@ export function formatError(error) {
|
|
|
37
37
|
content: [
|
|
38
38
|
{
|
|
39
39
|
type: 'text',
|
|
40
|
-
text: JSON.stringify({ success: false, error: message, ...(details ? { details } : {}) }, null, 2),
|
|
40
|
+
text: JSON.stringify({ success: false, error: message, ...(details ? { details } : {}), ...context }, null, 2),
|
|
41
41
|
},
|
|
42
42
|
],
|
|
43
43
|
isError: true,
|
package/dist/types.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export interface OpenSshMasterInfo {
|
|
|
18
18
|
sshConnection?: string;
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
+
export declare const DEFAULT_EXEC_TIMEOUT_MS = 30000;
|
|
21
22
|
export declare const DEFAULT_EXEC_MAX_OUTPUT_SIZE: number;
|
|
22
23
|
export declare const HARD_EXEC_MAX_OUTPUT_SIZE: number;
|
|
23
24
|
export type RemotePlatform = 'posix' | 'windows';
|
|
@@ -93,7 +94,7 @@ export interface ExternalTransferCapability {
|
|
|
93
94
|
commandShell?: CommandShell;
|
|
94
95
|
remotePathStyle?: RemotePathStyle;
|
|
95
96
|
}
|
|
96
|
-
export type ConnectionFailureStage = 'preflight' | 'authentication' | 'ready_timeout' | 'transport_or_handshake' | 'unknown';
|
|
97
|
+
export type ConnectionFailureStage = 'preflight' | 'authentication' | 'ready_timeout' | 'transport_or_handshake' | 'host_key' | 'unknown';
|
|
97
98
|
export type ConnectionStep = 'key_read' | 'jump_connect' | 'jump_forward' | 'target_connect';
|
|
98
99
|
export interface ConnectionFailureDetails {
|
|
99
100
|
failureStage: ConnectionFailureStage;
|
|
@@ -101,6 +102,18 @@ export interface ConnectionFailureDetails {
|
|
|
101
102
|
retryable: boolean;
|
|
102
103
|
suggestion?: string;
|
|
103
104
|
keyAclStatus?: 'key_path_usable' | 'key_acl_insecure' | 'key_acl_unverified';
|
|
105
|
+
hostKey?: {
|
|
106
|
+
algorithm?: string;
|
|
107
|
+
keyType: string;
|
|
108
|
+
fingerprint: string;
|
|
109
|
+
knownKeys: {
|
|
110
|
+
keyType: string;
|
|
111
|
+
fingerprint: string;
|
|
112
|
+
file: string;
|
|
113
|
+
line: number;
|
|
114
|
+
revoked: boolean;
|
|
115
|
+
}[];
|
|
116
|
+
};
|
|
104
117
|
}
|
|
105
118
|
export interface ExecOptions {
|
|
106
119
|
timeout?: number;
|
|
@@ -120,7 +133,10 @@ export interface ExecResult {
|
|
|
120
133
|
success: boolean;
|
|
121
134
|
stdout: string;
|
|
122
135
|
stderr: string;
|
|
123
|
-
exitCode: number;
|
|
136
|
+
exitCode: number | null;
|
|
137
|
+
exitSignal?: string;
|
|
138
|
+
operationStatus?: 'completed' | 'failed' | 'unknown';
|
|
139
|
+
retryable?: boolean;
|
|
124
140
|
duration: number;
|
|
125
141
|
failureKind?: 'remote_command' | 'ssh_transport' | 'timeout';
|
|
126
142
|
stdoutTruncated?: boolean;
|
|
@@ -140,7 +156,7 @@ export interface ExecResult {
|
|
|
140
156
|
identity?: string;
|
|
141
157
|
cwd?: string;
|
|
142
158
|
resolvedCwd?: string;
|
|
143
|
-
shell?:
|
|
159
|
+
shell?: CommandShell;
|
|
144
160
|
profileLoaded?: boolean;
|
|
145
161
|
envInjectedKeys?: string[];
|
|
146
162
|
timedOut?: boolean;
|
|
@@ -250,6 +266,7 @@ export interface PtySessionInfo {
|
|
|
250
266
|
active: boolean;
|
|
251
267
|
}
|
|
252
268
|
export interface PtyReadResult {
|
|
269
|
+
parserError?: string;
|
|
253
270
|
data: string;
|
|
254
271
|
dataBase64?: string;
|
|
255
272
|
active: boolean;
|
package/dist/types.js
CHANGED
package/dist/utf8.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare function isUtf8ContinuationByte(value: number): boolean;
|
|
2
2
|
export declare function ensureUtf8Boundary(buffer: Buffer, offset: number, field: string): void;
|
|
3
3
|
export declare function retainUtf8Suffix(buffer: Buffer, maxBytes: number): Buffer;
|
|
4
|
-
export declare function utf8SafeEnd(buffer: Buffer, start: number, requestedEnd: number, stream: string, limitedByMaxBytes?: boolean): number;
|
|
4
|
+
export declare function utf8SafeEnd(buffer: Buffer, start: number, requestedEnd: number, stream: string, limitedByMaxBytes?: boolean, allowEmpty?: boolean): number;
|
package/dist/utf8.js
CHANGED
|
@@ -31,7 +31,7 @@ export function retainUtf8Suffix(buffer, maxBytes) {
|
|
|
31
31
|
}
|
|
32
32
|
return buffer.subarray(start);
|
|
33
33
|
}
|
|
34
|
-
export function utf8SafeEnd(buffer, start, requestedEnd, stream, limitedByMaxBytes = requestedEnd < buffer.length) {
|
|
34
|
+
export function utf8SafeEnd(buffer, start, requestedEnd, stream, limitedByMaxBytes = requestedEnd < buffer.length, allowEmpty = false) {
|
|
35
35
|
let end = requestedEnd;
|
|
36
36
|
if (limitedByMaxBytes) {
|
|
37
37
|
while (end > start && isUtf8ContinuationByte(buffer[end])) {
|
|
@@ -47,7 +47,7 @@ export function utf8SafeEnd(buffer, start, requestedEnd, stream, limitedByMaxByt
|
|
|
47
47
|
end = sequenceStart;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
if (end === start && requestedEnd > start && limitedByMaxBytes) {
|
|
50
|
+
if (end === start && requestedEnd > start && limitedByMaxBytes && !allowEmpty) {
|
|
51
51
|
throw new Error(`maxBytes is too small to read the next UTF-8 character from ${stream}`);
|
|
52
52
|
}
|
|
53
53
|
return end;
|
package/dist/windows-acl.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type AclStatus = 'key_path_usable' | 'key_acl_insecure' | 'key_acl_unverified';
|
|
2
2
|
export declare function windowsAclScript(filePath: string, apply: boolean): string;
|
|
3
3
|
export declare function windowsTemporaryPathScript(name: string): string;
|
|
4
|
+
export declare function checkWindowsKnownHostsIntegrity(filePath: string): void;
|
|
4
5
|
export declare function checkWindowsAcl(filePath: string, apply?: boolean): AclStatus;
|
package/dist/windows-acl.js
CHANGED
|
@@ -2,90 +2,177 @@ import { spawnSync } from 'node:child_process';
|
|
|
2
2
|
import { encodedPowershell, quotePowershell } from './remote-platform.js';
|
|
3
3
|
export function windowsAclScript(filePath, apply) {
|
|
4
4
|
const target = quotePowershell(filePath);
|
|
5
|
-
return
|
|
6
|
-
$ErrorActionPreference = 'Stop'
|
|
7
|
-
$path =
|
|
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
|
-
if (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
$
|
|
44
|
-
|
|
45
|
-
[Console]::WriteLine('
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
5
|
+
return ('\n' +
|
|
6
|
+
"$ErrorActionPreference = 'Stop'\n" +
|
|
7
|
+
'$path = ' +
|
|
8
|
+
`${target}` +
|
|
9
|
+
'\n' +
|
|
10
|
+
'$identity = [System.Security.Principal.WindowsIdentity]::GetCurrent().Us' +
|
|
11
|
+
'er\n' +
|
|
12
|
+
"$system = [System.Security.Principal.SecurityIdentifier]::new('S-1-5-18'" +
|
|
13
|
+
')\n' +
|
|
14
|
+
"$administrators = [System.Security.Principal.SecurityIdentifier]::new('S" +
|
|
15
|
+
"-1-5-32-544')\n" +
|
|
16
|
+
'$allowed = @($identity.Value, $system.Value, $administrators.Value)\n' +
|
|
17
|
+
'$acl = Get-Acl -LiteralPath $path\n' +
|
|
18
|
+
`${apply
|
|
19
|
+
? '\n' +
|
|
20
|
+
'$acl.SetAccessRuleProtection($true, $false)\n' +
|
|
21
|
+
'foreach ($rule in @($acl.GetAccessRules($true, $true, ' +
|
|
22
|
+
'[System.Security.Principal.SecurityIdentifier]))) {\n' +
|
|
23
|
+
' $acl.RemoveAccessRuleSpecific($rule)\n' +
|
|
24
|
+
'}\n' +
|
|
25
|
+
'foreach ($sid in @($identity, $system, $administrators)) {\n' +
|
|
26
|
+
' $rule = [System.Security.AccessControl.FileSystemAccessRule]::ne' +
|
|
27
|
+
'w($sid, [System.Security.AccessControl.FileSystemRights]::FullContro' +
|
|
28
|
+
'l, [System.Security.AccessControl.AccessControlType]::Allow)\n' +
|
|
29
|
+
' $acl.AddAccessRule($rule)\n' +
|
|
30
|
+
'}\n' +
|
|
31
|
+
'Set-Acl -LiteralPath $path -AclObject $acl\n' +
|
|
32
|
+
'$acl = Get-Acl -LiteralPath $path\n'
|
|
33
|
+
: ''}` +
|
|
34
|
+
'\n' +
|
|
35
|
+
'if (-not $acl.AreAccessRulesProtected -or\n' +
|
|
36
|
+
' $allowed -notcontains ' +
|
|
37
|
+
'$acl.GetOwner([System.Security.Principal.SecurityIdentifier]).Value) {\n' +
|
|
38
|
+
" [Console]::WriteLine('insecure'); exit 0\n" +
|
|
39
|
+
'}\n' +
|
|
40
|
+
'$own = $false\n' +
|
|
41
|
+
'foreach ($rule in $acl.GetAccessRules($true, $true, ' +
|
|
42
|
+
'[System.Security.Principal.SecurityIdentifier])) {\n' +
|
|
43
|
+
" if ($rule.AccessControlType -eq 'Allow') {\n" +
|
|
44
|
+
' if ($allowed -notcontains $rule.IdentityReference.Value) { ' +
|
|
45
|
+
"[Console]::WriteLine('insecure'); exit 0 }\n" +
|
|
46
|
+
' if ($rule.IdentityReference.Value -eq $identity.Value) { $own = ' +
|
|
47
|
+
'$true }\n' +
|
|
48
|
+
' }\n' +
|
|
49
|
+
'}\n' +
|
|
50
|
+
"if (-not $own) { [Console]::WriteLine('insecure'); exit 0 }\n" +
|
|
51
|
+
'$item = Get-Item -LiteralPath $path -Force\n' +
|
|
52
|
+
'if ($item -is [IO.FileInfo]) {\n' +
|
|
53
|
+
' try {\n' +
|
|
54
|
+
' $stream = [IO.File]::Open($path, [IO.FileMode]::Open, ' +
|
|
55
|
+
'[IO.FileAccess]::Read, [IO.FileShare]::ReadWrite)\n' +
|
|
56
|
+
' $stream.Dispose()\n' +
|
|
57
|
+
' } catch {\n' +
|
|
58
|
+
" [Console]::WriteLine('unverified'); exit 0\n" +
|
|
59
|
+
' }\n' +
|
|
60
|
+
'}\n' +
|
|
61
|
+
"[Console]::WriteLine('usable')\n");
|
|
50
62
|
}
|
|
51
63
|
export function windowsTemporaryPathScript(name) {
|
|
52
|
-
return
|
|
53
|
-
$ErrorActionPreference = 'Stop'
|
|
54
|
-
$temp = [IO.Path]::GetTempPath()
|
|
55
|
-
$identity = [System.Security.Principal.WindowsIdentity]::GetCurrent().
|
|
56
|
-
|
|
57
|
-
$
|
|
58
|
-
|
|
59
|
-
$
|
|
60
|
-
|
|
61
|
-
$
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if ($current.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
64
|
+
return ('\n' +
|
|
65
|
+
"$ErrorActionPreference = 'Stop'\n" +
|
|
66
|
+
'$temp = [IO.Path]::GetTempPath()\n' +
|
|
67
|
+
'$identity = [System.Security.Principal.WindowsIdentity]::GetCurrent().Us' +
|
|
68
|
+
'er\n' +
|
|
69
|
+
"$system = [System.Security.Principal.SecurityIdentifier]::new('S-1-5-18'" +
|
|
70
|
+
')\n' +
|
|
71
|
+
"$administrators = [System.Security.Principal.SecurityIdentifier]::new('S" +
|
|
72
|
+
"-1-5-32-544')\n" +
|
|
73
|
+
'$allowed = @($identity.Value, $system.Value, $administrators.Value)\n' +
|
|
74
|
+
'$directory = Get-Item -LiteralPath $temp -Force\n' +
|
|
75
|
+
'if ($directory -isnot [IO.DirectoryInfo]) { throw ' +
|
|
76
|
+
"'privacy_not_enforced_on_windows: temporary path is not a directory' }\n" +
|
|
77
|
+
'$current = $directory\n' +
|
|
78
|
+
'while ($null -ne $current) {\n' +
|
|
79
|
+
' if (($current.Attributes -band [IO.FileAttributes]::ReparsePoint) ' +
|
|
80
|
+
'-ne 0) {\n' +
|
|
81
|
+
" throw 'privacy_not_enforced_on_windows: temporary directory has " +
|
|
82
|
+
"a reparse point'\n" +
|
|
83
|
+
' }\n' +
|
|
84
|
+
' $acl = Get-Acl -LiteralPath $current.FullName\n' +
|
|
85
|
+
' if ($current.FullName -eq $directory.FullName -and $allowed ' +
|
|
86
|
+
'-notcontains $acl.GetOwner([System.Security.Principal.SecurityIdentifier' +
|
|
87
|
+
']).Value) {\n' +
|
|
88
|
+
" throw 'privacy_not_enforced_on_windows: temporary directory " +
|
|
89
|
+
"owner is not trusted'\n" +
|
|
90
|
+
' }\n' +
|
|
91
|
+
' $rights = [System.Security.AccessControl.FileSystemRights]::Delete ' +
|
|
92
|
+
'-bor\n' +
|
|
93
|
+
' [System.Security.AccessControl.FileSystemRights]::DeleteSubdirec' +
|
|
94
|
+
'toriesAndFiles -bor\n' +
|
|
95
|
+
' [System.Security.AccessControl.FileSystemRights]::ChangePermissi' +
|
|
96
|
+
'ons -bor\n' +
|
|
97
|
+
' [System.Security.AccessControl.FileSystemRights]::TakeOwnership\n' +
|
|
98
|
+
' if ($current.FullName -eq $directory.FullName) {\n' +
|
|
99
|
+
' $rights = $rights -bor ' +
|
|
100
|
+
'[System.Security.AccessControl.FileSystemRights]::Write\n' +
|
|
101
|
+
' }\n' +
|
|
102
|
+
' foreach ($rule in $acl.GetAccessRules($true, $true, ' +
|
|
103
|
+
'[System.Security.Principal.SecurityIdentifier])) {\n' +
|
|
104
|
+
" if ($rule.AccessControlType -eq 'Allow' -and\n" +
|
|
105
|
+
' $allowed -notcontains $rule.IdentityReference.Value -and\n' +
|
|
106
|
+
' ($rule.PropagationFlags -band ' +
|
|
107
|
+
'[System.Security.AccessControl.PropagationFlags]::InheritOnly) -eq 0 ' +
|
|
108
|
+
'-and\n' +
|
|
109
|
+
' ($rule.FileSystemRights -band $rights) -ne 0) {\n' +
|
|
110
|
+
" throw 'privacy_not_enforced_on_windows: temporary directory " +
|
|
111
|
+
"allows another user to replace entries'\n" +
|
|
112
|
+
' }\n' +
|
|
113
|
+
' }\n' +
|
|
114
|
+
' $current = $current.Parent\n' +
|
|
115
|
+
'}\n' +
|
|
116
|
+
'[Console]::WriteLine([IO.Path]::Combine($directory.FullName, ' +
|
|
117
|
+
`${quotePowershell(name)}` +
|
|
118
|
+
'))\n');
|
|
119
|
+
}
|
|
120
|
+
export function checkWindowsKnownHostsIntegrity(filePath) {
|
|
121
|
+
if (process.platform !== 'win32') {
|
|
122
|
+
throw new Error('Windows ACL verification requires a native Windows process');
|
|
76
123
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
124
|
+
const script = "$ErrorActionPreference = 'Stop'\n" +
|
|
125
|
+
'$identity = [Security.Principal.WindowsIdentity]::GetCurrent().User.Valu' +
|
|
126
|
+
'e\n' +
|
|
127
|
+
"$trustedInstaller = [Security.Principal.NTAccount]::new('NT " +
|
|
128
|
+
"SERVICE\\TrustedInstaller').Translate([Security.Principal.SecurityIdentif" +
|
|
129
|
+
'ier]).Value\n' +
|
|
130
|
+
"$allowed = @($identity, 'S-1-5-18', 'S-1-5-32-544', $trustedInstaller)\n" +
|
|
131
|
+
'$current = Get-Item -LiteralPath ' +
|
|
132
|
+
`${quotePowershell(filePath)}` +
|
|
133
|
+
' -Force\n' +
|
|
134
|
+
'$target = $current.FullName\n' +
|
|
135
|
+
'$container = if ($current -is [IO.DirectoryInfo]) { $current.FullName } ' +
|
|
136
|
+
'else { $current.Directory.FullName }\n' +
|
|
137
|
+
'while ($null -ne $current) {\n' +
|
|
138
|
+
' $acl = Get-Acl -LiteralPath $current.FullName\n' +
|
|
139
|
+
' if ($allowed -notcontains ' +
|
|
140
|
+
'$acl.GetOwner([Security.Principal.SecurityIdentifier]).Value) { throw ' +
|
|
141
|
+
"'untrusted owner' }\n" +
|
|
142
|
+
' $rights = [Security.AccessControl.FileSystemRights]::Delete -bor\n' +
|
|
143
|
+
' [Security.AccessControl.FileSystemRights]::DeleteSubdirectoriesA' +
|
|
144
|
+
'ndFiles -bor\n' +
|
|
145
|
+
' [Security.AccessControl.FileSystemRights]::ChangePermissions ' +
|
|
146
|
+
'-bor\n' +
|
|
147
|
+
' [Security.AccessControl.FileSystemRights]::TakeOwnership\n' +
|
|
148
|
+
' if ($current.FullName -eq $target -or $current.FullName -eq ' +
|
|
149
|
+
'$container) {\n' +
|
|
150
|
+
' $rights = $rights -bor ' +
|
|
151
|
+
'[Security.AccessControl.FileSystemRights]::Write\n' +
|
|
152
|
+
' }\n' +
|
|
153
|
+
' foreach ($rule in $acl.GetAccessRules($true, $true, ' +
|
|
154
|
+
'[Security.Principal.SecurityIdentifier])) {\n' +
|
|
155
|
+
" if ($rule.AccessControlType -eq 'Allow' -and\n" +
|
|
156
|
+
' $allowed -notcontains $rule.IdentityReference.Value -and\n' +
|
|
157
|
+
' ($rule.PropagationFlags -band ' +
|
|
158
|
+
'[Security.AccessControl.PropagationFlags]::InheritOnly) -eq 0 -and\n' +
|
|
159
|
+
' ($rule.FileSystemRights -band $rights) -ne 0) { throw ' +
|
|
160
|
+
"'untrusted writer' }\n" +
|
|
161
|
+
' }\n' +
|
|
162
|
+
' $current = if ($current -is [IO.DirectoryInfo]) { $current.Parent } ' +
|
|
163
|
+
'else { $current.Directory }\n' +
|
|
164
|
+
'}\n' +
|
|
165
|
+
"[Console]::Write('verified')";
|
|
166
|
+
const encoded = encodedPowershell(script).split(' ').at(-1);
|
|
167
|
+
const result = spawnSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-EncodedCommand', encoded], {
|
|
168
|
+
timeout: 10_000,
|
|
169
|
+
encoding: 'utf8',
|
|
170
|
+
windowsHide: true,
|
|
171
|
+
maxBuffer: 16_384,
|
|
172
|
+
});
|
|
173
|
+
if (result.error || result.status !== 0 || result.stdout.trim() !== 'verified') {
|
|
174
|
+
throw new Error('known_hosts write integrity could not be verified on Windows');
|
|
84
175
|
}
|
|
85
|
-
$current = $current.Parent
|
|
86
|
-
}
|
|
87
|
-
[Console]::WriteLine([IO.Path]::Combine($directory.FullName, ${quotePowershell(name)}))
|
|
88
|
-
`;
|
|
89
176
|
}
|
|
90
177
|
export function checkWindowsAcl(filePath, apply = false) {
|
|
91
178
|
if (process.platform !== 'win32') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pyrokine/mcp-ssh",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "A comprehensive SSH MCP Server for Claude Code",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"lint": "eslint \"src/**/*.ts\" \"test/**/*.mjs\"",
|
|
17
17
|
"lint:fix": "eslint \"src/**/*.ts\" \"test/**/*.mjs\" --fix",
|
|
18
18
|
"test": "npm run build && node test/run-tests.mjs",
|
|
19
|
-
"format": "prettier --write
|
|
20
|
-
"format:check": "prettier --check
|
|
19
|
+
"format": "prettier --write src/ test/ README.md README_zh.md TESTING.md",
|
|
20
|
+
"format:check": "prettier --check src/ test/ README.md README_zh.md TESTING.md"
|
|
21
21
|
},
|
|
22
22
|
"keywords": [
|
|
23
23
|
"mcp",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
37
37
|
"@xterm/headless": "^6.0.0",
|
|
38
38
|
"ssh2": "^1.17.0",
|
|
39
|
-
"zod": "^4.
|
|
39
|
+
"zod": "^4.6.7"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@eslint/js": "^10.0.1",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"README_zh.md",
|
|
58
58
|
"LICENSE"
|
|
59
59
|
],
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "ca40950f56a051845f89c3b4b673bf5825c0e199"
|
|
61
61
|
}
|