OpenWrt Forum Archive

Topic: shc-3.8.7 shell script encryption for OpenWrt

The content of this topic has been archived between 28 Apr 2018 and 4 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi guys, i have been working on porting the shc software to openwrt, i have successfully compile the shc-3.8.7 as a mipsel ipk. It runs fine in 8.09.2 only there is no cc compiler included so shc only preforms the first step (creates the .c source from the .sh script/s) but it does not compile the resulting source into tyhe executable, since ther is no compiler present if gives the "cc: not found" error.

I have used shc flawlessly  on debian linux for a few years now and it works perfectly. Everything seems to be correct with the openwrt version aswell. only when i try to run the the executable i get the error msg  "mysrcipt: applet not found"  (**myscript is the executable created by shc from the  mtscript.sh**)  if i compile the same script for x86 it runs fine. I think the problem may have something to do with busybox. I have scoured the web for info, and anything reguarding embedded linuxs applet errors seem to point to busybox ??

If i was to compile gcc as an ipk and install in on the router, then compile the script natively (on the router), would this be any different then cross-compiling the .c produceced by shc ?

(** just to note i am using the SDK to cross-compile the .c source produced from the shc app on the router ,  i run shc on the router, and scp the resulting .c file to my SDK pakage dir. I have tried producing the .c on my linux box aswell and it make no difference, i still get the "applet not found" error.


I will give an example script and the resulting .c source produced by shc once i get it orginized in hopes that it will aid if solving this error


Any thought or suggestions welcome smile

Teara

Hi,
  I am having a similar problem - I compiled a shell script as listed below using "shc-3.8.7.2" into a "c" code, and then to an Openwrt executable. The executable, when run on a Openwrt platform, is exiting with "applet not found".  Has anyone encountered a similar porblem or has any one used "shc" on an openwrt platform.
shc-3.8.7 can be found at -- http://www.datsi.fi.upm.es/~frosal/sources/ .
  Please let me know.
thanks
Raj

--

#! /bin/sh
echo "TEST"

The "applet not found" errors happens when something calls busybox with a nonexisting command:

root@OpenWrt:~# busybox foo
foo: applet not found

It is impossible to tell what the problem is without seeing the generated executable.

Thanks for the reply. You are right in a way, but My problem is specifically with respect to using "shc" - a shell script compiler, which can be used to convert ".sh" files to executables that can be run on OPENwrt or linux systems.

you can type "strace busybox foo" or "strace busybox echo foo".  to find the crash points.

I am still stuck. but if some has tried "shc" on openwrt please give me a howl smile

thanks.
Raj

I know exactly where the "crash point" is, but that does not help to track down the actual issue with shc compiled scripts. I suspect the shc compiler puts some instructions in the embedded scripts which are not supported by busybox.

Thanks Jow. Finally found the issue after going through the "shc-3.8.7" code. The shc compiler is using "execv" command in the "c" code. BusyBox, for some reason, does not like it. I decided to put this aside for a while until I figure out how to replace "execv" command with "system" command, which works on busy box.

any news about? I'm facing the same problem.

Thank you

Try patch: http://sdrv.ms/136LGal

1. Patch shc-3.8.7.c ;
2. CrossCompill shc for you platform ;
3. Run shc on target platform with options: shc -r -B -i some-script.sh (-B - for supporting busybox) ;
4. It produse general C-code ;
5. CrossCompill C-code ;
6. Enjoy.

P.S. My platform is SH4.

Hi

The patch link can't be open.
Could please send the  patch to my email zi_zhi_guang@163.com
Thanks .

ddd203 wrote:

Try patch: http://sdrv.ms/136LGal

1. Patch shc-3.8.7.c ;
2. CrossCompill shc for you platform ;
3. Run shc on target platform with options: shc -r -B -i some-script.sh (-B - for supporting busybox) ;
4. It produse general C-code ;
5. CrossCompill C-code ;
6. Enjoy.

P.S. My platform is SH4.

I know this old topic..

but i have this problem too

I need shc for openwrt but dont know how compile?

some one please give me some directions?

I dont know any tags to seach about how to do this..

sorry bad english...

thanks for all!

(Last edited by gugaoforums on 29 Dec 2015, 22:25)

I'm install

opkg install make

root@openwrt:~/sda1/shc-3.8.9b# make
gcc -Wall  shc.c -o shc
make: gcc: Command not found
make: *** [shc] Error 127

what platform do you need it for ? rather the try and explain I have gone ahead and made an openwrt package with the patch applied. I will compile it and post it on my site for you to download and test ...just need to know what platform you need it for wink

Note once you compile the script you will need to take the resulting C code and recompile for your platform ...as per the instructions above

hostle19 wrote:

what platform do you need it for ? rather the try and explain I have gone ahead and made an openwrt package with the patch applied. I will compile it and post it on my site for you to download and test ...just need to know what platform you need it for wink

Note once you compile the script you will need to take the resulting C code and recompile for your platform ...as per the instructions above

I need shc for openwrt barrier breaker.

I have many bash scripts in my openwrt barrier breaker and I need to encrypt and run with the magic of shc

Thank you very much for your help my friend!!!

how to CrossCompill C-code to running in openwrt?

smile

hi friend  hostle19

where is your site?

If I can encrypt my bash openwrt script in my linux with shc...

get the c code

and crosscompile for openwrt

works this solution?

gugaoforums wrote:

If I can encrypt my bash openwrt script in my linux with shc...

get the c code

and cross-compile for openwrt

works this solution?

NO you need the shc binary to run the script after its compiled. So you install the openwrt shc package vi opkg install, then you use shc to convert your script into C code then you cross compile the resulting C code into a binary/ openwrt package then you again install it via opkg install.

At least that is the only way I ever got it to work, I have only used it for testing a few years ago so I could be wrong, regardless you'll need the shc package to install shc on your router to run the compiled scripts.

I still need to know what type of router your are using so I can compile it for that platform. My site is www.fire-wrt.com/forums ... its brand new smile

hostle19 wrote:
gugaoforums wrote:

If I can encrypt my bash openwrt script in my linux with shc...

get the c code

and cross-compile for openwrt

works this solution?

NO you need the shc binary to run the script after its compiled. So you install the openwrt shc package vi opkg install, then you use shc to convert your script into C code then you cross compile the resulting C code into a binary/ openwrt package then you again install it via opkg install.

At least that is the only way I ever got it to work, I have only used it for testing a few years ago so I could be wrong, regardless you'll need the shc package to install shc on your router to run the compiled scripts.

I still need to know what type of router your are using so I can compile it for that platform. My site is www.fire-wrt.com/forums ... its brand new smile

sorry for my bad english..

I need to run shc in openwrt barrier breaker in routers TPlink  mr3020 , mr3220 v1  v2, 1043nd

thanks for your help and patience!

hostle19 wrote:

file has been posted at my site..

http://fire-wrt.com/forums/showthread.p … ;p=2#post2

thanks friend!

but..

gugaoforums, you do not have permission to access this page. This could be due to one of several reasons:

Your user account may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.

I activated your account, you should be good to go now

for share...

shc -r -B -i -f /mnt/sda1/test.sh
shc parse(-f): No source file specified
shc Usage: shc [-e date] [-m addr] [-i iopt] [-x cmnd] [-l lopt] [-rvDTCABh] -f script

******************

shc -r -B -f /mnt/sda1/test.sh
/bin/sh: cc: not found
shc: Success

/mnt/sda1/test.sh
/mnt/sda1/test.sh.x.c

now I dont know what to do lololol

but I learn about crosscompile...

the guru's can tel if this true

source link
http://www.linux-magazine.com/Online/Fe … l-Compiler

warning! shc will not protect your sourcecode!

After executing the “protected script” run:

ps aux | grep “name of shc compiled script”

You will notice it uses a single process to execute the entire contents of your script and it is now displayed in it’s entirety in your shell window. You can then simply find and replace ^J with \n and ^I with \t and you have the full formatted source code.

Therefore any shc ‘compiled script’ can be reversed to original complete source code in seconds… It is utterly pointless and I really wish people would stop suggesting it as an obfuscation technique, it gives authors a false sense of security because at a glance the *file* it compiles appears to be very secure. No obfuscation technique is irreversible but the point is to at least make it complex enough that it becomes more effort than it is worth to a would be code thief.

shc however, can be reversed in seconds as I have just described above.

this bug was fix in version 3.89 ...here is the change log


CHANGES

3.8.9b    Fri, 4 Jan 2013 12:10:42 +0100 (CET)

    Lee Chisnall <lee@dnuk.com>
    - To work as daemon. 



3.8.9    Wed Apr 25 09:24:25 CEST 2012

    Thanks to Giacomo Picconi <giacomo.picconi@gpstudio.com> for:
    - Fixing a long standing bug making the source not hidden.


3.8.8    Mon Nov 28 11:26:25 CEST 2012

    "me".



3.8.7    Wed Feb 10 20:40:37 CET 2010

    - Bug on 64bit systems with expiration dates.

(Last edited by hostle19 on 31 Dec 2015, 06:36)