Running runas/psexec in powershell remote session is not working

1

I have a remote machine where PS-Remoting enabled and I am able to run commands and scripts from my client/workstation. I want to run certain tasks as different user, in other words not the same user as I connect the remote-session.

Why I am doing this ? I am using puppet-bolt for remote execution, where I can re-use some already existing puppet modules. And this bolt tools uses WinRM.

Issue I am facing is, while executing the below command directly on the remote machine works fine. I am using jetbrains runas utility.

# Executing this command directly on the remote machine's powershell prompt works.
C:\agent\tools\custom_runas.exe '-u:ad_domain\username' '-p:password' C:\Windows\System32\HOSTNAME.EXE

If I execute the same command over PS-RemoteSession (or) Invoke-Command gives me same error again. User which I use to connect WinRM service is an administrator user.

PS C:\WINDOWS\system32> Invoke-Command -ComputerName $CName -Credential $Crdn -ScriptBlock { C:\agent\tools\custom_runas.exe '-u:ad_domain\username' '-p:password' C:\Windows\System32\HOSTNAME.EXE }
JetBrains RunAs x86 1.0.0.061
Copyright (C) 2017 JetBrains. All rights reserved.
Runs a process under the specified windows user account.


Argument(s): -u:ad_domain\username -p:***** C:\Windows\System32\HOSTNAME.EXE


Settings:

    user_name:      username
    domain:         ad_domain
    working_directory:  C:\Users\UserName\Documents
    exit_code_base:     -100000
    integrity_level:    auto
    inheritance_mode:   auto
    show_mode:      hide
    self_testing:       0
    executable:     C:\Windows\System32\HOSTNAME.EXE
NotSpecified: (:String) [], RemoteException
    + CategoryInfo          : NotSpecified: (:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
    + PSComputerName        : remotemachine

NotSpecified: (:) [], RemoteException
Error: Access is denied.
CreateProcessWithLogonW returns the Win32 error 0x00000005.
    command_line_args:  

Some observations, running "runas" command on the PSRemoteSession session doesn't wait for entering password and I also tried using PsExec.exe apart of JetBrains runas which also has the same behavior.

powershell
puppet
powershell-remoting
asked on Stack Overflow Jun 14, 2019 by Fidel • edited Jun 14, 2019 by Fidel

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0