自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

使用Shell腳本制作Linux自解壓文件

系統(tǒng) Linux
前幾天在使用阿里云時候發(fā)現(xiàn)阿里工程師提供的一個腳本里,后面都是亂碼加密文件,并且文件只要一更改自解壓就會失效,心里是什么技術(shù)進行代碼加密,仔細查看代碼后發(fā)現(xiàn),原來是 .tar.gz 的二進制文件,把打包壓縮以后的文件進行直接存進shell腳本后面,從而實現(xiàn)自解壓,次篇文件 使用 tar 編碼進行嵌入存文件

前幾天在使用阿里云時候發(fā)現(xiàn)阿里工程師提供的一個腳本里,后面都是亂碼加密文件,并且文件只要一更改自解壓就會失效,心里是什么技術(shù)進行代碼加密,仔細查看代碼后發(fā)現(xiàn),原來是 .tar.gz 的二進制文件,把打包壓縮以后的文件進行直接存進shell腳本后面,從而實現(xiàn)自解壓,次篇文件使用 tar 編碼進行嵌入存文件。

一、系統(tǒng)環(huán)境說明

  • Centos 7 系統(tǒng)
  • shell使用自帶bash

二、開始編碼測試

1.先來看看阿里工程師編寫的部分代碼,從代碼可以看出后面一連串的亂碼是一個 .tar.gz 的打包壓縮文件,可以看到是使用 awk 進行獲取 .tar.gz 二進制開始行,所以才有那句話 #This line must be the last line of the file 。


#! /bin/bash
#
# Copyright (c) 2009-2015 Aliyun Corporation
# All Rights Reserved
.......
ARCHIVE=`awk '/^__ARCHIVE_BELOW__/ {print NR + 1; exit 0; }' "$0"`
tail -n+$ARCHIVE "$0" | tar -ixzvm -C $tmp_dir > /dev/null 2>&1 3>&1
if [ $? -ne 0 ]
then
    echo "Error: prepare env error, failed create extract xbstream..." >&2
    rm -rf $tmp_dir
    exit 1
fi
......
exit 0

