標籤:3.1 ida 參考 insecure roc 2.3 monit The 手工
一、登陸密碼加密認證指令碼應用情境
日常操作,經常明文指定了MySQL密碼來登入MySQL服務,在登入成功之後就會拋出下面的警告:
[[email protected] ~]# mysql -uroot -p‘wujianwei‘
Warning: Using a password on the command line interface can be insecure.Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 510Server version: 5.6.36-log Source distributionCopyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql>
對於要求嚴格的業務生產情境不允許出現Warning的,所以可能需要自己定製一下這個錯誤的邏輯。
當然如果不需要知道密碼,能不能換個方式來做呢,其實也行,在5.6中開始有了loginpath,和Oracle中的錢包的功能差不多,其實就是一種認證,做了授權,你不需要知道這些資訊,loginpath就是一道橋樑為你做了認證。
如果你是5.5的版本,沒了loginpath,有沒有其他的方案來滿足需求呢。
有的人可能這個時候開始問,需求是什麼?
我們設想一下,命令列的方式中,輸入純文字密碼,那還要密碼幹嘛,乾脆我輸入密碼的時候你別看,但是history命令裡面有啊。
所以這也算是一個風險點的入口,如果因為一些意外的情況登入,那麼這種情況就很尷尬了。這是需求一。
還有一種情境,如果我們有大量的MySQL環境,每個環境的DBA賬戶密碼是統一的,但是密碼很複雜。我們不能輸入明文,那麼就輸入密碼格式,那就意味著互動和手動輸入,手動輸入簡直了,你會發現這種操作真是原始,進階一點,用下keypass或者keepass等,這個是依賴於本地的環境配置。所以需求二的特點就是手工維護密碼囉嗦,手工輸入密碼太原始。
那我們寫指令碼,但是指令碼裡面的密碼還是可見的,調用的純文字密碼問題解決了,但是內容中的密碼還是可讀的。
所以這種情況下,一個很自然的方法就是加密。
其中一種是對密碼加密,比如我們得到一個密碼加密後的串,在需要調用的時候做一下解密,得到真實的密碼。這個過程是在指令碼裡的邏輯來實現,所以我們得到純文字密碼的機率要低一些。
另外一類就是對檔案加密,比如對整個檔案加密,加密之後檔案就沒法讀了。所以加密後的密碼又被加密了。對檔案加密有shell的方式還有python等語言。
如果要呼叫指令碼的時候,其實就是先解密檔案,然後調用解密邏輯,得到真正的密碼,然後開啟訪問的請求。
比如我得到了一個加密後的密碼串。調用的解密邏輯是decrypt_passwd,當然這個是可讀還可逆的。
二、Linux下用base64命令加解密字串
base64加密解密站長工具:
https://base64.supfree.net/
2.1加密:
[[email protected] ~]# echo wujianwei|base64 d3VqaWFud2VpCg==
2.2解密:
[[email protected] ~]# echo d3VqaWFud2VpCg==|base64 -dwujianwei
2.3下面對MySQLDatabase Backup的賬戶密碼加密的方式來源於base64加密
指令碼內容如下:
[[email protected] ~]# cat test03.sh
#!/bin/shPass=‘d3VqaWFud2VpCg==‘sock=/tmp/mysql.sockfunction decrypt_passwd{tmp_pass=$1dec_pass=`echo $tmp_pass|base64 -d`}decrypt_passwd $Passport=$1#if [ ! -n "$port" ]; then#echo ‘############################################‘#echo ‘Please input correct MySQL Port and try again.‘#echo ‘############################################‘#ps -ef|grep mysqld|grep -v grep |grep -v mysqld_safe#exit#fi/usr/local/mysql/bin/mysql -uroot -p$dec_pass -P$1 -S$sock
通過此指令碼登陸MySQL服務,到此處已經實現了指令碼密碼轉換方式登陸MySQL服務
[[email protected] ~]# sh test03.sh.sh 3306
Warning: Using a password on the command line interface can be insecure.Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 513Server version: 5.6.36-log Source distributionCopyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql>
三、Linux Shell 加密解密方法gzexe
參考地址:
http://www.isays.cn/7336.html
gzexe無需安裝任何軟體是linux內建的功能使用只需要執行命令即可
3.1、加密方法:
假如說我們這個指令碼名字叫test03.sh
那我們就在linux伺服器命令執行gzexe test03.sh即可
[[email protected] ~]# gzexe test03.shtest03.sh: 51.3%
原來的檔案就加密了之後會在目錄產生一個test03.sh~的檔案這個就是原來檔案的備份
[[email protected] ~]# ll test03.sh*-rwxr-xr-x 1 root root 1122 Jul 20 16:57 test03.sh-rwxr-xr-x 1 root root 587 Jul 20 16:55 test03.sh~
發現test03.sh指令碼已經變成二進位檔案
如:
[[email protected] ~]# chmod +x test03.sh[[email protected] ~]# ll test03.sh-rwxr-xr-x 1 root root 1128 Jul 20 22:56 test03.sh[[email protected] ~]# cp test03.sh /usr/local/sbin/
登陸MySQL:
[[email protected] ~]# test03.sh 3306
Warning: Using a password on the command line interface can be insecure.Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 517Server version: 5.6.36-log Source distributionCopyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql>
3.2、解密方法:
假如說我們這個指令碼名字叫test03.sh
那我們就執行
gzexe -d test03.sh
原來的檔案就加解密了放在目錄裡面
查看test03.sh內容,事實證明檔案內容已經解密了
[[email protected] ~]# cat test03.sh
#!/bin/shsock=/tmp/mysql.sockPass="d3VqaWFud2VpCg=="function decrypt_passwd{tmp_pass=$1dec_pass=`echo $tmp_pass|base64 -d`}decrypt_passwd $Passport=$1#if [ ! -n "$port" ]; then#echo ‘############################################‘#echo ‘Please input correct MySQL Port and try again.‘#echo ‘############################################‘#ps -ef|grep mysqld|grep -v grep |grep -v mysqld_safe#exit#fi/usr/local/mysql/bin/mysql -uroot -p$dec_pass -P$1 -S$sock
四、加密軟體shc
shc是linux的一款加密指令碼的外掛程式東西比較安全我們可以利用
4.1、shc軟體安裝
shc官網:https://github.com/yanncam/UnSHcwget -q http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.9.tgztar zxvf shc-3.8.9.tgzcd shc-3.8.9make
[[email protected] shc-3.8.9]# makecc -Wall shc.c -o shc*** Do you want to probe shc with a test script?*** Please try... make test[[email protected] shc-3.8.9]# make install*** Installing shc and shc.1 on /usr/local*** Do you want to continue? yesinstall -c -s shc /usr/local/bin/install -c -m 644 shc.1 /usr/local/man/man1/install: target `/usr/local/man/man1/‘ is not a directory: No such file or directorymake: *** [install] Error 1請建立 mkdir -p /usr/local/man/man1/ ,然後運行make install
4.2、常用參數介紹
-e date (指定到期日期)
-m message (指定到期提示的資訊)
-f script_name(指定要編譯的shell的路徑及檔案名稱)
-r Relax security. (可以相同作業系統的不同系統中執行)
-v Verbose compilation(編譯的詳細情況)
4.3、shc軟體加密使用
假如說我們這個指令碼名字叫test03.sh
那我們就執行
shc -v -f test03.sh
-v 是現實加密過程
-f 後面跟需要加密的檔案
[[email protected] ~]# shc -v -f test03.sh
shc shll=shshc [-i]=-cshc [-x]=exec ‘%s‘ "[email protected]"shc [-l]=shc opts=shc: cc test03.sh.x.c -o test03.sh.xshc: strip test03.sh.xshc: chmod go-r test03.sh.x[[email protected] ~]# ll test03.sh*-rwxr-xr-x 1 root root 598 Jul 20 17:36 test03.sh-rwx--x--x 1 root root 12376 Jul 20 17:36 test03.sh.x-rw-r--r-- 1 root root 12805 Jul 20 17:36 test03.sh.x.c
test03.sh.x為二進位檔案,賦予執行許可權後,可直接執行。更改名字mv test03.sh.x test03.sh
test03.sh.x.c 是c源檔案。基本沒用,可以刪除
[[email protected] ~]# mv test03.sh.x test03.sh
驗證檔案是否為二進位檔案:
登陸MySQL服務:
[[email protected] ~]# ./test03.sh 3306
Warning: Using a password on the command line interface can be insecure.Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 518Server version: 5.6.36-log Source distributionCopyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql>
4.4、shc到期加密法
另shc還提供了一種設定有效執行期限的方法,到期時間,如:
#shc -e 14/09/2016 -m -f test03.sh
選項“-e”指定到期時間,格式為“日/月/年”;選項“-m”指定到期後執行此shell程式的提示資訊。
如果在到期後執行,則會有如下提示:
#./test03.sh.x
./test03.sh.x: has expired!(檔案已經到期)
使用以上方法要注意,需防止使用者更改系統時間,可以通過在程式中加入自動更新系統時間的命令來解決此問題。
4.5、shc加密過的檔案的解密方法
利用這個指令碼來解密
https://github.com/yanncam/UnSHc
[[email protected] ~]# wget https://github.com/yanncam/UnSHc/archive/master.zip[[email protected] ~]# unzip master.zip Archive: master.zip202e5c200005a1b8e474fbfccfb983a582708da1 creating: UnSHc-master/ inflating: UnSHc-master/README.md creating: UnSHc-master/latest/ inflating: UnSHc-master/latest/unshc.sh creating: UnSHc-master/release/ creating: UnSHc-master/release/0.2/ inflating: UnSHc-master/release/0.2/unshc-v0.2.sh inflating: UnSHc-master/release/0.2/unshc-v0.2b.sh creating: UnSHc-master/release/0.3/ inflating: UnSHc-master/release/0.3/unshc-v0.3.sh creating: UnSHc-master/release/0.4/ inflating: UnSHc-master/release/0.4/unshc-v0.4.sh creating: UnSHc-master/release/0.5/ inflating: UnSHc-master/release/0.5/unshc-v0.5.sh creating: UnSHc-master/release/0.6/ inflating: UnSHc-master/release/0.6/unshc-v0.6.sh creating: UnSHc-master/release/0.7/ inflating: UnSHc-master/release/0.7/unshc-v0.7.sh creating: UnSHc-master/release/0.8/ inflating: UnSHc-master/release/0.8/unshc-v0.8.sh creating: UnSHc-master/sample/ inflating: UnSHc-master/sample/test.sh inflating: UnSHc-master/sample/test.sh.x inflating: UnSHc-master/sample/test.sh.x.c
[[email protected] latest]# cd /root/UnSHc-master/latest;
[[email protected] latest]# ./unshc.sh -h
_ _ _____ _ _ | | | | / ___| | | | | | | |_ __ \ `--.| |_| | ___ | | | | ‘_ \ `--. \ _ |/ __|| |_| | | | /\__/ / | | | (__ \___/|_| |_\____/\_| |_/\___|--- UnSHc - The shc decrypter.--- Version: 0.8------------------------------UnSHc is used to decrypt script encrypted with SHcOriginal idea from Luiz Octavio Duarte (LOD)Updated and modernized by Yann CAM- SHc : [http://www.datsi.fi.upm.es/~frosal/]- UnSHc : [https://www.asafety.fr/unshc-the-shc-decrypter/]------------------------------[*] Usage : ./unshc.sh [OPTIONS] <file.sh.x> -h | --help : print this help message -a OFFSET | --arc4 OFFSET : specify the arc4() offset arbitrarily (without 0x prefix) -d DUMPFILE | --dumpfile DUMPFILE : provide an object dump file (objdump -D script.sh.x > DUMPFILE) -s STRFILE | --stringfile STRFILE : provide a string dump file (objdump -s script.sh.x > STRFILE) -o OUTFILE | --outputfile OUTFILE : indicate the output file name[*] e.g : ./unshc.sh script.sh.x ./unshc.sh script.sh.x -o script_decrypted.sh ./unshc.sh script.sh.x -a 400f9b ./unshc.sh script.sh.x -d /tmp/dumpfile -s /tmp/strfile ./unshc.sh script.sh.x -a 400f9b -d /tmp/dumpfile -s /tmp/strfile -o script_decrypted.sh[[email protected] latest]#
[[email protected] ~]# /root/UnSHc-master/latest/unshc.sh test03.sh
_ _ _____ _ _ | | | | / ___| | | | | | | |_ __ \ `--.| |_| | ___ | | | | ‘_ \ `--. \ _ |/ __|| |_| | | | /\__/ / | | | (__ \___/|_| |_\____/\_| |_/\___|--- UnSHc - The shc decrypter.--- Version: 0.8------------------------------UnSHc is used to decrypt script encrypted with SHcOriginal idea from Luiz Octavio Duarte (LOD)Updated and modernized by Yann CAM- SHc : [http://www.datsi.fi.upm.es/~frosal/]- UnSHc : [https://www.asafety.fr/unshc-the-shc-decrypter/]------------------------------[*] Input file name to decrypt [test03.sh][+] ARC4 address call candidate : [0x400ea0][*] Extracting each args address and size for the 14 arc4() calls with address [0x400ea0]... [0] Working with var address at offset [0x6022e4] (0x2a bytes) [1] Working with var address at offset [0x6026af] (0x1 bytes) [2] Working with var address at offset [0x6026b1] (0x8 bytes) [3] Working with var address at offset [0x6026bb] (0x3 bytes) [4] Working with var address at offset [0x6027f7] (0xf bytes) [5] Working with var address at offset [0x602693] (0x1 bytes) [6] Working with var address at offset [0x60280a] (0x16 bytes) [7] Working with var address at offset [0x602695] (0x16 bytes) [8] Working with var address at offset [0x602825] (0x13 bytes) [9] Working with var address at offset [0x6026b0] (0x1 bytes) [10] Working with var address at offset [0x602838] (0x1 bytes) [11] Working with var address at offset [0x60239c] (0x257 bytes) [12] Working with var address at offset [0x60267d] (0x13 bytes) [13] Working with var address at offset [0x602668] (0x13 bytes)[*] Extracting password... [+] PWD address found : [0x6026e2] [+] PWD size found : [0x100][*] Executing [/tmp/0Kq6m3] to decrypt [test03.sh][*] Retrieving initial source code in [test03.sh.sh][*] All done![[email protected] ~]#
[[email protected] ~]# ll test03.sh*
-rwx--x--x 1 root root 12184 Jul 20 23:36 test03.sh-rw-r--r-- 1 root root 597 Jul 20 23:43 test03.sh.sh-rw-r--r-- 1 root root 11964 Jul 20 23:36 test03.sh.x.c[[email protected] ~]#
此時test03.sh.sh 這個檔案就是原來的檔案
[[email protected] ~]# cat test03.sh.sh
#!/bin/shsock=/tmp/mysql.sockPass="d3VqaWFud2VpCg=="function decrypt_passwd{tmp_pass=$1dec_pass=`echo $tmp_pass|base64 -d`}decrypt_passwd $Passport=$1#if [ ! -n "$port" ]; then#echo ‘############################################‘#echo ‘Please input correct MySQL Port and try again.‘#echo ‘############################################‘#ps -ef|grep mysqld|grep -v grep |grep -v mysqld_safe#exit#fi/usr/local/mysql/bin/mysql -uroot -p$dec_pass -P$1 -S$sock
到此處MySQL的登陸密碼的加密示範完畢。歡迎同學們一起交流學習
MySQL之登陸密碼加密認證指令碼