Steps on how to perform automate telnet commands with PowerShell WASP (Windows Automation Snapin for PowerShell)
- Install Chocolatey Package Manager by following my previous post
- Install the WASP Module
#Install wasp
choco install wasp -y
#Copy the following modules to Windows PowerShell Module Path
copy-item C:\ProgramData\chocolatey\lib\wasp -Recurse -Destination C:\Windows\system32\WindowsPowerShell\v1.0\Modules
copy-item C:\ProgramData\chocolatey\lib\autoload -Recurse -Destination C:\Windows\system32\WindowsPowerShell\v1.0\Modules
copy-item C:\ProgramData\chocolatey\lib\reflection -Recurse -Destination C:\Windows\system32\WindowsPowerShell\v1.0\Modules
#Import wasp module
Import-Module wasp
- Launch Command Prompt with Administrator Right and set the focus Windows to the CMD
#Start cmd
Start-Process -FilePath "cmd.exe" -Verb runas
Start-Sleep -Seconds 2
#Set Focused Windows
$window = Select-UIElement | ? Name -like "*cmd.exe"
- Prepare the commands that will be send to CMD automatically
#Send Command to telnet windows - Example based on Telnet to Email Server using SMTP Commands
$TelnetTo = "telnet mail.aventistech.info 25"
$Helo = "helo"
$MailFrom = "mail from:<[email protected]>"
$RcptTo = "rcpt to:<[email protected]>"
$Data = "data"
$Subject = "Subject:Email Testing"
$Commands = @($TelnetTo,$Helo,$MailFrom,$RcptTo,$Data,$Subject)
Foreach ($Command in $Commands) {
$window | Send-UIKeys $Command
#Send Enter
$window | Send-UIKeys "~"
#Delay of 1 Second
Start-Sleep -Seconds 1
}
#Send Email
$window | Send-UIKeys "~"
$window | Send-UIKeys "."
$window | Send-UIKeys "~"
#Exit SMTP telnet Session
$window | Send-UIKeys "quit"
$window | Send-UIKeys "~"
- Commands are executed with the output shown in CMD automatically