利用certutil.exe实现在批处理(bat)中嵌入可执行文件或者各种媒体、图片之类二进制文件的简单方法!
实际上利用certutil.exe 把二进制文件(包括各种文件,exe可执行程序,图片,声音,mp3) 经过base64编码为文本,可以实现把这些文件嵌入到批处理代码中。
###有什么用?:
举个例子,批处理经常需要依赖其它命令行工具实现自动化脚本,如果把这些工具转成文本嵌入到代码中,贴到网上就可以直接把可用的代码发出去了。不需要上传附件。
###缺点:
base64编码后的文本比原文件长1/3,加上如果依赖的文件体积大,转换出来的文本内容会非常长。这个缺点影响了这个玩法的实用性。
xp 中没有certutil 这个工具,影响了适用范围。
如果依赖多个文件,需要用winrar 打包成exe 自解压文件,然后再编码。
certutil 是一个证书工具,功能挺丰富的,参数非常多,我这里只截取和base64编码相关的帮助信息:
``` C:\Users\Administrator>certutil.exe /"htmlcode">@echo off certutil -decode "%~f0" hello.mp3 start hello.mp3 exit /b 1 -----BEGIN CERTIFICATE----- /+MgxAAUcQZgA0YYALhaemECCEECZNO7u7vGiIiI/7u7u6InxE57v+j+ifoBiz4g cDgYlHMLv+oH35QEP5TqB8//8HDgnB/g+D5d/8oc8v+UB+GJR3BCJw+XD/8u8EEA QAAUCgUCgUD/4yLECRWRPtJfjUAAoFAoFAe997lwJ35Twn+Wfemd/M3TCjiKAuH6 ThO2rqKA0MQ986vujKj97ehhiRAoIFAAKDH4Y9/0qdb/8utJp/nL/oh7w+go9H63 /8UVYYgEAna26X/FY2gtJAX/4yDEDheD7u4fxygDhs/mGECXznOHxh2850FA0Vv8 7ixf0cit7UuX60Mchn/Re+lUjdVexLlZE60OUz/sv///T/NVpaliArIZXXvXf/83 /dZNGrKRmK6v/RR2vceBkMxSptrrS/1hQf/jIsQLFZrm/j44RN4BJ/RRw02+AaEL 8jCEPgNCEL9hCEMHxCD/PNITPUVBka2KmaiI6dPT9Xrovun///R/dWS0UwMdwZAI DB0FRhpLf5XUxR1TDBqz9aFKyBQAHIG2N388oIIJItv9L//jIMQQGALW5X5SBJoG oR3PUwSaUa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Ou/+MgxC8fw2J8y5hAAGNVhmj/yQ9DkagKiZVdmn//GDyjxXVIVYZpVY// /u7huJmRUYzSqwzSqx///+cqipC050k5TSzarDXKrw3/////axNSTWrWUcoKlitX //4lEuXWCCAKAFCFBY7/4yLECxRq9kQXyBAAGirKKmrsx1Q1///KXK3Q3//lL/// /KX//0No/KXL//MbMbUpXl/5S0MZkMbKUu1DVLlKWhhQwGoKneJYKuEQcLfrO8Gv 8SpMQU1FMy45Ni4xqqqqqqqqqqqqqqr/4yDEFQAAA0gAAAAAqqqqqqqqqqqqqqqq qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqg== -----END CERTIFICATE-----2016年8月31日 22:52:03 codegay
windows 2012 Server x64 测试可行。xp上不带certutil,听说2000以上的系统才带有这个命令工具。使用其它系统的同学,如果可以请测试反馈一下是否可行。扩展阅读
《certutil - decode/encode BASE64/HEX strings.Print symbols by HEX code. 》
用 certutil 实现 Hex2Bin 和 Base64 加解密 https://www.jb51.net/article/93966.htm