Sign in to follow this  
Followers 0
RichE

I'm stuck with problem network auditor

3 posts in this topic

I wrote a network auditor autoit app recently, but a friend who requires to do custom reports ask if I could help, so here's where the problem lies, I've split the process into two seperate autoit exe's, the main console, and a sub process, I can pass the required info from the main to the sub, and I know the info is getting there but in an effort to eventually allow for custom WMI queries the sub script doesn't seem to like the info to run the WMI queries and was wondering if anyone could help me.

each sub process creates a .tmp file (of the ip address without the dots) which it can dump the output from the WMI Queries (onto line 1), once completed it writes (audit finished) onto line 2, the main .exe waits until it sees either "Audit Finished" or "Audit Incomplete" and takes the relevant action.

main .exe (Oracle.exe)

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=search v2.ico
#AutoIt3Wrapper_Outfile=Oracle.exe
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_Comment=Oracle Network Auditor
#AutoIt3Wrapper_Res_Description=Oracle Network Auditor
#AutoIt3Wrapper_Res_Fileversion=1.0.0.29
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#AutoIt3Wrapper_Res_LegalCopyright=Richard Easton 2011
#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.6.1
 Author:         Richard Easton for MSCI

 Script Function:
    Oracle with custom audit options.
    written for Robert France as a favour
    so his sec team can produce reports as required.

#ce ----------------------------------------------------------------------------


;includes (do not delete these).
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
;required by listview
#include <ListViewConstants.au3>
#include <GuiListView.au3>
#include <StaticConstants.au3>
;Required by Tabs
#include <TabConstants.au3>
#include <WindowsConstants.au3>
;required by Encryption controls
#include <Crypt.au3>
;required to export the listviews
#include <_GUICtrlListView_CreateArray.au3>
#include <_GUICtrlListView_SaveCSV.au3>
;required by date function
#include <Date.au3>
;used by gui to set tab focus
#include <GuiTab.au3>

if @OSVersion = "WIN7" Then
    #RequireAdmin
EndIf

$credsini = @ScriptDir & "\Creds.ini"

Global $g_eventerror = 0

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")
;gui section (creates the GUI centered on the desktop)
$oracle = GUICreate("Oracle", 882, 665, -1, -1, BitOR($WS_SYSMENU,$WS_DLGFRAME,$WS_CLIPSIBLINGS), $WS_EX_TOOLWINDOW)
GUISetIcon(@scriptdir & "\Search v2.ico")
TraySetIcon(@ScriptDir & "\Search v2.ico")
;main tab container.
$Tabz = GUICtrlCreateTab(7, 5, 870, 638)
GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)



;settings tab
;######################################################
;# in this section you will be able to select which   #
;# audit options you require to gather, each hardware #
;# is in it's own group to make it easier to define   #
;# the variables for use in the app.                  #
;######################################################
$settings = GUICtrlCreateTabItem("Settings")
$credsgroup = GUICtrlCreateGroup(" Credentials ", 680, 31, 185, 225)
GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
GUICtrlCreateLabel("Username", 688, 56, 48, 17)
$user = GUICtrlCreateInput(@username, 688, 80, 169, 21)
GUICtrlCreateLabel("Password", 688, 112, 45, 17)
$pass = GUICtrlCreateInput("", 688, 136, 169, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL))
GUICtrlCreateLabel("Domain", 688, 168, 37, 17)
$domain = GUICtrlCreateInput("", 688, 192, 169, 21)
$savedetails = GUICtrlCreateButton("Save Details", 688, 224, 75, 25, $WS_GROUP)
GUICtrlSetBkColor(-1, 0xC0DCC0)
$resetdetails = GUICtrlCreateButton("Reset", 784, 224, 75, 25, $WS_GROUP)
GUICtrlSetBkColor(-1, 0x0066CC)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$auditsettings = GUICtrlCreateGroup(" Audit Settings", 16, 32, 657, 601)
GUICtrlSetFont(-1, 8, 400, 0, "Verdana")

;workstation options
$WS = GUICtrlCreateGroup(" Workstation ", 24, 56, 161, 129)
$WSName = GUICtrlCreateCheckbox("Workstation Name", 32, 80, 145, 17)
$WSVendor = GUICtrlCreateCheckbox("Workstation Vendor", 32, 104, 145, 17)
$WSModel = GUICtrlCreateCheckbox("Workstation Model", 32, 128, 145, 17)
$WSSerial = GUICtrlCreateCheckbox("Workstation Serial Number", 32, 152, 145, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)




;network interface card
$nic = GUICtrlCreateGroup(" Networking ", 24, 192, 161, 153)
$NICIP = GUICtrlCreateCheckbox("IP Address", 32, 240, 97, 17)
$NICVendor = GUICtrlCreateCheckbox("NIC Vendor", 32, 264, 97, 17)
$NICModel = GUICtrlCreateCheckbox("NIC Model", 32, 288, 97, 17)
$NICDriver = GUICtrlCreateCheckbox("NIC Driver", 32, 312, 97, 17)
$MACAddress = GUICtrlCreateCheckbox("MAC Address", 32, 216, 97, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)



;memory
$MEM = GUICtrlCreateGroup(" Memory ", 24, 352, 161, 81)
$MemVendor = GUICtrlCreateCheckbox("Memory Vendor", 32, 376, 97, 17)
$MemPhysical = GUICtrlCreateCheckbox("Memory (Physcial)", 32, 400, 145, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)


