首页
社区
课程
招聘
[原创]kctf2021 第四题 英雄救美
发表于: 2021-5-17 22:21 6654

[原创]kctf2021 第四题 英雄救美

2021-5-17 22:21
6654

载入IDA,这里对输入进行了三个判断,长度是否大于64,是否是特定数组中的字符,是否符合数组。

取出在数组中的位置,进行如下操作,存入二维数组,判断是否为符合数独

使用脚本求出数独

得到的正确数独为

按照空的顺序打印出字符串即可,每行后加上没有输入的位数。

之后的逻辑为:求出其MD5值,利用这个MD5对后面代码进行解密,只有正确的MD5才会是程序正确运行形式为,

# 特定数组
inum = [0x24, 0x42, 0x50, 0x56, 0x3A, 0x75, 0x62, 0x66, 0x59, 0x70, 0x7D, 0x5D, 0x44, 0x74, 0x4E, 0x3E,
        0x61, 0x54, 0x5E, 0x4D, 0x47, 0x6D, 0x4A, 0x51, 0x23, 0x2A, 0x48, 0x72, 0x60, 0x4F, 0x27, 0x77,
        0x6A, 0x69, 0x63, 0x30, 0x21, 0x68, 0x64, 0x79, 0x7B, 0x6F, 0x5A, 0x7A, 0x2D, 0x40, 0x6E, 0x2B,
        0x3F, 0x26, 0x25, 0x73, 0x5F, 0x2F, 0x67, 0x3C, 0x65, 0x5B, 0x57, 0x29, 0x58, 0x55, 0x78, 0x52,
        0x46, 0x53, 0x4C, 0x52, 0x41, 0x3B, 0x2E, 0x6C, 0x3D, 0x43, 0x45, 0x6B, 0x76, 0x4B, 0x2D, 0x28
]
# 特定数组
inum = [0x24, 0x42, 0x50, 0x56, 0x3A, 0x75, 0x62, 0x66, 0x59, 0x70, 0x7D, 0x5D, 0x44, 0x74, 0x4E, 0x3E,
        0x61, 0x54, 0x5E, 0x4D, 0x47, 0x6D, 0x4A, 0x51, 0x23, 0x2A, 0x48, 0x72, 0x60, 0x4F, 0x27, 0x77,
        0x6A, 0x69, 0x63, 0x30, 0x21, 0x68, 0x64, 0x79, 0x7B, 0x6F, 0x5A, 0x7A, 0x2D, 0x40, 0x6E, 0x2B,
        0x3F, 0x26, 0x25, 0x73, 0x5F, 0x2F, 0x67, 0x3C, 0x65, 0x5B, 0x57, 0x29, 0x58, 0x55, 0x78, 0x52,
        0x46, 0x53, 0x4C, 0x52, 0x41, 0x3B, 0x2E, 0x6C, 0x3D, 0x43, 0x45, 0x6B, 0x76, 0x4B, 0x2D, 0x28
]
 
# 原数独数组
map = [0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
       0x09, 0x02, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x07,
       0x08, 0x03, 0x00, 0x00, 0x00, 0x05, 0x04, 0x00, 0x00,
       0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
       0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00,
       0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00,
       0x00, 0x00, 0x04, 0x09, 0x00, 0x00, 0x00, 0x07, 0x01,
       0x03, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x09, 0x04,
       0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x06, 0x00
]
# 原数独数组
map = [0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
       0x09, 0x02, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x07,
       0x08, 0x03, 0x00, 0x00, 0x00, 0x05, 0x04, 0x00, 0x00,
       0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
       0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00,
       0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00,
       0x00, 0x00, 0x04, 0x09, 0x00, 0x00, 0x00, 0x07, 0x01,
       0x03, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x09, 0x04,
       0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x06, 0x00
]
import datetime
class solution(object):
    def __init__(self,board):
        self.b = board
        self.t = 0
 
    def check(self,x,y,value):
        for row_item in self.b[x]:
            if row_item == value:
                return False
        for row_all in self.b:
            if row_all[y] == value:
                return False
        row,col=x/3*3,y/3*3
        row3col3=self.b[row][col:col+3]+self.b[row+1][col:col+3]+self.b[row+2][col:col+3]
        for row3col3_item in row3col3:
            if row3col3_item == value:
                return False
        return True
 
    def get_next(self,x,y):
        for next_soulu in range(y+1,9):
            if self.b[x][next_soulu] == 0:
                return x,next_soulu
        for row_n in range(x+1,9):
            for col_n in range(0,9):
                if self.b[row_n][col_n] == 0:
                    return row_n,col_n
        return -1,-1 
 
    def try_it(self,x,y):
        if self.b[x][y] == 0:
            for i in range(1,10):
                self.t+=1
                if self.check(x,y,i):
                    self.b[x][y]=i
                    next_x,next_y=self.get_next(x,y)
                    if next_x == -1: #
                        return True  #
                    else:       
                        end=self.try_it(next_x,next_y)
                        if not end:   #
                            self.b[x][y] = 0    #
                        else:
                            return True
 
    def start(self):
        begin = datetime.datetime.now()
        if self.b[0][0] == 0:
            self.try_it(0,0)
        else:
            x,y=self.get_next(0,0)
            self.try_it(x,y)
        for i in self.b:
            print i
        end = datetime.datetime.now()
        print '\ncost time:', end - begin
        print 'times:',self.t
        return
 
 
s=solution(
       [[0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00],
       [0x09, 0x02, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x07],
       [0x08, 0x03, 0x00, 0x00, 0x00, 0x05, 0x04, 0x00, 0x00],
       [0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00],
       [0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00],
       [0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00],
       [0x00, 0x00, 0x04, 0x09, 0x00, 0x00, 0x00, 0x07, 0x01],
       [0x03, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x09, 0x04],
       [0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x06, 0x00]]
       )
s.start()
import datetime
class solution(object):
    def __init__(self,board):
        self.b = board
        self.t = 0
 
    def check(self,x,y,value):
        for row_item in self.b[x]:
            if row_item == value:
                return False
        for row_all in self.b:
            if row_all[y] == value:
                return False
        row,col=x/3*3,y/3*3
        row3col3=self.b[row][col:col+3]+self.b[row+1][col:col+3]+self.b[row+2][col:col+3]
        for row3col3_item in row3col3:
            if row3col3_item == value:
                return False
        return True
 
    def get_next(self,x,y):
        for next_soulu in range(y+1,9):
            if self.b[x][next_soulu] == 0:
                return x,next_soulu
        for row_n in range(x+1,9):
            for col_n in range(0,9):
                if self.b[row_n][col_n] == 0:
                    return row_n,col_n
        return -1,-1 
 
    def try_it(self,x,y):
        if self.b[x][y] == 0:
            for i in range(1,10):
                self.t+=1
                if self.check(x,y,i):
                    self.b[x][y]=i
                    next_x,next_y=self.get_next(x,y)
                    if next_x == -1: #
                        return True  #
                    else:       
                        end=self.try_it(next_x,next_y)
                        if not end:   #
                            self.b[x][y] = 0    #
                        else:
                            return True
 
    def start(self):
        begin = datetime.datetime.now()
        if self.b[0][0] == 0:
            self.try_it(0,0)
        else:
            x,y=self.get_next(0,0)

[注意]APP应用上架合规检测服务,协助应用顺利上架!

最后于 2021-5-18 11:05 被kanxue编辑 ,原因:
收藏
免费 1
支持
分享
最新回复 (0)
游客
登录 | 注册 方可回帖
返回
//