0x00 ewm
拼图题,题目给出85张图片,按照图片修改时间递增排序,发现有85张图片,猜测是 5 * 17 的排布,脚本合并图片不对,又猜测是6*14的图片,删掉第一张图片,重新合并得到二维码。
脚本如下:
#-*- coding:utf-8 -*-
import PIL.Image as Image
import os
IMAGES_PATH = 'D:\\Desktop\\1\\0c0b0a79-1c40-45d0-9d8d-da3dbfc3930a\\all\\'
IMAGES_FORMAT = ['.jpg', '.JPG']
IMAGE_SIZE = 256
IMAGE_ROW = 14 #生成图片的行
IMAGE_COLUMN =6 #生成图片的列
IMAGE_SAVE_PATH = 'D:\\Desktop\\1\\0c0b0a79-1c40-45d0-9d8d-da3dbfc3930a\\1.jpg' #结果保存地址
#按修改时间排序
def sort_file_by_time(file_path):
files = os.listdir(file_path)
if not files:
return
else:
files = sorted(files, key=lambda x: os.path.getmtime(os.path.join(file_path, x)))
return files
image_names = sort_file_by_time(IMAGES_PATH)
print(image_names)
# 简单的对于参数的设定和实际图片集的大小进行数量判断
if len(image_names) > IMAGE_ROW * IMAGE_COLUMN:
raise ValueError("不能合成图片!")
def image_compose():
to_image = Image.new('RGB', (IMAGE_COLUMN * IMAGE_SIZE, IMAGE_ROW * IMAGE_SIZE))
for y in range(1, IMAGE_ROW + 1):
for x in range(1, IMAGE_COLUMN + 1):
from_image = Image.open(IMAGES_PATH + image_names[IMAGE_COLUMN * (y - 1) + x - 1]).resize(
(IMAGE_SIZE, IMAGE_SIZE),Image.ANTIALIAS)
to_image.paste(from_image, ((x - 1) * IMAGE_SIZE, (y - 1) * IMAGE_SIZE))
return to_image.save(IMAGE_SAVE_PATH)
image_compose()
0x01 findme
首先分析源码,大概逻辑是要求我们在200次之内猜出正确的数字,范围在(0,2^128)之间,输入newkey和newground相当于我们猜测的范围,在这个范围内输入g1和g2进行判断。
思路:利用二分法,根据返回值,调整我们的猜测范围,逐渐缩小我们猜测范围。
pow(abs(secret-g1)-abs(secret-g2),2)<pow(abs(g2-g1),2)
,这个判断就是当我们猜测的值在(g1,g2)之间时返回1,否则返回2。
脚本如下:
#-*- coding:utf-8 -*-
from pwn import *
p = remote('121.40.216.20',9999)
def std(num):
return hex(num)[2:].strip('L')
def send(p,num):
print p.recv()
print num
p.sendline(std(num))
top = 2**128
bot = 1
mid1 = (top-bot)//3+1
g1 = top
g2 = bot + mid1
flag = 0
for _ in range(200):
if (g1-g2)<3:
for i in range(3):
send(p,bot)
send(p,top)
g1 = g1 + i
send(p,g1)
send(p.g1)
print p.recv()
break
send(p,bot)
send(p,top)
send(p,g1)
send(p.g2)
mid = (g2+g1)/2
s = p.recv()
if s== '1':
print 1
flag = 1
temp_g1 = g1
temp_g2 = g2
temp_mid = mid
g2 = mid
elif s=='2':
if flag ==1:
g1 = temp_mid
g2 = temp_g2
else:
g2 = g1
g1 = g1 + mid1
else:
print s