crc检验原理实际上就是一个p位二进制序列之后附加一个r位二进制检验码(序列), 从而构成一个总长为n=p+r位的二进制序列, 附加在数据序列之后的这个检验码与数据序列的内容之间存在这某种特定的关系. 如果干扰因素使数据序列中的某一位或者某些位发生变化,这种特定的关系就会被破坏, 因此通过这种特性可以利用来爆破文件的内容.
文件的内容只有相同的时候他的crc校验才会一样.只要已知压缩文件的长度已知就可以获取他的crc32值来与我们的内容计算得到的值进行相互比较, 从而得到文件内容.(前提是文件内容长度够小才可以通过这种方法来实现,否则内容过长pc的算力有限)
现在有一个flag.zip 里面有一个flag.txt 文件 密码未知
使用模块如下:
import string
import zipfile
import binascii
pig@deep:~/Desktop/crc32碰撞$ zipinfo flag.zip
Archive: flag.zip
Zip file size: 166 bytes, number of entries: 1
-rw-a-- 6.3 fat 4 Bx stor 19-Oct-29 20:52 flag.txt
1 file, 4 bytes uncompressed, 4 bytes compressed: 0.0%
得到文件的内容为4个字节长度
def getcrc():
f = zipfile.ZipFile("flag.zip", "r")
GetCrc = f.getinfo("flag.txt")
crc = GetCrc.CRC
jisuancrc(crc) // 将得到的crc的值传递给接下来需要计算crc的模块
def jisuancrc(crc):
for a in dic:
for b in dic:
for c in dic:
for d in dic:
s = a + b + c + d
s = str(s).encode() //注意python2和python3之间的编码方式的不同, 如果是python2版本则不需要这行
if (binascii.crc32(s)) == crc: // 如果是python2还需要加上0xfffffff 使crc值都是正值,python3则不需要
print (s)
return
字典模块通过string模块得到
dic = string.ascii_letters + string.digits + '+-={}'
调用:
if __name__ = "__main__":
getcrc()
0x80e245d8
b'123a'
[Finished in 6.7s]
如果文件内容过长的话, 通过这种方式就不现实了.
解压文件得到如下的压缩文件
pig@deep:~/Desktop/123$ ls
out0.zip out19.zip out28.zip out37.zip out46.zip out55.zip out64.zip
out10.zip out1.zip out29.zip out38.zip out47.zip out56.zip out65.zip
out11.zip out20.zip out2.zip out39.zip out48.zip out57.zip out66.zip
out12.zip out21.zip out30.zip out3.zip out49.zip out58.zip out67.zip
out13.zip out22.zip out31.zip out40.zip out4.zip out59.zip out6.zip
out14.zip out23.zip out32.zip out41.zip out50.zip out5.zip out7.zip
out15.zip out24.zip out33.zip out42.zip out51.zip out60.zip out8.zip
out16.zip out25.zip out34.zip out43.zip out52.zip out61.zip out9.zip
out17.zip out26.zip out35.zip out44.zip out53.zip out62.zip
out18.zip out27.zip out36.zip out45.zip out54.zip out63.zip
得到每个压缩包都是4个字节的大小, 压缩的文件为data.txt, 通过脚本得到文件内容, 脚本如下:
#!/usr/bin/python
# -*- coding=utf8 -*-
"""
# @Author : pig
# @CreatedTime:2020-01-22 21:44:34
# @Description :
"""
import zipfile
import string
import binascii
def jisuan(crc):
for a in dic:
for b in dic:
for c in dic:
for d in dic:
s = a + b + c + d
s = str(s).encode()
if crc == (binascii.crc32(s)):
print (s)
f.write(s.decode('utf-8'))
return
def getcrc():
for i in range(68):
file = 'out' + str(i) + '.zip'
f = zipfile.ZipFile(file, 'r')
GetCrc = f.getinfo('data.txt')
crc = GetCrc.CRC
print (hex(crc))
jisuan(crc)
dic = string.ascii_letters + string.digits + '+/='
f = open('out.txt', 'w+')
getcrc()
f.close()
运行结果部分如下:
0x75f90d3a
b'z5Bz'
0xbb21560
b'AAAN'
0x9b0d08f1
b'AAAA'
0x9b0d08f1
b'AAAA'
0x30fa0c4d
b'AKo+'
0xbaab6848
b'egCA'
0xc2a03377
b'IwBJ'
0x9b0d08f1
b'AAAA'
0x56c367d7
b'VAAA'
0x8881454e
b'AAKG'
0xf399b503
b'NKv+'
0x8a39ea8d
b'a2Md'
0xf8522b5f
b'SR0z'
0x22e2c069
b'AwAB'
0x9b0d08f1
b'AAAA'
0xabc2f082
b'Q01U'
0x1b10de7b
b'CRUU'
0x4246c91b
b'y91B'
0x5a277153
b'T5Uk'
0xe54efe07
b'SNPo'
0x65e4ea0a
b'j5hF'
0xdb4eed2e
b'EVFB'
0xac675758
b'Rvef'
0x3c84028a
b'HSBC'
0x2b91ca65
b'fG0r'
0x1200cac6
b'uGnK'
0x422dd115
b'nygs'
0xa40a3790
b'Myj8'
0x7cbac4f2
b'SBaZ'
0x33a35543
b'HxsY'
0x2aa2f2bf
b'HY84'
0xe5493ec
b'LEZ2'
0x3196a7ea
b'4cXt'
0x4e1b1b60
b'Z01y'
0xa00b3338
b'3k1K'
0x26f1c2c4
b'1YJ0'
0x776956ca
b'vpK9'
0x37f3cd7
b'HwqU'
0xc7e6946c
b'zb6u'
0xd6f0e0b6
b'9z8i'
0x533d25ef
b'gEr3'
0x20e4f175
b'dCCQ'
0x3e45a71b
b'LQAd'
0x9b0d08f1
b'AAAA'
0xfa23e40b
b'HQAA'
0x4d4c79c0
b'AAJi'
0x2edc1696
b'0efV'
0x4dcce21e
b'T2Md'
0x86e357e2
b'SR0w'
0xe3094587
b'CAAg'
0x9b0d08f1
b'AAAA'
0x6174723d
b'Zmxh'
0x5a3c911f
b'Zy50'
0xf14e1946
b'eHQA'
0xf7d5bb98
b'sDRp'
0xd5aaac4b
b'ZmZp'
0xbbf6f69f
b'eCB0'
0xc31189d5
b'aGUg'
0xc5bf6c84
b'Zmls'
0x6a2864de
b'ZSBh'
0x80122009
b'bmQg'
0x6823cb5a
b'Z2V0'
0xec5157cc
b'IHRo'
0x1a429051
b'ZSBm'
0xc997df0d
b'bGFn'
0x86bcd0ce
b'xD17'
0xe5d81889
b'AEAH'
0x4134031c
b'AA=='
[Finished in 316.6s]
可以看见才多长这个东西很考验pc的性能, 然后直接进行base64解码, 得到的内容转为rar格式的文件, 然后补全文件头得到flag, 这里具体就不阐述了
得到的内容如下:
z5BzAAANAAAAAAAAAKo+egCAIwBJAAAAVAAAAAKGNKv+a2MdSR0zAwABAAAAQ01UCRUUy91BT5UkSNPoj5hFEVFBRvefHSBCfG0ruGnKnygsMyj8SBaZHxsYHY84LEZ24cXtZ01y3k1K1YJ0vpK9HwqUzb6u9z8igEr3dCCQLQAdAAAAHQAAAAJi0efVT2MdSR0wCAAgAAAAZmxhZy50eHQAsDRpZmZpeCB0aGUgZmlsZSBhbmQgZ2V0IHRoZSBmbGFnxD17AEAHAA==
个人网站