2

I'm trying to configure autologon.exe using the command line (via PsExec). However, the special characters in the password are causing issues.

Given this password: I'vegotspe"cia"char@ters

This command works:

Start-Process 'C:\Autologon.exe' -ArgumentList 'username','hostname','"I''vegotspe\"cia\"char@ters"','/accepteula'

However since I'm using PsExec the I need to make the call with "/c" so I have the following command.

powershell.exe /c  "Start-Process 'C:\Autologon.exe' -ArgumentList 'username','hostname','"I''vegotspe\"cia\"char@ters"','/accepteula'"

This command doesn't output any errors but it doesn't work either. It works if I don't have the double-quote character. Any idea how I can make this work?

I'm using PyPsexec so once I get the above command working; the call would look like this

c.run_executable("powershell.exe", arguments=''' /c Start-Process 'C:\Autologon.exe' -ArgumentList 'username','hostname','"I''vegotspe\"cia\"char@ters"','/accepteula' ''')

UPDATE 1: Just tried the EncodedCommand as @lit suggested but I seem to have the same syntax issue since it needs to be wrapped in quotations.

COMMAND:

[Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes("Start-Process 'C:\Autologon.exe' -ArgumentList 'username','hostname','"I''vegotspe\"cia\"char@ters"','/accepteula'"))

OUTPUT:

ine:1 char:140
+ ... ess 'C:\Autologon.exe' -ArgumentList 'username','hostname','"I''vegot ...
+                                                                  ~
Missing ')' in method call.
At line:1 char:140
+ ... username','hostname','"I''vegotspe\"cia\"char@ters"','/accepteula'"))
+                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token 'I''vegotspe\"cia\"char@ters"','/accepteula'"' in expression or statement.
At line:1 char:184
+ ... username','hostname','"I''vegotspe\"cia\"char@ters"','/accepteula'"))
+                                                                        ~
Unexpected token ')' in expression or statement.
At line:1 char:185
+ ... username','hostname','"I''vegotspe\"cia\"char@ters"','/accepteula'"))
+                                                                         ~
Unexpected token ')' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingEndParenthesisInMethodCall
MTG
  • 163
  • 2
  • 12
  • The `/c` parameter is `-Command`. It is not clear how `psexec` is used. Is this `psexec` from the SysInternals kit? Why are `psexec` and `powershell` being used? See also the powershell `-EncodedCommand` parameter. – lit Aug 05 '20 at 02:33
  • It is the same PsExec but a python library (PyPsExec) exists to make it easier to incorporate in scripts. PsExec is used so I can remotely execute this command and Powershell is used to make the call to Autologin. – MTG Aug 05 '20 at 03:11
  • Just tried the encoded command (updated the original question with results) – MTG Aug 05 '20 at 03:23
  • 1
    so is the target a Windows box? Or the source, I suppose. Is there a reason you're not simply doing a remote `Invoke-Command`? – LeeM Aug 05 '20 at 06:40

1 Answers1

0

I suggest storing the password in a variable. Then use the call operator &. That may work better than trying to pass a wierd string.

& C:\Autologon.exe /accepteula username hostname $password 

It might help to put all the arguments in variables, depending on how /accepteula goes.

But if you're going to run it from your psexec equivalent - which implies it's using the command interpreter - why the Powershell?

Perhaps the complex password is no good if you simply run it on a command line - I don't know if you've tested it. It might make life easier to simplify it so it's a long string with "enough" complexity. Or you could can set a variable for your password using the SET command.

set PWD=I'vegotspe"cia"char@ters"
C:\Autologon.exe /accepteula username hostname %PWD%

It might need a CMD /C before the executable, depending on how your Python thing works. No point adding extra interpreters like Powershell if you don't need them.

LeeM
  • 1,118
  • 8
  • 18