شائع شدہ سورس
سورس ZIP ڈاؤن لوڈ کریں
CH-J Server Manager
ایپلیکیشن کی کسی مخصوص ریلیز کی ڈائریکٹریز اور فائلیں دیکھیں۔
CH-J / Server Manager
368 فائلیں
core-20261017T201717Z-057348c4a70f
شامل کیا گیا: تاریخ درج نہیں · بلڈ کیا گیا:
1
"use strict";3
const { SessionError } = require("./sessionManager");5
// Runs fixed PowerShell scripts over an existing SSH session to Windows OpenSSH. The command line is only6
// a short -EncodedCommand bootstrap (valid for cmd.exe, Windows PowerShell and PowerShell 7 default shells and7
// far below the 8191 character cmd.exe limit). The script and one JSON argument object follow on stdin as8
// base64 lines, so user input is never concatenated into a command and secrets never reach a command line.9
// Windows has no sudo: the result reports whether the session token is elevated, and the scripts refuse10
// administrative work otherwise instead of trying to bypass UAC.11
const BOOTSTRAP = "$ErrorActionPreference='Stop';$ProgressPreference='SilentlyContinue';$i=[Console]::In;"12
+ "$c=[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($i.ReadLine()));"13
+ "$a=[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($i.ReadLine()));"14
+ "& ([ScriptBlock]::Create($c)) $a";15
const POWERSHELL = "powershell.exe";17
function encodedCommand(source, executable = POWERSHELL) {18
return `${executable} -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand ${Buffer.from(source, "utf16le").toString("base64")}`;19
}21
function bootstrapInput(script, args) {22
const encode = (text) => Buffer.from(text, "utf8").toString("base64");23
return `${encode(script)}\n${encode(JSON.stringify(args))}\n`;24
}26
function cleanMessage(text, limit = 600) {27
return String(text || "").replace(/[\x00-\x08\x0b-\x1f\x7f]/g, " ").replace(/\s+/g, " ").trim().slice(0, limit);28
}30
// Parses the single result line; everything else (CLIXML progress, banners) is ignored.31
function parseWindowsOutput(stdout, stderr, code, errorPrefix = "USERS_") {32
const lines = String(stdout || "").split(/\r?\n/);33
const result = lines.find((line) => line.startsWith("CHJ_RESULT:"));34
if (result) {35
try { return JSON.parse(Buffer.from(result.slice(11), "base64").toString("utf8")); }36
catch { throw new SessionError(`${errorPrefix}PROTOCOL_ERROR`, "The Windows helper returned unreadable data."); }37
}38
const error = lines.find((line) => line.startsWith("CHJ_ERR:"));39
if (error) {40
const match = error.match(/^CHJ_ERR:([A-Z0-9_]{2,64}):([A-Za-z0-9+/=]*)\s*$/);41
if (match) throw new SessionError(`${errorPrefix}${match[1]}`, cleanMessage(Buffer.from(match[2], "base64").toString("utf8")) || match[1]);42
}43
const text = `${stdout || ""}\n${stderr || ""}`;44
if (code === 9009 || /is not recognized as (an internal or external command|the name of a cmdlet)|powershell(\.exe)?: (command )?not found/i.test(text)) {45
throw new SessionError(`${errorPrefix}POWERSHELL_UNAVAILABLE`, "Windows PowerShell (powershell.exe) could not be started over this SSH session.");46
}47
if (/language mode|ConstrainedLanguage|cannot be loaded because running scripts is disabled/i.test(text)) {48
throw new SessionError(`${errorPrefix}POWERSHELL_RESTRICTED`, "PowerShell is restricted by policy (Constrained Language Mode or script blocking); CH-J does not bypass it.");49
}50
throw new SessionError(`${errorPrefix}PROTOCOL_ERROR`, `The Windows helper did not return a result (exit ${code}). ${cleanMessage(stderr.replace(/<[^>]+>/g, " "), 300)}`);51
}53
class WindowsExecutor {54
constructor(options) {55
this.sessionManager = options.sessionManager;56
this.logger = options.logger;57
}59
// args.op selects one fixed operation inside the script; the script validates every field again.60
async run(sessionId, { script, args, timeoutMs = 120000, purpose, errorPrefix = "USERS_" }) {61
const record = this.sessionManager._requireConnected(sessionId);62
const channel = this.sessionManager._execStream(record, encodedCommand(BOOTSTRAP), {63
timeoutMs,64
outputLimit: 16 * 1024 * 1024,65
onUpdate: (controller, kind) => { if (kind === "open") { controller.write(bootstrapInput(script, args)); controller.end(); } }66
});67
const result = await channel.done;68
try { return parseWindowsOutput(result.stdout, result.stderr, result.code, errorPrefix); }69
catch (error) {70
this.logger?.warn("Windows remote operation failed.", { sessionId, purpose, code: error.code });71
throw error;72
}73
}74
}76
module.exports = { BOOTSTRAP, WindowsExecutor, bootstrapInput, encodedCommand, parseWindowsOutput };SHA-256
8fcc1951fc6d0294caed0b07d6311ded5c5d81452e13e8718727ca6a04b92153CH-J Proprietary Software License 1.14 · سورس CH-J Proprietary Software License 1.14 کے تحت فراہم کیا جاتا ہے۔ اس کی دستیابی لائسنس کی شرائط نہیں بدلتی اور نہ ہی اضافی حقوق دیتی ہے۔
آرکائیو کا SHA-256
cf4455b698f0f28e456a37b1834976a0194d8486acb7101052d59a838745cca3