c - How to use a modified ls program to execute another program? -
i got modified 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 have given long, try again.\n"); return 0; } strcat(command,argv[1]); system(command); }else{ printf("this special nsa-modified 'ls' program. see 'man ls' further details on how use it.\n"); printf("usage: %s [flags & files]\n",argv[0]); } return 0; } i have execute program called get-code don't have privileges execute without ls (the modified ls in same directory get-code program), how can execute get-code program using modified ls?
can me?
glad teacher said allowed. have bigger problem real-life issue -- trying exploit security hole, , that's not idea in real world.
this exercise designed show how careful have when writing code don't open big security holes in system. "ls" command not have option exec program. program adds absolutely have in arg1 end of string "/bin/ls". if know shell, know ";" character separates 2 commands. can think of way set argument has semi-colon , command want run?
Comments
Post a Comment