昨天在整理之前公司的一个运维脚本,这个脚本功能十分强大,它基本覆盖了我们Oracle数据库运维的命令。
而后,我又对改脚本进行个性化的调整,使脚本更加符合我的使用。但是脚本只是单纯的由SQL组成的shell脚本,无论谁拿到了这个脚本很快就可以山寨一份。
为了避免泄漏前公司的资料(已咨询过离职后的员工仍然可以使用,但不要传播就好了。其实给别人用估计也没法查出来),加上自己的一些小成果。
在网上查找有没办法可以将shell脚本进行加密,于是我就找到了一款工具------- Shc ( generic shell script compiler )
百度百科居然把安装和使用的步骤了列出来了。。。。
以上都是来自百度百科,哈哈。下面我们来实际操作一下
使用-h来查看帮助
这样子,我就可以将脚本加密,在其他环境使用了~~
而后,我又对改脚本进行个性化的调整,使脚本更加符合我的使用。但是脚本只是单纯的由SQL组成的shell脚本,无论谁拿到了这个脚本很快就可以山寨一份。
为了避免泄漏前公司的资料(已咨询过离职后的员工仍然可以使用,但不要传播就好了。其实给别人用估计也没法查出来),加上自己的一些小成果。
在网上查找有没办法可以将shell脚本进行加密,于是我就找到了一款工具------- Shc ( generic shell script compiler )
百度百科居然把安装和使用的步骤了列出来了。。。。
简介
使用 shc 对 Linux shell
脚本加密.
shc是一个专业的加密shell脚本的工具.它的作用是把
shell脚本转换为一个可执行的
二进制文件,这个办法很好的解决了脚本中含有IP、密码等不希望公开的问题.
不过从网上看到的评论,虽然能够加密,但是有心的话还是能够破解的,如果对于民用的话还是足够了。
网上的下载地址几乎都没有资源,我从别的地方下了一份,需要的话可以联系我~~
不过从网上看到的评论,虽然能够加密,但是有心的话还是能够破解的,如果对于民用的话还是足够了。
网上的下载地址几乎都没有资源,我从别的地方下了一份,需要的话可以联系我~~
安装
tar zxvf shc-3.8.tgz
cd shc-3.8
make test
make
make test
make strings
make install
使用方法:
shc -r -f script-name
运行后会生成两个文件,script-name.x 和 script-name.x.c. 其中script-name.x是加密后的可执行的
二进制文件;用./script-name即可运行,script-name.x.c是生成 script-name.x的原文件(c语言).
实例
下载到系统后,安装执行:
# tar xzvf shc-3.8.6.tgz
# cd shc-3.8.6
# mkdir -p /
usr/local/man/man1
这步是必须的,不然安装过程中会报错,shc将安装命令到/usr/local/bin/目录下;将帮助文档存放在/usr/local/man/man1/目录下,如果系统中无此目录,安装时会报错,可创建此目录后再执行安装:
# make install
这是要回答yes或者y,不能直接回车,否则会报错
使用方法:shc -f script-name
“-f”选项指定需要加密的程序,若要将
shell程序script.s加密,执行:
# shc -f script.s
如果要查看执行过程中详细信息,可以添加选项“-v”。执行完成后将产生两个文件:“script.s.x.c”和“script.s.x”,命令shc首先通过shell程序生成其C语言的
源代码“script.s.x.c”,然后对它进行编译生成加密后的可执行的
二进制文件“script.s.x”,运行“script.s.x”可以看到此程序执行结果:
# shc -e 18/10/2006 -m " It’s too late to run this script " -f script.s
以上都是来自百度百科,哈哈。下面我们来实际操作一下
使用-h来查看帮助
点击(此处)折叠或打开
- [root@ydit shc-3.8.7]# shc -h
- shc Version 3.8.7, Generic Script Compiler
- shc Copyright (c) 1994-2009 Francisco Rosales <frosal@fi.upm.es>
- shc Usage: shc [-e date] [-m addr] [-i iopt] [-x cmnd] [-l lopt] [-rvDTCAh] -f script
-
- -e %s Expiration date in dd/mm/yyyy format [none] ----设置过期时间
- -m %s Message to display upon expiration ["Please contact your provider"] ----到期时显示的消息
- -f %s File name of the script to compile ----要编译的脚本的文件名
- -i %s Inline option for the shell interpreter i.e: -e
- -x %s eXec command, as a printf format i.e: exec('%s',@ARGV);
- -l %s Last shell option i.e: --
- -r Relax security. Make a redistributable binary
- -v Verbose compilation
- -D Switch ON debug exec calls [OFF]
- -T Allow binary to be traceable [no]
- -C Display license and exit
- -A Display abstract and exit
- -h Display help and exit
-
- Environment variables used:
- Name Default Usage
- CC cc C compiler command
- CFLAGS <none> C compiler flags
-
- Please consult the shc(1) man page.
点击(此处)折叠或打开
- 先写一个t.sh的shell脚本
- [root@ydit shc-3.8.7]# cat t.sh
- echo "cyx";
- 使用shc加密,发现有报错
- [root@ydit shc-3.8.7]# shc -e 27/07/2016 -m "contact 77954090@qq.com" -f t.sh
- shc: invalid first line in script: echo "cyx";
- shc: Success
- 测试发现,需要在开头添加使用的shell类型,之后就没有出现报错了。
- [root@ydit shc-3.8.7]# cat t.sh
- #!/bin/sh
- echo "cyx";
- [root@ydit shc-3.8.7]# shc -e 27/07/2016 -m "contact 77954090@qq.com" -f t.sh
- 运行完之后会生成两个文件,一个是加密后的可执行的二进制文件,一个是生成 script-name.x的原文件(c语言).
- [root@ydit shc-3.8.7]# ls -ltr
- total 204
- -rw-r-----. 1 1000 1000 17982 May 10 1996 Copying
- -rwxr-x---. 1 1000 1000 336 Feb 22 2003 match
- -rw-r-----. 1 1000 1000 1544 Jun 19 2003 shc.README
- -rwxr-x---. 1 1000 1000 155 Jun 20 2003 pru.sh
- -rwxr-x---. 1 1000 1000 52 Jun 20 2003 test.csh
- -rw-r-----. 1 1000 1000 3136 Jul 8 2004 shc.1
- -rw-r-----. 1 1000 1000 4558 Jul 8 2004 shc.html
- -rwxr-x---. 1 1000 1000 138 Nov 13 2004 test.bash
- -rwxr-x---. 1 1000 1000 142 Jan 18 2008 test.ksh
- -rw-r-----. 1 1000 1000 24962 Feb 11 2010 shc-3.8.7.c
- -rw-r-----. 1 1000 1000 1940 Feb 11 2010 Makefile
- -rw-r-----. 1 1000 1000 3637 Feb 11 2010 CHANGES
- lrwxrwxrwx. 1 1000 1000 11 Jul 25 17:51 shc.c -> shc-3.8.7.c
- -rwxr-xr-x. 1 root root 37213 Jul 25 17:51 shc
- -rwxrwxrwx. 1 root root 44323 Jul 25 17:54 dxsql
- -rw-r--r--. 1 root root 24 Jul 26 11:19 t.sh
- -rw-r--r--. 1 root root 9434 Jul 26 11:20 t.sh.x.c
- -rwx--x--x. 1 root root 11616 Jul 26 11:20 t.sh.x
- 测试t.sh.x能否使用,并查看里面的内容。发现直接使用sh无法使用,需要用./的方式。打开都是乱码。
- [root@ydit shc-3.8.7]# sh t.sh.x
- t.sh.x: t.sh.x: cannot execute binary file
- [root@ydit shc-3.8.7]# ./t.sh.x
- cyx
- [root@ydit shc-3.8.7]# cat t.sh.x
- ELF>?
- @@P&@@@@@@@@@@ ` `H ( ( `( @@DDP錿d@@llQ錿/lib64/ld-linux-x86-64.so.2GNUGNU讪i=桟3E筲忕`謴0@!??艍惸箿@9驄r
这样子,我就可以将脚本加密,在其他环境使用了~~
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29123031/viewspace-2122558/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29123031/viewspace-2122558/