AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 531364
Accepted
derobert
derobert
Asked: 2013-08-16 14:09:09 +0800 CST2013-08-16 14:09:09 +0800 CST 2013-08-16 14:09:09 +0800 CST

让当前登录的用户进入 Windows XP Pro 系统

  • 772

我们有一台 XP 机器,它在清晨运行计划任务,不幸的是,它必须登录到某个用户的桌面才能工作。不幸的是,该用户有时会被注销——要么是管理员登录(忘记重新登录正确的用户),要么是重新启动以应用安全更新等。

我想让 Nagios 监视当前登录的用户,以确认它是正确的。Nagios 在 Linux 上运行。

到目前为止,我已经为当前用户寻找了一个 SNMP 变量;我没有运气。我尝试使用 grep'd 获取用户名,并在登录前和登录后进行了操作,并检查了差异,但没有发现任何用处。snmpbulkwalk -m all -v2c -c community machine

我检查了net命令(来自 Samba),但我没有看到任何东西——尽管我承认我可能错过了一些东西。各种session选项似乎只显示net会话(即使我使用我的域管理员帐户)。

windows
  • 2 2 个回答
  • 6295 Views

2 个回答

  • Voted
  1. Best Answer
    Ryan Ries
    2013-08-16T15:13:35+08:002013-08-16T15:13:35+08:00

    %WINDIR%\System32\dllcache\query.exe session将为您提供 WinXP 上所有当前登录用户的列表。

    出于某种原因,query.exe 不在我的 WinXP 测试机器上的路径环境变量中,所以我指定了整个路径。

    询问

    如果您需要能够通过 RPC/DCOM 远程获取此信息的东西,请查看我写的一些内容:

    http://myotherpcisacloud.com/post/2013/01/16/Usersexe-v1003.aspx

    http://www.myotherpcisacloud.com/post/2013/01/13/Getting-RDP-Sessions-with-Client-Computer-Name.aspx

    顺便说一句,您需要尽快退出 XP。它很老了。

    编辑:好的,我会给你另一个选择,因为这些都没有帮助你。您想使用您的 Linux 机器通过网络查询这台 WinXP 机器。您想使用 WMI。您已找到适用于 Linux 的 WMI 客户端。到目前为止,一切都很好。

    这将使您当前通过 WMI WQL 查询登录本地或远程计算机的用户。我在 Powershell 中写了这个。抱歉,我不会(阅读:不能)为您将其转换为 Perl 或 Bash,但只要您可以执行 WQL 查询,概念仍然相同:

    $Sessions = Get-WMIObject -Query "SELECT * FROM Win32_LogonSession WHERE LogonType=2 OR LogonType=10"
    Foreach($Session In $Sessions)
    {
        If($Session -AND $Session.PSObject.Properties.Match('LogonId').Count)
        {
            Get-WMIObject -Query "Associators Of {Win32_LogonSession.LogonId=$($Session.LogonId)} WHERE AssocClass=Win32_LoggedOnUser Role=Dependent"
        }
    }
    

    LogonTypes 2 和 10 涵盖本地和远程交互会话,但不包括服务登录、网络登录或批处理登录。

    是的,您确实需要访问 WinXP 机器的权限。这不仅仅是为了匿名网络进程而咳出所有这些数据。WinXP 上的本地组不是很细化,因为 WinXP 很老了,而且它的安全性远不如现代版本的 Windows……我的意思是把你的网络监控用户放在 WinXP 机器的本地 Admins 组中可能是你最好的选择。但是,如果您仍想遵循最小权限原则,我推荐您,在这种情况下,您可以使用 WMI 控制台 wmimgmt.msc,并将权限设置为您想要分配权限的任何帐户。

    • 6
  2. derobert
    2013-08-21T13:46:28+08:002013-08-21T13:46:28+08:00

    谢谢你@Ryan Ries,这是我正在使用的实际 Perl 脚本。希望它对其他人有用。它似乎工作正常,请随时报告任何错误。如果我发现任何东西,我会尽量记住更新它。

    另外,除了将监控用户放在管理员中之外,我找不到任何方法可以在 XP 上进行这项工作。我认为这是在 XP 上执行此操作的唯一方法。

    #!/usr/bin/perl -w
    use 5.010;
    use IPC::Run qw(run);
    use Nagios::Plugin;
    use strict;
    
    my $np = Nagios::Plugin->new(
        shortname => 'check_windows_user',
        version   => '0.01',
        license   => 'Copyright 2013 Customer Relationship Metrics, LC. Based on a Powerhell program by Ryan Ries. CC-BY-SA http://creativecommons.org/licenses/by-sa/3.0/',
        usage =>
            'Usage: %s -H <host> -A <authfile> -u <user>|-s <sid> -w <threshold> -c <threshold>',
        extra => <<EXTRA
    
    Thresholds are in session counts.
    
    See http://nagiosplug.sourceforge.net/developer-guidelines.html for a
    description of the threshold format.
    EXTRA
    );
    
    $np->add_arg(
        spec     => 'host|H=s',
        help     => '-H, --host=hostname',
        required => 1,
    );
    $np->add_arg(
        spec     => 'user|u=s',
        help     => '-u, --user=username',
        required => 0,
    );
    $np->add_arg(
        spec     => 'sid|s=s',
        help     => '-s, --sid=sid',
        required => 0,
    );
    $np->add_arg(
        spec     => 'authentication_file|authentication-file|A=s',
        help     => '-A, --authentication-file=FILE',
        required => 1,
    );
    $np->add_arg(
        spec     => 'warning|w=s',
        help     => '-w, --warning=INTEGER:INTEGER',
        required => 1,
    );
    $np->add_arg(
        spec     => 'critical|c=s',
        help     => '-c, --critical=INTEGER:INTEGER',
        required => 1,
    );
    $np->getopts;
    $np->set_thresholds(
        warning  => $np->opts->warning,
        critical => $np->opts->critical
    );
    
    # setup
    local $SIG{ALRM} = sub { die "alarm timed out\n" };
    alarm 30;
    
    my $target_user = defined $np->opts->user ? lc $np->opts->user : undef;
    my $target_sid  = defined $np->opts->sid  ? lc $np->opts->sid  : undef;
    
    my @wmic = (
        'wmic',
        -A => $np->opts->authentication_file,
        ('//' . $np->opts->host));
    my $wmic_out;
    
    # get all logon ids
    my @all_logon_ids;
    run [
        @wmic,
        q{SELECT LogonId FROM Win32_LogonSession WHERE LogonType = 2 or LogonType = 10}
        ],
        \undef, \$wmic_out;
    @all_logon_ids = split("\n", $wmic_out);
    
    $all_logon_ids[0] =~ /^CLASS: Win32_LogonSession$/
        or die "Unexpected wmic result: $wmic_out";
    $all_logon_ids[1] =~ /^LogonId$/
        or die "Unexpected wmic result: $wmic_out";
    splice @all_logon_ids, 0, 2;
    
    # get user of each logon, check if matches
    my $session_count = 0;
    foreach my $logon_id (@all_logon_ids) {
        # does not seem to be a way to specify which fields we want, or
        # their order  :-(
        #
        # also, it only seems to do delimited data — pick a character that
        # isn't going to occur in the data. And unit separator is even for
        # that purpose!
        run [
            @wmic,
            '--delimiter' => "\x1F",
            qq{Associators Of {Win32_LogonSession.LogonId=$logon_id} WHERE AssocClass=Win32_LoggedOnUser Role=Dependent}
            ],
            \undef, \$wmic_out;
    
        # sessions get left in Win32_LogonSession after log out (sometimes).
        next if '' eq $wmic_out;
    
        my @tmp = split("\n", $wmic_out);
        3 == @tmp && $tmp[0] =~ /^CLASS: Win32_UserAccount$/
            or die "Unexpected associator: $wmic_out";
        my %record;
        @record{map lc, split("\x1F", $tmp[1])} = map lc,
            split("\x1F", $tmp[2]);
    
        # try to disqualify
        defined $target_user && $target_user ne $record{caption}
            and next;
        defined $target_sid && $target_sid ne $record{sid}
            and next;
    
        # qualified
        ++$session_count;
    }
    
    $np->add_message($np->check_threshold($session_count),
        "$session_count sessions");
    
    $np->nagios_exit($np->check_messages);
    

    变更日志

    • 显然,如果您通过远程桌面注销会话,并且不登录其他用户,则会话将留在 Win32_LogonSession 中,但没有任何关联。状态始终为空,因此无法以这种方式过滤。按缺乏关联进行过滤。如果没有这个两行修复,插件就会死掉(因此返回未知)。
    • 3

相关问题

  • 知道任何适用于 Windows 的快速可编写脚本的 ftp 客户端吗?[关闭]

  • 如果 Windows 服务崩溃,如何自动重新启动它?

  • 无法安排任务(访问被拒绝)

  • 物理机重启时自动重启虚拟机(VMWare)

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve