Skip to content

Commit 6495e11

Browse files
committed
v4.0.3 Enhance -H flag
1 parent 6efba2a commit 6495e11

File tree

4 files changed

+134
-21
lines changed

4 files changed

+134
-21
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
CHANGES
22

3+
4.0.3 Tue Nov 20 08:22:20 UTC 2018
4+
5+
* Enhance -H flag by intika <https://github.com/intika> (Hide commands arguments from ps and cmdline)
6+
37
4.0.2 Tue Nov 20 08:22:20 UTC 2018
48

59
* Remove -s flag (experimental feature not working as expected by intika <https://github.com/intika>)

configure

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#! /bin/sh
22
# Guess values for system-dependent variables and create Makefiles.
3-
# Generated by GNU Autoconf 2.69 for shc 4.0.2.
3+
# Generated by GNU Autoconf 2.69 for shc 4.0.3.
44
#
55
# Report bugs to <http://github.com/neurobin/shc/issues>.
66
#
@@ -580,8 +580,8 @@ MAKEFLAGS=
580580
# Identity of this package.
581581
PACKAGE_NAME='shc'
582582
PACKAGE_TARNAME='shc'
583-
PACKAGE_VERSION='4.0.2'
584-
PACKAGE_STRING='shc 4.0.2'
583+
PACKAGE_VERSION='4.0.3'
584+
PACKAGE_STRING='shc 4.0.3'
585585
PACKAGE_BUGREPORT='http://github.com/neurobin/shc/issues'
586586
PACKAGE_URL=''
587587

@@ -1279,7 +1279,7 @@ if test "$ac_init_help" = "long"; then
12791279
# Omit some internal or obsolete options to make the list less imposing.
12801280
# This message is too long to be a string in the A/UX 3.1 sh.
12811281
cat <<_ACEOF
1282-
\`configure' configures shc 4.0.2 to adapt to many kinds of systems.
1282+
\`configure' configures shc 4.0.3 to adapt to many kinds of systems.
12831283
12841284
Usage: $0 [OPTION]... [VAR=VALUE]...
12851285
@@ -1346,7 +1346,7 @@ fi
13461346

13471347
if test -n "$ac_init_help"; then
13481348
case $ac_init_help in
1349-
short | recursive ) echo "Configuration of shc 4.0.2:";;
1349+
short | recursive ) echo "Configuration of shc 4.0.3:";;
13501350
esac
13511351
cat <<\_ACEOF
13521352
@@ -1437,7 +1437,7 @@ fi
14371437
test -n "$ac_init_help" && exit $ac_status
14381438
if $ac_init_version; then
14391439
cat <<\_ACEOF
1440-
shc configure 4.0.2
1440+
shc configure 4.0.3
14411441
generated by GNU Autoconf 2.69
14421442
14431443
Copyright (C) 2012 Free Software Foundation, Inc.
@@ -1863,7 +1863,7 @@ cat >config.log <<_ACEOF
18631863
This file contains any messages produced by compilers while
18641864
running configure, to aid debugging if configure makes a mistake.
18651865
1866-
It was created by shc $as_me 4.0.2, which was
1866+
It was created by shc $as_me 4.0.3, which was
18671867
generated by GNU Autoconf 2.69. Invocation command line was
18681868
18691869
$ $0 $@
@@ -2733,7 +2733,7 @@ fi
27332733
27342734
# Define the identity of the package.
27352735
PACKAGE='shc'
2736-
VERSION='4.0.2'
2736+
VERSION='4.0.3'
27372737
27382738
27392739
cat >>confdefs.h <<_ACEOF
@@ -5311,7 +5311,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
53115311
# report actual input values of CONFIG_FILES etc. instead of their
53125312
# values after options handling.
53135313
ac_log="
5314-
This file was extended by shc $as_me 4.0.2, which was
5314+
This file was extended by shc $as_me 4.0.3, which was
53155315
generated by GNU Autoconf 2.69. Invocation command line was
53165316
53175317
CONFIG_FILES = $CONFIG_FILES
@@ -5368,7 +5368,7 @@ _ACEOF
53685368
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
53695369
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
53705370
ac_cs_version="\\
5371-
shc config.status 4.0.2
5371+
shc config.status 4.0.3
53725372
configured by $0, generated by GNU Autoconf 2.69,
53735373
with options \\"\$ac_cs_config\\"
53745374

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
AC_INIT([shc], [4.0.2], [http://github.com/neurobin/shc/issues])
1+
AC_INIT([shc], [4.0.3], [http://github.com/neurobin/shc/issues])
22
AC_CONFIG_AUX_DIR(config)
33
#prefix="/usr"
44
AC_CONFIG_SRCDIR([src/shc.c])

src/shc.c

Lines changed: 119 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
static const char my_name[] = "shc";
20-
static const char version[] = "Version 4.0.2";
20+
static const char version[] = "Version 4.0.3";
2121
static const char subject[] = "Generic Shell Script Compiler";
2222
static const char cpright[] = "GNU GPL Version 3";
2323
static const struct { const char * f, * s, * e; }
@@ -147,6 +147,86 @@ static int BUSYBOXON_flag = 0;
147147

148148
static const char * RTC[] = {
149149
"",
150+
"#if HARDENING",
151+
"static const char * shc_x[] = {",
152+
"\"/*\",",
153+
"\" * Copyright 2019 - Intika <intika@librefox.org>\",",
154+
"\" * Replace ******** with secret read from fd 21\",",
155+
"\" * Also change arguments location of sub commands (sh script commands)\",",
156+
"\" * gcc -Wall -fpic -shared -o shc_secret.so shc_secret.c -ldl\",",
157+
"\" */\",",
158+
"\"\",",
159+
"\"#define _GNU_SOURCE /* needed to get RTLD_NEXT defined in dlfcn.h */\",",
160+
"\"#define PLACEHOLDER \\\"********\\\"\",",
161+
"\"#include <dlfcn.h>\",",
162+
"\"#include <stdlib.h>\",",
163+
"\"#include <string.h>\",",
164+
"\"#include <unistd.h>\",",
165+
"\"#include <stdio.h>\",",
166+
"\"#include <signal.h>\",",
167+
"\"\",",
168+
"\"static char secret[128000]; //max size\",",
169+
"\"typedef int (*pfi)(int, char **, char **);\",",
170+
"\"static pfi real_main;\",",
171+
"\"\",",
172+
"\"// copy argv to new location\",",
173+
"\"char **copyargs(int argc, char** argv){\",",
174+
"\" char **newargv = malloc((argc+1)*sizeof(*argv));\",",
175+
"\" char *from,*to;\",",
176+
"\" int i,len;\",",
177+
"\"\",",
178+
"\" for(i = 0; i<argc; i++){\",",
179+
"\" from = argv[i];\",",
180+
"\" len = strlen(from)+1;\",",
181+
"\" to = malloc(len);\",",
182+
"\" memcpy(to,from,len);\",",
183+
"\" // zap old argv space\",",
184+
"\" memset(from,'\\\\0',len);\",",
185+
"\" newargv[i] = to;\",",
186+
"\" argv[i] = 0;\",",
187+
"\" }\",",
188+
"\" newargv[argc] = 0;\",",
189+
"\" return newargv;\",",
190+
"\"}\",",
191+
"\"\",",
192+
"\"static int mymain(int argc, char** argv, char** env) {\",",
193+
"\" //fprintf(stderr, \\\"Inject main argc = %d\\\\n\\\", argc);\",",
194+
"\" return real_main(argc, copyargs(argc,argv), env);\",",
195+
"\"}\",",
196+
"\"\",",
197+
"\"int __libc_start_main(int (*main) (int, char**, char**),\",",
198+
"\" int argc,\",",
199+
"\" char **argv,\",",
200+
"\" void (*init) (void),\",",
201+
"\" void (*fini)(void),\",",
202+
"\" void (*rtld_fini)(void),\",",
203+
"\" void (*stack_end)){\",",
204+
"\" static int (*real___libc_start_main)() = NULL;\",",
205+
"\" int n;\",",
206+
"\"\",",
207+
"\" if (!real___libc_start_main) {\",",
208+
"\" real___libc_start_main = dlsym(RTLD_NEXT, \\\"__libc_start_main\\\");\",",
209+
"\" if (!real___libc_start_main) abort();\",",
210+
"\" }\",",
211+
"\"\",",
212+
"\" n = read(21, secret, sizeof(secret));\",",
213+
"\" if (n > 0) {\",",
214+
"\" int i;\",",
215+
"\"\",",
216+
"\" if (secret[n - 1] == '\\\\n') secret[--n] = '\\\\0';\",",
217+
"\" for (i = 1; i < argc; i++)\",",
218+
"\" if (strcmp(argv[i], PLACEHOLDER) == 0)\",",
219+
"\" argv[i] = secret;\",",
220+
"\" }\",",
221+
"\"\",",
222+
"\" real_main = main;\",",
223+
"\"\",",
224+
"\" return real___libc_start_main(mymain, argc, argv, init, fini, rtld_fini, stack_end);\",",
225+
"\"}\",",
226+
"\"\",",
227+
"0};",
228+
"#endif /* HARDENING */",
229+
"",
150230
"/* rtc.c */",
151231
"",
152232
"#include <sys/stat.h>",
@@ -281,26 +361,51 @@ static const char * RTC[] = {
281361
"} ",
282362
"/* End Seccomp Sandboxing Init */",
283363
"",
364+
"void shc_x_file() {",
365+
" FILE *fp;",
366+
" int line = 0;",
367+
"",
368+
" if ((fp = fopen(\"/tmp/shc_x.c\", \"w\")) == NULL ) {exit(1); exit(1);}",
369+
" for (line = 0; shc_x[line]; line++) fprintf(fp, \"%s\\n\", shc_x[line]);",
370+
" fflush(fp);fclose(fp);",
371+
"}",
372+
"",
373+
"int make() {",
374+
" char * cc, * cflags, * ldflags;",
375+
" char cmd[4096];",
376+
"",
377+
" cc = getenv(\"CC\");",
378+
" if (!cc) cc = \"cc\";",
379+
"",
380+
" sprintf(cmd, \"%s %s -o %s %s\", cc, \"-Wall -fpic -shared\", \"/tmp/shc_x.so\", \"/tmp/shc_x.c -ldl\");",
381+
" if (system(cmd)) {remove(\"/tmp/shc_x.c\"); return -1;}",
382+
" remove(\"/tmp/shc_x.c\"); return 0;",
383+
"}",
384+
"",
284385
"void arc4_hardrun(void * str, int len) {",
285386
" //Decode locally",
286387
" char tmp2[len];",
388+
" char tmp3[len+1024];",
287389
" memcpy(tmp2, str, len);",
288390
"",
289391
" unsigned char tmp, * ptr = (unsigned char *)tmp2;",
290-
"",
291392
" int lentmp = len;",
292393
" int pid, status;",
293394
" pid = fork();",
294-
"",
395+
"",
396+
" shc_x_file();",
397+
" if (make()) {exit(1);}",
398+
"",
399+
" setenv(\"LD_PRELOAD\",\"/tmp/shc_x.so\",1);",
400+
"",
295401
" if(pid==0) {",
296402
"",
297403
" //Start tracing to protect from dump & trace",
298404
" if (ptrace(PTRACE_TRACEME, 0, 0, 0) < 0) {",
299-
" printf(\"Operation not permitted\\n\");",
300405
" kill(getpid(), SIGKILL);",
301406
" _exit(1);",
302407
" }",
303-
"",
408+
"",
304409
" //Decode Bash",
305410
" while (len > 0) {",
306411
" indx++;",
@@ -314,25 +419,29 @@ static const char * RTC[] = {
314419
" len--;",
315420
" }",
316421
"",
317-
" //Exec bash script",
422+
" //Do the magic",
423+
" sprintf(tmp3, \"%s %s\", \"'********' 21<<<\", tmp2);",
424+
"",
425+
" //Exec bash script //fork execl with 'sh -c'",
318426
" system(tmp2);",
319427
"",
320428
" //Empty script variable",
321429
" memcpy(tmp2, str, lentmp);",
322430
"",
431+
" //Clean temp",
432+
" remove(\"/tmp/shc_x.so\");",
433+
"",
323434
" //Sinal to detach ptrace",
324435
" ptrace(PTRACE_DETACH, 0, 0, 0);",
325436
" exit(0);",
326437
" }",
327-
" else {",
328-
" wait(&status);",
329-
" }",
438+
" else {wait(&status);}",
330439
"",
331440
" /* Seccomp Sandboxing - Start */",
332441
" seccomp_hardening();",
333442
"",
334443
" exit(0);",
335-
"} ",
444+
"}",
336445
"#endif /* HARDENING */",
337446
"",
338447
"/*",

0 commit comments

Comments
 (0)