Jump to content

Reading From Command Prompt Window Using StdinWirte/StdoutRead/StderrRead


Recommended Posts

Hello All,

I am writing a script that runs cmd which prompts users to input their username and password before continuing with the script. Once the login command is recieved, the user has to wait for cmd to prompt the user to input their password. the problem is, I cannot brag what the cmd is outputting to the screen. Here is a little piece of the code (radius meaning 2-factor authentication)

Local $Pid = Run("C:\Windows\system32\cmd.exe", "", @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD)
Local $data = ''

$Username = InputBox('USERNAME','ENTER YOUR USERNAME','','') ;Prompt User for username

StdinWrite($Pid, 'pacli default VAULT="Vault Dev" USER='& $Username &' FOLDER=Root' & @CRLF)
;sign the user onto the vault
StdinWrite($Pid, 'pacli logon radius = yes'&@CRLF )

Sleep(1500)
While True
    $data &= StderrRead($Pid)
    If @extended Then ExitLoop
WEnd
MsgBox(0, "STDERR REPORT", $data)
$data = ''

After cmd recieves the command it will prompt the user by outputting "Password: ". How do I know when it is ready for the password?

The screenshot is what comes up in the cmd window. The "Password: " pops up a couple of seconds after the command is executed.

I tried to use stdoutRead as well as using @error instead of @extended, but no luck. I have also tried waiting and then prompting the user for the password and writting it to the cmd and that also did not work. I was hoping that the stdinwrite would just output it where it propmted for the password. Here is what that code looked like:

Local $Pid = Run("C:\Windows\system32\cmd.exe", "", @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD)
Local $data = ''

$Username = InputBox('USERNAME','ENTER YOUR USERNAME','','') ;Prompt User for username

StdinWrite($Pid, 'pacli default VAULT="Vault Dev" USER='& $Username &' FOLDER=Root' & @CRLF)
;sign the user onto the vault
StdinWrite($Pid, 'pacli logon RADIUS = YES '&@CRLF )

Sleep(1500)
$token = InputBox('PASSWORD', 'ENTER YOUR RSA TOKEN (HARDWRAE OR SOFTWWARE TOKENS ):', '', '*')
StdinWrite($Pid, $token & @CRLF)

Does anyone have any tips? Pacli is a third party executiable so it may have to do with pacli and not autoit, I just want to cover all of the bases. Thanks!

L_2541.tmp.png

Edited by Chance1
added scrren shot
Link to comment
Share on other sites

  • Developers

Déjà vu ...  and see you are back to square one.  what happened?

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I was able to complete the script when the password was being passed in with the logon command like this:

StdinWrite($Pid, 'pacli logon PASSWORD = '& InputBox('PASSWORD', 'ENTER YOUR PASSWORD', '', '*') &@CRLF )

but now I have to do pretty much the same script except with two factor authentication instead of a password. A 2 factor cannot be passed in with the logon command, it can only notify pacli that the user will use 2 factor, it does so by saying "radius = yes". From there the cmd window then prompts the user for their "password" which is really just their 2 factor. The problem is that I cannot output the 2factor to the cmd window, nor can I tell when the cmd window is ready to receive (and has accepted) the 2 factor. I tried just sleeping for a couple seconds, then prompting the user to enter their 2 factor, then outputting their 2 factor to the cmd window; like so: 

Sleep(5000) 
$token=InputBox("RSA TOKEN", 'ENTER YOUR RSA TOKEN (HARDWRAE OR SOFTWWARE TOKENS)')
StdinWrite($Pid, $token & @CRLF)

And after the happens, the script seems to run but  it doesn't. I place message boxes along the way asking for output as well as output at the end (all from stdoutRead) and nothing shows, leading me to believe that the commands are not getting passed to the cmd using stdinwrite.

 

Any tips? At this point, I believe it is a pacli issue more than an autoit one. Thanks

Link to comment
Share on other sites

This is what I ended up doing before ... but it does not work with the two factor for some reason. With this, I only needed to see if an error was thrown, now I need to interact with what the cmd window is throwing back at the user

StdinWrite($Pid, 'pacli logon PASSWORD = '& InputBox('PASSWORD', 'ENTER YOUR PASSWORD', '', '*') &@CRLF )

;error check if user sucessfully loged on
Sleep(1500)
$data  &= StderrRead($Pid)
If StringInStr($data, "Authentication") Then

 

Link to comment
Share on other sites

So I got it some what working. I am able to output to the prompt by using this code

$winhandle=0
$process= $Pid

For $i = 1 to $Windowlist[0][0]
    If WinGetProcess($Windowlist[$i][1])= $process Then
        $winhandle=$Windowlist[$i][1]
    EndIf
Next

msgbox(0,"Window handle for "& $process, $winhandle)

ControlSend($winhandle,"","", $token & "{Enter}") 
;where $token is the user input password

And it registers in the output too. But When I continue one with the next command, it says that the user is not logged on. This is almost certain a pacli question, but I figured that it could be an autoit one to. The next line after the password is shown correctly in the output below, but and error is thrown saying that there is not a user logged in. To ouput the following commands, I am using StdinWrite, and you can see that I used ControlSend to send the password to the cmd. Could that also be the reason? I send the enter as well as to notify the cmd that that is the end of the password.  I have tried not doing that, putting in StdinWrite($Pid, @CRLF) after the control send command and nothing seems to work. Any thoughts guys? Thanks.

 

outputradius.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...