Script works as WSH, but in a HTA Sub it goes berzerker - hta

I'm trying to build some Subs inside an HTA that run the following code. The script works fine as standalone WSH script, but when I put the code in a sub in my HTA it goes BERZERK. My command window appears a bunch of times, I think it is launching a new process for each WshShell.Sendkeys. I have tried numerous things, but am obviously missing something. Even when I have the HTA call the script externally I get the same wacky behavior, but I can run this in a wsh script and it works fine...
Please help!!
set WshShell=CreateObject("WScript.Shell")
WshShell.run "cmd.exe"
WScript.Sleep 500
WshShell.SendKeys "telnet 130.160.176.219 4998"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 5000
WshShell.SendKeys "sendir,1:1,1,37764,1,1,340,168,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,22,21,64,21,22,21,64,21,22,21,22,21,22,21,22,21,64,21,22,21,64,21,22,21,64,21,64,21,64,21,64,21,4833"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys "sendir,1:1,10,37764,1,1,340,168,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,22,21,22,21,22,21,22,21,64,21,22,21,22,21,22,21,64,21,64,21,64,21,64,21,22,21,64,21,4833"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys "sendir,1:1,5,37764,1,1,340,168,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,22,21,64,21,22,21,22,21,22,21,22,21,22,21,22,21,64,21,22,21,64,21,64,21,64,21,64,21,64,21,4833"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys "sendir,1:1,11,37764,1,1,340,168,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,22,21,64,21,64,21,64,21,64,21,22,21,64,21,22,21,64,21,22,21,22,21,22,21,22,21,64,21,22,21,64,21,4833"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys "sendir,1:1,1,37764,1,1,340,168,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,22,21,64,21,22,21,64,21,22,21,22,21,22,21,22,21,64,21,22,21,64,21,22,21,64,21,64,21,64,21,64,21,4833"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys ("^{]}q{Enter}exit{Enter}")
//WScript.Quit

Related

How to write a fake local server with Terminal

I'm making network requests with my mobile app. I would like to simulate a server for error handling because the server I will eventually make requests to is not up yet
I don't want to spend a lot of time coding my own server
I want to make a request to a server, and have the server respond with..
a 400 response
a 200 response
no response
Terminal commands for each test
everywhere that says 11.11.11.11 you should enter your IP Address instead
400 response test
while true; do echo -e "HTTP/1.1 400 Bad Request\n\n $(date)" | nc -l 11.11.11.11 1500; sleep 3; done
when the test is complete, hit control + c in the terminal until the process stops
200 response test
while true; do echo -e "HTTP/1.1 200 OK\n\n $(date)" | nc -l 11.11.11.11 1500; sleep 3; done
when the test is complete, hit control + c in the terminal until the process stops
No response test
nc -l 11.11.11.11 1500
when the test is complete, hit control + c in the terminal until the process stops

Errorcode 800a0bb9

I'm reviving an old ASP Classic app for a client. The database is up and running, but it seems the app is having trouble connecting to it.
There is no readme or database configuration file. I searched the codebase for any Server.CreateObject("ADODB.Connection") statements but couldn't find any.
I also searched for some kind of initialization of the cnnDB variable which seems to hold the ADODB connection, but to no avail.
Adovbs.inc is included in Default.asp line 10:
10 <!--#include file="includes/adovbs.inc" -->
11 <!--#include file="includes/pageinit.asp" -->
Log file:
#Software: Microsoft Internet Information Services 7.5
#Version: 1.0
#Date: 2015-09-03 14:55:57
#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) sc-status sc-substatus sc-win32-status time-taken
2015-09-03 14:55:57 ::1 GET / |41|800a0bb9|Arguments_are_of_the_wrong_type__are_out_of_acceptable_range__or_are_in_conflict_with_one_another. 80 - ::1 Mozilla/5.0+(Windows+NT+6.1;+WOW64;+Trident/7.0;+rv:11.0)+like+Gecko 500 0 0 46
Errorcode 800a0bb9 at line 41 in Default.asp
Default.asp:
38 Dim rsAccount_configuration,strSQLaccount_configuration
39 Set rsAccount_configuration = Server.CreateObject("ADODB.RecordSet")
40 strSQLaccount_configuration="select * from account_configuration where username='" & session("username") & "'"
41 rsAccount_configuration.Open strSQLaccount_configuration, cnnDB, adOpenStatic, adLockReadOnly
Thanks a bunch guys. The solution was to add the following to pageinit.asp
set cnnDB=Server.CreateObject("ADODB.Connection")
cnnDB.Open "DRIVER={SQL Server};SERVER=myserver;Trusted_Connection=Yes;DATABASE=mydb"
#Shadow Wizard, cnnDB was indeed Empty

Invoke-RestMethod : The operation has timed out

