【问题标题】:how to use this in terminal:如何在终端中使用它:
【发布时间】:2014-03-10 22:37:19
【问题描述】:

我有一个修改后的 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 程序位于同一目录中),所以我该如何欺骗system() 使用修改后的 ls 执行获取代码?

【问题讨论】:

  • 提示:system 总是将其字符串传递给/bin/sh
  • 您是在问如何使用该程序运行任意代码?您必须选择一个 argv[1] 以便 command 在 ls 之后执行其他操作。
  • 上面的代码是修改后的 ls 程序的代码,它将以 root 权限运行,但是我没有运行我需要运行的 get-code 程序的权限......但我没有知道如何使用这个 ls 程序来执行 get-code 程序......你能帮忙吗?我已经忙了一个星期了
  • 这是为了上课吗?为什么不问问你的教授?这是一个相对简单的问题,如果您遇到困难,应该让您的教授知道。
  • 教授没有回应,因为这是在 linux 上完成的“黑客”作业,网络黑客课程已经完成并且是同类中最好的,但其余的在这比我(可能是因为他们来自更高的阶层)我今年 17 岁,是荷兰人,我现在确实很挣扎

标签: c terminal


【解决方案1】:

关键是这一行:strcat(command,argv[1]); 你怎样才能让命令不仅仅是 ls?

要在同一行执行多个命令,可以用; 字符分隔它们。所以echo "hello"; echo "world" 会让shell 一个接一个地执行这两个命令。知道了,怎么让system(command);ls之后执行get-code

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-16
    • 2014-07-23
    • 2011-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-20
    相关资源
    最近更新 更多