#if 0 shc Version 4.0.3, Generic Shell Script Compiler GNU GPL Version 3 Md Jahidul Hamid shc -rf motd.sh #endif static char data [] = #define msg1_z 65 #define msg1 ((&data[10])) "\226\246\074\257\217\075\136\317\366\063\227\333\062\046\235\223" "\102\136\201\312\076\157\273\022\140\022\321\165\330\333\320\322" "\045\204\147\077\247\350\225\074\122\114\213\223\360\215\113\117" "\177\033\131\013\150\140\130\327\172\203\005\214\173\231\245\377" "\057\110\041\216\231\344\035\031\202\163\210\371\150\355\254\220" "\365\362\156\075" #define rlax_z 1 #define rlax ((&data[84])) "\106" #define chk1_z 22 #define chk1 ((&data[90])) "\133\012\007\156\242\037\160\252\127\164\221\274\156\102\344\022" "\341\236\106\157\002\161\306\115\105\317\116" #define msg2_z 19 #define msg2 ((&data[112])) "\326\030\075\132\235\061\040\014\233\311\055\122\260\215\110\126" "\100\320\263\326" #define opts_z 1 #define opts ((&data[132])) "\265" #define date_z 1 #define date ((&data[133])) "\032" #define inlo_z 3 #define inlo ((&data[134])) "\227\323\260" #define shll_z 39 #define shll ((&data[140])) "\051\077\162\213\054\104\176\005\005\124\101\231\334\343\144\325" "\306\254\057\157\377\002\301\355\037\223\117\065\241\367\230\001" "\311\040\333\367\333\061\237\377\277\057" #define xecc_z 15 #define xecc ((&data[182])) "\241\177\375\110\123\131\177\214\360\023\024\272\225\327\241\213" "\235\341" #define text_z 2143 #define text ((&data[655])) "\252\111\253\105\117\364\034\004\314\060\027\164\073\136\025\256" "\222\142\261\273\242\043\041\226\050\303\025\046\146\360\056\021" "\071\331\127\211\315\164\215\232\244\244\016\340\002\043\216\224" "\206\100\117\051\144\161\277\215\064\325\263\233\305\342\255\377" "\274\004\210\212\170\025\044\035\272\062\375\274\126\214\121\335" "\314\240\006\061\021\306\276\105\233\161\341\141\124\216\141\020" "\223\352\232\013\377\276\051\272\361\047\166\110\263\307\045\200" "\150\054\261\171\362\160\277\216\342\241\360\066\057\121\106\302" "\073\340\316\073\236\370\365\220\037\154\330\323\063\375\124\234" "\051\006\025\034\166\325\253\130\167\233\216\246\354\324\151\050" "\264\070\143\123\060\131\343\120\305\274\043\371\272\167\225\343" "\176\253\000\364\201\253\114\370\106\333\237\063\260\010\134\144" "\101\300\270\162\031\234\302\337\130\346\331\023\136\156\366\334" "\032\367\320\233\243\035\223\352\371\063\035\251\074\172\016\175" "\072\306\357\124\143\262\064\274\230\015\317\366\173\306\323\226" "\275\243\061\140\301\305\113\272\370\151\143\064\343\161\262\036" "\070\241\162\233\124\246\127\354\263\047\343\057\355\266\305\253" "\132\367\014\033\275\127\326\265\300\071\352\243\253\234\301\344" "\076\064\177\223\333\327\177\217\377\143\277\354\031\205\230\163" "\174\244\217\071\374\145\357\274\237\332\140\113\167\042\057\266" "\127\256\111\062\206\310\301\205\054\201\162\105\006\012\271\202" "\257\110\274\253\256\254\150\115\206\310\230\375\353\307\264\102" "\166\375\165\375\306\067\203\362\270\365\070\276\000\361\101\257" "\071\375\132\347\251\302\065\060\213\315\056\167\225\342\271\014" "\340\056\012\246\146\215\231\036\202\321\334\203\303\035\062\374" "\033\215\344\304\120\031\365\333\347\043\122\175\006\014\212\346" "\073\224\215\241\041\046\300\244\370\234\047\273\272\131\270\325" "\347\234\232\067\266\217\023\236\263\146\033\271\162\246\237\256" "\072\055\120\134\124\020\000\114\255\050\146\376\055\363\021\044" "\317\141\111\001\354\304\204\242\006\364\251\062\152\175\344\123" "\223\333\301\017\366\056\045\246\124\221\303\037\057\065\016\111" "\175\365\326\207\305\016\344\314\346\022\307\204\020\344\344\140" "\015\053\222\262\262\024\367\161\327\352\233\273\006\116\105\125" "\170\362\220\277\302\251\076\172\126\070\144\250\130\054\013\206" "\365\025\100\233\012\147\366\204\010\335\253\327\135\134\274\102" "\257\132\112\274\305\253\077\153\044\120\336\007\251\206\132\221" "\277\342\065\336\103\275\025\250\074\222\221\372\246\054\312\333" "\153\010\170\314\307\340\034\242\105\147\260\010\163\305\241\323" "\067\162\056\070\027\220\336\372\120\375\116\377\177\162\203\071" "\155\223\306\006\351\113\363\107\047\144\156\372\371\272\354\140" "\147\360\103\056\323\354\217\240\075\357\365\144\321\132\335\333" "\112\344\163\265\021\101\377\012\100\171\322\115\033\221\103\375" "\347\060\232\332\320\360\326\210\351\306\115\372\360\162\102\047" "\123\313\201\211\271\017\133\220\323\075\325\010\317\357\104\334" "\354\016\027\240\252\216\160\337\107\321\252\135\246\272\175\112" "\145\146\215\241\223\341\353\050\361\201\052\340\115\163\340\055" "\007\355\015\332\340\114\022\027\115\255\310\055\272\331\120\305" "\216\256\347\325\335\013\220\071\167\217\115\142\001\221\316\305" "\263\250\221\266\305\114\051\241\352\013\023\030\125\312\061\356" "\341\254\036\356\243\102\256\142\206\017\013\124\034\202\210\366" "\200\175\326\374\376\073\023\212\273\226\346\257\177\251\354\132" "\251\025\354\121\042\255\362\125\375\353\243\263\300\056\307\112" "\110\344\131\024\024\023\153\244\220\155\360\201\155\310\222\162" "\050\376\041\027\372\232\252\264\223\127\154\101\253\112\025\057" "\030\072\025\104\274\125\273\321\263\240\045\007\332\227\046\050" "\300\313\222\357\335\104\173\370\140\003\352\176\157\207\243\355" "\073\105\340\270\312\212\133\027\171\250\307\163\045\057\015\270" "\120\062\052\351\346\301\346\107\256\266\226\356\223\021\126\341" "\063\347\141\375\144\361\044\312\332\176\211\012\105\151\052\173" "\120\007\154\377\252\076\023\152\016\066\073\124\373\362\353\076" "\041\113\170\172\166\071\011\243\002\123\035\224\261\115\361\207" "\067\075\027\301\253\007\106\140\153\121\123\000\130\200\371\047" "\166\007\154\151\246\314\244\360\240\143\142\177\024\200\363\353" "\001\267\127\011\212\076\133\313\056\035\210\347\243\373\242\067" "\257\342\103\251\262\125\352\303\136\026\313\046\025\045\371\150" "\312\226\335\145\340\262\235\204\211\047\356\111\111\317\046\226" "\136\006\136\337\063\170\233\274\343\213\244\341\250\164\075\066" "\027\127\351\300\373\236\113\335\074\106\103\347\211\007\207\360" "\344\227\072\343\014\325\332\317\315\153\034\064\130\046\163\214" "\345\137\334\127\052\104\053\020\146\275\306\031\343\054\104\311" "\153\072\053\352\307\320\277\177\333\225\174\153\111\360\312\016" "\300\010\174\157\022\031\307\070\013\177\000\134\037\136\377\125" "\071\215\373\114\345\015\042\210\176\332\340\363\171\364\366\010" "\222\114\227\011\077\371\163\114\362\025\353\126\175\145\244\024" "\020\301\244\265\155\002\070\374\154\243\022\211\247\076\325\103" "\042\226\154\062\366\236\315\230\030\220\331\065\326\072\310\065" "\276\203\060\131\223\301\105\016\254\211\016\267\061\136\333\273" "\107\134\151\024\256\074\326\147\223\331\160\314\366\262\155\270" "\113\224\371\305\067\063\360\235\174\264\244\003\321\044\033\134" "\151\044\042\112\321\377\171\265\375\152\127\236\033\253\050\145" "\346\363\312\014\272\031\052\347\013\043\043\210\176\371\323\275" "\010\205\350\001\123\074\046\013\373\175\311\274\234\342\166\341" "\256\012\372\237\016\200\075\113\221\277\302\162\323\176\154\163" "\160\365\141\167\203\111\311\073\231\353\271\317\162\042\337\000" "\204\112\161\114\241\125\373\062\023\371\206\165\122\175\130\102" "\135\157\175\206\362\206\356\075\140\273\276\141\103\222\321\276" "\121\363\131\177\036\106\360\040\074\067\174\337\066\043\062\024" "\116\006\157\217\075\014\101\210\327\216\120\362\050\354\163\210" "\236\101\210\021\040\365\325\140\115\365\147\153\375\237\045\132" "\071\044\250\340\270\315\236\251\037\273\303\124\320\372\353\255" "\306\276\157\024\206\302\375\346\360\360\205\074\244\064\204\334" "\102\327\202\030\270\203\102\047\016\311\131\204\323\243\204\213" "\205\001\266\252\273\274\075\237\111\160\210\244\012\201\027\252" "\070\135\164\361\020\042\062\303\325\365\235\017\340\141\016\340" "\132\112\063\365\064\325\230\062\166\311\252\007\227\300\356\034" "\161\300\345\135\233\214\301\200\303\045\000\047\001\233\075\177" "\231\003\255\365\050\171\002\043\341\362\156\353\207\122\333\144" "\215\362\307\226\263\255\057\375\022\176\134\250\007\161\177\206" "\366\330\044\126\132\237\171\006\211\032\012\011\376\173\154\056" "\335\012\062\014\257\310\247\043\145\275\374\026\343\106\266\022" "\237\151\221\215\336\346\124\044\237\306\200\217\020\067\173\206" "\004\222\357\253\264\174\105\256\117\346\027\145\120\100\016\341" "\022\322\234\210\270\136\220\261\356\277\146\343\306\274\143\263" "\134\067\231\045\365\267\341\044\341\371\157\144\227\014\274\213" "\317\033\141\226\306\237\162\316\327\335\300\253\247\037\253\204" "\166\344\166\131\132\007\344\205\251\064\224\132\330\216\000\332" "\260\155\044\361\041\105\131\152\114\071\126\007\111\036\206\337" "\250\373\166\204\345\155\236\046\061\260\125\121\171\127\033\100" "\132\173\201\174\330\133\357\143\254\242\051\053\143\302\055\104" "\014\164\041\265\017\366\160\211\240\142\073\232\171\051\216\313" "\037\306\070\170\322\262\101\023\032\001\236\301\222\366\022\134" "\162\340\334\070\126\367\231\065\211\033\165\144\063\057\361\326" "\033\153\212\364\107\017\200\241\134\300\210\314\217\131\246\222" "\224\237\204\344\001\003\131\170\005\310\315\117\073\055\061\272" "\121\320\152\045\247\265\327\263\052\103\165\011\242\050\301\377" "\153\223\201\134\042\261\105\113\372\345\067\176\147\150\033\013" "\241\027\027\371\245\173\243\346\233\377\144\252\111\023\306\004" "\332\052\241\276\243\204\036\241\244\117\323\024\050\375\224\320" "\202\264\233\023\037\320\214\145\152\030\075\152\333\343\273\024" "\170\160\013\305\272\070\017\114\035\066\017\214\165\356\237\024" "\224\042\133\306\252\027\316\241\277\043\260\105\106\367\367\247" "\316\141\300\357\271\111\267\065\174\117\135\374\335\156\370\203" "\000\032\307\311\222\331\117\266\256\316\133\220\336\247\175\205" "\101\104\265\257\335\236\031\074\350\100\111\361\020\227\000\033" "\231\147\126\040\101\357\336\263\057\220\140\207\173\323\107\175" "\155\240\174\351\145\157\152\310\341\231\000\173\353\352\251\314" "\234\037\225\070\032\000\021\047\124\124\313\231\310\311\307\226" "\123\130\317\371\056\205\021\237\315\271\351\107\001\175\026\075" "\333\146\272\041\131\143\147\052\352\245\151\232\037\244\343\275" "\265\307\176\234\122\106\140\047\001\365\070\153\176\051\115\366" "\115\103\344\045\325\367\377\124\150\170\256\243\135\351\337\345" "\263\161\373\221\016\332\130\366\257\233\344\060\200\144\325\123" "\346\240\045\366\327\004\325\253\206\371\175\003\327\321\011\333" "\360\022\223\356\241\341\065\104\061\057\371\374\366\053\040\376" "\303\364\353\052\345\004\340\210\313\035\335\347\100\222\203\037" "\366\364\213\275\132\143\253\177\376\032\334\366\171\152\077\305" "\043\057\211\345\123\074\277\076\162\002\300\230\061\074\305\325" "\021\052\064\005\077\324\132\132\134\001\303\343\304\165\223\373" "\246\056\114\006\374\144\120\174\223\360\005\346\324\342\061\123" "\206\036\123\062\161\314\143\251\200\217\365\035\274\004\013\052" "\072\163\242\224\040\341\134\043\150\157\255\030\153\357\321\060" "\011\216\172\011\172\102\052\316\261\104\101\034\221\324\123\171" "\346\202\006\101\133\120\241\147\112\172\301\263\104\157\225\024" "\015\255\347\114\107\241\155\027\334\340\311\072\031\305\000\016" "\076\007\227\347\252\260\173\321\266\063\024\050\217\147\074\026" "\375\322\131\376\177\176\347\246\323\346\365\217\013\316\013\071" "\216\127\125\242\073\015\061\031\014\060\033\112\004\311\112\306" "\050\056\045\332\333\345\377\156\233\017\050\153\340\105\170\163" "\313\152\055\115\272\311\134\230\335\013\113\227\204\112\055\253" "\123\305\145\216\173\040\312\260\153\211\147\113\152\206\160\370" "\367\105\022\041\247\132\227\022\237\060\323\176\263\236\137\023" "\010\264\066\136\033\340\011\274\217\246\267\176\105\243\203\222" "\112\221\141\173\000\072\322\274\107\157\017\311\007\273\351\357" "\223\373\040\324\067\005\355\034\276\340\252\350\054\001\173\264" "\205\045\261\307\167\303\137\172\044\076\335\060\171\122\120\022" "\341\055\365\306\032\323\273\216\255\200\270\053\351\362\271\337" "\274\062\320\062\331\225\213\323\006\304\341\224\060\375\034\350" "\040\203\200\242\136\110\112\071\014\053\021\336\066\075\021\147" "\026\235\351\321\163\223\302\030\313\105\112\013\370\264\166\271" "\136\336\210\053\076\067\304\102\174\236\001\335\136\020\121\175" "\235\230\373\116\227\057\113\070\371\012\170\347\025\231\131\252" "\162\046\313\177\127\230\261\367\006\142\345\107\204\111\036\260" "\211\246\131\063\045\123\324\207\065\010\147\202\301\075\151\136" "\327\240\024\147\264\263\033\032\317\324" #define tst2_z 19 #define tst2 ((&data[2817])) "\074\257\000\031\167\117\173\243\310\074\135\110\034\101\302\144" "\067\341\042\332\246\241\214" #define pswd_z 256 #define pswd ((&data[2900])) "\014\102\111\064\113\261\266\014\356\037\153\306\300\177\056\164" "\063\111\217\002\035\034\167\222\130\046\063\345\062\051\201\076" "\154\313\162\270\175\051\305\154\111\060\062\011\260\140\176\343" "\251\015\345\307\052\134\131\202\203\214\150\265\266\352\354\360" "\121\074\340\147\325\205\210\035\225\111\135\260\350\176\044\057" "\005\023\063\147\177\003\104\110\372\305\357\131\116\334\112\237" "\031\053\007\357\260\217\014\106\331\151\367\301\350\033\361\355" "\056\044\125\256\047\232\366\042\137\346\174\255\303\307\115\335" "\362\124\314\243\344\330\351\276\102\340\177\052\374\161\030\053" "\225\155\331\275\007\320\337\147\267\134\025\172\043\142\127\025" "\267\043\271\234\374\242\133\076\203\332\150\200\114\200\253\341" "\356\204\236\366\125\176\135\014\333\163\207\376\326\337\024\216" "\003\315\052\377\160\205\076\363\140\246\163\255\047\037\216\026" "\244\055\014\371\254\152\005\207\336\215\205\264\154\231\102\157" "\147\155\157\327\363\255\313\124\124\077\001\173\136\220\222\002" "\275\237\373\152\012\001\361\350\216\166\234\373\020\337\153\167" "\114\332\116\100\207\032\224\333\131\226\127\267\046\351\271\344" "\210\265\116\222\266\077\173\105\266\027\101\307\366\254\077\103" "\206\216\203\015\250\030\351\001\256\100\270\325\052\162\271\262" "\047\010\105\336\107\301\044\376\330\145\306\317\021\005\364\043" "\266\146\334\063\220\241\237\331\321\322\342\202\062\141\145\334" "\156\112\243\231\247\374\034\052\211\204\340\077\156\324\143\044" "\073\077\130\313\340" #define chk2_z 19 #define chk2 ((&data[3198])) "\311\207\064\345\171\114\202\167\124\064\037\045\124\175\123\112" "\116\014\051\220\007\265\374\351\232" #define lsto_z 1 #define lsto ((&data[3220])) "\242" #define tst1_z 22 #define tst1 ((&data[3226])) "\167\015\267\000\222\041\373\241\076\175\136\302\066\143\352\272" "\050\055\313\037\222\305\070\161\041\267\353\230\100\000"/* End of data[] */; #define hide_z 4096 #define SETUID 0 /* Define as 1 to call setuid(0) at start of script */ #define DEBUGEXEC 0 /* Define as 1 to debug execvp calls */ #define TRACEABLE 1 /* Define as 1 to enable ptrace the executable */ #define HARDENING 0 /* Define as 1 to disable ptrace/dump the executable */ #define BUSYBOXON 0 /* Define as 1 to enable work with busybox */ #if HARDENING static const char * shc_x[] = { "/*", " * Copyright 2019 - Intika ", " * Replace ******** with secret read from fd 21", " * Also change arguments location of sub commands (sh script commands)", " * clang -Wall -fpic -shared -o shc_secret.so shc_secret.c -ldl", " */", "", "#define _GNU_SOURCE /* needed to get RTLD_NEXT defined in dlfcn.h */", "#define PLACEHOLDER \"********\"", "#include ", "#include ", "#include ", "#include ", "#include ", "#include ", "", "static char secret[128000]; //max size", "typedef int (*pfi)(int, char **, char **);", "static pfi real_main;", "", "// copy argv to new location", "char **copyargs(int argc, char** argv){", " char **newargv = malloc((argc+1)*sizeof(*argv));", " char *from,*to;", " int i,len;", "", " for(i = 0; i 0) {", " int i;", "", " if (secret[n - 1] == '\\n') secret[--n] = '\\0';", " for (i = 1; i < argc; i++)", " if (strcmp(argv[i], PLACEHOLDER) == 0)", " argv[i] = secret;", " }", "", " real_main = main;", "", " return real___libc_start_main(mymain, argc, argv, init, fini, rtld_fini, stack_end);", "}", "", 0}; #endif /* HARDENING */ /* rtc.c */ #include #include #include #include #include #include #include #include /* 'Alleged RC4' */ static unsigned char stte[256], indx, jndx, kndx; /* * Reset arc4 stte. */ void stte_0(void) { indx = jndx = kndx = 0; do { stte[indx] = indx; } while (++indx); } /* * Set key. Can be used more than once. */ void key(void * str, int len) { unsigned char tmp, * ptr = (unsigned char *)str; while (len > 0) { do { tmp = stte[indx]; kndx += tmp; kndx += ptr[(int)indx % len]; stte[indx] = stte[kndx]; stte[kndx] = tmp; } while (++indx); ptr += 256; len -= 256; } } /* * Crypt data. */ void arc4(void * str, int len) { unsigned char tmp, * ptr = (unsigned char *)str; while (len > 0) { indx++; tmp = stte[indx]; jndx += tmp; stte[indx] = stte[jndx]; stte[jndx] = tmp; tmp += stte[indx]; *ptr ^= stte[tmp]; ptr++; len--; } } /* End of ARC4 */ #if HARDENING #include #include #include #include #define PR_SET_PTRACER 0x59616d61 /* Seccomp Sandboxing Init */ #include #include #include #include #include #include #include #include #include #include #include #include #include #define ArchField offsetof(struct seccomp_data, arch) #define Allow(syscall) \ BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, SYS_##syscall, 0, 1), \ BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW) struct sock_filter filter[] = { /* validate arch */ BPF_STMT(BPF_LD+BPF_W+BPF_ABS, ArchField), BPF_JUMP( BPF_JMP+BPF_JEQ+BPF_K, AUDIT_ARCH_X86_64, 1, 0), BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_KILL), /* load syscall */ BPF_STMT(BPF_LD+BPF_W+BPF_ABS, offsetof(struct seccomp_data, nr)), /* list of allowed syscalls */ Allow(exit_group), /* exits a process */ Allow(brk), /* for malloc(), inside libc */ Allow(mmap), /* also for malloc() */ Allow(munmap), /* for free(), inside libc */ /* and if we don't match above, die */ BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_KILL), }; struct sock_fprog filterprog = { .len = sizeof(filter)/sizeof(filter[0]), .filter = filter }; /* Seccomp Sandboxing - Set up the restricted environment */ void seccomp_hardening() { if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) { perror("Could not start seccomp:"); exit(1); } if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &filterprog) == -1) { perror("Could not start seccomp:"); exit(1); } } /* End Seccomp Sandboxing Init */ void shc_x_file() { FILE *fp; int line = 0; if ((fp = fopen("/data/data/com.termux/files/usr/tmp/shc_x.c", "w")) == NULL ) {exit(1); exit(1);} for (line = 0; shc_x[line]; line++) fprintf(fp, "%s\n", shc_x[line]); fflush(fp);fclose(fp); } int make() { char * cc, * cflags, * ldflags; char cmd[4096]; cc = getenv("CC"); if (!cc) cc = "clang"; sprintf(cmd, "%s %s -o %s %s", cc, "-Wall -fpic -shared", "/data/data/com.termux/files/usr/tmp/shc_x.so", "/data/data/com.termux/files/usr/tmp/shc_x.c -ldl"); if (system(cmd)) {remove("/data/data/com.termux/files/usr/tmp/shc_x.c"); return -1;} remove("/data/data/com.termux/files/usr/tmp/shc_x.c"); return 0; } void arc4_hardrun(void * str, int len) { //Decode locally char tmp2[len]; char tmp3[len+1024]; memcpy(tmp2, str, len); unsigned char tmp, * ptr = (unsigned char *)tmp2; int lentmp = len; int pid, status; pid = fork(); shc_x_file(); if (make()) {exit(1);} setenv("LD_PRELOAD","/data/data/com.termux/files/usr/tmp/shc_x.so",1); if(pid==0) { //Start tracing to protect from dump & trace if (ptrace(PTRACE_TRACEME, 0, 0, 0) < 0) { kill(getpid(), SIGKILL); _exit(1); } //Decode Bash while (len > 0) { indx++; tmp = stte[indx]; jndx += tmp; stte[indx] = stte[jndx]; stte[jndx] = tmp; tmp += stte[indx]; *ptr ^= stte[tmp]; ptr++; len--; } //Do the magic sprintf(tmp3, "%s %s", "'********' 21<<<", tmp2); //Exec bash script //fork execl with 'sh -c' system(tmp2); //Empty script variable memcpy(tmp2, str, lentmp); //Clean temp remove("/data/data/com.termux/files/usr/tmp/shc_x.so"); //Sinal to detach ptrace ptrace(PTRACE_DETACH, 0, 0, 0); exit(0); } else {wait(&status);} /* Seccomp Sandboxing - Start */ seccomp_hardening(); exit(0); } #endif /* HARDENING */ /* * Key with file invariants. */ int key_with_file(char * file) { struct stat statf[1]; struct stat control[1]; if (stat(file, statf) < 0) return -1; /* Turn on stable fields */ memset(control, 0, sizeof(control)); control->st_ino = statf->st_ino; control->st_dev = statf->st_dev; control->st_rdev = statf->st_rdev; control->st_uid = statf->st_uid; control->st_gid = statf->st_gid; control->st_size = statf->st_size; control->st_mtime = statf->st_mtime; control->st_ctime = statf->st_ctime; key(control, sizeof(control)); return 0; } #if DEBUGEXEC void debugexec(char * sh11, int argc, char ** argv) { int i; fprintf(stderr, "shll=%s\n", sh11 ? sh11 : ""); fprintf(stderr, "argc=%d\n", argc); if (!argv) { fprintf(stderr, "argv=\n"); } else { for (i = 0; i <= argc ; i++) fprintf(stderr, "argv[%d]=%.60s\n", i, argv[i] ? argv[i] : ""); } } #endif /* DEBUGEXEC */ void rmarg(char ** argv, char * arg) { for (; argv && *argv && *argv != arg; argv++); for (; argv && *argv; argv++) *argv = argv[1]; } void chkenv_end(void); int chkenv(int argc) { char buff[512]; unsigned long mask, m; int l, a, c; char * string; extern char ** environ; mask = (unsigned long)getpid(); stte_0(); key(&chkenv, (void*)&chkenv_end - (void*)&chkenv); key(&data, sizeof(data)); key(&mask, sizeof(mask)); arc4(&mask, sizeof(mask)); sprintf(buff, "x%lx", mask); string = getenv(buff); #if DEBUGEXEC fprintf(stderr, "getenv(%s)=%s\n", buff, string ? string : ""); #endif l = strlen(buff); if (!string) { /* 1st */ sprintf(&buff[l], "=%lu %d", mask, argc); putenv(strdup(buff)); return 0; } c = sscanf(string, "%lu %d%c", &m, &a, buff); if (c == 2 && m == mask) { /* 3rd */ rmarg(environ, &string[-l - 1]); return 1 + (argc - a); } return -1; } void chkenv_end(void){} #if HARDENING static void gets_process_name(const pid_t pid, char * name) { char procfile[BUFSIZ]; sprintf(procfile, "/proc/%d/cmdline", pid); FILE* f = fopen(procfile, "r"); if (f) { size_t size; size = fread(name, sizeof (char), sizeof (procfile), f); if (size > 0) { if ('\n' == name[size - 1]) name[size - 1] = '\0'; } fclose(f); } } void hardening() { prctl(PR_SET_DUMPABLE, 0); prctl(PR_SET_PTRACER, -1); int pid = getppid(); char name[256] = {0}; gets_process_name(pid, name); if ( (strcmp(name, "bash") != 0) && (strcmp(name, "/bin/bash") != 0) && (strcmp(name, "sh") != 0) && (strcmp(name, "/bin/sh") != 0) && (strcmp(name, "sudo") != 0) && (strcmp(name, "/bin/sudo") != 0) && (strcmp(name, "/usr/bin/sudo") != 0) && (strcmp(name, "gksudo") != 0) && (strcmp(name, "/bin/gksudo") != 0) && (strcmp(name, "/usr/bin/gksudo") != 0) && (strcmp(name, "kdesu") != 0) && (strcmp(name, "/bin/kdesu") != 0) && (strcmp(name, "/usr/bin/kdesu") != 0) ) { printf("Operation not permitted\n"); kill(getpid(), SIGKILL); exit(1); } } #endif /* HARDENING */ #if !TRACEABLE #define _LINUX_SOURCE_COMPAT #include #include #include #include #include #include #include #if !defined(PT_ATTACHEXC) /* New replacement for PT_ATTACH */ #if !defined(PTRACE_ATTACH) && defined(PT_ATTACH) #define PT_ATTACHEXC PT_ATTACH #elif defined(PTRACE_ATTACH) #define PT_ATTACHEXC PTRACE_ATTACH #endif #endif void untraceable(char * argv0) { char proc[80]; int pid, mine; switch(pid = fork()) { case 0: pid = getppid(); /* For problematic SunOS ptrace */ #if defined(__FreeBSD__) sprintf(proc, "/proc/%d/mem", (int)pid); #else sprintf(proc, "/proc/%d/as", (int)pid); #endif close(0); mine = !open(proc, O_RDWR|O_EXCL); if (!mine && errno != EBUSY) mine = !ptrace(PT_ATTACHEXC, pid, 0, 0); if (mine) { kill(pid, SIGCONT); } else { perror(argv0); kill(pid, SIGKILL); } _exit(mine); case -1: break; default: if (pid == waitpid(pid, 0, 0)) return; } perror(argv0); _exit(1); } #endif /* !TRACEABLE */ char * xsh(int argc, char ** argv) { char * scrpt; int ret, i, j; char ** varg; char * me = argv[0]; if (me == NULL) { me = getenv("_"); } if (me == 0) { fprintf(stderr, "E: neither argv[0] nor $_ works."); exit(1); } ret = chkenv(argc); stte_0(); key(pswd, pswd_z); arc4(msg1, msg1_z); arc4(date, date_z); if (date[0] && (atoll(date) 1) ? ret : 0; /* Args numbering correction */ while (i < argc) varg[j++] = argv[i++]; /* Main run-time arguments */ varg[j] = 0; /* NULL terminated array */ #if DEBUGEXEC debugexec(shll, j, varg); #endif execvp(shll, varg); return shll; } int main(int argc, char ** argv) { #if SETUID setuid(0); #endif #if DEBUGEXEC debugexec("main", argc, argv); #endif #if HARDENING hardening(); #endif #if !TRACEABLE untraceable(argv[0]); #endif argv[1] = xsh(argc, argv); fprintf(stderr, "%s%s%s: %s\n", argv[0], errno ? ": " : "", errno ? strerror(errno) : "", argv[1] ? argv[1] : "" ); return 1; }