我正在寻找一种方法来查询活动目录或短信或一些东西,所以我可以得到已经login到多台服务器的Windows服务器的用户列表。 这将像在Linux上检查lastlog文件。 除了用户名外,我不需要时间或其他任何东西。
一些输出如下所示:SERVERNAME:shatnerw,nimoyl,kelleyd,
任何关于这个的意见都会很棒。 即使是“在VB脚本中使用这个函数”。
谢谢你,ablackhat
编辑:到目前为止,我发现信息是在HKEY_LOCAL_MACHINE \ SOFTWARE \微软\的Windows NT \ CurrentVersion \ ProfileList的registry。 它有一个很好的guid。 现在我需要找出一种方法来远程查询。
如果你只是想要个人资料列表,PowerShell可能是你最好的select。
$Server = 'RemoteServer' $Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $Server)
这将实例化$ reg作为HKLM中远程registry对象的持有者。 为了得到你想要的位:
$ProfileList = $Reg.OpenSubKey('SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList')
这将使用configuration文件本身的子项来填充$ ProfileList。 然后提取用户列表:
Write-Host "`n$Server: " -nonewline ForEach ($SID in $ProfileList.GetValueNames()) { $ProfileKey = $ProfileList.OpenSubKey($SID) # Get the ProfileImagePath key $ProfileKey.GetValue("ProfileImagePath") # Break the path up into an array, using \ as the delimiter $PathBits = $ProfileKey.Split("\") # The last element of the array is our user, find the last element $LastIndex = $PathBits.Count - 1 # Dump the last element to something useful $User = $PathBits[$LastIndex] # Output the user write-host " $User" -nonewline }
或者接近于此。 这是我的头顶。
创build适用于要监视的服务器的GPO,并在“计算机configuration”>“策略”>“Windows设置”>“安全设置”>“本地策略”>“审核策略”下,根据您的要求在成功和/或失败上启用“审核login事件”
如果您正在监视的服务器是DC,则不要启用审核帐户login事件。 用户使用其域用户帐户login时,会在域控制器上生成帐户login事件,以便您看到太多事件。
简而言之,当用户login到计算机时创build“login事件”,当用户使用他们的域用户帐户login时,在域控制器上创build“帐户login事件”,但login到的计算机交互式地生成帐户login事件。 这是你想监视的。 再加上EventForwarding(对于你的服务器),你可以监视你自己的事件日志,或者使用SNMP陷阱来捕获使用evntwin.exe的事件并将它们转发到SNMP监视/警报系统。
在用户工作站上,我实际上使用了一个VBScript,它打开一个隐藏的IE进程到一个安装了PHP / MySQL的内部服务器,它只是将用户名转储到数据库中。 VBScript:
Set oIE = CreateObject("InternetExplorer.Application") Set oNet = CreateObject("WScript.Network") sComputerName = oNet.ComputerName sUsername = oNet.UserName oIE.Navigate "http://intranet/logon/logon.php?un=" & Trim(sUsername) & "&ma=" & Trim(sComputerName) Do While oIE.Busy = True WScript.Sleep 500 Loop oIE.Quit Set oIE = Nothing WScript.Quit
显然你需要Web服务器,PHP和MySQL数据库,如果你感兴趣的话,请告诉我,我也会把这些数据挖出来。 您也可以使用GPO来应用此function,但有一点需要注意,它只能在GPO的“用户configuration”部分下运行。
那么,那里有两个select。 HTH。
编辑:这是上面提到的PHP脚本。 真的很简单。
mysql_connect('mysqlserver', 'username', 'password'); mysql_select_db('database'); $un = trim(addslashes($_GET['un'])); $ma = trim(addslashes($_GET['ma'])); mysql_query("INSERT INTO userlist (user_logon_name, machine_name, logon_time) VALUES ('$un', '$ma', now())"); echo "User ". $_GET['un']. " logged on.";
干杯