Jump to content

Send commands to Openssl


topten
 Share

Recommended Posts

Ah, great thanx. I am trying to interact with openssl

$SSL_Exe_loc  ="C:\OpenSSL-Win32\bin\"

Local $iPID = Run($SSL_Exe_loc & "openssl.exe s_client -connect pop.gmail.com:995", @SystemDir, @SW_SHOW, $STDIN_CHILD + $STDOUT_CHILD)

 Local $sOutput = "" ; Store the output of StdoutRead to a variable.

    While 1
        $sOutput &= StdoutRead($iPID) ; Read the Stdout stream of the PID returned by Run.

        if StringInStr ($sOutput, "OK") then
        ;
        StdinWrite ($iPID, "USER ASD")
        
        endif
        If @error Then ; Exit the loop if the process closes or StdoutRead returns an error.
            ExitLoop
        EndIf
    WEnd
ConsoleWrite ($sOutput)

I get the first stdout, "OK" then I am trying to send USER comand- but I get no response. It looks like Openssl doesnt receive Stdin?

Link to comment
Share on other sites

I've never used this command personally. When I see this question "how to interact with command prompt" people usually tell the op to look up those functions I gave you earlier. Unfortunately, I won't be able to help you further. I do hope someone else can answer your question.

 

Edit: Did you read the remarks carefully? Take a look at the examples. The reason why I said this is because when I looked at the documentation, in the example, it uses

StdinWrite($iPID, "Banana" & @CRLF & "Elephant" & @CRLF & "Apple" & @CRLF & "Deer" & @CRLF & "Car" & @CRLF)

Note the @crlf. It might not be working because you aren't pressing enter to submit the command. Like I said originally, I have never used this function and I'm only speculating.

Edited by BetaLeaf

 

 

Link to comment
Share on other sites

I too have a similar issue where I am trying to send a command to an established Plink.exe connection and I am experiencing the same problem as you are having Stdinwrite / Stdoutread.  I get the initial connection through stdout but the follow up command though stdin does not seem to get executed, have spent a couple of days on this trying various peeps examples etc without success.

I hope you get a solution soon.

 

 

Link to comment
Share on other sites

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>

Example1()
Example2()

