跟踪本地用户帐户以进行安全审计

跟踪本地用户帐户以进行安全审计

我想编制一份来自网络上所有服务器的本地用户帐户列表。这将包括域和非域 W2K3 计算机。运行 net user 并将结果传输到文件的脚本?任何帮助都非常感谢。谢谢

答案1

快速而粗略的方法

你需要Microsoft 的 PsExec使此脚本正常工作。我假设您可以使用相同的用户名和密码连接到非域成员和域成员计算机。如果这不可能,请告诉我,我会稍微修改一下脚本。

将机器名称列表放入 machines.txt 并运行:

@echo off

for /F "delims=" %%i in (machines.txt) do (
 psexec \\%%i NET USER > %%i.txt
)

您最终会得到一堆格式为 computer-name.txt 的文本文件,每台计算机上的输出都是“NET USER”。

Fancy(tm) 方式

这样做非常草率,而且输出结果解析起来也相当困难。下面是 VBScript 中更漂亮的脚本:

Option Explicit

Dim dictGroupsToIgnore, dictUsersToIgnore, objNetwork, strComputer
Dim colUsers, colGroups, objGroup, objUser

' Debugging
Const DEBUGGING = True

' Constants for comparison of accounts to ignore list
Const MATCH_EXACT = 1
Const MATCH_LEFT = 2

Set dictGroupsToIgnore = CreateObject("Scripting.Dictionary")
' dictGroupsToIgnore.Add "Name of group you want to ignore (matching left only)", MATCH_LEFT
' dictGroupsToIgnore.Add "Name of group you want to ignore", MATCH_EXACT

' Accounts to ignore during copying
Set dictUsersToIgnore = CreateObject("Scripting.Dictionary")
' dictUsersToIgnore.Add "Name of user you want to ignore (matching left only)", MATCH_LEFT
' dictUsersToIgnore.Add "Name of user you want to ignore", MATCH_EXACT

' Should this account be ignored
Function IgnoreObject(Name, dictNames)
    Dim strToIgnore

    IgnoreObject = False

    For Each strToIgnore in dictNames

        ' Match Exact
        If (dictNames.Item(strToIgnore) = MATCH_EXACT) and (UCase(Name) = UCase(strToIgnore)) Then
            IgnoreObject = True
            Exit Function
        End If

        ' Match left
        If (dictNames.Item(strToIgnore) = MATCH_LEFT) and (Left(UCase(Name), Len(strToIgnore)) = UCase(strToIgnore)) Then
            IgnoreObject = True
            Exit Function
        End If

    Next' strToIgnore
End Function

' Main

Set objNetwork = CreateObject("Wscript.Network")

While NOT WScript.StdIn.AtEndOfStream

    strComputer = WScript.StdIn.ReadLine

    ' Get accounts on source computer and loop through them, copying as necessary
    Set colUsers = GetObject("WinNT://" & strComputer)
    colUsers.Filter = Array("user")

    For Each objUser In colUsers
        If IgnoreObject(objUser.Name, dictUsersToIgnore) = False Then
            WScript.Echo strComputer & Chr(9) & "user" & Chr(9) & objUser.Name
        End If
    Next ' objUser

    ' Get groups on source computer and loop through them, copying as necessary
    Set colGroups = GetObject("WinNT://" & strComputer)
    colGroups.Filter = Array("group")

    ' Put user into destination groups
    For Each objGroup In colGroups
        If IgnoreObject(objGroup.Name, dictGroupsToIgnore) = False then
            For Each objUser In objGroup.Members
                WScript.Echo strComputer & Chr(9) & "group" & Chr(9) & objGroup.Name & Chr(9) & "member" & Chr(9) & objUser.Name
            Next ' objUser
        End If
    Next 'objGroup
Wend ' WScript.StdIn.AtEndOfStream

我还添加了一些“忽略”群组或用户的功能。

  • 将不应报告的任何组名添加到 dictGroupsToIgnore 列表中(如脚本中所示)。MATCH_EXACT 表示组名完全匹配。MATCH_LEFT 表示仅匹配组名的最左侧部分(即,假设名称匹配后有一个“*”)。

  • 将不应报告的任何用户名添加到 dictUsersToIgnore 列表中(如脚本中所示)。MATCH_EXACT 和 MATCH_LEFT 与 dictGroupsToIgnores 列表具有相同的含义(即“IUSR_”与 MATCH_LEFT 意味着不会报告以“IUSR_”开头的任何用户帐户)。

调用此脚本将输入从文本文件重定向到文本文件(即“cscript script-name.vbs < machines.txt > report.txt”),您将获得以下格式的 TAB 分隔输出:

computer_name   user   username
computer_name   group  groupname   member   member_1_name
computer_name   group  groupname   member   member_2_name
computer_name   group  groupname   member   member_3_name
...

您可能不需要群组信息,但稍后可以轻松过滤掉。

如果您需要使用不同的凭据连接到每台机器,请告诉我,我会稍微修改一下脚本。

答案2

我记得几年前做过类似的事情。大概有 5 种方法可以通过脚本轻松完成此操作,但是最近我被介绍给 SYDI,我建议您查看一下,它可能比本地用户审计跟踪更有用。

http://sydiproject.com/tools/sydi-audit-localgroups/

站点摘要:使用场景您可能想要跟踪组织中有多少本地管理员,也许有些用户被“临时”置于本地管理员组中,但现在已获得其提供的所有权限。即使您的组织尚未禁止本地管理访问,您仍可能希望能够清楚地看到哪些用户被授予此访问权限。Power Users 组可以是您想要监视的另一个组。

如果您拥有标准化环境,则客户端上的组结构应该都相同。您可以使用该工具查找任何不应该存在的附加组。

使用脚本 与许多其他 SYDI 工具一样,此脚本用 vbscript 编写,旨在从 cscript.exe 运行。要使用它,您需要提供一个参数,其中包含 SYDI 服务器输出文件的路径:

Cscript.exe sydi-audit-localgroups.vbs -xN:\SYDI\Output

让我知道它是如何工作的

最好的,尼克

相关内容