Skip to content

Instantly share code, notes, and snippets.

@vector-sec
Created August 5, 2016 05:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vector-sec/c4d43d7c710001503bef737c6daf67ff to your computer and use it in GitHub Desktop.
Save vector-sec/c4d43d7c710001503bef737c6daf67ff to your computer and use it in GitHub Desktop.
VBscript for making a GET request to Duo's Auth API
Function ToString(rabyt,datatype)
With CreateObject("MSXML2.DOMDocument")
.LoadXML "<root />"
.DocumentElement.DataType = datatype
.DocumentElement.nodeTypedValue = rabyt
ToString = Replace(.DocumentElement.text, vbLf, "")
End With
End Function
Function ToSHA1HMAC(sTextToHash, sSharedSecretKey)
Dim asc, enc, hex, bytes, TextToHash, SharedSecretKey
Set asc = CreateObject("System.Text.UTF8Encoding")
Set enc = CreateObject("System.Security.Cryptography.HMACSHA1")
TextToHash = asc.Getbytes_4(sTextToHash)
SharedSecretKey = asc.Getbytes_4(sSharedSecretKey)
enc.Key = SharedSecretKey
bytes = enc.ComputeHash_2((TextToHash))
hex = ToString(bytes,"bin.Hex")
hex = asc.Getbytes_4(hex)
base64 = ToString(hex,"bin.base64")
ToSHA1HMAC = base64
End Function
Function LPad(s, l, c)
Dim n : n = 0
If l > Len(s) Then n = l - Len(s)
LPad = String(n, c) & s
End Function
Function WebRequest(apihost,reqpath,method,date,auth,params)
set webclient = CreateObject("Microsoft.XMLHTTP")
webclient.open method,"https://" & apihost & reqpath,False
webclient.setRequestHeader "Date", "date"
Dim req, ikey
req = date & "\n" & method & "\n" & apihost & "\n" & reqpath & "\n" & params
auth = ToSHA1HMAC(req,"<SECRET_KEY>")
ikey = "<INTEGRATION_KEY>"
auth = "Basic " & ikey & ":" & auth
webclient.setRequestHeader "Authorization", auth
Dim resp
webclient.send
msgbox webclient.responseText
End Function
Dim d, month, day, dayname, year, hour, minute, second, dtStr
Set d = CreateObject("WbemScripting.SWbemDateTime")
d.SetVarDate (now())
d = d.GetVarDate(false)
month = Left(MonthName(DatePart("m",d)),3)
year = DatePart("yyyy",d)
day = LPad(DatePart("d",d),2,"0")
dayname = WeekdayName(DatePart("d",d),1,2)
hour = LPad(DatePart("h",d),2,"0")
minute = LPad(DatePart("n",d),2,"0")
second = LPad(DatePart("s",d),2,"0")
dtStr = dayname & ", " & day & " " & month & " " & year & " " & hour & ":" & minute & ":" & second & " GMT"
WebRequest "<API_HOST>","/auth/v2/ping","GET",dtStr,"",""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment