ubuntu14.04 x86编译upx 3.92 及so加固
的參考文章:
http://www.cnblogs.com/fishou/p/4202061.html
?
1.download upx和所依賴的組件
upx3.92:https://www.pysol.org:4443/hg/upx.hg/archive/tip.tar.gz LZMA4.43:http://nchc.dl.sourceforge.net/project/sevenzip/LZMA%20SDK/4.43/lzma443.tar.bz2 UCL1.03:http://www.oberhumer.com/opensource/ucl/download/ucl-1.03.tar.gz ZLIB1.2.3http://pkgs.fedoraproject.org/repo/pkgs/zlib/zlib-1.2.3.tar.gz/debc62758716a169df9f62e6ab2bc634/zlib-1.2.3.tar.gz?
2.解壓到/home/local/upx下
1 root@study:/home/local/upxmake# ll 2 3 總用量 24 4 5 drwxr-xr-x 6 root root 4096 8月 16 10:08 ./ 6 7 drwxr-xr-x 3 root root 4096 8月 16 09:55 ../ 8 9 drwxr-xr-x 5 root root 4096 8月 16 09:55 lzma443/ 10 11 drwxrwxrwx 10 jack users 4096 7月 20 2004 ucl-1.03/ 12 13 drwxr-xr-x 4 root root 4096 8月 16 10:28 upx-hg-22a77e02b61f/ 14 15 drwxr-xr-x 11 501 80 4096 7月 18 2005 zlib-1.2.3/?
3.設(shè)置環(huán)境變量
export UPX_ZLIBDIR=/home/local/upxmake/zlib-1.2.3/export UPX_DIR=/home/local/upxmake/upx-hg-22a77e02b61f/export UPX_LZMA_VERSION=0x443export UPX_UCLDIR=/home/local/upxmake/ucl-1.03/export UPX_LZMADIR=/home/local/upxmake/lzma443/注:這種方式設(shè)置的環(huán)境變量只在當(dāng)前shell環(huán)境下有效 當(dāng)我們?cè)诹硗庖粋€(gè)shell環(huán)境下輸入:env |grep UPX是沒有顯示結(jié)果的
?
?
4.進(jìn)入到/home/local/upxmake/upx-hg-22a77e02b61f/的根目錄下make all進(jìn)行編譯
如果在編譯的過程中提示:找不到zlib.h 這個(gè)錯(cuò)誤是因?yàn)閦lib包沒有安裝,安裝后問題即可解決。但有一點(diǎn)請(qǐng)注意安裝命令是:
sudo apt-get install zlib1g-dev,而非sudo apt-get install zlib
?
如果提示 usr/bin/ld: cannot find -lucl 參考:http://www.jb51.net/LINUXjishu/211594.html
usr/bin/ld: cannot find -lxxx錯(cuò)誤的通用解決方法
? ?執(zhí)行:apt-get install libucl-dev即可
?
5.編譯成功的話 在$(UPX_ROOT)|src下生成一個(gè)upx.out的文件
root@study:/home/local/upxmake# ./upx-hg-22a77e02b61f/src/upx.outUltimate Packer for eXecutablesCopyright (C) 1996 - 2015UPX 3.92 Markus Oberhumer, Laszlo Molnar & John Reiser Mar 30th 2015Usage: upx.out [-123456789dlthVL] [-qvfk] [-o file] file..Commands:-1 compress faster -9 compress better-d decompress -l list compressed file .....................UPX comes with ABSOLUTELY NO WARRANTY; for details visit http://upx.sf.net?
使用UPX進(jìn)行android so加固
?
在native代碼中:
1.在native代碼中定義全局變量用于增加生成的二進(jìn)制的體積,否則會(huì)提示錯(cuò)誤:
編譯UPX出現(xiàn)“NotCompressibleException”錯(cuò)誤。
?????????分析:UPX對(duì)被加殼的二進(jìn)制文件有最小限制,太小的文件將無法被加殼。
?????????解決方案:在native代碼中定義足夠大的數(shù)據(jù)變量,使得編譯出來的二進(jìn)制文件容易達(dá)??????????到UPX的要求
C:int const dummy_to_make_this_compressible[100000] = {1,2,3};C++:extern "C" int const dummy_to_make_this_compressible[100000] = {1,2,3};2.要加殼的so需要有_init段
?編譯UPX出現(xiàn)“UnknownExecutableFormatException”錯(cuò)誤。
? ? ? ? 分析:被加殼的二進(jìn)制文件必須存在init段,否則UPX將無法脫殼還原原始代碼。
? ? ? ? 解決方案:在native代碼中定義_init()方法,需要注意C和C++的區(qū)別
//在native代碼添加_init段 void _init(void) { }注:_init并非區(qū)段,只是一個(gè)導(dǎo)出函數(shù).NDK會(huì)生成對(duì)應(yīng)的區(qū)段并融合在某個(gè)大區(qū)段中,所以你從區(qū)段表看不到它
?
?我們以一個(gè)簡(jiǎn)單的例子libhello.so為例子hello.c代碼如下
#include <jni.h>void _init(void){}/** jni規(guī)定 本地方法名 Java_調(diào)用本地方法類所在的包名_類名_方法名* JNIEnv * env java環(huán)境,提供函數(shù)供調(diào)用* jobject obj 調(diào)用本地方法的對(duì)象** typedef const struct JNINativeInterface* JNIEnv;* JNIEnv <=> struct JNINativeInterface** env : JNIEnv * <=> struct JNINativeInterface*** (*env)->NewStringUTF();*/ jstring Java_com_itheima_helloworld_MainActivity_helloFromC(JNIEnv *env, jobject obj){// 把C字符串轉(zhuǎn)化為java中字符串return (*env)->NewStringUTF(env,"hello world"); }用readelf工具查看libhello.so是否有_init段
正如前面所說的 section table沒有_init段
readelf -S libhello.so
使用readelf -d libhello.so 可以看到_INIT
?
將libhello.so放在 ?($UPX_ROOT)|src目錄下進(jìn)行加殼 執(zhí)行
?
?
使用upx加殼的so的section table被抹除了
?
我們用IDA對(duì)比下libhello.so加密的效果
未加密效果:代碼是赤裸裸的啊
?
?upx加密后:
1.section table信息抹除了
2.看下jni函數(shù)
?
反編譯看下:
?
?
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/Reverser/p/5778042.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的ubuntu14.04 x86编译upx 3.92 及so加固的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 吃西瓜 最大子矩阵 三维的。 rqnoj
- 下一篇: Ubuntu 12.10连接米2