Windows 和系统进程

发布于 2024-08-25 02:16:45 字数 295 浏览 3 评论 0原文

注意:我已经在超级用户上以类似的格式问过这个问题,但看起来它可能更适合这里。 它肯定也与编程有关,因为它涉及 Win32 API、一般 Windows 和进程管理的部分内容。

因此,有些进程无法使用 taskkill 终止 - 一般而言是系统进程。但也有,例如我的防病毒程序,使其自身“不可终止”。

  • Windows下如何访问和主要终止系统进程? (微软的kill.exe不起作用)

  • 防病毒程序等进程如何保护自身?那么,如何才能再次关闭它们呢?

Note: I've asked this question in a similiar format on superuser but it seems like it may fit here on SO better.
It definitely also is about programming as it concerns parts of the Win32 API, Windows in general and process management.

So there are these processes that can't be terminated with taskkill - system processes in general. But there also is, for example my Anti Virus program that makes itself "unterminateable".

  • How can I access and mainly terminate system processes under windows? (kill.exe by Microsoft doesn't work)

  • How do processes like anti-virus programs protect themselves? How can you turn them off again, then?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜光 2024-09-01 02:16:45

您将需要 API 挂钩来防止进程终止。 API 挂钩并不容易,因为它需要系统范围的 dll 注入和内存编辑或设备驱动程序。阅读本文来了解一下。

幸运的是,有现有的库,例如这个,不幸的是我认为它现在是共享软件。我还发现了这个,你可能可以在谷歌上找到更多免费软件的东西。

要回答您的第一个问题,终止系统进程相当简单。在 C# 中,使用 Process.Kill 方法您可以终止系统进程并导致蓝屏如果从 Windows 系统服务执行此操作,至少在 Windows 7 上(我通过惨痛的教训才了解到这一点...)。使用 TerminateProcess() 函数执行此操作仅当您启用某些权限时,从服务外部才能工作: http://www.codase .com/search/call?name=AdjustTokenPrivileges - 如果我没记错的话,您需要启用 SE_DEBUG_NAME。

要关闭您的防病毒软件,他们通常有一个菜单:)。要强制终止它们,您必须使用它们不挂钩的终止方法。 此页面描述了很多内容。

这是一个可以终止您想要的进程的示例,假设所使用的 API 函数没有被挂钩。 除非您知道自己在做什么,否则请勿运行此程序,因为它可能会导致蓝屏!

#include <stdio.h>
#include <windows.h>
#include <process.h>
#include <iostream>

using namespace std;

int EnablePrivilege(const char * lpPrivilegeName, BOOL bEnable)
{
    TOKEN_PRIVILEGES Privileges;
    ZeroMemory(&Privileges, sizeof(Privileges));

    HANDLE hToken;
    BOOL bResult;

    if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
        return 1;
    Privileges.PrivilegeCount = 1;
    Privileges.Privileges[0].Attributes = (bEnable) ? SE_PRIVILEGE_ENABLED : 0;
    if (!LookupPrivilegeValue(NULL, lpPrivilegeName,
                               &Privileges.Privileges[0].Luid))
    {


        CloseHandle(hToken);
        return 2;
    }
    bResult = AdjustTokenPrivileges(hToken, FALSE, &Privileges, sizeof(Privileges), NULL, NULL);
    CloseHandle(hToken);
    return bResult;
}

int main()
{
    cout << EnablePrivilege(SE_DEBUG_NAME, TRUE);

    HANDLE procHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, 500); // replace 500 with the PID of the process you want to terminate - can be taken from taskmanager.

    TerminateProcess(procHandle, 0);

    CloseHandle(procHandle);
}

You will need API hooking to guard your process against termination. API hooking is not easy, as it requires either system-wide dll injection and memory editing or a device driver. Read this to get an idea.

Luckily, there are existing libraries out there, like this one, which I think is shareware now unfortunately. I also found this, and you can probably find more freeware stuff on google.

To answer your first question, terminating system processes is fairly easy. In C# using the Process.Kill method you can terminate system processes and cause a blue screen if doing it from a windows system service, at least on Windows 7 (I learned this the hard way...). Doing it using the TerminateProcess() function from outside a service will only work if you enable certain permissions: http://www.codase.com/search/call?name=AdjustTokenPrivileges - if I'm not mistaken you need to enable SE_DEBUG_NAME.

To turn off your antivirus, well, they usually have a menu for that :). To forcefully terminate them, you'll have to use a termination method that they don't hook. This page describes a lot.

Here's a sample that can terminate the processes you want, supposing the used API functions aren't hooked. DO NOT RUN THIS UNLESS YOU KNOW WHAT YOU'RE DOING AS IT CAN CAUSE A BLUE SCREEN!

#include <stdio.h>
#include <windows.h>
#include <process.h>
#include <iostream>

using namespace std;

int EnablePrivilege(const char * lpPrivilegeName, BOOL bEnable)
{
    TOKEN_PRIVILEGES Privileges;
    ZeroMemory(&Privileges, sizeof(Privileges));

    HANDLE hToken;
    BOOL bResult;

    if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
        return 1;
    Privileges.PrivilegeCount = 1;
    Privileges.Privileges[0].Attributes = (bEnable) ? SE_PRIVILEGE_ENABLED : 0;
    if (!LookupPrivilegeValue(NULL, lpPrivilegeName,
                               &Privileges.Privileges[0].Luid))
    {


        CloseHandle(hToken);
        return 2;
    }
    bResult = AdjustTokenPrivileges(hToken, FALSE, &Privileges, sizeof(Privileges), NULL, NULL);
    CloseHandle(hToken);
    return bResult;
}

int main()
{
    cout << EnablePrivilege(SE_DEBUG_NAME, TRUE);

    HANDLE procHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, 500); // replace 500 with the PID of the process you want to terminate - can be taken from taskmanager.

    TerminateProcess(procHandle, 0);

    CloseHandle(procHandle);
}
伴梦长久 2024-09-01 02:16:45

如果以“正常”方式终止进程不起作用,则需要采取更极端的措施。您可以尝试提高安全级别,但这可能不起作用。

这里有两种相当暴力的方法,您可以尝试,都要求您能够成功注入目标应用程序(NT 4 上的失败率为 2%,XP 上的失败率为 5%,Vista、Windows 7 等上的失败率更高) )。

并在注入的 DLL 的 DLLMain 中执行以下操作之一:

  • 您可以尝试使用 CreateRemoteThread() 将 DLL 注入应用程序,
  • 注册一个异常处理程序,然后引发一个异常,您将使用异常处理程序捕获该异常。在异常处理程序中导致另一个异常(和/或堆栈溢出)。异常处理过程中出现异常会导致程序立即死亡。
void KillApp()
{
    int *p;

    p = NULL;

    __try
    {
            *b = 0;
    }
    __except(EXCEPTION_EXECUTE_HANDLER)
    {
        killApp();
    }
}

大量有关使用 CreateRemoteThread 注入的文章

If terminating a process the "normal" way doesn't work, then more extreme measures are required. You can try elevating your security level, but that may not work.

Here are two rather brute force methods you can try, both requiring you to be able to successfully inject into the target application (2% failure rate on NT 4, 5% failure rate on XP, higher failure rate on Vista, Windows 7, etc).

You could try injecting a DLL into the application using CreateRemoteThread() and in the DLLMain for the injected DLL do one of the following:

  • Call ExitProcess(exitCode);
  • Register an exception handler, then cause an exception which you will catch with your exception handler. In your exception handler cause another exception (and/or stackoverflow). Exception during exception handling will cause instant program death.
void KillApp()
{
    int *p;

    p = NULL;

    __try
    {
            *b = 0;
    }
    __except(EXCEPTION_EXECUTE_HANDLER)
    {
        killApp();
    }
}

Plenty of articles on injecting using CreateRemoteThread

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文