首页 > 其他 > 详细

特殊的日子—IDF实验室CTF训练营

时间:2016-01-09 13:41:53      阅读:444      评论:0      收藏:0      [点我收藏+]

题目地址:http://ctf.idf.cn/index.php?g=game&m=article&a=index&id=50

Python3.5

 

特殊的日子

2015-01-06 18:09:25 作者:admin 255 2


每个人的一生中都会或多或少有那么几个对自己很重要的日子,比如对于我来说,这一天就很重要。

答案格式wctf{日期}  //友情提示,此题需要暴力破解,但只是爆破这段密文,不是爆破这个网站。。 = =!

就是这一天↓

4D1FAE0B


题目来源:难度:★☆分值:3已解答数:252FirstBlood:A

 

需要暴力破解,猜想可能是用了某种加密算法,答案是日期,应该是YYYYMMDD格式

在网上搜索之后发现是CRC32算法,

python3中有binascii和zlib中都包含crc32加密

注意(原文):

Note

To generate the same numeric value across all Python versions and platforms, use crc32(data) & 0xffffffff. If you are only using the checksum in packed binary format this is not necessary as the return value is the correct 32-bit binary representation regardless of sign.

要生成所有的Python版本和平台相同的数值,使用CRC32 (数据)& 0xffffffff 。
import zlib

def crc32(strs):
    crc=zlib.crc32(strs.encode(utf-8))
    return %x % (crc & 0xffffffff)
result=4D1FAE0B.lower()
for year in range(1000,3000):
    for month in range(1,13):
        for day in range(1,32):
            years=str(year)
            #month=(month<10)?(‘0‘+str(month)):(str(month))
            months=str(month) if(month>=10) else (0+str(month))
            #day=day<10?(‘0‘+str(day)):(str(day))
            days=str(day) if(day>=10) else (0+str(day))
            strs=years+months+days
            if(crc32(strs)==result):
                print(strs)
                exit()

总结:

     python3中没有三目运算符,可用 为真时的结果 if 判定条件 else 为假时的结果  代替

     zlib.crc32()参数为bytes对象,不能用str,故需要用str.encode(‘utf-8‘) 转化为bytes

 

三重循环消耗时间,内存都很多,在网上发现大神写法:(使用了itertools.product函数)

import zlib
def crc32(st):
    crc = zlib.crc32(st.encode(utf-8))
    if crc > 0:
      return "%x" % (crc & 0xffffffff)
    else:
      return "%x" % (crc & 0xffffffff)

#生成年‘1000‘~‘3000‘
year = [str(i) for i in range(1000,3000)]
#生成月‘01‘~‘12‘
month = [str(i) if i>9 else (str(0)+str(i)) for i in range(1,13) ]
#生成日‘01‘~‘31‘
day = [str(i) if i>9 else (str(0)+str(i)) for i in range(1,32) ]

#题目所给
realDate = 4D1FAE0B.lower()

#穷举日期计算crc32值然后与题目给的值进行比对,一样则输出
import itertools
#利用itertools.product()生成年月日的所有组合
for item in itertools.product(year,month,day):
    date = ‘‘.join(item)
    if crc32(date) == realDate:
        print(date)

特殊的日子—IDF实验室CTF训练营

原文:http://www.cnblogs.com/DreamZero/p/5116125.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!