shc encryption
shc is a tool for encrypting scripts. It uses RC4 encryption algorithm to convert shell programs into binary files (supports dynamic and static link libraries)
installation
# wget http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.9b.tgz # tar zxvf shc-3.8.9b.tgz # cd shc-3.8.9b # mkdir -p /usr/local/man/man1/ # make install
Common parameters:
-e date (specify the expiration date) -m message (specify the expiration message) -f script_name (specify the path and file name of the shell to be compiled) -r Relax security. (can be executed on different systems with the same operating system) - v Verbose compilation (details of compilation)
Commonly used methods:
# shc -v -r -f shellname
After execution, a shellname.x and shellname.c file will be generated, just use the shellname.x file, and the name can be modified at will.
shellname.x is the encrypted binary executable file shellname.c is the C source code file after script conversion
If an error is reported during the execution of the shellname.x file, you can modify the shellname.c file and recompile it into a binary file after the modification:
# gcc -o shellname.x shellname.c
The following is an error I encountered during the execution process, the specific error output did not stay:
When the first line of my script reads #! / Usr / bin / env bash, an error will occur when using the shc encryption tool. The solution is to replace it with #! / Usr / bin / bash or #! / Bin / bah
rpm packaging
Use rpmbuild to package shellname.x binary file into rpm file
Install related tools:
# yum install rpmbuild rpmdevtools -y # rpmdev-setuptree // The working directory will be generated automatically
The working directory is as follows:
~/rpmbuild
~/rpmbuild/SOURCES
~/rpmbuild/SPECS
~/rpmbuild/BUILD
~/rpmbuild/RPMS
~/rpmbuild/RPMS/i386
~/rpmbuild/SRPMS
At the time, the author Baidu copied a shell spec and modified the spec, but after the packaging was completed, the installation of the rpm package reported an error. Later, rpmrebuild was used to modify the spec.
# rpmrebuild -e -p shellname.rpm // Spec will be regenerated, and the content of the spec will be re-modified according to the prompts inside. This part is used for troubleshooting later, and it is not needed now
# cd rpmbuild / # vi BUILD / shellname.spec // Copy the following to the spec file, this file is the core of the rpm package Summary: Prepare net environment Name: shellname.x Version: 43 Release: el7 License: GPL Group: System Environment / Base ExclusiveArch: x86_64 Provides: shellname.x = 43-el7 Provides: shellname.x (x86-64) = 43-el7 Requires (pre): / bin / sh #requires Obviously the dependencies required to install the rpm package, According to your situation, you can fill in Requires (post): / bin / sh #If you don't fill in, you can also package successfully Requires (preun): / bin / sh Requires: libc.so.6 () (64bit) Requires: libc.so. 6 (GLIBC_2.14) (64bit) Requires: libc.so. 6 (GLIBC_2.2.5) (64bit) Requires: libc.so.6 (GLIBC_2.7) (64bit) Requires: rtld (GNU_HASH) % description # Describe the content, just fill in the shellname.x prepare net bridge environment % prep # The work before packaging,% {buildroot} is the project root directory, and% {_ binddir} refers to the / usr / bin directory mkdir -p% {buildroot}% {_ bindir} # The directory required to create the project , When the rpm package is installed, it will generate _binddir directory install -c -m 755 $ OLDPWD / shellname.x% {buildroot}% {_ bindir} /shellname.x # Copy the package file to the project directory exit 0 % files # Contents included here to fill out the project, will also be in this generation out /usr/bin/shellname.x #% {_} # bindir here I had to fill in, perform the rpm installation error, because access is not enough, now the comment #% dir % attr (0755, root, root) "/ usr / bin" # I have filled in here, and I get an error when performing rpm installation. The reason is not enough. % attr (0755, root, root) "/usr/bin/shellname.x" # Modify permissions and belong to % pre -p / bin / sh # Unclear meaning, generated after rpmrebuild repair % post -p / bin / sh # Same as above, generated after rpmrebuild repair % preun -p / bin / sh # Same as above , Generated after rpmrebuild repair % define __spec_install_pre / bin / true # Same as % build # This should be the % clean required to compile the source code package # Build project cleanup rm -rf% {buildroot} % changelog # Not clear
Use rpm -bb /BUILD/shellname.spec Note that shellname.x is placed in the rpmbuild directory
The generated rpm package is in the rpmbuild / RPMS / directory, and the output rpm package can be installed! rpm -ivh shellname.rpm
Use shellname.x after installation to see if there is this command
Extended link:
https://blog.csdn.net/rocky_zhm/article/details/51755257 About shc
https://blog.csdn.net/txgc1009/article/details/6833764 About rpmbuild
http://fedoraproject.org/wiki/Packaging/RPMMacros#RPM_directory_macrosAbout rpmbuild
https://blog.csdn.net/weixin_33779515/article/details/92567570 About rpmbuild