Func Example1()
    Local $iPID = Run(@ComSpec & ' /C DIR ', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    Local $sOutput = ""
    While 1
        $sOutput = StdoutRead($iPID)
        If @error Then ; Exit the loop if the process closes or StdoutRead returns an error.
            ExitLoop
        EndIf
        if stringlen($sOutput)<>0 then
            ConsoleWrite($sOutput)
        endif
    WEnd
EndFunc   ;==>Example

func example2()
    $pid = Run(@comspec ,@SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD)
    StdinWrite($pid,"cd ")
    StdinWrite($pid,"C:\")
    StdinWrite($pid,@CRLF)

    Local $data
    Sleep(2000)
    $data &= StdoutRead($pid)

    ConsoleWrite("***** Output *****" & @CRLF & $data & @LF)

    StdinWrite($pid,"cd ")
    StdinWrite($pid,"C:\prog*")
    StdinWrite($pid,@CRLF)
    StdinWrite($pid)
    Sleep(2000)
    $data &= StdoutRead($pid)
    ConsoleWrite("***** Output *****" & @CRLF & $data & @LF)
endfunc

 

Link to comment
Share on other sites

  • 11 months later...

Hello,

I am trying to send data to the openssl but still like user @topten, I get sent only the first command "s_client -connect pop.gmail.com:995" but then if I send "user" or other command I received the output of my command.

This is the code that I trying:

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>

Example2()



func example2()
    $pid = Run("C:\OpenSSL\bin\openssl.exe" ,@SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD)
    StdinWrite($pid,"s_client ")
    StdinWrite($pid,"-connect ")
    StdinWrite($pid,"pop.gmail.com:995 ")
    StdinWrite($pid,@CRLF)

    Local $data
    Sleep(2000)
    $data &= StdoutRead($pid)

    ConsoleWrite("***** Output1 *****" & @CRLF & $data & @LF)

    StdinWrite($pid,"USER ")
    StdinWrite($pid,"xxxxxx")
    StdinWrite($pid,@CRLF)
    Sleep(2000)
    $data &= StdoutRead($pid)
    ConsoleWrite("***** Output2 *****" & @CRLF & $data & @LF)
endfunc

and this is the data that I received in console:

Loading 'screen' into random state -***** Output1 *****
OpenSSL> CONNECTED(00000160)
---
Certificate chain
 0 s:/C=US/ST=California/L=Mountain View/O=Google Inc/CN=pop.gmail.com
   i:/C=US/O=Google Inc/CN=Google Internet Authority G2
 1 s:/C=US/O=Google Inc/CN=Google Internet Authority G2
   i:/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA
 2 s:/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA
   i:/C=US/O=Equifax/OU=Equifax Secure Certificate Authority
---
Server certificate
-----BEGIN CERTIFICATE-----
MIIEfjCCA2agAwIBAgIIPuwJUUDwDUUwDQYJKoZIhvcNAQELBQAwSTELMAkGA1UE
BhMCVVMxEzARBgNVBAoTCkdvb2dsZSBJbmMxJTAjBgNVBAMTHEdvb2dsZSBJbnRl
cm5ldCBBdXRob3JpdHkgRzIwHhcNMTcwMTI1MTAxMTAxWhcNMTcwNDE5MTAwODAw
WjBnMQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwN
TW91bnRhaW4gVmlldzETMBEGA1UECgwKR29vZ2xlIEluYzEWMBQGA1UEAwwNcG9w
LmdtYWlsLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAM9m8OKv
O4EguafQbZZm7x1fBFkgG1TJCb29cGXwZHO8naSlICz1g+UTlUjLerrT5q9aGAVp
lx+Kie/PEFA0ADdazp23aaTUjgOd7DXNymvJlYdsmcnqB61hrFU3RS5M99qiQlz1
njrOeDagnHJmknYWFl6qbikK1y4WiU0qnMFj3c+wHzu+hwA9od05CiNPnXcXoa6C
htURJmlMl9a0/ySBouR4Yt9wu1/EgN0pE1y/1mUOdeBL7NT/Gb1uTEkIbnpunic7
QOr166XHa9LukckJ6WjR33UVD4JZk51Zo2lnYSDYNo8zJfP1CrsV/lpIPZ90ZLRH
Ztul3IGMyp8P4c0CAwEAAaOCAUowggFGMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggr
BgEFBQcDAjAYBgNVHREEETAPgg1wb3AuZ21haWwuY29tMGgGCCsGAQUFBwEBBFww
WjArBggrBgEFBQcwAoYfaHR0cDovL3BraS5nb29nbGUuY29tL0dJQUcyLmNydDAr
BggrBgEFBQcwAYYfaHR0cDovL2NsaWVudHMxLmdvb2dsZS5jb20vb2NzcDAdBgNV
HQ4EFgQU5FxQI9h1Gv+EWNnwWvjDz4FJ6XswDAYDVR0TAQH/BAIwADAfBgNVHSME
GDAWgBRK3QYWG7z2aLV29YG2u2IaulqBLzAhBgNVHSAEGjAYMAwGCisGAQQB1nkC
BQEwCAYGZ4EMAQICMDAGA1UdHwQpMCcwJaAjoCGGH2h0dHA6Ly9wa2kuZ29vZ2xl
LmNvbS9HSUFHMi5jcmwwDQYJKoZIhvcNAQELBQADggEBAD5ZnVeDrykZ2ZLcQgB2
6UXBSH5xxIoxiEXthLTlua9ZFZDxHqvCWoRA801S1YBd2u1aYIUVu6mBP/2tlFtK
NiUHrCzHax56T2dx+aWXrdkxtawfjq3TFJJve13tAFjOormXujquSPZNg8E2XDM+
ddKjSYEBJJxlCNqZZ8/k5IZ6+ufhgG60LmbylUESDNHLDlQDcaVwO6VyR39SiDQO
8o8igSz2lKNL9yuzPZrZmQUuciafeoieA3bXcRugXdicCOqvw8MbHeFMAycN2lcJ
xj/QUajuXQh4HVy0hR8elnkkTxyhKRWFWvbpYeUdJ9Czj0DykzLdPOpT1E0yqWtg
K+4=
-----END CERTIFICATE-----
subject=/C=US/ST=California/L=Mountain View/O=Google Inc/CN=pop.gmail.com
issuer=/C=US/O=Google Inc/CN=Google Internet Authority G2
---
No client certificate CA names sent
---
SSL handshake has read 3231 bytes and written 450 bytes
---
New, TLSv1/SSLv3, Cipher is AES128-SHA
Server public key is 2048 bit
Compression: NONE
Expansion: NONE
SSL-Session:
    Protocol  : TLSv1
    Cipher    : AES128-SHA
    Session-ID: 63E849E975FDDF8C1B7A73584B2AC8C25AA9B36FF0B9797B57EF2C6AAC06BA7E
    Session-ID-ctx: 
    Master-Key: EED3707F16E2DCCE4102AE7AAE98115D7B11C512721AA892454D18CF9A916F5060342174BDB569179B1CEA9FB901415A
    Key-Arg   : None
    Start Time: 1486249400
    Timeout   : 300 (sec)
    Verify return code: 20 (unable to get local issuer certificate)
---
+OK Gpop ready for requests from 5.15.96.225 d1mb46299998wrb

***** Output2 *****
OpenSSL> CONNECTED(00000160)
---
Certificate chain
 0 s:/C=US/ST=California/L=Mountain View/O=Google Inc/CN=pop.gmail.com
   i:/C=US/O=Google Inc/CN=Google Internet Authority G2
 1 s:/C=US/O=Google Inc/CN=Google Internet Authority G2
   i:/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA
 2 s:/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA
   i:/C=US/O=Equifax/OU=Equifax Secure Certificate Authority
---
Server certificate
-----BEGIN CERTIFICATE-----
MIIEfjCCA2agAwIBAgIIPuwJUUDwDUUwDQYJKoZIhvcNAQELBQAwSTELMAkGA1UE
BhMCVVMxEzARBgNVBAoTCkdvb2dsZSBJbmMxJTAjBgNVBAMTHEdvb2dsZSBJbnRl
cm5ldCBBdXRob3JpdHkgRzIwHhcNMTcwMTI1MTAxMTAxWhcNMTcwNDE5MTAwODAw
WjBnMQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwN
TW91bnRhaW4gVmlldzETMBEGA1UECgwKR29vZ2xlIEluYzEWMBQGA1UEAwwNcG9w
LmdtYWlsLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAM9m8OKv
O4EguafQbZZm7x1fBFkgG1TJCb29cGXwZHO8naSlICz1g+UTlUjLerrT5q9aGAVp
lx+Kie/PEFA0ADdazp23aaTUjgOd7DXNymvJlYdsmcnqB61hrFU3RS5M99qiQlz1
njrOeDagnHJmknYWFl6qbikK1y4WiU0qnMFj3c+wHzu+hwA9od05CiNPnXcXoa6C
htURJmlMl9a0/ySBouR4Yt9wu1/EgN0pE1y/1mUOdeBL7NT/Gb1uTEkIbnpunic7
QOr166XHa9LukckJ6WjR33UVD4JZk51Zo2lnYSDYNo8zJfP1CrsV/lpIPZ90ZLRH
Ztul3IGMyp8P4c0CAwEAAaOCAUowggFGMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggr
BgEFBQcDAjAYBgNVHREEETAPgg1wb3AuZ21haWwuY29tMGgGCCsGAQUFBwEBBFww
WjArBggrBgEFBQcwAoYfaHR0cDovL3BraS5nb29nbGUuY29tL0dJQUcyLmNydDAr
BggrBgEFBQcwAYYfaHR0cDovL2NsaWVudHMxLmdvb2dsZS5jb20vb2NzcDAdBgNV
HQ4EFgQU5FxQI9h1Gv+EWNnwWvjDz4FJ6XswDAYDVR0TAQH/BAIwADAfBgNVHSME
GDAWgBRK3QYWG7z2aLV29YG2u2IaulqBLzAhBgNVHSAEGjAYMAwGCisGAQQB1nkC
BQEwCAYGZ4EMAQICMDAGA1UdHwQpMCcwJaAjoCGGH2h0dHA6Ly9wa2kuZ29vZ2xl
LmNvbS9HSUFHMi5jcmwwDQYJKoZIhvcNAQELBQADggEBAD5ZnVeDrykZ2ZLcQgB2
6UXBSH5xxIoxiEXthLTlua9ZFZDxHqvCWoRA801S1YBd2u1aYIUVu6mBP/2tlFtK
NiUHrCzHax56T2dx+aWXrdkxtawfjq3TFJJve13tAFjOormXujquSPZNg8E2XDM+
ddKjSYEBJJxlCNqZZ8/k5IZ6+ufhgG60LmbylUESDNHLDlQDcaVwO6VyR39SiDQO
8o8igSz2lKNL9yuzPZrZmQUuciafeoieA3bXcRugXdicCOqvw8MbHeFMAycN2lcJ
xj/QUajuXQh4HVy0hR8elnkkTxyhKRWFWvbpYeUdJ9Czj0DykzLdPOpT1E0yqWtg
K+4=
-----END CERTIFICATE-----
subject=/C=US/ST=California/L=Mountain View/O=Google Inc/CN=pop.gmail.com
issuer=/C=US/O=Google Inc/CN=Google Internet Authority G2
---
No client certificate CA names sent
---
SSL handshake has read 3231 bytes and written 450 bytes
---
New, TLSv1/SSLv3, Cipher is AES128-SHA
Server public key is 2048 bit
Compression: NONE
Expansion: NONE
SSL-Session:
    Protocol  : TLSv1
    Cipher    : AES128-SHA
    Session-ID: 63E849E975FDDF8C1B7A73584B2AC8C25AA9B36FF0B9797B57EF2C6AAC06BA7E
    Session-ID-ctx: 
    Master-Key: EED3707F16E2DCCE4102AE7AAE98115D7B11C512721AA892454D18CF9A916F5060342174BDB569179B1CEA9FB901415A
    Key-Arg   : None
    Start Time: 1486249400
    Timeout   : 300 (sec)
    Verify return code: 20 (unable to get local issuer certificate)
---
+OK Gpop ready for requests from 5.15.96.225 d1mb46299998wrb

>Exit code: 0    Time: 4.406

 

I also tried:

$pid = Run("C:\OpenSSL\bin\openssl.exe" ,@SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD)
    StdinWrite($pid,"s_client ")
    StdinWrite($pid,"-connect ")
    StdinWrite($pid,"pop.gmail.com:995 " & @CRLF)

    Local $data
    Sleep(2000)
    $data &= StdoutRead($pid)

    ConsoleWrite("***** Output1 *****" & @CRLF & $data & @LF)

    StdinWrite($pid,"USER ")
    StdinWrite($pid,"ronysb92" & @CRLF )

    Sleep(2000)
    $data &= StdoutRead($pid)
    ConsoleWrite("***** Output2 *****" & @CRLF & $data & @LF)

 

because I saw:

    ; Calling StdinWrite without a second parameter closes the stream.
    StdinWrite($iPID)

but still no succes in sending second command

 

 

Want I can do to be able to send more command and to receive them?

Edited by rony2006
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...