AD Sunucu Güveni Doğrulama Betik Araştırma işlemi

AD_Validate_Server_Trust_Event.ProbeAction (ProbeActionModuleType)

Element properties:

TypeProbeActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
InputTypeSystem.Event.Data
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
DS ProbeAction System.CommandExecuterProbe Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
LogSuccessEventstring$Config/LogSuccessEvent$Başarılı Olayı Günlüğe Kaydet
ComputerAccountstring$Config/ComputerAccount$Bilgisayar Hesabı
TimeoutSecondsint$Config/TimeoutSeconds$Zaman Aşımı (saniye)

Source Code:

<ProbeActionModuleType ID="AD_Validate_Server_Trust_Event.ProbeAction" Accessibility="Internal" Batching="false" PassThrough="false">
<Configuration>
<xsd:element name="TargetComputerName" type="xsd:string"/>
<xsd:element name="LogSuccessEvent" type="xsd:boolean"/>
<xsd:element name="ComputerAccount" type="xsd:string"/>
<xsd:element name="TimeoutSeconds" type="xsd:int"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="LogSuccessEvent" Selector="$Config/LogSuccessEvent$" ParameterType="string"/>
<OverrideableParameter ID="ComputerAccount" Selector="$Config/ComputerAccount$" ParameterType="string"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<ProbeAction ID="DS" TypeID="System!System.CommandExecuterProbe">
<ApplicationName>%windir%\system32\cscript.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>//nologo $file/AD_Validate_Server_Trust_Event.vbs$ $Config/TargetComputerName$ $Config/LogSuccessEvent$ $Config/ComputerAccount$</CommandLine>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>AD_Validate_Server_Trust_Event.vbs</Name>
<Contents><Script>
'*************************************************************************
' Script Name - AD Validate Server Trust Event
'
' Purpose - Runs in response to NetLogon event 5723. If the second
' parameter is a server trust account then the event is
' propagated, otherwise it is ignored.
'
' Assumptions - Script is only ever run in response to NetLogon 5723 and
' the event parameters are available to the script.
'
' Parameters - LogSuccessEvent - Indicates whether to log an event when
' the script completes successfully (that is without
' logging any errors)
'
' (c) Copyright 2002, Microsoft Corporation, All Rights Reserved
' Proprietary and confidential to Microsoft Corporation
'*************************************************************************

Option Explicit

'Event Constants
Const EVENT_TYPE_SUCCESS = 0
Const EVENT_TYPE_ERROR = 1
Const EVENT_TYPE_WARNING = 2
Const EVENT_TYPE_INFORMATION = 4

' Event IDs
Const EVENT_ID_EVENT_RULE_ONLY = 2
Const EVENT_ID_AGENTLESS = 98
Const EVENT_ID_SUCCESS = 99
Const EVENT_ID_SCRIPT_ERROR = 1000
Const EVENT_ID_GOOD_STATE = 18960
Const EVENT_ID_BAD_STATE = 1040

'Other constants
Const SCRIPT_NAME = "AD Validate Server Trust Event"

' TypedPropertyBag
const PerformanceDataType = 2
const StateDataType = 3

Dim owParams, IsTargetAgentless,TargetFQDNComputer, oAPI, bLogSuccess, oBag, ComputerAccount
IsTargetAgentless = false
Set oAPI = CreateObject("Mom.ScriptAPI")
Err.Clear

Sub Main()
On Error Resume Next

If Not(IsTargetAgentless) Then
Dim dtStart
dtStart = Now()

Set owParams = WScript.Arguments
if owParams.Count &lt; 3 Then
Wscript.quit -1
End if
TargetFQDNComputer = owParams(0)
bLogSuccess = CBool(owParams(1))'LogSuccessEvent
ComputerAccount = owParams(2)

' Get the computer account name and search for it, retrieving the
' userAccountControl property.
Dim strComputerAccount
strComputerAccount = ComputerAccount

' Bind to the rootDSE to get the default naming context
Dim oRootDSE
Set oRootDSE = GetObject("LDAP://" &amp; TargetFQDNComputer &amp; "/RootDSE")
If Err = 0 Then
' Construct the query string
Dim strQuery
strQuery = "&lt;LDAP://" &amp; TargetFQDNComputer &amp; "/" &amp; oRootDSE.Get("DefaultNamingContext") &amp; _
"&gt;;(SAMAccountName=" &amp; strComputerAccount &amp; ");userAccountControl;subtree"

' Get an ADO connection object to do the search
Dim oADOConn
Set oADOConn = CreateObject("ADODB.Connection")
oADOConn.Provider = "ADSDsOObject"
oADOConn.Open "ADs Provider"

