Shell 脚本加密解密工具之 shc

文章
林里克斯

shc是一个脚本编译工具, 使用 RC4 加密算法, 它能够把 shell 程序转换成二进制可执行文件(支持静态链接和动态链接)。

实验平台:CentOS 7.7.1908

shc Version 4.0.3



一、安装


  • 源码安装

1.下载

$ wget http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.9b.tgz

http://www.datsi.fi.upm.es/~frosal/sources
https://github.com/neurobin/shc

2.解压安装

$ tar xf shc-3.8.9b.tgz 
$ cd shc-3.8.9b
$ makdir -p /usr/local/man/man1/
$ make install
*** Installing shc and shc.1 on /usr/local
*** ¿Do you want to continue? y   #输入 y 不然会报错
install -c -s shc /usr/local/bin/
install -c -m 644 shc.1 /usr/local/man/man1/
  • yum 安装
$ yum -y install shc

二、参数详解


1.用法

$ shc Usage: shc [-e date] [-m addr] [-i iopt] [-x cmnd] [-l lopt] [-o outfile] [-rvDSUHCABh] -f script

2.参数

$ shc -h
shc Version 4.0.3, Generic Shell Script Compiler

    -e %s  #指定脚本到期时间 格式:dd/mm/yyyy
    -m %s  #指定脚本到期时间后显示的消息 ["Please contact your provider"]
    -f %s  #指定需要编译的脚本
    -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: --
    -o %s  #输出的文件名
    -r     #放宽安全性。制作可重新分发的二进制文件,该二进制文件在运行相同操作系统的不同系统上执行。您可以使用此选项释放二进制文件,以供其他人使用
    -v     #输出编译的详细情况
    -S     Switch ON setuid for root callable programs [OFF]
    -D     #打开调试执行程序调用
    -U     #使二进制文件不可跟踪
    -H     Hardening : extra security protection [no]
           Require bourne shell (sh) and parameters are not supported
    -C     #显示许可证
    -A     #显示摘要
    -B     #为 BusyBox 编译
    -h     #显示帮助

三、使用案例


1.简单用法

$ cat 1.sh 
#!/bin/bash

Date=`date '+%Y-%m-%d %H:%M:%S'`
echo $Date

$ bash 1.sh 
2020-10-20 21:50:11

$ shc -r -f 1.sh
$ ls -l
-rw-r--r-- 1 root  root         58 Oct 20 21:50 1.sh
-rwxrwxr-x 1 root  root      11216 Oct 20 21:51 1.sh.x
-rw-r--r-- 1 root  root      17804 Oct 20 21:51 1.sh.x.c
#1.sh.x 编译过后的不可读 shell,可执行
#1.sh.x.c 是脚本的源文件,可删除

$ ./1.sh.x 
2020-10-20 21:54:27

2.设置脚本超时时间

$ shc -r -e "1/11/2020" -m "timeout" -f 1.sh

执行后就显示超时信息

$ ./1.sh.x 
$ ./1.sh.x: has expired!
timeout

3.编译一个不可追踪的二进制文件

$ shc -v -Uf 1.sh 
shc shll=bash
shc [-i]=-c
shc [-x]=exec '%s' "$@"
shc [-l]=
shc opts=
shc: cc   1.sh.x.c -o 1.sh.x
shc: strip 1.sh.x
shc: chmod ug=rwx,o=rx 1.sh.x

在其他机器上执行后就会报错

$ ./1.sh.x 
./1.sh.x: ˿Ȩ²¨­¤N £δOdڏG
MʚX+莕H¤/?,¾֜Ӛe9⧊.l3¨씸Cr~xW[4 
                             �'-±!\U?xu$¬lDP§s?ZL·j?h®
VʶR?
    _Xÿ9Ĵ⑦nUNqHc9S¹ȔXŀR7!zC?°Z©¦x
zڑ?�J´?d0*(币?3m
                \ªzGªƻ°¸V/º_ɣF$=¾,Ӊ㗷m?L­5?ʩkнS

Over~

版权协议须知!

本篇文章来源于 Uambiguous ,如本文章侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意

1135 0 2020-10-20


分享:
icon_mrgreen.gificon_neutral.gificon_twisted.gificon_arrow.gificon_eek.gificon_smile.gificon_confused.gificon_cool.gificon_evil.gificon_biggrin.gificon_idea.gificon_redface.gificon_razz.gificon_rolleyes.gificon_wink.gificon_cry.gificon_surprised.gificon_lol.gificon_mad.gificon_sad.gificon_exclaim.gificon_question.gif
博主卡片
林里克斯 博主大人
一个致力于Linux的运维平台
运维时间
搭建这个平台,只为分享及记载自己所遇之事和难题。

现在时间 2024-04-30

今日天气
站点统计
  • 文章总数:240篇
  • 分类总数:29个
  • 评论总数:10条
  • 本站总访问量 217371 次

@奥奥

@Wong arrhenius 牛比

@MakerFace 厉害了!