提升 mach_inject 的使用权限

发布于 2024-08-01 23:27:43 字数 51 浏览 2 评论 0原文

如何使用授权 API 将用户权限提升为 root,以便可以使用 mach_inject?

How do you elevate user rights to root using the Authorization API so that it is possible to use mach_inject?

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

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

发布评论

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

评论(3

蝶…霜飞 2024-08-08 23:27:44

对于那些希望在 macOS 10.11 及更高版本上使用 mach_inject(内部使用 task_for_pid())的用户,您需要添加适当的权限才能使其工作。 然后用 sudo 运行。 请参阅下面的示例: https://gist.github.com/attilathedud/e58917c9fd095a84fd5bbfb31674be05

/*
    Full explanation is available here: http://attilathedud.me/mac-os-x-el-capitan-10-11-and-task_for_pid/
*/

/*
    To compile, create a file called Info.plist with the following content:

    <?xml version="1.0" encoding="UTF-8"?>  
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">  
    <plist version="1.0">  
    <dict>  
        <key>SecTaskAccess</key>
        <array>
            <string>allowed</string>
        </array>
    </dict>  
    </plist>  

    When compiling, use -sectcreate to create a section for the plist:

    gcc task_for_pid.c -sectcreate __TEXT __info_plist ./Info.plist -o task_for_pid  

    Run using sudo ./task_for_pid _some_pid
 */

/*!
*   task_for_pid.c: Given a pid in argv[ 1 ], return the mach task port.
*/
#include <stdio.h>
#include <stdlib.h>
#include <mach/mach.h>

int main( int argc, char** argv )
{
    kern_return_t kern_return = 0;

    mach_port_t task = 0;

    long int pid = 0;

    char *endptr = NULL;

    if( argc < 2 ) 
    {
        return 0;
    }

    pid = strtol( argv[ 1 ], &endptr, 10 );

    kern_return = task_for_pid( mach_task_self(), pid, &task );
    if( kern_return != KERN_SUCCESS ) 
    {
        printf( "task_for_pid failed: %s\n", mach_error_string( kern_return ) );
        return 0;
    }

    printf( "%u\n", task );

    return 0;
}

您可以只要至少设置了该权利并且您拥有正确的权限,就可以使用终端程序和 cocoa 应用程序执行此操作。

For those who wish to use mach_inject (which uses task_for_pid() internally) for macOS 10.11 and above, you will need to add the proper entitlement for this to work. Then run with sudo. See the example below: https://gist.github.com/attilathedud/e58917c9fd095a84fd5bbfb31674be05

/*
    Full explanation is available here: http://attilathedud.me/mac-os-x-el-capitan-10-11-and-task_for_pid/
*/

/*
    To compile, create a file called Info.plist with the following content:

    <?xml version="1.0" encoding="UTF-8"?>  
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">  
    <plist version="1.0">  
    <dict>  
        <key>SecTaskAccess</key>
        <array>
            <string>allowed</string>
        </array>
    </dict>  
    </plist>  

    When compiling, use -sectcreate to create a section for the plist:

    gcc task_for_pid.c -sectcreate __TEXT __info_plist ./Info.plist -o task_for_pid  

    Run using sudo ./task_for_pid _some_pid
 */

/*!
*   task_for_pid.c: Given a pid in argv[ 1 ], return the mach task port.
*/
#include <stdio.h>
#include <stdlib.h>
#include <mach/mach.h>

int main( int argc, char** argv )
{
    kern_return_t kern_return = 0;

    mach_port_t task = 0;

    long int pid = 0;

    char *endptr = NULL;

    if( argc < 2 ) 
    {
        return 0;
    }

    pid = strtol( argv[ 1 ], &endptr, 10 );

    kern_return = task_for_pid( mach_task_self(), pid, &task );
    if( kern_return != KERN_SUCCESS ) 
    {
        printf( "task_for_pid failed: %s\n", mach_error_string( kern_return ) );
        return 0;
    }

    printf( "%u\n", task );

    return 0;
}

You can do this with both terminal programs and cocoa apps as long as at least that entitlement is set and you have the right privileges.

浮光之海 2024-08-08 23:27:43

您无需成为 root 即可使用 mach_inject; 相反,您需要签署您的代码。 仅出于测试目的(在 10.4/10.5 中),您还可以使应用程序 setgid procmod。

有关详细信息,请参阅 TN2206

You don't need to be root to use mach_inject; instead, you need to sign your code. For testing purposes only (and in 10.4/10.5) you can also make your application setgid procmod.

See TN2206 for more information.

一抹微笑 2024-08-08 23:27:43

老问题,但答案不正确:

除非您拥有 pid/task,否则您实际上需要成为 root 或成为 procmod 的成员。 在 OS X 中,这与代码签名关系不大。 Mach_inject/Mach_star 由Mach trap task_for_pid() 使用,需要上述权限。 在 iOS 中,您还需要相应的权利(task_for_pid-allow),这就是代码签名派上用场的地方(使用 ldid 进行自签名)。

Old question, but incorrect answer:

Unless you own the pid/task, you actually do need to EITHER be root or be a member of procmod. In OS X, this has little to do with code signing. Mach_inject/Mach_star use by the Mach trap task_for_pid(), which requires the above privileges. In iOS , you also need the corresponding entitlement (task_for_pid-allow), which is where code signing would come in handy (using ldid for self signing).

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