If Err = 0 Then
' Perform the search
Dim rsResults
Set rsResults = oADOConn.Execute(strQuery)
If Err = 0 Then
Dim bFoundAccount, State, EventID
bFoundAccount = False
State = "GOOD"
EventID = EVENT_ID_GOOD_STATE
Set oBag= oAPI.CreateTypedPropertyBag(StateDataType)

Do While Not rsResults.EOF
bFoundAccount = True
If rsResults.Fields("UserAccountControl") And &amp;H2000 Then
' We have found a computer account that is a server trust account
' generate an event (manually because we want to set some
' specific fields) that will be turned into an alert.
State ="BAD"
EventID = EVENT_ID_BAD_STATE
Exit Do
End If
rsResults.MoveNext
Loop

Call oBag.AddValue("State",State)
Call oBag.AddValue("EventID",EventID)
Call oAPI.addItem(oBag)
oAPI.ReturnItems

If bLogSuccess = True Then
CreateEvent EVENT_ID_SUCCESS, EVENT_TYPE_INFORMATION, "The script '" &amp; _
SCRIPT_NAME &amp; "' completed in " &amp; DateDiff("s", Now(), dtStart) &amp; _
" seconds."
End If
Else
ScriptError "executing the search '" &amp; strQuery &amp; "'." &amp; GetErrorString(Err)
End If
Else
ScriptError "creating the ADO Connection object." &amp; GetErrorString(Err)
End If
Else
ScriptError "connecting to the RootDSE. (" &amp; "LDAP://" &amp; TargetFQDNComputer &amp; "/RootDSE" &amp; ")" &amp; GetErrorString(Err)
End If
'Else
' CreateEvent EVENT_ID_EVENT_RULE_ONLY, EVENT_TYPE_WARNING, "The script '" &amp; _
' SCRIPT_NAME &amp; "' can only be run by event 5723 from NetLogon."
'End If
Else
CreateEvent EVENT_ID_AGENTLESS, EVENT_TYPE_ERROR, "The AD Management Pack does not support the agentless management mode." &amp; vbCrLf &amp; _
"The script '" &amp; SCRIPT_NAME &amp; "' will not execute." &amp; vbCrLf &amp; _
"To prevent this alert being generated again, either change the monitoring " &amp; _
"mode of this computer to agent-managed " &amp; _
"or disable the rule that generated this alert."
End If
End Sub

'******************************************************************************
Sub ScriptError(strError)
'
' Purpose: Records a script error.
'
' Parameters: strError, the description of the error to record
'
CreateEvent EVENT_ID_SCRIPT_ERROR, EVENT_TYPE_WARNING, "The script '" &amp; SCRIPT_NAME &amp; _
"' failed while " &amp; strError
End Sub

'******************************************************************************
Function GetErrorString(oErr)
'
' Purpose: Attempts to find the description for an error if an error with
' no description is passed in.
'
' Parameters: oErr, the error object
'
' Return: String, the description for the error. (Includes the error code.)
'
Dim lErr, strErr
lErr = oErr
strErr = oErr.Description

On Error Resume Next
If 0 &gt;= Len(strErr) Then
' If we don't have an error description, then check to see if the error
' is a 0x8007xxxx error. If it is, then look it up.
Const ErrorMask = &amp;HFFFF0000
Const HiWord8007 = &amp;H80070000
Const LoWordMask = 65535 ' This is equivalent to 0x0000FFFF

If (lErr And ErrorMask) = HiWord8007 Then
' Attempt to use 'net helpmsg' to get a description for the error.
Dim oShell
Set oShell = CreateObject("WScript.Shell")
If Err = 0 Then
Dim oExec
Set oExec = oShell.Exec("net helpmsg " &amp; (lErr And LoWordMask))

Dim strMessage, i
Do
strMessage = oExec.stdout.ReadLine()
i = i + 1
Loop While (Len(strMessage) = 0) And (i &lt; 5)

strErr = strMessage
End If
End If
End If

GetErrorString = vbCrLf &amp; "The error returned was: '" &amp; strErr &amp; "' (0x" &amp; Hex(lErr) &amp; ")"
End Function

'******************************************************************************
Sub CreateEvent(lngEventID, lngEventType, strMessage)
'
' Purpose: To create a MOM event
'
' Arguments: lngEventID, the event ID
' lngEventType, the event type (see values at top of file)
' strMessage, the message text for the event
'
oAPI.LogScriptEvent "AD Validate Server Trust Event", lngEventID, lngEventType, strMessage
End Sub

Call Main()

</Script></Contents>
<Unicode>1</Unicode>
</File>
</Files>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
<InputType>System!System.Event.Data</InputType>
</ProbeActionModuleType>