【发布时间】:2014-03-10 21:30:37
【问题描述】:
我得到了一个修改后的 ls:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char **argv){
char command[50];
strcpy(command,"/bin/ls ");
gid_t egid = getegid();
setregid(egid, egid);
if(argc > 1) {
if(strlen(argv[1]) > 40) {
printf("The command you have given is too long, try again.\n");
return 0;
}
strcat(command,argv[1]);
system(command);
}else{
printf("This is a special NSA-modified 'ls' program. See 'man ls' for further details on how to use it.\n");
printf("USAGE: %s [flags & files]\n",argv[0]);
}
return 0;
}
我必须执行一个名为 get-code 的程序,但我没有权限在没有 ls 的情况下执行它(修改后的 ls 与 get-code 程序位于同一目录中),那么我该如何执行使用修改后的 ls 获取代码程序?
有人可以帮我吗?
【问题讨论】:
-
system()将执行command,就好像它被输入到 shell 中一样。你需要找到一种方法来欺骗system()在ls之后运行另一个命令。 -
这是我已经发现的,但我不知道有什么额外的命令@rmartinjak
-
"我必须执行一个名为 get-code 的程序"
-
已经做了 ./ls -exec /some-maps/get-code {} \;就像我说的我没有其他权限,只有 ls 是可以使用 root 权限打开的,我不知道如何使用 ls @rmartinjak 执行
-
这是作业吗?这看起来像是正确检查输入是否有特殊字符(清理输入)的练习,因为结果是违反安全性的。作为提示,您可以将参数放在引号中,然后您键入的任何字符都将包含在参数中,即使是对 shell 具有特殊含义的字符。
标签: c linux terminal privileges ls