2022-03-31 一些后续
small weiner
來(lái)源:dvctf2022
Someone I hate sent me an insulting message using RSA. Can you retrieve his private key?
Flag format: dvCTFze8trgl8bvbq with d in decimal (base 10)
上次嘗試了離散對(duì)數(shù)沒有解出來(lái),
根據(jù)題目,嘗試維納攻擊(在e過大或過小的情況下,可使用算法從e中快速推斷出d的值。)
但是依舊沒有解出來(lái)
翻到一篇大佬的博客
利用格約基可以解這道題
構(gòu)造格子并用LLL格約基
然后解題
總的代碼就是
Secure Or Not Secure
來(lái)源:dvctf2022
I made secure application but i lost my cookie and now I can't connect. Can you help me?nc challs.dvc.tf 2600nc進(jìn)入
------ Welcome to my secure login system ------ 1. Login 2. Register 3. Exit ----------------------------------------------- >>> 2 Username: re Password: re Here is your cookie: wr2TBvKa+oU0HY7emHvxwwgozYdLN6f1q76CQ5o+ahBzZv0Qf9p2645P90f+TqW566M5wYbOeg== ------ Welcome to my secure login system ------ 1. Login 2. Register 3. Exit ----------------------------------------------- >>> 1 Cookie: wr2TBvKa+oU0HY7emHvxwwgozYdLN6f1q76CQ5o+ahBzZv0Qf9p2645P90f+TqW566M5wYbOeg== You're not the admin! The cookie b'username=re\x00\x00\x00\x00\x00\x00;admin=False;password=re\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' is invalid! ------ Welcome to my secure login system ------ 1. Login 2. Register 3. Exit ----------------------------------------------- >>> 2 Username: a Password: a Here is your cookie: wr2TBvKa+oU0DuvemHvxwwgozYdLN6f1q76CQ5o+ahBzZv0Qf9p2+OtP90f+TqW566M5wYbOeg== ------ Welcome to my secure login system ------ 1. Login 2. Register 3. Exit ----------------------------------------------- >>> 1 Cookie: \xc2\xbd\x93\x06\xf2\x9a\xfa\x854\x0e\xeb\xde\x98{\xf1\xc3\x08(\xcd\x87K7\xa7\xf5\xab\xbe\x82C\x9a>j\x10sf\xfd\x10\x7f\xdav\xf8\xebO\xf7G\xfeN\xa5\xb9\xeb\xa39\xc1\x86\xcez Are you trying to cheat?! ------ Welcome to my secure login system ------ 1. Login 2. Register 3. Exit ----------------------------------------------- >>> 3上次去對(duì)base進(jìn)行了解碼,沒有解出來(lái)有用的東西
分析上面內(nèi)容我們可以看到,當(dāng)?shù)卿洉r(shí)使用的Cookie時(shí)注冊(cè)得到的時(shí)候會(huì)返回You're not the admin!并且這時(shí)系統(tǒng)是可以通過Cookie推測(cè)出用戶名是re,并且admin=False;而第二次嘗試,我輸入的Cookie不是注冊(cè)得到,系統(tǒng)返回的是Are you trying to cheat?!
依舊參考那位師傅的博客,這位大佬直接想到了異或
將Cookie進(jìn)行base64解碼的結(jié)果例b'\xc2\xbd\x93\x06\xf2\x9a\xfa\x854\x1d\x8e\xde\x98{\xf1\xc3\x08(\xcd\x87K7\xa7\xf5\xab\xbe\x82C\x9a>j\x10sf\xfd\x10\x7f\xdav\xeb\x8eO\xf7G\xfeN\xa5\xb9\xeb\xa39\xc1\x86\xcez'與b'username=re\x00\x00\x00\x00\x00\x00;admin=False;password=re\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'進(jìn)行異或
不信邪的去看了下,發(fā)現(xiàn)確實(shí)是一樣長(zhǎng)的
然后將異或得到的結(jié)果與將admin改成True之后的再次進(jìn)行異或
最后重新用base64封裝好就能去登錄了
非常佩服這位大佬,下面看大佬的代碼
import base64def xor(var, key):return bytes(a ^ b for a, b in zip(var, key))cookie = 'cbCVPcNz4b9mfY8sFPIjV0AzXYy1UuuF9Kmzf7w7a6/j6ZsHVLndCeaQ9tGTeU61o1GKk7+llQ==' enc = base64.b64decode(cookie) plain = b'username=\x00\x00\x00\x00\x00\x00\x00\x00;admin=False;password=\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' a = b'admin=False;password=\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' b = b'admin=True;password=\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' c = enc[18:] #18 là v? trí admin t??ng ?ng trong enc key = xor(a,c) tmp = xor(b,key)print(base64.b64encode(enc[:18]+ tmp )) #b'cbCVPcNz4b9mfY8sFPIjV0AzXYy1UuuF5rqqaeJwer3j7YMaQuDgCeaQ9tGTeU61o1GKk7+l'再瞻仰一下大佬的成功
Cwyptographic Owacle
來(lái)源:dvctf2022
Nya :3
nc challs.dvc.tf 2601
import ecdsa import random import hashlib import time from Crypto.Cipher import AES from Crypto.Util.Padding import pad from Crypto.Util.number import long_to_bytesFLAG = b'dvCTF{XXXXXXXXXXXXXXXXXXX}'def encrypt_flag(priv):key = long_to_bytes(priv)cipher = AES.new(key, AES.MODE_ECB)text = cipher.encrypt(pad(FLAG, 16))print(text.hex())m = 0print("Hiii ~~ Pwease feel fwee to use my sooper dooper cwyptographic owacle! ~~~~~~") while True:print("[1] > Sign your own message ≧?≦")print("[2] > Get the signed flag uwu ~~ ")print("[3] > Quit (pwease don't leave me)")try:n = int(input())if n<0 or n>3:raiseexcept:print("Nice try ?_?")exit(1)if n==1:msg = input("What's your message senpai? (●′ω`●) > ")G = ecdsa.NIST256p.generatororder = G.order()priv = random.randrange(1,order)Public_key = ecdsa.ecdsa.Public_key(G, G * priv)Private_key = ecdsa.ecdsa.Private_key(Public_key, priv)k = random.randrange(1, 2**128) if m==0 else int(time.time())*mm = int(hashlib.sha256(msg.encode()).hexdigest(),base=16)sig = Private_key.sign(m, k)print (f"Signature (r,s): ({sig.r},{sig.s})")elif n==2:if m==0:G = ecdsa.NIST256p.generatororder = G.order()priv = random.randrange(1,order)encrypt_flag(priv)else:print("Cya (?︵?) ")exit(1)上次的嘗試
Hiii ~~ Pwease feel fwee to use my sooper dooper cwyptographic owacle! ~~~~~~ [1] > Sign your own message ≧?≦ [2] > Get the signed flag uwu ~~ [3] > Quit (pwease don't leave me) 1 What's your message senpai? (●′ω`●) > re Signature (r,s): (5574199079485227229736032865599767885817418344312674047445645256117624859582,51462972268344716865531777000256743426644776909735353695777643263919964904375) [1] > Sign your own message ≧?≦ [2] > Get the signed flag uwu ~~ [3] > Quit (pwease don't leave me) 2 3fbb20769e7cb4c00c5fd86a8ca8ba23f5b4b38dfa9cba4c9db98d45ca5a008e5658dfdcffcfcab9671fd038e299fcde [1] > Sign your own message ≧?≦ [2] > Get the signed flag uwu ~~ [3] > Quit (pwease don't leave me) 3 Cya (?︵?)依舊只在這位大神這找到了解題
但是這道題并沒有看懂解題過程,也不明白這個(gè)時(shí)間在這里意味著什么
還是貼一下大神的代碼,等下次來(lái)看是不是能看懂
import ecdsa import random import libnum import hashlib import sys import time from Crypto.Cipher import AES from Crypto.Util.Padding import pad,unpad from Crypto.Util.number import long_to_bytes from pwn import * # connect server p = remote('challs.dvc.tf', 2601)m = int(hashlib.sha256('a'.encode()).hexdigest(),base=16) G = ecdsa.NIST256p.generator order = G.order()def decrypt_flag(priv,enc):key = long_to_bytes(priv)enc = bytes.fromhex(enc)print(enc)cipher = AES.new(key, AES.MODE_ECB)flag = unpad(cipher.decrypt(enc),16)return flag# sign l?n ??u p.sendlineafter(b"[3] > Quit (pwease don't leave me)", b'1') p.sendline(b'a')# sign l?n 2 p.sendlineafter(b"[3] > Quit (pwease don't leave me)", b'1') p.sendline(b'a') k = int(time.time())*mp.recvuntil(b'\r\n') p.recvuntil(b"What's your message senpai? (\xe2\x97\x8f\xc2\xb4\xcf\x89\xef\xbd\x80\xe2\x97\x8f) > ") p.recvuntil(b"Signature (r,s): (")# Nh?n r,s và encrypt_flag ? l?n sign th? 2 r = p.recvuntil(b',', drop = True) s = p.recvuntil(b')\r\n', drop = True) p.sendline(b'2') p.recvuntil(b"[1] > Sign your own message \xe2\x89\xa7\xe2\x97\xa1\xe2\x89\xa6\r\n[2] > Get the signed flag uwu ~~ \r\n[3] > Quit (pwease don't leave me)\r\n")enc = p.recvuntil(b'\r\n', drop = True) r = int(r.decode('utf-8')) s = int(s.decode('utf-8')) enc = enc.decode('utf-8') # print(r,s) # print(enc)# Brute force giá tr? c?a k l?u vào m?ng, có th? chênh l?ch vài giay gì ?ó maybekey = [] for i in range(10):a = int(time.time()-i)*mmaybekey.append(a)b = int(time.time()+i)*mmaybekey.append(b) print(maybekey)# k?t h?p k,m tìm l?i priv r?i decrypt AES.MODE_ECB r_inv = libnum.invmod(r, order) for i in maybekey:try_private_key = (r_inv * ((i * s) - m)) % ordertry:flag = decrypt_flag(try_private_key,enc)print(flag)except:print("None") # dvCTF{y0u_h4v3_500p32_d00p32_c2yp70_5kill5_uwu}RSA
來(lái)源:dvctf2022
Easy
Our team has found a cipher text: there seems to be some clues to decipher it. Can you help us to read it?
n = 0x7CD1020889B4382BE84B3F14EAAE242755CC1BD56F431B348F4FF8F207A96F41AFCF3EBDF4C17CB6537AD4B01B9FF9497763B22D013B614C8FCDB0C34F9D88F1A523013791EDFEB1FBBA160799892C118892FB7F199C9957DF5A26DAB4D776E5226F06ACD05412F6DD2B1B75D24CE9DC2DDAC513BCB96CD9B97F9BEF8543A3A1phi = 0x7CD1020889B4382BE84B3F14EAAE242755CC1BD56F431B348F4FF8F207A96F41AFCF3EBDF4C17CB6537AD4B01B9FF9497763B22D013B614C8FCDB0C34F9D88F037D2317D3864035ECE8BCDD458711B788B5B3FDFD5164F7D736D0A56F416E8C16126E3868D73F54AF4D61F6033E069994319C849460C60A725A0F4DD97EDCC84e = 0x10001ct = 0x268D7D5F5593EA30F536635B58585620B51D2D143AFE4734635C259278D61413D0C89678E81EDF466B1E45E27EBF802F62F61263E499A516465163C7CB668F94258B3424C3E2BD76634923DECD670E4B6034F8FD00C76F9DAD00A72DB22B70B9408C89FCEE4C9B0D2D4B5664284328711BFAD57FBE1EDCC0854AAD57390DCAD6Hint:There is another decoding step after the decryption!
一直不知道要解碼解什么碼,從十六進(jìn)制轉(zhuǎn)為十進(jìn)制是我沒想到的
n = 87649082972615446885156213990388141958462041885187282183358321369043253078954716183685582963065012168992348062798954305060720006415266001335650005751863897735171741039420405425935144397447296138110870810719506425543947491726403454512721294407851871180512317063750030012483422248351385763316752934512386876321 phi = 87649082972615446885156213990388141958462041885187282183358321369043253078954716183685582963065012168992348062798954305060720006415266001335650005751863878602037628450194440652151553598137526621296494079379835255789373284025572667141114891644303376103362880682087270696210666254302024051328494090372669885572 e = 65537 ct = 27072622593514815453879432614324701776473574595747953216191498481974488509392434673536099100283731897243171732583922534894433636848515336632487302801454568578704912185172822029407973421574599852974535422485632743936976338461213855442178470548247222162434148032907372865397517157263392748002249405715658427094這有什么區(qū)別嗎🤨
import gmpy2 from Crypto.Util.number import long_to_bytes n = 87649082972615446885156213990388141958462041885187282183358321369043253078954716183685582963065012168992348062798954305060720006415266001335650005751863897735171741039420405425935144397447296138110870810719506425543947491726403454512721294407851871180512317063750030012483422248351385763316752934512386876321 phi = 87649082972615446885156213990388141958462041885187282183358321369043253078954716183685582963065012168992348062798954305060720006415266001335650005751863878602037628450194440652151553598137526621296494079379835255789373284025572667141114891644303376103362880682087270696210666254302024051328494090372669885572 e = 65537 ct = 27072622593514815453879432614324701776473574595747953216191498481974488509392434673536099100283731897243171732583922534894433636848515336632487302801454568578704912185172822029407973421574599852974535422485632743936976338461213855442178470548247222162434148032907372865397517157263392748002249405715658427094d = gmpy2.invert(e,phi) m = pow(ct,d,n)print(m) print(long_to_bytes(m)) #100118678470123102108521039599861127251114116518811695988695828352125 #b'\x03\xb6\xaf\x06\x92g\x03"\xecu\xb7\xee\x13?\xcb\xa4\x8f\xee\xd7\xf9(\x9dy/J好的,事實(shí)證明是沒有區(qū)別的
而我上次沒做出來(lái)居然是因?yàn)?#xff0c;m轉(zhuǎn)ASCII碼轉(zhuǎn)錯(cuò)了
🤨
再轉(zhuǎn)一次
先把十進(jìn)制轉(zhuǎn)成十六進(jìn)制0x3b6af0692670322ec75b7ee133fcba48feed7f9289d792f4acc154c7d
等等,為啥這次十六進(jìn)制長(zhǎng)度是奇數(shù)
難道不應(yīng)該在最后剩一個(gè),而應(yīng)該在開頭?
好的,依舊不對(duì)
一位解出來(lái)的師傅給的轉(zhuǎn)ASCII碼的網(wǎng)址是: https://onlineasciitools.com/convert-decimal-to-ascii
神奇的是,他跟我的m都是一樣的,為啥人家解出來(lái)了,而我沒有??
ICMP
來(lái)源:dvctf2022
上次只找到了
但是這位神奇的師傅找到了
這位師傅的解題過程是
Well, got to look at elsewhere.
The id of the packets look like Hex numbers. The packets are exported as plaintext with the “Export Packet Dissections > As Plain Text” function in WireShark.
First, the packets are arranged according to the seq number, then the id is extracted and converted from Hex number to ASCII, then decoded as Base64. The flag is then revealed.
不懂,照例收集一下
Sudoku
這道依舊沒找到題解
總結(jié)
以上是生活随笔為你收集整理的2022-03-31 一些后续的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SM2算法
- 下一篇: crypto-RSA-常用解密代码块