;Primary Hard Drive
$HDD = GUICtrlCreateGroup(" Primary Hard Drive ", 24, 440, 161, 129)
$HDDVendor = GUICtrlCreateCheckbox("HDD vendor", 32, 464, 97, 17)
$HDDModel = GUICtrlCreateCheckbox("HDD Model", 32, 488, 97, 17)
$HDDSize = GUICtrlCreateCheckbox("HDD Size", 32, 512, 97, 17)
$HDDSerial = GUICtrlCreateCheckbox("HDD Serial", 32, 536, 97, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)



;Grpahics options
$GC = GUICtrlCreateGroup(" Graphics", 192, 56, 161, 105)
$GCVendor = GUICtrlCreateCheckbox("GC Vendor", 200, 80, 97, 17)
$GCModel = GUICtrlCreateCheckbox("GC Model", 200, 104, 97, 17)
$GCDriver = GUICtrlCreateCheckbox("GC Driver", 200, 128, 97, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)


;Audio options
$SC = GUICtrlCreateGroup(" Audio ", 192, 176, 161, 81)
$SCVendor = GUICtrlCreateCheckbox("SC Vendor", 200, 200, 97, 17)
$SCModel = GUICtrlCreateCheckbox("SC Model", 200, 224, 97, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)


;Mobo options
$MB = GUICtrlCreateGroup(" Mainboard ", 192, 264, 161, 169)
$MBVendor = GUICtrlCreateCheckbox("MB Vendor", 200, 288, 97, 17)
$MBModel = GUICtrlCreateCheckbox("MB Model", 200, 312, 97, 17)
$MBBIOSVer = GUICtrlCreateCheckbox("MB BIOS Version", 200, 336, 113, 17)
$MBBIOSDate = GUICtrlCreateCheckbox("MB BIOS Date", 200, 360, 97, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)


;cpu options
$CPU = GUICtrlCreateGroup(" Processor ", 192, 440, 161, 129)
$CPUVendor = GUICtrlCreateCheckbox("CPU Vendor", 200, 464, 97, 17)
$CPUModel = GUICtrlCreateCheckbox("CPU Model", 200, 488, 97, 17)
$CPUSpeed = GUICtrlCreateCheckbox("CPU Speed", 200, 512, 97, 17)
$CPUCores = GUICtrlCreateCheckbox("CPU Cores", 200, 536, 97, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)

;operating system options
$os = guictrlcreategroup(" Operating System ", 363, 56, 161, 105)
$OSName = GUICtrlCreateCheckbox("OS Name", 371, 80, 97, 17)
$OSServicepack = GUICtrlCreateCheckbox("Service Pack", 371, 104, 97, 17)
$OSArch = GUICtrlCreateCheckbox("Architecture", 371, 128, 97, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)

;User options
$us = GUICtrlCreateGroup(" User ", 363, 176, 161, 81)
$cusr = GUICtrlCreateCheckbox("Current User", 371, 200, 97, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
;save current settings
$savesettings = GUICtrlCreateButton("Save Settings", 24, 592, 75, 25, $WS_GROUP)
GUICtrlSetBkColor(-1, 0xC0DCC0)

;select all options
$selectall = GUICtrlCreateButton("Select All", 104, 592, 75, 25, $WS_GROUP)
GUICtrlSetBkColor(-1, 0xA6CAF0)

;deselect all options
$deselectall = GUICtrlCreateButton("Deselect All", 184, 592, 75, 25, $WS_GROUP)
GUICtrlSetBkColor(-1, 0x0066CC)
GUICtrlCreateGroup("", -99, -99, 1, 1)

;IP Ranges to scan
$IPRanges = GUICtrlCreateGroup("IP Ranges ", 680, 264, 185, 169)
GUICtrlSetFont(-1, 8, 400, 0, "Verdana")

;start range
GUICtrlCreateLabel("Start IP Address", 688, 288, 94, 17)
$SIP = guictrlcreateinput("0.0.0.0",688, 312, 169, 25)

;end range
GUICtrlCreateLabel("End IP Address", 688, 344, 94, 17)
$EIP = guictrlcreateinput("0.0.0.0",688, 368, 169, 25)

;save current ranges as default
$saveips = GUICtrlCreateButton("Save Ranges", 688, 400, 73, 25, $WS_GROUP)
GUICtrlSetBkColor(-1, 0xC0DCC0)

;clear ranges to 0.0.0.0
$resetips = GUICtrlCreateButton("Reset", 784, 400, 75, 25, $WS_GROUP)
GUICtrlSetBkColor(-1, 0x0066CC)
GUICtrlCreateGroup("", -99, -99, 1, 1)

;the magic button
;##############################
;# will call the go procedure #
;##############################
$go = GUICtrlCreateButton("GO", 688, 600, 171, 25, $WS_GROUP)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xC0DCC0)
GUICtrlSetCursor (-1, 0)




;Audit tab
;######################################################
;# Each individual session will list here, so you can #
;# track if a workstation has been audited            #
;#                                                    #
;# if is also exportable to .CSV file                 #
;######################################################
$Audit = GUICtrlCreateTabItem("Audit")
$audlist = GUICtrlCreateListView("", 16, 32, 841, 569, -1, $LVS_EX_GRIDLINES)
;$audlist = GUICtrlCreateListView("Workstation Name|Vendor|Model|Serial Number|MAC Address|IP Address|NIC Vendor|NIC Model|NIC Driver|Memory Vendor|Memory Physical|" & _
;"HDD Vendor|HDD Model|HDD Size|HDD Serial|Graphics Card Vendor|Graphics Card Model|Graphics Driver|Audio Vendor|Audio Model|Mainboard Vendor|Mainboard Model" & _
;"|Mainboard BIOS Version|Mainboard BIOS Date|CPU Vendor|CPU Model|CPU Speed|CPU Cores|OS Name|OS Service Pack|OS Architecture", 16, 32, 841, 569,-1,$LVS_EX_GRIDLINES)
GUICtrlSetFont(-1, 8, 400, 0, "verdana")
GUICtrlSetBkColor(-1, 0xFFFFE1)
;will call the pro2csv procedure
$aud2csv = GUICtrlCreateButton("Export to .CSV", 16, 608, 121, 25, $WS_GROUP)
GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
GUICtrlSetBkColor(-1, 0xC0DCC0)



