Linux下文件加密方法总结 您所在的位置:网站首页 gzexe加密模块 Linux下文件加密方法总结

Linux下文件加密方法总结

2024-07-17 07:09| 来源: 网络整理| 查看: 265

shc是一个专业的加密shell脚本的工具.它的作用是把shell脚本转换为一个可执行的二进制文件,这个办法很好的解决了脚本中含有IP、

密码等不希望公开的问题。

  

如果你的shell脚本包含了敏感的口令或者其它重要信息, 而且你不希望用户通过ps -ef(查看系统每个进程的状态)捕获敏感信息. 你可以

使用shc工具来给shell脚本增加一层额外的安全保护. shc是一个脚本编译工具, 使用RC4加密算法, 它能够把shell程序转换成二进制可执

行文件(支持静态链接和动态链接). 该工具能够很好的支持: 需要加密, 解密, 或者通过命令参数传递口令的环境.

  

shc的官网下载地址: 

http://www.datsi.fi.upm.es/~frosal/sources/

  

安装方法:

[root@ipsan-node03 ~]# cd /usr/local/src/

[root@ipsan-node03 src]# wget http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.9.tgz

[root@ipsan-node03 src]# tar -zvxf shc-3.8.9.tgz

[root@ipsan-node03 src]# cd shc-3.8.9

[root@ipsan-node03 shc-3.8.9]# mkdir -p /usr/local/man/man1

这步是必须的,不然安装过程中会报错,shc将安装命令到/usr/local/bin/目录下;

将帮助文档存放在/usr/local/man/man1/目录下,如果系统中无此目录,安装时会报错,可创建此目录后再执行安装

  

[root@ipsan-node03 shc-3.8.9]# make install

这是要回答yes或者y,不能直接回车,否则会报错

  

需要注意的是,sch只能能shell脚本文件进行加密,其他文件都不可以!

  

sch加密使用方法:

"-f"选项指定需要加密的程序

[root@ipsan-node03 ~]# ls

text.sh

[root@ipsan-node03 ~]# cat text.sh

#!/bin/bash

echo "hahaha"

[root@ipsan-node03 ~]# shc -r -f text.sh

[root@ipsan-node03 ~]# ls

text.sh  text.sh.x  text.sh.x.c

  

注意:要有-r选项, -f 后跟要加密的脚本名。

运行后会生成两个文件,script-name.x 和 script-name.x.c

script-name.x是加密后的可执行的二进制文件.

./script-name.x 即可运行.

script-name.x.c是生成script-name.x的原文件(c语言)

[root@ipsan-node03 ~]# ./text.sh

hahaha

[root@ipsan-node03 ~]# ./text.sh.x

hahaha

  

通常从安全角度考虑:

使用sch命令对shell脚本文件进行加密后,只需保留.x的二进制文件即可,其他两个文件均可以删除!

[root@ipsan-node03 ~]# ls

text.sh  text.sh.x  text.sh.x.c

[root@ipsan-node03 ~]# rm -rf text.sh

[root@ipsan-node03 ~]# rm -rf text.sh.x.c

[root@ipsan-node03 ~]# ls

text.sh.x

[root@ipsan-node03 ~]# ./text.sh.x

hahaha

  

另外:

shc还提供了一种设定有效执行期限的方法,可以首先使用shc将shell程序转化为二进制,并加上过期时间,如:

[root@ipsan-node03 ~]# shc -e 28/02/2018 -m "this script file is about to expire" -v -r -f text.sh

shc shll=bash

shc [-i]=-c

shc [-x]=exec '%s' "$@"

shc [-l]=

shc opts=

shc: cc  text.sh.x.c -o text.sh.x

shc: strip text.sh.x

shc: chmod go-r text.sh.x

[root@ipsan-node03 ~]# ls

text.sh  text.sh.x  text.sh.x.c

  

解释:

-e:指定过期时间为2018年2月28日

-m:过期后打印出的信息;

-v: verbose

-r: 可在相同操作系统的不同主机上执行

-f: 指定源shell

  

如果在过期后执行,则会有如下提示:

[root@ipsan-node03 ~]# ./text.sh.x

./text.sh.x: this script file is about to expire

使用以上方法要注意,需防止用户更改系统时间,可以通过在程序中加入自动更新系统时间的命令来解决此问题!!

  

sch的帮助命令:

[root@ipsan-node03 ~]# shc -help

shc Version 3.8.9, Generic Script Compiler

shc Copyright (c) 1994-2012 Francisco Rosales

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   (指定要编译的shell的路径及文件名)

    -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     C compiler flags

  

    Please consult the shc(1) man page.

  

说明:

经测试,相同在操作系统,shc后的可执行二进制文件直接可以移植运行,但不同操作系统可能会出现问题,

比如将上面的test.sh.x的二进制文件在CentOS6.9上加密后移到redhat as5u4上不能运行,出现"Floating point exception"错误提示,

但移到另一台CentOS6.9上直接运行没问题。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

      专题文章
        CopyRight 2018-2019 实验室设备网 版权所有