本帖最后由 新手965682 于 2026-11-30 11:29 编辑
在SCP>=6.12.0的版本,可以使用"执行云主机内部指令"配合"获取云主机内部脚本的执行结果"来完成。执行云主机内部指令有几个需要注意的点: 1、目标云主机必须已安装vmtool且已设置操作系统密码,传密码需要先进行加密,guest_password加密示例如下: - import re
- from Crypto.Cipher import PKCS1_v1_5
- from Crypto.PublicKey import RSA
- def encrypt_guest_password(password: str, public_key_hex: str) -> str:
- modulus = public_key_hex.strip()
- if not re.fullmatch(r"(?:[0-9a-fA-F]{2})+", modulus):
- raise ValueError("公钥必须是十六进制 RSA 模数")
- if not password:
- raise ValueError("密码不能为空")
- key = RSA.construct((int(modulus, 16), 65537))
- return PKCS1_v1_5.new(key).encrypt(password.encode("utf-8")).hex()
复制代码- import java.math.BigInteger;
- import java.nio.charset.StandardCharsets;
- import java.security.GeneralSecurityException;
- import java.security.KeyFactory;
- import java.security.spec.RSAPublicKeySpec;
- import javax.crypto.Cipher;
- public final class GuestPasswordEncryption {
- public static String encryptGuestPassword(String password, String publicKeyHex)
- throws GeneralSecurityException {
- String modulus = publicKeyHex == null ? "" : publicKeyHex.trim();
- if (!modulus.matches("(?:[0-9a-fA-F]{2})+")) {
- throw new IllegalArgumentException("Expected the hexadecimal RSA modulus from data.public_key");
- }
- if (password == null || password.isEmpty()) {
- throw new IllegalArgumentException("Guest password must not be empty");
- }
- RSAPublicKeySpec key = new RSAPublicKeySpec(new BigInteger(modulus, 16), BigInteger.valueOf(65537));
- Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
- cipher.init(Cipher.ENCRYPT_MODE, KeyFactory.getInstance("RSA").generatePublic(key));
- byte[] encrypted = cipher.doFinal(password.getBytes(StandardCharsets.UTF_8));
- StringBuilder hex = new StringBuilder(encrypted.length * 2);
- for (byte value : encrypted) {
- hex.append(Character.forDigit((value >>> 4) & 0x0f, 16));
- hex.append(Character.forDigit(value & 0x0f, 16));
- }
- return hex.toString();
- }
- }
复制代码2、script_text需要使用base64先编码,不传明文指令 3、获取云主机内部脚本的执行结果返回的指令结果也是base64编码的,需要解码回来 |