简单小工具,存个源码,若有需要,直接复制就好
功能就是存储两文件的hex值于文本当中,然后对比hex值,输出哪行相同。在相同的相邻几行插入木马即可。
用法:
Usage: imgcom.py [options]
Options:
-h, --help show this help message and exit
--f1=IMG1 <input img name>
--t1=OUT1 <input out file name>
--f2=IMG2 <input img name>
--t2=OUT2 <input out file name>
源码:
import optparse
def loadimg(img,txt):
try:
f = open(img,'rb')
outfile = open(txt, "w")
n = 0; #记录大小
s = f.read(1)
while s:
byte = ord(s)
n = n+1
outfile.write(hex(byte).ljust(4,'0').replace('0x','') + " ")
if n%16==0:
outfile.write(hex(byte).ljust(4,'0').replace('0x','') + "\n")
s = f.read(1)
print(img+' total bytes: %d'%n)
f.close()
except:
print('Error:no search "'+img+'"')
def compare(txt1,txt2):
f1 = open(txt1,'r')
f2 = open(txt2,'r')
i = 0;
comlist = []
for tempf1 in f1:
i = i+1
if(tempf1==f2.readline()):
comlist.append(i)
f1.close()
f2.close()
print('两文件hex 以下行数相同:')
for l in comlist:
print(l,end=' ')
def start():
parse = optparse.OptionParser()
parse.add_option("--f1", dest="img1", type="string", help="<input img name>", default="noURL")
parse.add_option("--t1", dest="out1", type="string", help="<input out file name>", default="noURL")
parse.add_option("--f2", dest="img2", type="string", help="<input img name>", default="noURL")
parse.add_option("--t2", dest="out2", type="string", help="<input out file name>", default="noURL")
(options, args) = parse.parse_args()
loadimg(options.img1,options.out1)
loadimg(options.img2, options.out2)
compare(options.out1,options.out2)
start()
经过试验,二次渲染对gif改变最小。jpg渲染之后几乎只有文件头与之前相同。所以建议使用gif图片马突破二次渲染。