VBs to log (.txt) telnet output - vbscript

A very simple script to save time for something i (repeatedly) need to check # work;
Set cloner = CreateObject("WScript.Shell")
cloner.SendKeys"telnet 0.0.0.0"
cloner.SendKeys("{Enter}")
WScript.Sleep 1000
cloner.SendKeys("whatever")
And, i'd like this to output to a .txt.

try this one
Set cloner = CreateObject("WScript.Shell")
cloner.Run "cmd.exe"
WScript.Sleep 1000
cloner.SendKeys"telnet 0.0.0.0 -f out.txt"
cloner.SendKeys("{Enter}")
WScript.Sleep 1000
cloner.SendKeys("whatever")

The code just producing a blank txt; no string in it.

Try:
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.run("telnet.exe")
WScript.Sleep 500
WshShell.SendKeys("set logfile filename.txt{Enter}")
WScript.Sleep 500
WshShell.SendKeys("open 0.0.0.0{Enter}")
WScript.Sleep 500
WshShell.SendKeys("whatever")
this will create a file named filename in the working directory, can be replaced with absolute path aswell.

Related

Piping text into netcat using WScript.Exec

I'm playing a CTF and looking to pipe some content into netcat in order to illicit a response from an application listening on a port.
Here's what I'm trying to do:
Dim oShell : Set oShell = CreateObject("WScript.Shell")
oShell.Run "C:\\users\\me\\Desktop\\my_app.exe"
WScript.Sleep 1000
oShell.Exec "echo hello > C:\\users\\me\\Desktop\\netcat\\nc.exe 127.0.0.1 4444"
What I get is an error
WshShell.Exec: The system cannot find the file specified.
Which I presume is about the echo command as removing it works fine. What am I doing wrong?
#m0atz as #omegastripes mentioned, you need to use StdIn. The following demonstrates how:
Dim wshShell, oExec, buffer
Set wshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("C:\\users\\me\\Desktop\\netcat\\nc.exe 127.0.0.1 4444")
oExec.StdIn.Write "hello" & vbCrLf
buffer = ""
While Not oExec.StdOut.AtEndOfStream
buffer = buffer & oExec.StdOut.Read(1)
Wend
WScript.Echo buffer

Insert a user variable to wshshell for a Telnet script

I am trying to find how to make the Telnet IP address a variable that the user supplies. The script works fine as it is but there many host addresses that I have to run this script on. As it is I have to edit the file with the new IP address each time I use it. The full script has many Sendkeys entries that I have removed.
job>
script language="VBScript">
Option Explicit
On Error Resume Next
Dim WshShell
set WshShell=CreateObject("WScript.Shell")
WshShell.run "cmd.exe"
WScript.Sleep 1000
WshShell.SendKeys "telnet 160.221.230.127"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys "user XXX XXX"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys "cci resetapb cancel"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WScript.Quit
</script>
</job>
You can prompt for input using InputBox
dim res: res = InputBox("enter ip address", "?", "192.168.1.1")
msgbox res
Parameters are:
prompt
dialog title
default
Use this example
Set WshShell = CreateObject("WScript.Shell")
ServerIP = InputBox ("Enter IP")
WshShell.Run ("telnet " & ServerIP)
WScript.Sleep(500)
WshShell.SendKeys("login~")
WScript.Sleep 100
WshShell.SendKeys("password~")
WScript.Sleep 100

vbs log out with delay

I want to log out my computer with delay in a vbscript. Here is what i've tried so far:
Dim ObjShell
Set ObjShell = CreateObject("WScript.Shell")
ObjShell = msgbox("Wollen Sie den Computer herunterfahren ?", +vbYesNo+vbExclamation, "")
If ObjShell = 6 then
Set ShellObject = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}").ExecQuery("select * from Win32_OperatingSystem where Primary=true")
For Each sys In ShellObject
Sys.Win32Shutdown 0
Next
End if
I do want to know how i can create a delay.
You can use WScript.Exec "shutdown.exe -L -F -t 30" to let the waiting be done by shutdown or use Wscript.Sleep 30000 to initiate a wait before the next statement is executed.
Both times are 30 seconds in this example.

Waiting till the particular message is displayed on console

Here is my VBS code
Set wshshell = wscript.CreateObject("WScript.Shell")
Wshshell.run "C:\Temp\Executable.exe -c -dir C:\Productdir"
'Wait till "This will install the product on your computer. Press OK, Cancel" appears
WScript.Sleep 10000
WshShell.SendKeys "~"
Is it possible "rather than hard-coded sleep of 10 secs" to add something like this for e.g. if consolemessage="This will install the product on your computer. Press OK, Cancel" then WshShell.SendKeys "~"?
Can WScript.StdOut be used to capture the console messages in the above case? I was not able to do it.
You can read StdOut of a process when you execute the program using the Exec method.
Set wshshell = wscript.CreateObject("WScript.Shell")
Set p = Wshshell.Exec("C:\Temp\Executable.exe -c -dir C:\Productdir")
Do While p.Status = 0
output = ""
Do Until p.StdOut.AtEndOfStream
c = p.StdOut.Read(1)
WScript.StdOut.Write c 'write read characters to the command prompt
output = output & c
If InStr(output, "This will install the product") > 0 Then
'do stuff
Exit Do
End If
Loop
WScript.Sleep 100
Loop

how do i input a parameter explicitly from outside to the program in vbscript?

i have written a program which calculates the HASH of all files of a folder and saves it an an xml file. now my objective is that i want to give the folder to be evaluated, explicitly from outside the program
Dim WshShell, oExec, input
Set WshShell = CreateObject("WScript.Shell")
Set oExec =_
WshShell.exec("C:\Users\Administrator\Downloads\fciv.exe -md5 -r -xml _
d.xml C:\openssl")
input = ""
Do While oexec.status=0
WScript.Sleep 5000
Loop
this is the program. i tried adding inputbox command thinking i would be able to give the input explicitly. here is the modified program
Dim WshShell, oExec, strin
Set WshShell = CreateObject("WScript.Shell")
strin= inputbox("folder")
Set oExec =_
WshShell.exec("C:\Users\Administrator\Downloads\fciv.exe -md5 -r -xml ex.xml strin")
input = ""
Do While oexec.status=0*
WScript.Sleep 1000
Loop
this is not working :( pls help. what exactly shud i be using thr? also how do i give the same input using a cmd file???
You just need to use the string concatenation operator & to build the command string:
Dim WshShell, oExec, strin
Set WshShell = CreateObject("WScript.Shell")
strin= inputbox("folder")
Set oExec =_
WshShell.exec("C:\Users\Administrator\Downloads\fciv.exe -md5 -r -xml ex.xml """ & strin & """")
input = ""
Do While oexec.status=0
WScript.Sleep 1000
Loop
I took the liberty of adding the appropriate double-quotes in case the input path has spaces. You might want to also add in some validation of the path, eg:
dim fso: set fso = CreateObject("Scripting.FileSystemObject")
if not fso.FolderExists(strin) then
WScript.Echo strin & " not found"
WScript.Quit 1
end if

Resources