fix(host-deployer): do base64 windows password (#25071)

This commit is contained in:
wanyaoqi
2026-06-28 08:24:48 +08:00
committed by GitHub
parent 7802f909e0
commit 1b742b49e9
2 changed files with 10 additions and 5 deletions
+9 -4
View File
@@ -15,6 +15,7 @@
package fsdriver
import (
"encoding/base64"
"fmt"
"math/rand"
"path"
@@ -453,8 +454,6 @@ func (w *SWindowsRootFs) ChangeUserPasswd(part IDiskPartition, account, gid, pub
tool.CheckPath()
success := false
// symbol ^ is escape character is batch file.
password = strings.ReplaceAll(password, "^", "")
if rinfo != nil && version.GE(rinfo.CurrentVersion, "6.1") {
success = w.deployPublicKeyByGuest(account, password)
} else {
@@ -492,6 +491,10 @@ func (w *SWindowsRootFs) ChangeUserPasswd(part IDiskPartition, account, gid, pub
return secret, nil
}
func encodeWindowsScriptPassword(passwd string) string {
return base64.StdEncoding.EncodeToString([]byte(passwd))
}
func (w *SWindowsRootFs) deployPublicKeyByGuest(uname, passwd string) bool {
if !w.deploySetupCompleteScripts(uname, passwd) {
return false
@@ -506,13 +509,14 @@ func (w *SWindowsRootFs) deployPublicKeyByGuest(uname, passwd string) bool {
w.appendGuestBootScript("chgpwd", bootScript)
logPath := w.guestDebugLogPath
chksum := stringutils2.GetMD5Hash(passwd + logPath[(len(logPath)-10):])
passwdEnc := encodeWindowsScriptPassword(passwd)
chgpwdScript := strings.Join([]string{
w.MakeGuestDebugCmd("change password step 1"),
strings.Join([]string{
`%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe`,
` -executionpolicy bypass %SystemRoot%\chgpwd.ps1`,
fmt.Sprintf(" %s %s %s %s", uname, passwd, chksum, logPath),
fmt.Sprintf(" %s %s %s %s", uname, passwdEnc, chksum, logPath),
}, ""),
`del %SystemRoot%\chgpwd.ps1`,
w.MakeGuestDebugCmd("change password step 2"),
@@ -535,9 +539,10 @@ func (w *SWindowsRootFs) deploySetupCompleteScripts(uname, passwd string) bool {
if w.putGuestScriptContents("/windows/chgpwd_setup.ps1", WinScriptChangePassword) != nil {
return false
}
passwdEnc := encodeWindowsScriptPassword(passwd)
cmds := []string{
`%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass %SystemRoot%\chgpwd_setup.ps1 ` +
fmt.Sprintf("%s %s", uname, passwd),
fmt.Sprintf("%s %s", uname, passwdEnc),
"Net stop wuauserv",
}
for _, v := range [][3]string{
+1 -1
View File
@@ -17,7 +17,7 @@ package fsdriver
const WinScriptChangePassword = `
$username = $args[0]
$passwd = $args[1]
$passwd = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($args[1]))
$loghash = $args[2]
$logpath = $args[3]
Function ChangePassword($u, $p) {