Option Explicit

Dim DSN
Dim datestamp
DSN = “yourdbname” ‘specify user-friendly name here, it will be modified by the line below.
DSN = “DSN=” & DSN & “;”
Dim objFSO
Dim objFolder
Dim objFiles
Dim File
Dim strFileName

datestamp = fctGetDate()

‘Wscript.Echo datestamp

Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objFolder = objFso.GetFolder(“E:\repository\it\datax\ovaldi_reports\” & datestamp & “\”)
Set objFiles = objFolder.Files

‘intRowPosition = 2 ‘Inventory data begins to be written to row 2 of each worksheet
For Each File in objFiles
strFileName = File.Name
‘Use the value of computer name for the first instance of each row of data.
‘strComputerName = Mid(strFileName,1,(Instr(strFileName,”.”)))

Next

ripSite(“file:////servername/datax\ovaldi_reports\” & datestamp & “\” & strFileName)

Function FormatDate( _
byVal strDate, _
byVal strFormat _
)

‘ Accepts strDate as a valid date/time,
‘ strFormat as the output template.
‘ The function finds each item in the
‘ template and replaces it with the
‘ relevant information extracted from strDate.
‘ You are free to use this code provided the following line remains
‘ www.adopenstatic.com/resources/code/formatdate.asp

‘ Template items
‘ %m Month as a decimal no. 2
‘ %M Month as a padded decimal no. 02
‘ %B Full month name February
‘ %b Abbreviated month name Feb
‘ %d Day of the month eg 23
‘ %D Padded day of the month eg 09
‘ %O Ordinal of day of month (eg st or rd or nd)
‘ %j Day of the year 54
‘ %Y Year with century 1998
‘ %y Year without century 98
‘ %w Weekday as integer (0 is Sunday)
‘ %a Abbreviated day name Fri
‘ %A Weekday Name Friday
‘ %H Hour in 24 hour format 24
‘ %h Hour in 12 hour format 12
‘ %N Minute as an integer 01
‘ %n Minute as optional if minute <> 00
‘ %S Second as an integer 55
‘ %P AM/PM Indicator PM

On Error Resume Next

Dim intPosItem
Dim int12HourPart
Dim str24HourPart
Dim strMinutePart
Dim strSecondPart
Dim strAMPM

‘ Insert Month Numbers
strFormat = Replace(strFormat, “%m”, DatePart(“m”, strDate), 1, -1, vbBinaryCompare)

‘ Insert Padded Month Numbers
strFormat = Replace(strFormat, “%M”, Right(“0” & DatePart(“m”, strDate), 2), 1, -1, vbBinaryCompare)

‘ Insert non-Abbreviated Month Names
strFormat = Replace(strFormat, “%B”, MonthName(DatePart(“m”, strDate), False), 1, -1, vbBinaryCompare)

‘ Insert Abbreviated Month Names
strFormat = Replace(strFormat, “%b”, MonthName(DatePart(“m”, strDate), True), 1, -1, vbBinaryCompare)

‘ Insert Day Of Month
strFormat = Replace(strFormat, “%d”, DatePart(“d”,strDate), 1, -1, vbBinaryCompare)

‘ Insert Padded Day Of Month
strFormat = Replace(strFormat, “%D”, Right (“0” & DatePart(“d”,strDate), 2), 1, -1, vbBinaryCompare)

‘ Insert Day of Month Ordinal (eg st, th, or rd)
strFormat = Replace(strFormat, “%O”, GetDayOrdinal(Day(strDate)), 1, -1, vbBinaryCompare)

‘ Insert Day of Year
strFormat = Replace(strFormat, “%j”, DatePart(“y”,strDate), 1, -1, vbBinaryCompare)

‘ Insert Long Year (4 digit)
strFormat = Replace(strFormat, “%Y”, DatePart(“yyyy”,strDate), 1, -1, vbBinaryCompare)

‘ Insert Short Year (2 digit)
strFormat = Replace(strFormat, “%y”, Right(DatePart(“yyyy”,strDate),2), 1, -1, vbBinaryCompare)

‘ Insert Weekday as Integer (eg 0 = Sunday)
strFormat = Replace(strFormat, “%w”, DatePart(“w”,strDate,1), 1, -1, vbBinaryCompare)

‘ Insert Abbreviated Weekday Name (eg Sun)
strFormat = Replace(strFormat, “%a”, WeekDayName(DatePart(“w”,strDate,1), True), 1, -1, vbBinaryCompare)

‘ Insert non-Abbreviated Weekday Name
strFormat = Replace(strFormat, “%A”, WeekDayName(DatePart(“w”,strDate,1), False), 1, -1, vbBinaryCompare)

‘ Insert Hour in 24hr format
str24HourPart = DatePart(“h”,strDate)
If Len(str24HourPart) < 2 then str24HourPart = “0” & str24HourPart
strFormat = Replace(strFormat, “%H”, str24HourPart, 1, -1, vbBinaryCompare)

‘ Insert Hour in 12hr format
int12HourPart = DatePart(“h”,strDate) Mod 12
If int12HourPart = 0 then int12HourPart = 12
strFormat = Replace(strFormat, “%h”, int12HourPart, 1, -1, vbBinaryCompare)

‘ Insert Minutes
strMinutePart = DatePart(“n”,strDate)
If Len(strMinutePart) < 2 then strMinutePart = “0” & strMinutePart
strFormat = Replace(strFormat, “%N”, strMinutePart, 1, -1, vbBinaryCompare)

‘ Insert Optional Minutes
If CInt(strMinutePart) = 0 then
strFormat = Replace(strFormat, “%n”, “”, 1, -1, vbBinaryCompare)
Else
If CInt(strMinutePart) < 10 then strMinutePart = “0” & strMinutePart
strMinutePart = “:” & strMinutePart
strFormat = Replace(strFormat, “%n”, strMinutePart, 1, -1, vbBinaryCompare)
End If

‘ Insert Seconds
strSecondPart = DatePart(“s”,strDate)
If Len(strSecondPart) < 2 then strSecondPart = “0” & strSecondPart
strFormat = Replace(strFormat, “%S”, strSecondPart, 1, -1, vbBinaryCompare)

‘ Insert AM/PM indicator
If DatePart(“h”,strDate) >= 12 then
strAMPM = “PM”
Else
strAMPM = “AM”
End If

strFormat = Replace(strFormat, “%P”, strAMPM, 1, -1, vbBinaryCompare)

FormatDate = strFormat

End Function

Function odbcexec(DSN,query)
Dim objConnection, objRecordSet, x
‘problems when running this from x64 edition
‘http://www.tino.nl/index.php/2008/03/13/32bit-stuff-on-64bit-windows-server-2003/
Set objConnection = CreateObject(“ADODB.Connection”)
Set objRecordset = CreateObject(“ADODB.Recordset”)
‘DSN = “DSN=” & DSN & “;”
on error resume Next
objConnection.Open DSN
if (Err.Number <> 0) then
wscript.echo vbCrLf & “!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!”
wscript.echo “ERROR!! Could not connect to the specified DSN”
wscript.echo “Error: ” & Err.Description & vbCrLf & “Error# ” & Err.Number
wscript.echo “!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!”
wscript.quit
end if
on error goto 0

‘objRecordset.CursorLocation = adUseClient
on error resume next
objRecordset.Open query, objConnection
if (Err.Number <> 0) then
wscript.echo vbCrLf & “!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!”
wscript.echo “ERROR!! The following query could not be executed: ” & query
wscript.echo vbCrLf & “Error: ” & Err.Description & vbCrLf & “Error# ” & Err.Number
wscript.echo “!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!”
end if
on error goto 0

for each x in objRecordset.fields
wscript.echo x.name & ” = ” & x.value
next

objConnection.Close

end function

Function GetDayOrdinal( _
byVal intDay _
)

‘ Accepts a day of the month
‘ as an integer and returns the
‘ appropriate suffix
On Error Resume Next

Dim strOrd

Select Case intDay
Case 1, 21, 31
strOrd = “st”
Case 2, 22
strOrd = “nd”
Case 3, 23
strOrd = “rd”
Case Else
strOrd = “th”
End Select

GetDayOrdinal = strOrd

End Function

Function fctGetDate()
Dim theday, themonthnum, themonth, theyear
fctGetDate = FormatDate(Date, “%Y%M%D”)
End Function

function ripSite(strURL)
‘on error resume next

‘these are basic values
Dim temp_string, intSearchResult, strSubject, strBody, quotes, strLicensed, strFacilityType, strAccreditation, strCapacity
Dim intStartLicensed, intEndLicensed, intStartFacilityType, intEndFacilityType, intStartAccreditation, intEndAccreditation
Dim intStartCapacity, intEndCapacity, intStartSearchAt, intStart, intEnd, strCollectionString, i, intLineStart, intLineEnd
Dim strLine, strLineArray, strCVE, strDescription, event_date, event_time, hostname, OS, OSver, architecture, if_name
Dim if_ip, if_mac, query
quotes = chr(34)
‘Dim EXPLANATION
temp_string = “string”

‘these are objects
Dim objXMLHTTP, xml

Set xml = CreateObject(“Microsoft.XMLHTTP”)
xml.Open “POST”, strURL, False
xml.Send

temp_string = xml.responseText
‘msgbox temp_string
‘wscript.quit

‘Find event_date
intStart = instr(temp_string,” Time

“)+153+27
intEnd = instr(intStart,temp_string,”

“)
event_date = Replace(Replace(mid(temp_string,intStart,intEnd-intStart),vbCrLf,” “),”,”,” “)
‘wscript.echo strCollectionString

‘find event_time
intStart = instr(intEnd,temp_string,” “)+17
intEnd = instr(intStart,temp_string,” “)
event_time = Replace(Replace(mid(temp_string,intStart,intEnd-intStart),vbCrLf,” “),”,”,” “)
‘wscript.echo strCollectionString
‘wscript.quit

‘find host name
intStart = instr(intEnd,temp_string,”Host Name”)+43
intEnd = instr(intStart,temp_string,” “)
hostname = Replace(Replace(mid(temp_string,intStart,intEnd-intStart),vbCrLf,” “),”,”,” “)
‘wscript.echo strCollectionString

‘find OS
intStart = instr(intEnd,temp_string,”Operating System”)+50
intEnd = instr(intStart,temp_string,” “)
OS = Replace(Replace(mid(temp_string,intStart,intEnd-intStart),vbCrLf,” “),”,”,” “)
‘wscript.echo strCollectionString

‘find OSver
intStart = instr(intEnd,temp_string,”Operating System Version”)+58
intEnd = instr(intStart,temp_string,” “)
OSver = Replace(Replace(mid(temp_string,intStart,intEnd-intStart),vbCrLf,” “),”,”,” “)
‘wscript.echo strCollectionString

‘find architecture
intStart = instr(intEnd,temp_string,”Architecture”)+46
intEnd = instr(intStart,temp_string,” “)
architecture = Replace(Replace(mid(temp_string,intStart,intEnd-intStart),vbCrLf,” “),”,”,” “)
‘wscript.echo strCollectionString

do
‘find if_name
intStart = instr(intEnd,temp_string,”Interface Name”)+48
intEnd = instr(intStart,temp_string,” “)
if_name = Replace(Replace(mid(temp_string,intStart,intEnd-intStart),vbCrLf,” “),”,”,” “)
‘wscript.echo strCollectionString

‘find if_ip
intStart = instr(intEnd,temp_string,”IP Address”)+44
intEnd = instr(intStart,temp_string,” “)
if_ip = Replace(Replace(mid(temp_string,intStart,intEnd-intStart),vbCrLf,” “),”,”,” “)
‘wscript.echo strCollectionString

‘find if_mac
intStart = instr(intEnd,temp_string,”MAC Address”)+45
intEnd = instr(intStart,temp_string,” “)
if_mac = Replace(Replace(mid(temp_string,intStart,intEnd-intStart),vbCrLf,” “),”,”,” “)
‘wscript.echo strCollectionString
‘wscript.quit
loop while (left(if_ip,1)=”0″)

‘delete records from the database that match this hostname, event_date, and event_time
query=”delete from oval_scans where event_date='”& event_date &”‘ and event_time='”& event_time &”‘ and hostname='”& hostname &”‘;”
odbcexec DSN,query

‘find “Reference ID” text as sarting point for vulns
intStart = instr(intEnd,temp_string,”Reference ID”)

do
‘loop the following section until an unknown, error, or false line is encountered

‘find the start of the next line to analyze
intLineStart = instr(intStart,temp_string,”

“)
‘wscript.echo “intLineEnd = ” & intLineEnd

strLine = mid(temp_string,intLineStart,intLineEnd-intLineStart)

‘split line so each column = an array element
strLineArray = split(strLine,”

‘remove

from array elements
for i=0 to ubound(strLineArray)
strLineArray(i) = Replace(strLineArray(i),” align=””center””>”,””)
strLineArray(i) = Replace(strLineArray(i),”

“,””)
strLineArray(i) = Replace(strLineArray(i),” “,””)
if (i=5) then strLineArray(i) = Replace(strLineArray(i),”>”,””)
‘wscript.echo strLineArray(i)
next
‘0 =
‘1 = OVAL ID
‘2 = Result
‘3 = Class
‘4 = Reference ID
‘5 = Title

‘is it true?
if (strLineArray(2)=”true”) then
‘is it a vuln?
if(strLineArray(3)=”vulnerability”) then
‘get the CVE
strCVE = strLineArray(4)

strCVE = mid(strCVE,instr(strCVE,”>”)+1,instrrev(strCVE,”<“)-(instr(strCVE,”>”)+1))
‘wscript.echo “CVE = ” & strCVE

‘get the description
strDescription = replace((replace(strLineArray(5),vbCrLf,””)),” “,””)
‘wscript.echo “strDescription = ” & strDescription & “bleh”

‘write it to the database!
query = “insert into oval_scans VALUES (‘” & event_date & “‘,'” & event_time & “‘,'” & hostname & “‘,'” & OS & “‘,'” & OSver & “‘,'” & architecture & “‘,'” & if_name & “‘,'” & if_ip & “‘,'” & if_mac & “‘,'” & strCVE & “‘,'” & strDescription & “‘);”
‘wscript.echo query
wscript.echo “Inserting ” & strCVE & ” for ” & hostname
odbcexec DSN,query
end if
end if

‘set the starting point of the next text search to the end of the current line
intStart = intLineEnd

loop while (strLineArray(2) = “true”)

Set xml = Nothing

end function