Chinaunix首页 | 论坛 | 博客
  • 博客访问: 985149
  • 博文数量: 195
  • 博客积分: 4890
  • 博客等级: 上校
  • 技术积分: 2221
  • 用 户 组: 普通用户
  • 注册时间: 2009-06-09 15:34
文章分类

全部博文(195)

文章存档

2014年(1)

2013年(8)

2012年(22)

2011年(9)

2010年(54)

2009年(101)

我的朋友

分类: LINUX

2011-09-07 16:30:56

Shc可以用来对shell脚本进行加密,可以将shell脚本转换为一个可执行的二进制文件。经过shc对shell脚本进行加密后,会同时生成两种个新的文件,一个是加密后的可执行的二进制文件(文件名以.x结束),另一个是C语言的原文件(文件名以.x.c结束)。


下面就说明一下shc的安装,参数,以及使用示例:
下载安装:
(官网下载地址: ~frosal/sources/)
# wget ~frosal/sources/shc-3.8.7.tgz
# cd shc-3.8.7
# make
# make install
(仅用make就可以完成安装,运行shc时要指出绝对路径;用make install,将shc安装到/usr/local/bin下,可以直接运行)

常用参数:
-e date
Expiration date in dd/mm/yyyy format [none](指定过期日期)

-m message
message to display upon expiration ["Please contact your provider"](指定过期提示的信息)

-f script_name
File name of the script to compile(指定要编译的shell的路径及文件名)

-r Relax security.
Make a redistributable binary which executes on different systems running the same operat-ing system.(可以相同操作系统的不同系统中执行)

-v Verbose compilation(编译的详细情况)

使用示例:
[root@centos54 tmp]# /usr/local/src/shc-3.8.7/shc -e 20/10/2010 -m "contact xxx@163.com" -v -r -f ./ex.sh
-e:指定过期时间为2010年10月20日
-m:过期后打印出的信息;
-v: verbose
-r: 可在相同操作系统的不同主机上执行
-f: 指定源shell

使用:

# shc -r -f script-name

注意:要有-r选项, -f 后跟要加密的脚本名.
运行后会生成两个文件,script-name.x 和 script-name.x.c
script-name.x是加密后的可执行的二进制文件.
./script-name 即可运行.
script-name.x.c是生成script-name.x的原文件(c语言)

但由于生成的文件需要动态谅解不能用作其他机器,需要下面的方法来生成静态的链接库文件。

生成静态链接的二进制可执行文件

可以通过下面的方法生成一个静态链接的二进制可执行文件:

# CFLAGS=-static shc -r -f test.sh

# file test.sh.x


自己在机器上测试

使用命令  wget ~frosal/sources/shc-3.8.7.tgz 下载并解压缩包后

[root@redhat shc-3.8.7]# cat shc.README

Purpose:

A generic shell script compiler. Shc takes a script, which is
specified on the command line and produces C source code. The
generated source code is then compiled and linked to produce a
stripped binary executable. Use with care.

Building:

Just do a "make"


Testing:

Try: "make test"
or: "shc -v -f match" then "match.x sh"

Caveat emptor: see Copyright

The results look fine to me, but I havn't used this in anger, but
the author has used shc for his work widely over SunOS, Solaris and
Linux, and done some testing on Irix and HPUX.

We tested it on a few SMALL ksh scripts - big tasks should probably
be written in C in the first place (see _SC_ARG_MAX below)!


Bugs:

The one (and I hope the only) limitation using shc is the
_SC_ARG_MAX system configuration parameter.

It limits the maximum length of the arguments to the exec function,
limiting the maximum length of the runnable script of shc.

!! - CHECK YOUR RESULTS CAREFULLY BEFORE USING - !!


Archived at: ftp://hpux.csc.liv.ac.uk/hpux/Languages/shc-2.4a
Archived by: steff@csc.liv.ac.uk

Author: Francisco Rosales Garcia
--------------------------------------------------------------------
Francisco Rosales Garc韆 TEL: +341 336 73 80
~frosal FAX: +34 1 336 73 73
Departamento de Arquitectura y Tecnolog韆 de Sistemas Inform醫icos
Facultad de Inform醫ica. Universidad Polit閏nica de Madrid. Espa馻
--------------------------------------------------------------------

[root@redhat shc-3.8.7]#
 


阅读(4312) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~