Tuesday, April 30, 2019

[Writeup] Mates SS3 Round 4

Programing

Đề bài làm bắt chúng ta phải làm sao từ 2 bình nước x, y có thể tích vx, vy và phải đong nước làm sao cho được z lít. Đây là bài toàn đong nước kinh điển, may mắn là mình đã được học qua ở trường nên có thể làm được bài này một cách nhanh chóng bằng thuật toán dẫn luật.

Soure code:



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'''
Luat 1: Neu VX day thi do nuoc trong binh X di               
Luat 2: Neu VY rong thi do day nuoc cho binh Y
Luat 3: Neu VX khong day va VY khong rong thi 
trut nuoc tu binh Y sang binh X cho den khi binh X day    

e lam rong binh
f lam day binh
o do tu binh nay sang binh kia

'''

from pwn import *
host = '125.235.240.166'

port =  11223
r = remote(host,port)
def dongnuoc(Vx,Vy,z):
    x = 0
    y = 0
    s = ''
    s = ""
    while (x!=z) and (y!=z):
        if x == Vx:
            x = 0
            s += '1:e_'
        if y == 0:
            y = Vy
            s += '2:f_'
        if y > 0:
            k = min(Vx-x,y)             
            x = x+k
            y = y-k 
            s += '2:o_'
    return s

def agr():
    r.recvuntil('1: ')
    Vx = int(r.recvuntil('\n').strip())
    r.recvuntil('2: ')
    Vy = int(r.recvuntil('\n').strip())
    r.recvuntil('z: ')
    z = int(r.recvuntil('\n').strip())
    return Vx,Vy,z

for i in range(5):   
    Vx,Vy,z = agr()
    s = dongnuoc(Vx,Vy,z)
    s = s[:-1]
    r.recvuntil('op> ')
    r.sendline(s)
    print r.recvuntil('\n')
    print r.recvuntil('\n')
r.interactive()


Forensics

Đề bài là một file pcap với giao thức chính là NTP và data strem là một chuỗi base64 nhưng không decode ra gì cả, sau khi xem tổng thể mình để ý thấy có 1 gói tin Malformed packet tra google mình biết đó là PNG bị hỏng trong quá trình chuyển tin. Để ý lại một lần nữa mình mới thấy là bản thân khá fail khi chỉ loại 1 loạt dấu !!! mà không thử loại loạt chữ AAA ở đầu. Thử decdoe bằng đoạn mới mình có một bức ảnh PNG chứa flag:


Monday, April 22, 2019

[Writeup] ASIS 2019 Quals

Flag collision


In this challenge, we need to sumbit two string differene but same length and same crc 32. After I try to brute force two string with length is 15 and submit to server, I received the example of admin is two strings:  ASIS{4LEVv9no8} and ASIS{wpQ78d6lk}. These things help me alot becasue in next stages, server will request random length of 2 strings but same crc32. 

After do some stuff, I realized if we add some stuff to that strings the crc32 still same.

For example:
CRC32(ASIS{wpQ78d6lkBBB}) and CRC32(ASIS{4LEVv9no8BBB}) is same.

Ok so we just need to add "B" word to strings and send to sever and take the flag
My code:



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import hashlib
import itertools
from pwn import *
import sys
def md5(pow_target):
    pow = ""
    for word in itertools.product(string.printable, repeat=5):
        if hashlib.md5(''.join(word)).hexdigest()[-6:] == pow_target:
            pow = ''.join(word)
            return pow
def sha1(pow_target):
    pow = ""
    for word in itertools.product(string.printable, repeat=5):
        if hashlib.sha1(''.join(word)).hexdigest()[-6:] == pow_target:
            pow = ''.join(word)
            return pow
def sha224(pow_target):
    pow = ""
    for word in itertools.product(string.printable, repeat=5):
        if hashlib.sha224(''.join(word)).hexdigest()[-6:] == pow_target:
            pow = ''.join(word)
            return pow
def sha256(pow_target):
    pow = ""
    for word in itertools.product(string.printable, repeat=5):
        if hashlib.sha256(''.join(word)).hexdigest()[-6:] == pow_target:
            pow = ''.join(word)
            return pow
def sha384(pow_target):
    pow = ""
    for word in itertools.product(string.printable, repeat=5):
        if hashlib.sha384(''.join(word)).hexdigest()[-6:] == pow_target:
            pow = ''.join(word)
            return pow
def sha512(pow_target):
    pow = ""
    for word in itertools.product(string.printable, repeat=5):
        if hashlib.sha512(''.join(word)).hexdigest()[-6:] == pow_target:
            pow = ''.join(word)
            return pow
host = '37.139.9.232'
port = 19199
r = remote(host,port)
msg = r.recvuntil('\n')
#print msg
msg = msg.split(' ')
#print msg
pow_target = msg[-1].strip()
if 'md5' in msg[-3]:
    payload = md5(pow_target)
elif 'sha1' in msg[-3]:
    payload = sha1(pow_target)
elif 'sha224' in msg[-3]:
    payload = sha1(pow_target)
elif 'sha256' in msg[-3]:
    payload = sha256(pow_target)
elif 'sha384' in msg[-3]:
    payload = sha384(pow_target)
elif 'sha512' in msg[-3]:
    payload = sha512(pow_target)
else:
    print msg[-3]
r.sendline(payload)
#print r.recv(1024)
print 'stage1'

r.sendline('ASIS{wpQ78d6lk}, ASIS{4LEVv9no8}')
#print r.recv(1024)
print 'stage2'
i=0
while 1:
    a = 'ASIS{4LEVv9no8'
    b = 'ASIS{wpQ78d6lk'
    if i == 14:
        print r.recv(1024)
        sys.exit()
    r.recvuntil(':)\n')
    msg = r.recvuntil(':|\n')
    msg = msg.split(' ')
    number = int(msg[10])
    repeat = number-len(a)-1
    a = a + "b" * repeat + "}"
    b = b + "b" * repeat + "}"
    m = str(a)+', '+str(b)
    m = str(m)
    r.sendline(m)
    i+=1
And I after 14 times, I took a flag:





Monday, April 1, 2019

[Writeup] Sunshine CTF 2019

Forensics

Golly

It's a code of Golly rle file, when I run a code given I just have a alphabet table:

Run it and nothing else, I read a rle file document at here. And I know a "$" represents the end of each row and an optional "!" represents the end of the pattern. So I just copy the paragraph after !$$$$ and I got

Flag: sun{th1s_w0nt_last}

Castles

Open the file in HXD I saw something like a hint:

Hey! Mario said something about a hidden key. Hesaid this: F2I and A1S, and that it was in two pieces

Because this is 001 file so I use FTK Imager to open it. And I found an JPG image of Mario: