Android shell作为另一个用户问题执行命令
我试图以系统用户的身份执行以下命令Android shell作为另一个用户问题执行命令,android,shell,Android,Shell,我试图以系统用户的身份执行以下命令 su - system -c "ls -l /" 这是输出 shell@android:/data/xxxx/xxxx # su - system -c "ls -l /" su - system -c "ls -l /" SuperSU - Copyright (C) 2012 - Chainfire 这是否意味着在安卓系统中,我不能使用shell作为另一个用户执行命令?还是su二进制中的一个问题 如何让shell作为另一个用户执行?我也尝试过为这个创建
su - system -c "ls -l /"
这是输出
shell@android:/data/xxxx/xxxx # su - system -c "ls -l /"
su - system -c "ls -l /"
SuperSU - Copyright (C) 2012 - Chainfire
这是否意味着在安卓系统中,我不能使用shell作为另一个用户执行命令?还是su二进制中的一个问题
如何让shell作为另一个用户执行?我也尝试过为这个创建一个shell脚本,但仍然是相同的输出。请给我一些建议
设备已根目录。问题是SuperSU包含与标准GNU su-one不兼容的su二进制文件 如果你用NDK为android编译su,并替换二进制文件,一切正常 您可以使用以下代码:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <pwd.h>
#include <sys/types.h>
#include <string.h>
#include <errno.h>
int main (int ac, char **av, char **env) {
int iret;
if (ac == 1) { // Run /bin/bash as root
iret = setuid(0);
if (iret == -1) {
fprintf(stderr, "This binary is u-s, use chmod u+s %s as root.\n", av[0]);
exit(-1);
}
strcpy(av[0], "/bin/bash");
iret = execve(av[0], av, env);
if (iret == -1) {
fprintf(stderr, "Can't execute a shell.\n");
exit(-1);
}
} else {
struct passwd *pswd = getpwnam(av[1]);
//printf("%d\n", pswd->pw_uid);
if (pswd == NULL) {
fprintf(stderr, "User %s does not exist.\n", av[1]);
exit(-1);
}
iret = setuid(pswd->pw_uid);
if (iret == -1) {
fprintf(stderr, "This binary is u-s, use chmod u+s %s as root.\n", av[0]);
exit(-1);
}
iret = execve(av[2], (char **)&av[2], env);
if (iret == -1) {
fprintf(stderr, "%s\n", strerror(errno));
exit(-1);
}
}
return 0;
}
编译它并将所有者更改为root。然后作为root用户运行chmod u+s./su。最后,作为普通用户运行您的命令:
$./su系统/bin/bash-c ls-l/