reversing.kr_ImagePic Write up

题目地址:http://reversing.kr/challenge.php

ImagePic

这题很有趣的样子,然后我一开始居然没看懂他给的程序是干嘛的!!!

首先吧,打开程序

1

excuse me???

3

原来白色的地方是可以用鼠标画东西的,然后check看看对不对

OD调试看看,在MessageBoxA下断点,跟踪到这一步 4

往上看,看到FindResourceA 、LoadResource、LockResource三个函数

但我并不知道这是干嘛的,只好去查查了

FindResourceA

Determines the location of a resource with the specified type and name in the specified module.

If the function succeeds, the return value is a handle to the specified resource’s information block. To obtain a handle to the resource, pass this handle to the LoadResource.aspx) function.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.aspx).

LoadResource

Retrieves a handle that can be used to obtain a pointer to the first byte of the specified resource in memory.

If the function succeeds, the return value is a handle to the data associated with the resource.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.aspx).

LockResource

Retrieves a pointer to the specified resource in memory.

If the loaded resource is available, the return value is a pointer to the first byte of the resource; otherwise, it is NULL.

所以这三个函数是用来加载资源的,那加载的又是啥资源???

我们观察这一段循环

5

从ecx和eax+ecx的地址偏移中取值比较,不同就调到004013CD,而这个地址就是Wrong的函数地址

到那两个地址看,发现是这样的一堆东西……6

一大片ff中包含着小小的00

还好之前玩了下github的tinyrenderer,对图像也知道一些东西

这是图片数据块,FF对应RGB中的白色,而00就是黑色了

循环中把输入图存在程序中的图逐位比较,只有全部一样才正确(几万个字节显然手动画不出嘛= =)

这里就要借助工具了,先把eax+ecx中的图片数据提取出来,我这里用到了exeScope

提取出来就是图片的字节数据,需要解释为图片。且从结构体指针中得知该图片宽高 = 200\150

这里提供几个思路

1.直接二进制打开,加入文件头

1
0000 0200 0000 0000 0000 0000 c800 9600 1820

PS:这是tga文件的文件头,其中c8 96 表示宽度高度,tga文件可以用Photoshop打开(其他不清楚)

2.借用Python的pillow图像库

1
2
3
4
5
6
7
8
9
10
11
from PIL import Image

width = 200
height = 150

fp = open('rgb.mem', 'rb')
data = fp.read()
im = Image.frombytes('RGB', (width, height), data)
im = im.transpose(Image.FLIP_TOP_BOTTOM)
im.show()
im.save('result.bmp')

PS:此代码是从网上copy来的,没有尝试这个,transpose是因为直接用data生成的图像是上下颠倒的

3.自己写程序处理

上面也提到了,之前在玩一个github的小项目,教学OpenGL的tinyrenderer

然后我用Java改写,于是就有了如下的源码处理,生成为.tga文件,并且让其上下翻转了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public static void main(String[] args) throws IOException {
TGAImage tgaImage = new TGAImage(200,150,TGAImage.RGB);
//drawLine(0, 0, 999, 999, tgaImage, TGAColor.RED);
tmpWrite("picture", tgaImage);
tgaImage.flipVertically();
//drawLine(20, 13, 40, 80, tgaImage, TGAColor.WHITE);
tgaImage.writeTgaFile("output.tga", false);
}

public static void tmpWrite(String fileName, TGAImage image) throws IOException{
FileInputStream file = new FileInputStream(fileName);
byte[] color_byte = new byte[TGAImage.RGB];
for(int i=0;i<150;i++){
for(int j=0;j<200;j++){
file.read(color_byte, 0, TGAImage.RGB);
TGAColor color = new TGAColor(color_byte, 0, TGAImage.RGB);
image.set(j, i, color);
}
}
file.close();
}

最后生成得到的图片

7

所以咯,flag就是 GOT 了

(还好之前玩了下tinyrenderer = =!)

×

赞助gif换电脑、吃双皮奶(逃

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

文章目录
  1. 1. FindResourceA
  2. 2. LoadResource
  3. 3. LockResource
,