Shell脚本嵌入到二进制代码中
目录
1 描述
2 技术点备忘
2.1 openssl加解密
~$ openssl enc -pass pass:123 -e -aes-256-cbc -in test.txt -out test.txt.enc ~$ openssl enc -pass pass:123 -d -aes-256-cbc -in test.txt.enc -out test.txt.new ### We can get more notice with wrong option. e.g.: --help, --xxx ~$ openssl enc --help unknown option '--help' options are -in <file> input file -out <file> output file -pass <arg> pass phrase source -e encrypt -d decrypt -a/-base64 base64 encode/decode, depending on encryption flag -k passphrase is the next argument -kfile passphrase is the first line of the file argument -md the next argument is the md to use to create a key from a passphrase. One of md2, md5, sha or sha1 -S salt in hex is the next argument -K/-iv key/iv in hex is the next argument -[pP] print the iv/key (then exit if -P) -bufsize <n> buffer size -nopad disable standard block padding -engine e use engine e, possibly a hardware device. Cipher Types -aes-128-cbc -aes-128-cbc-hmac-sha1 -aes-128-cfb -aes-128-cfb1 -aes-128-cfb8 -aes-128-ctr -aes-128-ecb -aes-128-gcm -aes-128-ofb -aes-128-xts -aes-192-cbc -aes-192-cfb ... ...
2.2 objcopy转换任意文件为二进制目标对象
~$ objcopy -I binary -O elf64-x86-64 -B i386 file.in file.o ~$ readelf -s test.o Symbol table '.symtab' contains 5 entries: Num: Value Size Type Bind Vis Ndx Name 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 1: 0000000000000000 0 SECTION LOCAL DEFAULT 1 2: 0000000000000000 0 NOTYPE GLOBAL DEFAULT 1 _binary_test_in_start 3: 0000000000000205 0 NOTYPE GLOBAL DEFAULT 1 _binary_test_in_end 4: 0000000000000205 0 NOTYPE GLOBAL DEFAULT ABS _binary_test_in_size #### => We need to define extern char variable with above name ~$ cat eg.c extern const char _binary_test_in_start; extern const char _binary_test_in_end; // #### => The data is positioned bewteen above symbol ... ... copy_region_to_data(&_binary_test_in_start, &_binary_test_in_end, "test.data"); // #### => DATA RANGE: [&_binary_test_in_start, &_binary_test_in_end)
2.3 strip symbol
~$ strip --strip-all test