从编译的bash脚本中检索纯文本脚本 [英] Retrieve plain text script from compiled bash script

查看:194
本文介绍了从编译的bash脚本中检索纯文本脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前段时间,我为我的学校写了一些bash脚本。我认为它是非常聪明的保护他们,所以我编译他们与 shc 到一个二进制文件。几个星期后,我失去了未编译的脚本,现在我只剩下我的二进制文件了。

Some time ago, i wrote some bash scripts for my school. I thought it would be very clever to 'protect' them, so i compiled them with shc into a binary file. Some weeks later, i lost the uncompiled scripts and now i have only my binarys left.

有一种方法从 shc 生成的二进制文件?我查看了 shc 的源代码,找到了一个没有运气的反编译二进制文件的方法。

Is there a way to retrieve the scripts back from the shc generated binarys? I looked into the source code of shc to find a way to decompile the binarys with no luck.

推荐答案

使用shc编译脚本不能保护它们。你不会这样得到更多的安全。 shc编译的二进制解码并在启动时将脚本加载到内存中。

Using shc to compile your scripts does not protect them. You don't get more security this way. The shc compiled binary decrypts and loads the script into memory when started. You could then, right after you started the binary, just segfault it and retrieve your script from the coredump.

这里有一个名为test.sh:

Here's a little example script named test.sh:

#! /bin/bash
echo "starting script and doing stuff"
sleep 1
echo "finished doing stuff"

使用shc编译:

shc -f test.sh

启动它作为后台进程,并立即将其进行segfault:

Start it as background process and segfault it right away:

./test.sh.x&  ( sleep 0.2 && kill -SIGSEGV $! )

睡眠0.2会给出二进制的足够时间以启动和解密原始脚本。变量$!包含最后一个后台进程的pid启动,所以我们可以很容易地用分段错误信号SIGSEGV(和kill -11 $!相同)杀死它。

sleep 0.2 will give the binary enough time to start up and decrypt the original script. The variable $! contains the pid of the last background process started, so we can easily kill it with the segmentation fault signal SIGSEGV (same as kill -11 $!).

[1]  + segmentation fault (core dumped)  ./test.sh.x

现在我们可以搜索原始脚本的转储:

Now we can search the dump for the original script:

cat core | strings

我们将dumpfile中的数据转换为字符串,然后将显示所有可打印字符该文件和我们现在可以看到垃圾之间的原始脚本:

We pipe the data in the dumpfile to strings, which will then show us all the printable characters in the file and we can now see the original script between the garbage:

...
4.0.37(2)-release
BASH_VERSINFO
BASH_VERSINFO
release
i686-pc-linux-gnu
BASH_EXECUTION_STRING
BASH_EXECUTION_STRING
                           #! /bin/bash
echo "starting script and doing stuff"
sleep 1
echo "finished doing stuff"
1000
EUID
EUID
1000
...

如果脚本相当大,核心文件大小与ulimit。
很简单,对吧?

If the script is pretty big, maybe you have to adjust the core file size with ulimit. Pretty easy, right?

这篇关于从编译的bash脚本中检索纯文本脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