I have a script that deletes resources and creates new ones. Every now and then it times out and I can't figure out why. It seems to happen when I run the script multiple times, but I couldn't get a definite pattern. I found that my server hasn't picked up the message yet since there's no logging for the request yet.
$old_values = Invoke-RestMethod -Uri $uri -Method Get
foreach($old_value in $old_values.result) {
Invoke-RestMethod -Uri "$uri&key=$old_value.id" -Method Delete
}
$new_value = Invoke-RestMethod -Uri "$uri" -Body "{}" -ContentType application/json -Method Post
Interesting note, I get occasional timeouts when I run the Invoke-RestMethod calls directly from powershell. I also ran them with Fiddler and never got timeouts.
[Edit] I've been checking the connections with netstat. While the commands are hanging, they're listed as ESTABLISHED. But I keep seeing TIME_WAIT connections listed to my server. Is there a chance my connections aren't getting closed?
The link David Brabant posted above contains this workaround that solved the problem for me:
$r = (Invoke-WebRequest -Uri $uri `
-Method 'POST' `
-ContentType 'application/json' `
-Body '{}' `
).Content | ConvertFrom-Json
Sorry to bring up old topic. We are using Win 7 now and PowerShell version 3.0
We encountered the same problem with POST method. When we POST the same JSON the 3rd time, powershell window will hang. After close and reopen it will work.
To get around it, simple add 2 lines at the end of POST:
$ServicePoint = [System.Net.ServicePointManager]::FindServicePoint('<URL>')
$ServicePoint.CloseConnectionGroup("")
refer:
https://social.technet.microsoft.com/wiki/contents/articles/29863.powershell-rest-api-invoke-restmethod-gotcha.aspx
I found Allanrbo's answer to still timeout after 3 or 4 runs.
I did the following instead:
powershell "(Invoke-RestMethod -Method 'Delete' -Uri '$uri').Content"

Command line command to open http sessions to a service

I want to know if it is possible to open http sessions to a service through command line or batch file.
What i want to achieve is check if a particular service is allowing more than x active connections .
Note: I cannot install any utility on my production machine.
Regards,
Prayag
Uhm... you can try to write a VBS file connecting to your webserver by telnet and requesting the root page.
Create a .vbs file and put this content. Then execute it from the prompt.
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd"
WScript.Sleep 100
WshShell.SendKeys "telnet www.yahoo.com 80~" 'subst www.yahoo.com with your host
WScript.Sleep 5000
WshShell.SendKeys "GET / HTTP/1.0~~"
WScript.Sleep 2000
WshShell.SendKeys "^C~" 'close telnet
WScript.Sleep 1000
WshShell.SendKeys "exit~" 'close prompt

how to post a http request from command line

Hi
I need to post a request to aspx page within dos command line.. How can I do that ?
telnet on port 80
For example:
telnet www.your-server.com/pageToTest.aspx 80
then type GET
All of these answers require installing a windows feature or other program. Powershell is installed by default and can be run from the command line
powershell -command "Invoke-WebRequest -Uri %url% -Method POST"
Create a .vbs file containing:
' Set your settings
strFileURL = "http://localhost/index.aspx"
strHDLocation = "stream.temp"
' Fetch the file
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
objXMLHTTP.open "GET", strFileURL, false
objXMLHTTP.send()
If objXMLHTTP.Status = 200 Then
Set objADOStream = CreateObject("ADODB.Stream")
objADOStream.Open
objADOStream.Type = 1 'adTypeBinary
objADOStream.Write objXMLHTTP.ResponseBody
objADOStream.Position = 0 'Set the stream position to the start
Set objFSO = Createobject("Scripting.FileSystemObject")
If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
objADOStream.SaveToFile strHDLocation
objADOStream.Close
Set objADOStream = Nothing
End if
Set objXMLHTTP = Nothing
' Delete the temp file
objFSO.DeleteFile strHDLocation
Set objFSO = Nothing
Then execute using:
cscript.exe scriptname.vbs
This can be done using wget.
I've had some good luck with cURL http://curl.haxx.se/ to replicate sending JSON to a webservice. Perhaps this might help you too.
This works on Windows 10
powershell -command "Invoke-WebRequest -UseBasicParsing -Method POST -Uri http://example.com/login -Body username=exampleuser'&'password=test"
More info here https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7.2
Telnet is really for connecting to a remote telnet server. In fact it (telnet server) is not present in Windows 10, only the client.
You better use PowerShell. Here is an example accessing ODATA service:
http://hodentekhelp.blogspot.com/2014/11/can-you-access-odata-with-powershell.html
Also review this thread:
https://social.technet.microsoft.com/Forums/en-US/035062dd-5052-4abe-bd9a-8714f4184806/there-is-no-telnet-server-in-windows-10-what-is-the-purpose-of-telnet-client?forum=win10itprogeneral
Another way is to use wget which is a common command line tool (v useful for downloading). On windows you can get it from here http://gnuwin32.sourceforge.net/packages/wget.htm and its already part of most Linux distros. To use simply do the following;-
wget google.com
and that will return the following
--2018-03-20 16:31:39-- http://google.com/
Resolving google.com... 216.58.204.14
Connecting to google.com|216.58.204.14|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://www.google.co.uk/?gfe_rd=cr&dcr=0&ei=dzexWqybGof38Afo3ZmACg [following]
--2018-03-20 16:31:39-- http://www.google.co.uk/?gfe_rd=cr&dcr=0&ei=dzexWqybGof38Afo3ZmACg
Resolving www.google.co.uk... 216.58.201.3
Connecting to www.google.co.uk|216.58.201.3|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `index.html#gfe_rd=cr&dcr=0&ei=dzexWqybGof38Afo3ZmACg'
[ <=> ] 12,441 --.-K/s in 0s
2018-03-20 16:31:40 (88.3 MB/s) - `index.html#gfe_rd=cr&dcr=0&ei=dzexWqybGof38Afo3ZmACg' saved [12441]

Resources