Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ajdiaz/bashc
A tool to convert/compile a bash script to a static linked x86 and x86_64 binary.
https://github.com/ajdiaz/bashc
Last synced: 6 days ago
JSON representation
A tool to convert/compile a bash script to a static linked x86 and x86_64 binary.
- Host: GitHub
- URL: https://github.com/ajdiaz/bashc
- Owner: ajdiaz
- License: gpl-3.0
- Created: 2016-10-18T20:21:01.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-03-06T18:30:07.000Z (over 1 year ago)
- Last Synced: 2024-08-02T16:05:44.419Z (3 months ago)
- Language: Shell
- Homepage: https://ajdiaz.me/bashc/
- Size: 46.9 KB
- Stars: 31
- Watchers: 2
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README
- License: LICENSE
Awesome Lists containing this project
README
▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄ ▄ ▄▄▄▄▄▄▄▄▄▄▄
▐░░░░░░░░░░▌ ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░▌ ▐░▌▐░░░░░░░░░░░▌
▐░█▀▀▀▀▀▀▀█░▌▐░█▀▀▀▀▀▀▀█░▌▐░█▀▀▀▀▀▀▀▀▀ ▐░▌ ▐░▌▐░█▀▀▀▀▀▀▀▀▀
▐░▌ ▐░▌▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌▐░▌
▐░█▄▄▄▄▄▄▄█░▌▐░█▄▄▄▄▄▄▄█░▌▐░█▄▄▄▄▄▄▄▄▄ ▐░█▄▄▄▄▄▄▄█░▌▐░▌
▐░░░░░░░░░░▌ ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░▌
▐░█▀▀▀▀▀▀▀█░▌▐░█▀▀▀▀▀▀▀█░▌ ▀▀▀▀▀▀▀▀▀█░▌▐░█▀▀▀▀▀▀▀█░▌▐░▌
▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌▐░▌
▐░█▄▄▄▄▄▄▄█░▌▐░▌ ▐░▌ ▄▄▄▄▄▄▄▄▄█░▌▐░▌ ▐░▌▐░█▄▄▄▄▄▄▄▄▄
▐░░░░░░░░░░▌ ▐░▌ ▐░▌▐░░░░░░░░░░░▌▐░▌ ▐░▌▐░░░░░░░░░░░▌
▀▀▀▀▀▀▀▀▀▀ ▀ ▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀ ▀▀▀▀▀▀▀▀▀▀▀BashC is a tool which get your bash script and produces an static linked
binary for Linux x86 and x86_64 machines (also support ARM and many other
OS, but I cannot test them yet) which runs your script.For example:
$ cat > myscript.sh << EOF
#!/bin/bash
echo "This is a test
EOF$ bashc myscript.sh myscript.bin
$ file myscript.bin
bashc: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically
linked, stripped
$ ./myscript.bin
This is a testNice eh!
---- Installation --------------------------------------------------------
From source code just run:
make
Easy :)
---- Internals ----------------------------------------------------------
This application is based on previous work from Robert Xu¹, which uses musl
instead of glibc avoiding calls to dlopen(3) to produce a static binary.I added some patches (in patch/ directory) to convert the bash binary in
a compiler tool. The patch does the following:1. Read the filesize of itself and jump (lseek) to the last byte of the
binary.
2. There read -20 chars as decimal number which represents the length of the
script to be executed
3. Jump again (lseek) to END - length readed in (2)
4. Bash interpret the code in current fd position.That is how bashc runs a script. To create the binary just concatenate to the
static patched bash, the script to run. Because of ELF header (and in theory
also Match) ensure us that execution will never reads after lenght scecified
in ELF header, then our script still safe after that position. During the
execution the algorithm explained above is running and the script is
interpreted.¹ https://github.com/robxu9/bash-static
---- Limitations --------------------------------------------------------
* Not tested in any other platform than Linux X86 and X86_64.
* The bash script code is concatenated in plain text, so no security here.
* We cannot use any external dependency for the script unless it was
previously compiled as builtin.
* If you call bashc from exec syscall, please use the full path to the
binary (prefixing current working directory if needed) to avoid problems
during the binary generation. Althoug the generated binary works fine
in any path (is script is designed for that), the compilation itself does not.