How can I compile binary shell script for FreeBSD? I tried the Linux binary emulator but it doesn't work.
-
What script? What language is it written in?– terdonMar 14, 2013 at 19:55
-
bash is used. I tried shc -f /test.sh inside freebsd 8. but the script is killed immediately. Command "file /test.sh.x" return : ELF 32-bit LSB executable, Intel 80386, version 1 (FreeBSD), dynamically linked (uses shared libs), for FreeBSD 8.0 (800107), stripped– Julio FongMar 14, 2013 at 20:15
3 Answers
There is really no such thing as a binary shell script (script means not binary) - although it is possible to tack an executable binary or a compressed file on the end of a shell script, which usually just contains a tail command to strip the shell script and decompress/preprocess and execute the binary.
If correctly set up the script should include the shell to use (#!/bin/sh would be the traditional unix default), or should use only commands common to all shells. Simple thing is to make it readonly for safety and open it with vi and have a look, and then just execute the payload command(s) on the file yourself (with adjustments as needed - often the point is to set up some environment variables or do some preprocessing, most often including decompression).
The shc
program is not a real shell compiler. From the manual page:
shc itself is not a compiler such as cc, it rather encodes and encrypts a shell script and generates C source code with the added expiration capability. It then uses the system compiler to compile a stripped binary which behaves exactly like the original script. Upon execution, the compiled binary will decrypt and execute the code with the shell -c option. Unfortunatelly, it will not give you any speed improvement as a real C program would
Some scripting languages like e.g. Python convert scripts into bytecode before executing them. Shells that can be used interactively usually don't, they are just interpreters.
One could even argue that save for some embelishments like variables, loops and other control structures, shells are mostly a front-end for the fork
and exec
functions.