@pyrokine/mcp-ssh 2.4.3 → 3.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/README.md +137 -26
- package/README_zh.md +121 -28
- package/dist/command-risk.d.ts +2 -1
- package/dist/command-risk.js +238 -87
- package/dist/directory-verification.d.ts +5 -3
- package/dist/directory-verification.js +187 -222
- package/dist/file-mode.d.ts +6 -0
- package/dist/file-mode.js +71 -0
- package/dist/file-ops.d.ts +30 -6
- package/dist/file-ops.js +618 -207
- package/dist/forward-manager.d.ts +2 -0
- package/dist/forward-manager.js +19 -10
- package/dist/operation-manager.d.ts +2 -1
- package/dist/operation-manager.js +8 -2
- package/dist/pty-manager.d.ts +5 -13
- package/dist/pty-manager.js +47 -15
- package/dist/remote-platform.d.ts +13 -0
- package/dist/remote-platform.js +132 -0
- package/dist/security.js +12 -2
- package/dist/session-manager.d.ts +13 -13
- package/dist/session-manager.js +320 -90
- package/dist/ssh-config.d.ts +3 -0
- package/dist/ssh-config.js +48 -20
- package/dist/tools/connection.js +59 -0
- package/dist/tools/exec.d.ts +1 -0
- package/dist/tools/exec.js +100 -31
- package/dist/tools/file.js +166 -85
- package/dist/tools/operation.js +1 -1
- package/dist/tools/pty.js +5 -3
- package/dist/tools/utils.js +2 -2
- package/dist/types.d.ts +37 -0
- package/dist/utf8.d.ts +1 -0
- package/dist/utf8.js +10 -0
- package/dist/windows-acl.d.ts +4 -0
- package/dist/windows-acl.js +109 -0
- package/package.json +2 -2
package/dist/utf8.d.ts
CHANGED
|
@@ -1,3 +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
|
+
export declare function retainUtf8Suffix(buffer: Buffer, maxBytes: number): Buffer;
|
|
3
4
|
export declare function utf8SafeEnd(buffer: Buffer, start: number, requestedEnd: number, stream: string, limitedByMaxBytes?: boolean): number;
|
package/dist/utf8.js
CHANGED
|
@@ -21,6 +21,16 @@ export function ensureUtf8Boundary(buffer, offset, field) {
|
|
|
21
21
|
throw new Error(`${field} must point to a UTF-8 character boundary`);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
+
export function retainUtf8Suffix(buffer, maxBytes) {
|
|
25
|
+
if (buffer.length <= maxBytes) {
|
|
26
|
+
return buffer;
|
|
27
|
+
}
|
|
28
|
+
let start = buffer.length - maxBytes;
|
|
29
|
+
while (start < buffer.length && isUtf8ContinuationByte(buffer[start])) {
|
|
30
|
+
++start;
|
|
31
|
+
}
|
|
32
|
+
return buffer.subarray(start);
|
|
33
|
+
}
|
|
24
34
|
export function utf8SafeEnd(buffer, start, requestedEnd, stream, limitedByMaxBytes = requestedEnd < buffer.length) {
|
|
25
35
|
let end = requestedEnd;
|
|
26
36
|
if (limitedByMaxBytes) {
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type AclStatus = 'key_path_usable' | 'key_acl_insecure' | 'key_acl_unverified';
|
|
2
|
+
export declare function windowsAclScript(filePath: string, apply: boolean): string;
|
|
3
|
+
export declare function windowsTemporaryPathScript(name: string): string;
|
|
4
|
+
export declare function checkWindowsAcl(filePath: string, apply?: boolean): AclStatus;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { encodedPowershell, quotePowershell } from './remote-platform.js';
|
|
3
|
+
export function windowsAclScript(filePath, apply) {
|
|
4
|
+
const target = quotePowershell(filePath);
|
|
5
|
+
return `
|
|
6
|
+
$ErrorActionPreference = 'Stop'
|
|
7
|
+
$path = ${target}
|
|
8
|
+
$identity = [System.Security.Principal.WindowsIdentity]::GetCurrent().User
|
|
9
|
+
$system = [System.Security.Principal.SecurityIdentifier]::new('S-1-5-18')
|
|
10
|
+
$administrators = [System.Security.Principal.SecurityIdentifier]::new('S-1-5-32-544')
|
|
11
|
+
$allowed = @($identity.Value, $system.Value, $administrators.Value)
|
|
12
|
+
$acl = Get-Acl -LiteralPath $path
|
|
13
|
+
${apply
|
|
14
|
+
? `
|
|
15
|
+
$acl.SetAccessRuleProtection($true, $false)
|
|
16
|
+
foreach ($rule in @($acl.GetAccessRules($true, $true, [System.Security.Principal.SecurityIdentifier]))) {
|
|
17
|
+
$acl.RemoveAccessRuleSpecific($rule)
|
|
18
|
+
}
|
|
19
|
+
foreach ($sid in @($identity, $system, $administrators)) {
|
|
20
|
+
$rule = [System.Security.AccessControl.FileSystemAccessRule]::new($sid, [System.Security.AccessControl.FileSystemRights]::FullControl, [System.Security.AccessControl.AccessControlType]::Allow)
|
|
21
|
+
$acl.AddAccessRule($rule)
|
|
22
|
+
}
|
|
23
|
+
Set-Acl -LiteralPath $path -AclObject $acl
|
|
24
|
+
$acl = Get-Acl -LiteralPath $path
|
|
25
|
+
`
|
|
26
|
+
: ''}
|
|
27
|
+
if (-not $acl.AreAccessRulesProtected -or
|
|
28
|
+
$allowed -notcontains $acl.GetOwner([System.Security.Principal.SecurityIdentifier]).Value) {
|
|
29
|
+
[Console]::WriteLine('insecure'); exit 0
|
|
30
|
+
}
|
|
31
|
+
$own = $false
|
|
32
|
+
foreach ($rule in $acl.GetAccessRules($true, $true, [System.Security.Principal.SecurityIdentifier])) {
|
|
33
|
+
if ($rule.AccessControlType -eq 'Allow') {
|
|
34
|
+
if ($allowed -notcontains $rule.IdentityReference.Value) { [Console]::WriteLine('insecure'); exit 0 }
|
|
35
|
+
if ($rule.IdentityReference.Value -eq $identity.Value) { $own = $true }
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (-not $own) { [Console]::WriteLine('insecure'); exit 0 }
|
|
39
|
+
$item = Get-Item -LiteralPath $path -Force
|
|
40
|
+
if ($item -is [IO.FileInfo]) {
|
|
41
|
+
try {
|
|
42
|
+
$stream = [IO.File]::Open($path, [IO.FileMode]::Open, [IO.FileAccess]::Read, [IO.FileShare]::ReadWrite)
|
|
43
|
+
$stream.Dispose()
|
|
44
|
+
} catch {
|
|
45
|
+
[Console]::WriteLine('unverified'); exit 0
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
[Console]::WriteLine('usable')
|
|
49
|
+
`;
|
|
50
|
+
}
|
|
51
|
+
export function windowsTemporaryPathScript(name) {
|
|
52
|
+
return `
|
|
53
|
+
$ErrorActionPreference = 'Stop'
|
|
54
|
+
$temp = [IO.Path]::GetTempPath()
|
|
55
|
+
$identity = [System.Security.Principal.WindowsIdentity]::GetCurrent().User
|
|
56
|
+
$system = [System.Security.Principal.SecurityIdentifier]::new('S-1-5-18')
|
|
57
|
+
$administrators = [System.Security.Principal.SecurityIdentifier]::new('S-1-5-32-544')
|
|
58
|
+
$allowed = @($identity.Value, $system.Value, $administrators.Value)
|
|
59
|
+
$directory = Get-Item -LiteralPath $temp -Force
|
|
60
|
+
if ($directory -isnot [IO.DirectoryInfo]) { throw 'privacy_not_enforced_on_windows: temporary path is not a directory' }
|
|
61
|
+
$current = $directory
|
|
62
|
+
while ($null -ne $current) {
|
|
63
|
+
if (($current.Attributes -band [IO.FileAttributes]::ReparsePoint) -ne 0) {
|
|
64
|
+
throw 'privacy_not_enforced_on_windows: temporary directory has a reparse point'
|
|
65
|
+
}
|
|
66
|
+
$acl = Get-Acl -LiteralPath $current.FullName
|
|
67
|
+
if ($current.FullName -eq $directory.FullName -and $allowed -notcontains $acl.GetOwner([System.Security.Principal.SecurityIdentifier]).Value) {
|
|
68
|
+
throw 'privacy_not_enforced_on_windows: temporary directory owner is not trusted'
|
|
69
|
+
}
|
|
70
|
+
$rights = [System.Security.AccessControl.FileSystemRights]::Delete -bor
|
|
71
|
+
[System.Security.AccessControl.FileSystemRights]::DeleteSubdirectoriesAndFiles -bor
|
|
72
|
+
[System.Security.AccessControl.FileSystemRights]::ChangePermissions -bor
|
|
73
|
+
[System.Security.AccessControl.FileSystemRights]::TakeOwnership
|
|
74
|
+
if ($current.FullName -eq $directory.FullName) {
|
|
75
|
+
$rights = $rights -bor [System.Security.AccessControl.FileSystemRights]::Write
|
|
76
|
+
}
|
|
77
|
+
foreach ($rule in $acl.GetAccessRules($true, $true, [System.Security.Principal.SecurityIdentifier])) {
|
|
78
|
+
if ($rule.AccessControlType -eq 'Allow' -and
|
|
79
|
+
$allowed -notcontains $rule.IdentityReference.Value -and
|
|
80
|
+
($rule.PropagationFlags -band [System.Security.AccessControl.PropagationFlags]::InheritOnly) -eq 0 -and
|
|
81
|
+
($rule.FileSystemRights -band $rights) -ne 0) {
|
|
82
|
+
throw 'privacy_not_enforced_on_windows: temporary directory allows another user to replace entries'
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
$current = $current.Parent
|
|
86
|
+
}
|
|
87
|
+
[Console]::WriteLine([IO.Path]::Combine($directory.FullName, ${quotePowershell(name)}))
|
|
88
|
+
`;
|
|
89
|
+
}
|
|
90
|
+
export function checkWindowsAcl(filePath, apply = false) {
|
|
91
|
+
if (process.platform !== 'win32') {
|
|
92
|
+
throw new Error('Windows ACL verification requires a native Windows process');
|
|
93
|
+
}
|
|
94
|
+
const command = encodedPowershell(windowsAclScript(filePath, apply));
|
|
95
|
+
const encoded = command.split(' ').at(-1);
|
|
96
|
+
const result = spawnSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-EncodedCommand', encoded], {
|
|
97
|
+
timeout: 10_000,
|
|
98
|
+
encoding: 'utf8',
|
|
99
|
+
windowsHide: true,
|
|
100
|
+
maxBuffer: 16_384,
|
|
101
|
+
});
|
|
102
|
+
if (result.error || result.status !== 0) {
|
|
103
|
+
return 'key_acl_unverified';
|
|
104
|
+
}
|
|
105
|
+
if (result.stdout.trim() === 'usable') {
|
|
106
|
+
return 'key_path_usable';
|
|
107
|
+
}
|
|
108
|
+
return result.stdout.trim() === 'insecure' ? 'key_acl_insecure' : 'key_acl_unverified';
|
|
109
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pyrokine/mcp-ssh",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "A comprehensive SSH MCP Server for Claude Code",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"url": "git+https://github.com/Pyrokine/claude-tools.git"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
36
|
+
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
37
37
|
"@xterm/headless": "^6.0.0",
|
|
38
38
|
"ssh2": "^1.17.0",
|
|
39
39
|
"zod": "^4.4.3"
|