;Error tab
;######################################################
;# Each individual error will list here, so you can   #
;# track if a workstation has an error                #
;#                                                    #
;# if is also exportable to .CSV file                 #
;######################################################
$Errors = GUICtrlCreateTabItem("Errors")
$Errlist = GUICtrlCreateListView("IP Address|Error Description|Date/Time", 16, 32, 841, 569,-1,$LVS_EX_GRIDLINES)
_GUICtrlListView_SetColumnWidth($errlist, 0, 150)
_GUICtrlListView_SetColumnWidth($errlist, 1, 400)
_GUICtrlListView_SetColumnWidth($errlist, 2, 200)

GUICtrlSetFont(-1, 8, 400, 0, "verdana")
GUICtrlSetBkColor(-1, 0xFFFFE1)
;will call the err2csv procedure
$err2csv = GUICtrlCreateButton("Export to .CSV", 16, 608, 121, 25, $WS_GROUP)
GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
GUICtrlSetBkColor(-1, 0xC0DCC0)

;progress tab
;######################################################
;# The status of each auditor is show here as either  #
;# "in Progress" or "Completed" and a time stamp of   #
;# the last status update.                            #
;#                                                    #
;# if is also exportable to .CSV file                 #
;######################################################
$progress = GUICtrlCreateTabItem("Progress")
$prolist = GUICtrlCreateListView("IP Address|Status|Date/Time", 16, 32, 841, 569,-1,$LVS_EX_GRIDLINES)
_GUICtrlListView_SetColumnWidth($prolist, 0, 150)
_GUICtrlListView_SetColumnWidth($prolist, 1, 250)
_GUICtrlListView_SetColumnWidth($prolist, 2, 200)
GUICtrlSetFont(-1, 8, 400, 0, "verdana")
GUICtrlSetBkColor(-1, 0xFFFFE1)
$pro2csv = GUICtrlCreateButton("Export to .CSV", 16, 608, 121, 25, $WS_GROUP)
GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
GUICtrlSetBkColor(-1, 0xC0DCC0)
GUICtrlCreateTabItem("")

;check most common options
guictrlsetstate($WSName, $gui_checked)
guictrlsetstate($WSVendor, $gui_checked)
guictrlsetstate($WSModel, $gui_checked)
guictrlsetstate($WSSerial, $gui_checked)
guictrlsetstate($CPUVendor, $gui_checked)
guictrlsetstate($CPUModel, $gui_checked)
guictrlsetstate($CPUSpeed, $gui_checked)
guictrlsetstate($CPUcores, $gui_checked)
guictrlsetstate($NICIP, $gui_checked)
guictrlsetstate($MACAddress, $gui_checked)
guictrlsetstate($MemPhysical, $gui_checked)
guictrlsetstate($HDDSize, $gui_checked)
guictrlsetstate($OSName, $gui_checked)
guictrlsetstate($OSServicepack, $gui_checked)
guictrlsetstate($cusr, $gui_checked)

If FileExists($credsini) Then
    ;read the credentials in the ini files
    $u = IniRead($credsini, "Credentials", "Username", "")
    $p = IniRead($credsini, "Credentials", "Password", "")
    $d = IniRead($credsini, "Credentials", "Domain", "")
    $csip = iniread($credsini, "IP Ranges", "Start Range", "")
    $ceip = iniread($credsini, "IP Ranges", "End Range", "")
    $s = stringsplit($csip, ".")
    $e = stringsplit($ceip, ".")
    ;decrypt the data
    _Crypt_Startup()
    $mac = ""
    $ckey = _Crypt_DeriveKey($mac, $CALG_DES)
    $du = _Crypt_DecryptData(Binary($u), $ckey, $CALG_USERKEY)
    $dp = _Crypt_DecryptData(Binary($p), $ckey, $CALG_USERKEY)
    $dd = _Crypt_DecryptData(Binary($d), $ckey, $CALG_USERKEY)
    _Crypt_Shutdown()

    ;put the decrypted data into the relevant boxes
    GUICtrlSetData($User, BinaryToString($du), "")
    GUICtrlSetData($Pass, BinaryToString($dp), "")
    GUICtrlSetData($Domain, BinaryToString($dd), "")
    if $s[3] > $e[3] or (($s[3] = $e[3]) and ($s[4] > $e[4])) Then
        Guictrlsetdata($SIP, "0.0.0.0")
        guictrlsetdata($eip, "0.0.0.0")
    Else
        Guictrlsetdata($SIP, $Csip)
        guictrlsetdata($eip, $ceip)
    EndIf
EndIf



GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
    Case $GUI_EVENT_CLOSE
        filedelete(@ScriptDir & "\temp\*.tmp")
        Exit
    case $resetips
        guictrlsetdata($SIP, "0.0.0.0","")
        guictrlsetdata($eip, "0.0.0.0","")
        Msgbox(64,"Oracle", "IP Ranges have been reset!", 5)
    case $resetdetails
        guictrlsetdata($user, "", "")
        guictrlsetdata($pass, "","")
        guictrlsetdata($domain, "","")
        Msgbox(64,"Oracle", "Credentials have been reset!", 5)
    case $savedetails
        $u = guictrlread($user)
        $p = guictrlread($pass)
        $d = guictrlread($domain)
        if $u = "" or $p = "" or $d = "" Then
            msgbox(48, "Warning!", "one of your credentials is missing!")
        Else
            _Crypt_Startup()
            $stepping = 14.3
            ProgressOn("Saving Settings", "Please wait, Encrypting Credentials", "Please Wait", -1, -1)
            $mac = ""
            ProgressSet($stepping, "Please wait, Encrypting Credentials", "Saving Settings")
            $ckey = _Crypt_DeriveKey($mac, $CALG_DES)
            ProgressSet($stepping * 2, "Please wait, Encrypting Credentials", "Saving Settings")
            IniWrite($credsini, "Credentials", "Username", _Crypt_EncryptData($u, $ckey, $CALG_USERKEY))
            ProgressSet($stepping * 3, "Please wait, Encrypting Credentials", "Saving Settings")
            IniWrite($credsini, "Credentials", "Password", _Crypt_EncryptData($p, $ckey, $CALG_USERKEY))
            ProgressSet($stepping * 4, "Please wait, Encrypting Credentials", "Saving Settings")
            IniWrite($credsini, "Credentials", "Domain", _Crypt_EncryptData($d, $ckey, $CALG_USERKEY))
            ProgressSet($stepping * 5, "Please wait, Encrypting Credentials", "Saving Settings")
            _Crypt_DestroyKey($ckey)
            ProgressSet($stepping * 6, "Please wait, Encrypting Credentials", "Saving Settings")
            _Crypt_Shutdown()
            ProgressSet($stepping * 7, "Please wait, Encrypting Credentials", "Saving Settings")
            Sleep(100)
            ProgressSet(100, "Credentials Encrypted", "Save Successful!")
            Sleep(1000)
            ProgressOff()
        EndIf
    case $saveips
        $s = guictrlread($SIP)
        $e = guictrlread($eip)
        if $s = "" or $e = "" Then
            Msgbox(64, "Warning!", "You have not specified any IP Ranges", 5)
        Else
            IniWrite($credsini, "IP Ranges", "Start Range", $s)
            IniWrite($credsini, "IP Ranges", "End Range", $e)
            Msgbox(64,"Oracle", "IP Ranges saved", 5)
        endif
    case $selectall
        guictrlsetstate($WSName, $gui_checked)
        guictrlsetstate($WSVendor, $gui_checked)
        guictrlsetstate($WSModel, $gui_checked)
        guictrlsetstate($WSSerial, $gui_checked)
        guictrlsetstate($CPUVendor, $gui_checked)
        guictrlsetstate($CPUModel, $gui_checked)
        guictrlsetstate($CPUSpeed, $gui_checked)
        guictrlsetstate($CPUcores, $gui_checked)
        guictrlsetstate($NICIP, $gui_checked)
        guictrlsetstate($NICVendor, $gui_checked)
        guictrlsetstate($NICModel, $gui_checked)
        guictrlsetstate($NICDriver, $gui_checked)
        guictrlsetstate($MACAddress, $gui_checked)
        guictrlsetstate($MemVendor, $gui_checked)
        guictrlsetstate($MemPhysical, $gui_checked)
        guictrlsetstate($HDDVendor, $gui_checked)
        guictrlsetstate($HDDmodel, $gui_checked)
        guictrlsetstate($HDDSize, $gui_checked)
        guictrlsetstate($HDDSerial, $gui_checked)
        guictrlsetstate($GCVendor, $gui_checked)
        guictrlsetstate($GCModel, $gui_checked)
        guictrlsetstate($GCDriver, $gui_checked)
        guictrlsetstate($SCVendor, $gui_checked)
        guictrlsetstate($SCModel, $gui_checked)
        guictrlsetstate($MBVendor, $gui_checked)
        guictrlsetstate($MBModel, $gui_checked)
        guictrlsetstate($MBBIOSVer, $gui_checked)
        guictrlsetstate($MBBIOSDate, $gui_checked)
        guictrlsetstate($CPUVendor, $gui_checked)
        guictrlsetstate($CPUModel, $gui_checked)
        guictrlsetstate($CPUSpeed, $gui_checked)
        guictrlsetstate($CPUcores, $gui_checked)
        guictrlsetstate($OSName, $gui_checked)
        guictrlsetstate($OSServicepack, $gui_checked)
        guictrlsetstate($OSArch, $gui_checked)
        guictrlsetstate($cusr, $gui_checked)
    case $deselectall
        guictrlsetstate($WSName, $gui_unchecked)
        guictrlsetstate($WSVendor, $gui_unchecked)
        guictrlsetstate($WSModel, $gui_unchecked)
        guictrlsetstate($WSSerial, $gui_unchecked)
        guictrlsetstate($CPUVendor, $gui_unchecked)
        guictrlsetstate($CPUModel, $gui_unchecked)
        guictrlsetstate($CPUSpeed, $gui_unchecked)
        guictrlsetstate($CPUcores, $gui_unchecked)
        guictrlsetstate($NICIP, $gui_unchecked)
        guictrlsetstate($NICVendor, $gui_unchecked)
        guictrlsetstate($NICModel, $gui_unchecked)
        guictrlsetstate($NICDriver, $gui_unchecked)
        guictrlsetstate($MACAddress, $gui_unchecked)
        guictrlsetstate($MemVendor, $gui_unchecked)
        guictrlsetstate($MemPhysical, $gui_unchecked)
        guictrlsetstate($HDDVendor, $gui_unchecked)
        guictrlsetstate($HDDmodel, $gui_unchecked)
        guictrlsetstate($HDDSize, $gui_unchecked)
        guictrlsetstate($HDDSerial, $gui_unchecked)
        guictrlsetstate($GCVendor, $gui_unchecked)
        guictrlsetstate($GCModel, $gui_unchecked)
        guictrlsetstate($GCDriver, $gui_unchecked)
        guictrlsetstate($SCVendor, $gui_unchecked)
        guictrlsetstate($SCModel, $gui_unchecked)
        guictrlsetstate($MBVendor, $gui_unchecked)
        guictrlsetstate($MBModel, $gui_unchecked)
        guictrlsetstate($MBBIOSVer, $gui_unchecked)
        guictrlsetstate($MBBIOSDate, $gui_unchecked)
        guictrlsetstate($CPUVendor, $gui_unchecked)
        guictrlsetstate($CPUModel, $gui_unchecked)
        guictrlsetstate($CPUSpeed, $gui_unchecked)
        guictrlsetstate($CPUcores, $gui_unchecked)
        guictrlsetstate($OSName, $gui_unchecked)
        guictrlsetstate($OSServicepack, $gui_unchecked)
        guictrlsetstate($OSArch, $gui_unchecked)
        guictrlsetstate($cusr, $gui_unchecked)
    case $aud2csv
            $output = _guictrlListView_CreateArray($audlist)
            $file = FileSelectFolder("Please Select the location for your .csv", "")
            $date = @MDAY & @MON & @YEAR
            if @error Then
                msgbox(64, "Warning!", "Invalid location!", 5)
            Else
                _guictrllistview_savecsv($output, $file & "\Audit_" & $date & ".csv")
                MsgBox(64, "Oracle", "Your Audit file is located here: " & $file)
            EndIf
    case $Pro2csv
            $output = _guictrlListView_CreateArray($Prolist)
            $file = FileSelectFolder("Please Select the location for your .csv", "")
            $date = @MDAY & @MON & @YEAR
            if @error Then
                msgbox(64, "Warning!", "Invalid location!", 5)
            Else
                _guictrllistview_savecsv($output, $file & "\Progress_" & $date & ".csv")
                MsgBox(64, "Oracle", "Your Progress log is located here: " & $file)
            EndIf
    case $err2csv
            $output = _guictrlListView_CreateArray($Errlist)
            $file = FileSelectFolder("Please Select the location for your .csv", "")
            $date = @MDAY & @MON & @YEAR
            if @error Then
                msgbox(64, "Warning!", "Invalid location!", 5)
            Else
                _guictrllistview_savecsv($output, $file & "\AuditErrors_" & $date & ".csv")
                MsgBox(64, "Oracle", "your Error log is located here: " & $file)
            EndIf

    case $go
        ;#########################################
        ;# read the selected options and deatils #
        ;#########################################
        ;workstation options
        $ws1 = guictrlread($WSName)
        $ws2 = guictrlread($WSVendor)
        $ws3 = guictrlread($WSModel)
        $ws4 = guictrlread($WSSerial)
        ;networking options
        $nw1 = guictrlread($MACAddress)
        $nw2 = guictrlread($NICIP)
        $nw3 = guictrlread($NICVendor)
        $nw4 = guictrlread($NICModel)
        $nw5 = guictrlread($NICDriver)
        ;memory
        $me1 = guictrlread($MemVendor)
        $me2 = guictrlread($MemPhysical)
        ;hdd
        $hd1 = guictrlread($HDDVendor)
        $hd2 = guictrlread($HDDmodel)
        $hd3 = guictrlread($HDDSize)
        $hd4 = guictrlread($HDDSerial)
        ;graphics
        $gc1 = guictrlread($GCVendor)
        $gc2 = guictrlread($GCmodel)
        $gc3 = guictrlread($GCDriver)
        ;audio
        $sc1 = guictrlread($scVendor)
        $sc2 = guictrlread($SCModel)
        ;mainboard
        $mb1 = guictrlread($MBVendor)
        $mb2 = guictrlread($MBModel)
        $mb3 = guictrlread($MBBIOSVer)
        $mb4 = guictrlread($MBBIOSDate)
        ;processor
        $cp1 = guictrlread($CPUVendor)
        $cp2 = guictrlread($CPUModel)
        $cp3 = guictrlread($CPUSpeed)
        $cp4 = guictrlread($CPUCores)
        ;Operating system
        $os1 = guictrlread($OSName)
        $os2 = guictrlread($OSServicepack)
        $os3 = guictrlread($OSArch)
        ;user options
        $cu = guictrlread($cusr)
        ;credentials
        $user = guictrlread($user)
        $pass = guictrlread($pass)
        $domain = guictrlread($domain)
        ;Ipranges
        $csip = guictrlread($sip)
        $ceip = guictrlread($eip)
        $s = StringSplit($csip, ".")
        $e = Stringsplit($ceip, ".")
        ;workstation
        DirCreate(@scriptdir & "\Temp")
        $criteria = @ScriptDir & "\Temp\Session.tmp"

        if $ws1 = 1 then
            _GUICtrlListView_AddColumn($audlist, "Workstation Name", 150, 0)
            filewriteline($criteria, "Win32_ComputerSystem,Name,$ws1")
        EndIf

        if $ws2 = 1 then
            _GUICtrlListView_AddColumn($audlist, "Vendor", 50, 0)
            filewriteline($criteria, "Win32_ComputerSystem,Manufacturer,$ws2")
        EndIf

        if $ws3 = 1 then
            _GUICtrlListView_AddColumn($audlist, "Model", 50, 0)
            filewriteline($criteria, "Win32_ComputerSystem,Model,$ws3")
        EndIf

        if $ws4 = 1 then
            _GUICtrlListView_AddColumn($audlist, "Serial Number", 150, 0)
            filewriteline($criteria, "Win32_BIOS,SerialNumber,$ws4")
        EndIf
        ;network
        if $nw1 = 1 then
            _GUICtrlListView_AddColumn($audlist, "MAC Address", 150, 0)
            filewriteline($criteria, "Win32_NetworkAdapter,MACAddress,$nw1")
        EndIf

        if $nw2 = 1 then
            _GUICtrlListView_AddColumn($audlist, "IP Address", 50, 0)
            filewriteline($criteria, "Win32_NetworkAdapterConfiguration,IPAddress,$nw2")
        EndIf

        if $nw3 = 1 then
            _GUICtrlListView_AddColumn($audlist, "NIC Vendor", 50, 0)
            filewriteline($criteria, "Win32_NetworkAdapter,Manufacturer,$nw3")
        EndIf

        if $nw4 = 1 then
            _GUICtrlListView_AddColumn($audlist, "NIC Model", 50, 0)
            filewriteline($criteria, "Win32_NetworkAdapter,ProductName,$nw4")
        EndIf

        if $nw5 = 1 then
            _GUICtrlListView_AddColumn($audlist, "NIC Driver", 50, 0)
            filewriteline($criteria, "Win32_NetworkAdapter,Description,$nw5")
        EndIf

        if $me2 = 1 then
            _GUICtrlListView_AddColumn($audlist, "Memory Size", 100, 0)
            filewriteline($criteria, "Win32_ComputerSystem,TotalPhysicalMemory,$me1,Round(($objItem.TotalPhysicalMemory / 1024 / 1024), 0)")
        EndIf

        if $hd1 = 1 then
            _GUICtrlListView_AddColumn($audlist, "HDD vendor", 50, 0)
            filewriteline($criteria, "Win32_DiskDrive,Manufacturer,$hd1")
        EndIf

        if $hd2 = 1 then
            _GUICtrlListView_AddColumn($audlist, "HDD Model", 50, 0)
            filewriteline($criteria, "Win32_DiskDrive,Model,$hd2")
        EndIf

        if $hd3 = 1 then
            _GUICtrlListView_AddColumn($audlist, "HDD Size", 50, 0)
            filewriteline($criteria, "Win32_DiskDrive,Size,$hd3")
        EndIf

        if $hd4 = 1 then
            _GUICtrlListView_AddColumn($audlist, "HDD Serial", 50, 0)
            filewriteline($criteria, "Win32_DiskDrive,SerialNumber,$hd4")
        EndIf

        if $gc1 = 1 then
            _GUICtrlListView_AddColumn($audlist, "Graphics Vendor", 50, 0)
            filewriteline($criteria, "Win32_VideoConfiguration,Name,$gc1")
        EndIf

        if $gc2 = 1 then
            _GUICtrlListView_AddColumn($audlist, "Graphics Model", 50, 0)
            filewriteline($criteria, "Win32_DisplayConfiguration,DeviceName,$gc2")
        EndIf

        if $gc3 = 1 then
            _GUICtrlListView_AddColumn($audlist, "Graphics Driver", 50, 0)
            filewriteline($criteria, "Win32_DisplayConfiguration,DriverVersion,$gc3")
        EndIf

        if $sc1 = 1 then
            _GUICtrlListView_AddColumn($audlist, "Soundcard Vendor", 50, 0)
            filewriteline($criteria, "Win32_SoundDevice,Manufacturer,$sc1")
        EndIf

        if $sc2 = 1 then
            _GUICtrlListView_AddColumn($audlist, "Soundcard Model", 50, 0)
            filewriteline($criteria, "Win32_SoundDevice,ProductName,$sc2")
        EndIf

        if $mb1 = 1 then
            _GUICtrlListView_AddColumn($audlist, "Mainboard Vendor", 50, 0)
            filewriteline($criteria, "Win32_BaseBoard,Manufacturer,$mb1")
        EndIf

        if $mb2 = 1 then
            _GUICtrlListView_AddColumn($audlist, "Mainboard Model", 50, 0)
            filewriteline($criteria, "Win32_BaseBoard,Model,$mb2")
        EndIf

        if $mb3 = 1 then
            _GUICtrlListView_AddColumn($audlist, "Mainboard Bios Ver", 50, 0)
            filewriteline($criteria, "Win32_BIOS,SMBIOSBIOSVersion,$mb3")
        EndIf

        if $mb4 = 1 then
            _GUICtrlListView_AddColumn($audlist, "Mainboard Bios Date", 50, 0)
            filewriteline($criteria, "Win32_BIOS,ReleaseDate,$mb4")
        EndIf

        if $cp1 = 1 then
            _GUICtrlListView_AddColumn($audlist, "CPU Vendor", 50, 0)
            filewriteline($criteria, "Win32_Processor,Manufacturer,$cp1")
        EndIf

        if $cp2 = 1 then
            _GUICtrlListView_AddColumn($audlist, "CPU Model", 50, 0)
            filewriteline($criteria, "Win32_Processor,ProcessorType,$cp2")
        EndIf

        if $cp3 = 1 then
            _GUICtrlListView_AddColumn($audlist, "CPU Speed", 50, 0)
            filewriteline($criteria, "Win32_Processor,MaxClockSpeed,$cp3")
        EndIf

        if $cp4 = 1 then
            _GUICtrlListView_AddColumn($audlist, "CPU Cores", 50, 0)
            filewriteline($criteria, "Win32_Processor,NumberOfCores,$cp4")
        EndIf

        if $os1 = 1 then
            _GUICtrlListView_AddColumn($audlist, "OS Name", 50, 0)
            filewriteline($criteria, "Win32_OperatingSystem,Name,$os1")
        EndIf

        if $os2 = 1 then
            _GUICtrlListView_AddColumn($audlist, "OS Service Pack", 50, 0)
            filewriteline($criteria, "Win32_OperatingSystem,CSDVersion,$os2")
        EndIf

        if $os3 = 1 then
            _GUICtrlListView_AddColumn($audlist, "OS Architecture", 50, 0)
            filewriteline($criteria, "Win32_OperatingSystem,OSArchitecture,$os3")
        EndIf

        if $cu = 1 Then
            _GUICtrlListView_AddColumn($audlist, "Current User", 50, 0)
            filewriteline($criteria, "Win32_ComputerSystem,UserName,$cu4")
        EndIf

        ;######################################
        ;# pass these details to the sub .exe #
        ;######################################
        guictrlsetstate($eip, $GUI_DISABLE)
        ;check for null credential fields
        if $user = "" or $pass = "" or $domain = "" Then
            Msgbox(64,"Oracle", "One or more of your credentials is missing!")
        ElseIf $s[3] > $e[3] or (($s[3] = $e[3] and $s[4] > $e[4])) Then
            ;error check ip ranges
            Msgbox(48,"Oracle", "There is a problem with your IP ranges!")
        elseif ($s[3] = $e[3] and $s[4] = $e[4]) Then
            ;error check ip ranges
            Msgbox(48,"Oracle", "There is a problem with your IP ranges!")
        Else
            ;create current IP
            $wsip = $s[1] & "." & $s[2] & "." & $s[3] & "." & $s[4]
            ;create final IP
            $finalIP = $e[1] & "." & $e[2] & "." & $e[3] & "." & $e[4]
            $p = 0
            ;error count
            $e = 0
            ;ping error handler
            $pingerror = 0
            _GUICtrlTab_SetCurFocus($Tabz, 3)

            Do
                $var = ping($wsip, 250)
                ;create a .tmp file for the info to be returned to by the Oracle-sub .exe
                $info = @scriptdir & "\temp\" & $s[1] & $s[2] & $s[3] & $s[4] & ".tmp"
                if $var Then
                    ;get current time
                    $tCur = _Date_Time_GetSystemTime()
                    $litem = GUICtrlCreateListViewItem($WSIP & "|In Progress|"&  _Date_Time_SystemTimeToDateTimeStr($tCur), $Prolist)
                    run('Oracle-sub.exe ' & $WSIP & " " & $user & " " & $pass & " " & $domain)
                    $result = filereadline($info, 2)
                    if $result <> "Audit Finished" Then
                        do
                            sleep(100)
                            $result = filereadline($info, 2)
                        until $result = "Audit Finished" or $result = "Audit incomplete"
                    EndIf


                    $tCur = _Date_Time_GetSystemTime()
                    if $result = "Audit Finished" Then
                        guictrlsetdata($litem, "|Audit Completed|"&  _Date_Time_SystemTimeToDateTimeStr($tCur), "")
                        $audit = filereadline($info, 1)
                        GUICtrlCreateListViewItem($audit, $audlist)
                        ;filedelete($info)


                    Elseif $result = "Audit Incomplete" Then
                        guictrlsetdata($litem, "|Unable to audit|"&  _Date_Time_SystemTimeToDateTimeStr($tCur), "")
                        GUICtrlCreateListViewItem($wsip & "|Unable to complete audit|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $errlist)
                        $e = $e +1
                        GUICtrlSetData($errors, "Errors (" & $e & ")", "")

                    EndIf


                    ;increase last octet by 1
                    $s[4] = $s[4] +1
                    ;check last octet, if it's 256 then reset back to 1 and increase 3rd octet by 1
                    if $s[4] = 256 Then
                        $s[3] = $s[3]+1
                        $s[4] = 1
                        $wsip = $s[1] & "." & $s[2] & "." & $s[3] & "." & $s[4]
                        ;increase the progress count by 1
                        $p = $p +1
                        ;update the tab count
                        guictrlsetdata($audit, $p & " Audited", "")
                        ;update the start IP address
                        guictrlsetdata($sip, $WSIP, "")
                        ;complete the tmp for that workstation

                    Else
                        $p = $p +1
                        $wsip = $s[1] & "." & $s[2] & "." & $s[3] & "." & $s[4]
                        ;update the tab count
                        guictrlsetdata($audit, $p & " Audited", "")
                        ;update the start IP address
                        guictrlsetdata($sip, $WSIP, "")
                        ;complete the tmp for that workstation
                        ;filedelete($info)
                    EndIf

                Else
                    $PingError = 1
                    CALL("MYErrFunc")

                EndIf

            Until $wsip = $finalIP
            msgbox(64,"Oracle", "IP ranges processed successfully", 10)
            _GUICtrlTab_SetCurFocus($tabz, 1)

        EndIf
        guictrlsetstate($eip, $GUI_ENABLE)




EndSwitch
WEnd
Exit

Func MyErrFunc()
    $tCur = _Date_Time_GetSystemTime()
    if $pingerror = 1 Then
        GUICtrlCreateListViewItem($WSIP & "|is not responding to a ping request|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Errlist)
    Else
        GUICtrlCreateListViewItem($WSIP & "|" & $oMyError.windescription & "|" & _Date_Time_SystemTimeToDateTimeStr($tCur), $Errlist)
    EndIf

    $s[4] = $s[4] +1
        if $s[4] = 256 Then
            $s[3] = $s[3]+1
            $s[4] = 1
            $wsip = $s[1] & "." & $s[2] & "." & $s[3] & "." & $s[4]
            $e = $e +1
            GUICtrlSetData($errors, "Errors (" & $e & ")", "")
            guictrlsetdata($sip, $WSIP, "")
        else
            $wsip = $s[1] & "." & $s[2] & "." & $s[3] & "." & $s[4]
            $e = $e +1
            GUICtrlSetData($errors, "Errors (" & $e & ")", "")
            guictrlsetdata($sip, $WSIP, "")
        EndIf

    Local $err = $oMyError.number
    $pingerror = 0
    If $err = 0 Then $err = -1

    $g_eventerror = $err  ; to check for after this function returns
Endfunc

sub .exe (Oracle-sub.exe)

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=search.ico
#AutoIt3Wrapper_outfile=Oracle-sub.exe
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_Comment=Oracle Auditor Sub process
#AutoIt3Wrapper_Res_Description=Oracle Auditor Sub process
#AutoIt3Wrapper_Res_Fileversion=1.0.0.21
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#AutoIt3Wrapper_Res_LegalCopyright=Richard Easton 2011
#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.6.1
 Author:         Richard Easton

 Script Function:
    Oracle Sub.exe.

#ce ----------------------------------------------------------------------------

#include <File.au3>

; Script Start - Add your code below here

$wsip = $cmdline[1]
$user = $cmdline[2]
$pass = $cmdline[3]
$domain = $cmdline[4]
$s = stringsplit($wsip, ".")
$info = @scriptdir & "\Temp\" & $s[1] & $s[2] & $s[3] & $s[4] & ".tmp"
$criteria = @ScriptDir & "\Temp\Session.tmp"
$critcount = _FileCountLines($criteria)
Opt("TrayIconHide", 1)


$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

$objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator")
If Not IsObj($objSWbemLocator) Then
EndIf

Global $g_eventerror = 0    ; to be checked to know if com error occurs. Must be reset after handling.

$objSWbemServices = $objSWbemLocator.ConnectServer($cmdline[1], "root\cimv2", $domain & "\" & $user, $pass)
    If IsObj($objSWbemServices) Then
                $critcount = _FileCountLines($criteria)
                $l = 1
                do
                    $readcrit = filereadline($criteria, $l)
                    $split = stringsplit($readcrit, ",")
                    $query = '"select * from ' & $split[1] & '"'
                    $colItems = $objSWbemServices.ExecQuery($query)
                    if $g_eventerror Then
                        $g_eventerror = 0
                    Else
                        if IsObj($colItems) Then
                            For $objItem In $colItems
                                $result = $ObjItem & "." & $split[2]
                                msgbox(64, "", $result)
                                Filewrite($info, $result & "|")
                            Next
                        endif
                    EndIf
                until $l = $critcount +1

                filewriteline($info, "Audit Finished")
    EndIf

Exit

Func MyErrFunc()
    SetError(1) ; something to check for when this function returns
    filewriteline($info, @CRLF)
    filewriteline($info, "Audit incomplete")

EndFunc   ;==>MyErrFunc

Thanks in advance


RichE

[font="'Arial Narrow';"]Current projects[/font]

[font="'Arial Narrow';"]are on my site [/font]Sellostring

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

right I've tracked down the problem in this, and got one part working

the info is contained in a session.tmp that is created each time the audit process is ran, and each line contain the following information:

this option has been selected (signified by the 1),

Win32_ComputerSystem,Name,1

this option is to be skipped,

Win32_ComputerSystem,Name,0

and the string is split by the "," , and the query works by doing the following, define the query string as a variable, ergo $query

$query = "Select * from " & $split[1]
$colItems = $objSWbemServices.ExecQuery($query)

so this works, but then the sub part of the WMI query (the Sub item) won't work,

if $split[2] = "CSDVersion" and $split[3] = 1 Then
if $g_eventerror or @error Then
$g_eventerror = 0
$errdesc = $split[2]
Else
if IsObj($colItems) Then
For $objItem In $colItems
$out = $objItem.CSDVersion  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< this works, because the sub item is manual set
 
;$out = "$objItem." & $split[2]  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< this doesn't work, even thought the variable is passed ok, and gets an
                                            ;error when the "s don't encapsulate the $objitem. I can just ignore the warning and compile it but obviously it errors.
 
Filewrite($info, $out)
Next
endif
EndIf
$l = $l +1
if $l = $critcount Then
filewriteline($info, @CR &"Audit Finished")
sleep(60)
Exit
Else
Filewrite($info, "|")
EndIf
Else
$l = $l +1
if $l = $critcount Then
filewriteline($info, @CR &"Audit Finished")
sleep(60)
Exit
EndIf
EndIf

if I can crack this, the amount of line of code would be reduce 100 fold, and I would then be able to add in custom queries for more obscure WMI information that wouldn't normally be required.

any help would greatly be welcomed.

thanks in advance

Edited by RichE

RichE

[font="'Arial Narrow';"]Current projects[/font]

[font="'Arial Narrow';"]are on my site [/font]Sellostring

Share this post


Link to post
Share on other sites

Did you try

$out = Execute("$objItem." & $split[2])

Adam

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0