用shc加密shell脚本 - linux进阶屋 - 51CTO技术博客

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

 
下面就说明一下shc的安装,参数,以及使用示例:
下载安装:
(官网下载地址: http://www.datsi.fi.upm.es/~frosal/sources/)
# wget http://www.datsi.fi.upm.es/~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 "lianxi aaa@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.x 即可运行.
script-name.x.c是生成script-name.x的原文件(c语言)
 
说明:
经我测试,相同在操作系统,shc后的可执行二进制文件直接可以移植运行,但不同操作系统可能会出现问题,如我将源shell在CentOS5.4上加密后移到redhat as5u4上不能运行,出现“Floating point exception”错误提示,但移到另一台CentOS5.4上直接运行没问题。
我的过程:
在编译的时候,make ->make test->make install
root@qustdjx-K42JZ:/home/qustdjx/test# shc -r -f test1.sh
root@qustdjx-K42JZ:/home/qustdjx/test# ls
shc-3.8.7      test11.sh   test1.sh.x.c  test4.sh   test6.sh~  test9.sh
shc-3.8.7.tgz  test11.sh~  test2.sh      test4.sh~  test7.sh   test9.sh~
test           test1.sh    test2.sh~     test5.sh   test7.sh~  test.sh
test10.sh      test1.sh~   test3.sh      test5.sh~  test8.sh   test.sh~
test10.sh~     test1.sh.x  test3.sh~     test6.sh   test8.sh~
root@qustdjx-K42JZ:/home/qustdjx/test#




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值