1

I am facing an issue when try to obfuscate my script with shc(installed on Ubuntu 20.04 which running on VMware, the memory size is 4 GB), the original script (test.sh) size is about 462 KB, after running shc command as shc -U -f test.sh -o testbin.bin, I create a new file as testbin.bin about 600 KB, and I try to run it directly as below:

user@ubuntu:~/Obfuscate_Script$ sudo ./testbin.bin
./testbin.bin: Argument list too long: /bin/bash

I realize the problem encounter is on shc man page as below:
BUGS The maximum size of the script that could be executed once compiled is limited by the operating system configuration parameter _SC_ARG_MAX (see sysconf(2))

I try to follow some reference documents such as “Argument list too long”: How do I deal with it, without changing my command? or Increase stack size in Linux with setrlimit, and tried below, first I increase the stack size as unlimited value by ulimit -s unlimited, and check with getconf ARG_MAX, it seems works which increase from default value to maximum VMware setting memory as 4 GB

user@ubuntu:~$ getconf ARG_MAX
2097152
user@ubuntu:~$ ulimit -s unlimited
user@ubuntu:~$ getconf ARG_MAX
4611686018427387903

But when I start to generate binary file again as testbin.bin, now it showing below Warning as:

user@ubuntu:~/Obfuscate_Script$ shc -U -f test.sh -o testbin.bin
shc: WARNING!!
   Scripts of length near to (or higher than) the current System limit on
   "maximum size of arguments to EXEC", could comprise its binary execution.
   In the current System the call sysconf(_SC_ARG_MAX) returns -1 bytes
   and your script "test.sh" is 467776 bytes length.

Then I run the testbin.bin file again, not surprise, it still showing same issue, looks like ulimit -s unlimited not actually work:

user@ubuntu:~/Obfuscate_Script$ sudo ./testbin.bin
./testbin.bin: Argument list too long: /bin/bash
user@ubuntu:~/Obfuscate_Script$ getconf ARG_MAX
4611686018427387903

I don't know why the Warning message come again since I manually increase stack size to maximum value on Virtual machine already. My Ubuntu 20.04 is running running on VMware 15.5.6 by default setup as 4 GB memory (which i can increase even more, but should not be the root cause), please let me know how to overcome the shc argument list too long issue, do we need to modify any config file or some settings to resolve that Warning ? thank you !

Lampard
  • 394
  • 7
  • 23
  • 2
    From https://unix.stackexchange.com/questions/120642/what-defines-the-maximum-size-for-a-command-single-argument?rq=1, it appears that in addition to the `ARG_MAX` limit on the *total size* of the argument list, there are separate hardcoded limits on the *number* of arguments (`MAX_ARG_STRINGS`), and the maximum length of *each* one (`MAX_ARG_STRLEN`). I would guess you are running into the latter. You'd have to recompile the kernel in order to increase it. – Nate Eldredge Aug 12 '20 at 00:53
  • Indeed, on my system, `MAX_ARG_STRLEN` is 128K, so an argument several hundred KB long would exceed it. – Nate Eldredge Aug 12 '20 at 00:59
  • Hi, Nate Eldredge, thank you providing new perspective to see the issue, I need to have a detail check on suggested resource – Lampard Aug 12 '20 at 01:08
  • Actually go through the link, i think you are right, only manually re-assign unlimited value to stack size will not work, it actually hook by other related arguments also, need to change all of them, and 2nd suggest link provide details partially resolve my doubt, need to try with my Virtual ubuntu, thanks – Lampard Aug 12 '20 at 09:48

0 Answers0