#This line must be the last line of the file
__ARCHIVE_BELOW__
^_<8b>^H^@_÷^U^@^C?[wX^TW×?à<82><8b>¨Y°!<92>?<8a>5±DD<8c>ˉo(?+?<92>^L??,<8c>lc^K?h2v<8c>?T0F? á^^RM¢??]^T<8d>F<

2.編寫的測試代碼如下


#!/bin/bash
#Test shell self-extracting
TmpDir=/tmp

ARCHIVE=$(awk '/^__ARCHIVE_BELOW__/ {print NR + 1; exit 0; }' "$0")
tail -n+$ARCHIVE "$0" | tar -xzvm -C $TmpDir > /dev/null 2>&1 3>&1
if [ $? == 0 ];then
        echo "Success"
else
        echo "Fail"
fi


exit 0
#This line must be the last line of the file
__ARCHIVE_BELOW__

3.創(chuàng)建一個 test 文件夾,里面建兩個文件分別是 TestA 和 TestB ,文件里面分別寫著 This is TestA 和 This is TestB

[root@gz--vm-workstation-0001 scripts]# mkdir test
[root@gz--vm-workstation-0001 scripts]# cd test/
[root@gz--vm-workstation-0001 test]# echo "This is TestA" > TestA
[root@gz--vm-workstation-0001 test]# echo "This is TestB" > TestB
[root@gz--vm-workstation-0001 test]# cat TestA 
This is TestA
[root@gz--vm-workstation-0001 test]# cat TestB
This is TestB
[root@gz--vm-workstation-0001 test]#

4.把文件進行打包加壓嵌入 shell 腳本(也可以使用cat .tar.gz 文件嵌入 shell 腳本),并且刪除 test 文件夾


[root@gz--vm-workstation-0001 scripts]# tar  -zcvm test >> SelfExtracting.sh 
test/
test/TestA
test/TestB
[root@gz--vm-workstation-0001 scripts]# ls
SelfExtracting.sh  test
[root@gz--vm-workstation-0001 scripts]# rm -rf test
[root@gz--vm-workstation-0001 scripts]# ls
SelfExtracting.sh

5.再次查看 SelfExtracting.sh 腳本,發(fā)現(xiàn)已經(jīng)有 .tar.gz 的二進制文件,但注意此時的腳本不能修改和增加任何字符

#!/bin/bash
#Test shell self-extracting
TmpDir=/tmp

ARCHIVE=$(awk '/^__ARCHIVE_BELOW__/ {print NR + 1; exit 0; }' "$0")
tail -n+$ARCHIVE "$0" | tar -xzvm -C $TmpDir > /dev/null 2>&1 3>&1
if [ $? == 0 ];then
        echo "Success"
else
        echo "Fail"
fi


exit 0
#This line must be the last line of the file
__ARCHIVE_BELOW__
^_<8b>^H^@^\<8e>¨Z^@^Cí?M
?0^P<86>á?=En`|ùéú<9e>?^Wp!èaD??;íB<8b> a"<95>a?^P<9a>@^B^Y?2í§)?M]Nμ1<96>Y=?e-?<89><8d>?<94><82><9e>^S^W}kl?\Wq<9d>òq′?<8c>?<90>?<9d>?′?Qy??×??T^]sà)<84>×ùKZ?/<9a>?<84>?^[?ê<95>?e?ù÷??du<94>'°?u5X????zw|×?ó?_¢nó?+X?^?G?^C^@^@^@^@^@^@^@^@^@^@°I7^Z<8a>êá^@(^@^@

6.運行腳本 SelfExtracting.sh 測試

[root@gz--vm-workstation-0001 scripts]# ./SelfExtracting.sh
Success
[root@gz--vm-workstation-0001 scripts]# ls
SelfExtracting.sh

7.聰明的你可能發(fā)現(xiàn),運行顯示成功,怎么不見原來的的目錄呢,哈哈哈,有沒有注意我們是把解壓目錄指向 /tmp 下面,返回去查看上面腳本定義的變量,所以查看如下

[root@gz--vm-workstation-0001 test]# cd /tmp/test
[root@gz--vm-workstation-0001 test]# ls
TestA  TestB
[root@gz--vm-workstation-0001 test]# cat TestA 
This is TestA
[root@gz--vm-workstation-0001 test]# cat TestB
This is TestB
[root@gz--vm-workstation-0001 test]#

8.在深入研究過程中,看到一篇博客[點擊這里查看],發(fā)現(xiàn)還有專門的命令可以搞定在腳本嵌入二進制文件: uuencode,安裝這個工具請在命令行輸入yum install sharutils 進行安裝,原理和tar一樣,具體操作留給各位去探究了咯。

總結(jié): Shell 自解壓腳本在很多情況可以使用,比如防止別人進行修改你的文件,把一些必要的文件發(fā)給別人時候,如果使用的是 linux ,可以進行嵌入到shell腳本,就發(fā)一個腳本給別人,他們一運行就可以得到他們需要的文件或者配置,如果他們自作聰明打開文件進行修改,哈哈哈哈哈哈哈,對不起,腳本直接報錯運行不了。

責(zé)任編輯:華軒 來源: 微技術(shù)之家
相關(guān)推薦

2024-01-19 16:37:17

Linux操作系統(tǒng)

2009-08-04 09:53:21

linux創(chuàng)建文件命令tail命令自解壓

2021-12-03 08:00:00

腳本數(shù)據(jù)容器

2014-08-08 16:17:49

shell腳本linux

2024-11-27 09:19:25

2017-07-03 12:19:46

LinuxShell交換文件

2009-11-18 13:52:30

PHP shell腳本

2022-06-21 09:26:21

Shell腳本JavaScript

2021-03-14 09:28:24

Linux Shell腳本

2022-10-09 10:18:44

LinuxShell腳本

2023-05-20 17:45:25

LinuxShell

2009-12-01 09:13:51

shell腳本linux

2012-05-08 11:11:43

Linuxcrontab命令

2015-08-10 14:42:40

Explain SheShell 命令

2019-08-12 07:45:44

Linux腳本shell

2010-03-23 17:06:01

2009-12-03 10:06:33

Ubuntushell腳本

2017-08-11 17:20:07

LinuxShell

2022-06-09 08:07:15

Shell腳本Linux

2018-08-15 08:45:38

點贊
收藏

51CTO技術(shù)棧公眾號