[CSAW CTF 2013] CSAWpad (Crypto100)

CSAWpad – 100 Points

Solved by 141 teams.

csawpad.py

File dự phòng:

Nội dung chính

Ở bài này, chúng ta được cung cấp 2 hàm encrypt và decrypt, cùng một vài dòng text đã bị mã hóa. Nhiệm vụ khỏi nói cũng biết, đó là giải mã chúng.

Mình không cố hiểu thuật toán, mà mình thử xem nó làm gì cái đã:

[python]print encrypt(‘thisismypadpadpad’, ‘thisismytext’).encode(‘hex’)
print encrypt(‘thisismypadpadpad’, ‘ahisismytext’).encode(‘hex’)
print encrypt(‘thisismypadpadpad’, ‘thisismytex’).encode(‘hex’)[/python]

cho ra output:

[sh]746c52985298381d86116b86
6f6c52985298381d86116b86
746c52985298381d86116b[/sh]

Như vậy là, nó giống như một phép hoán đổi byte-to-byte vậy, nên giải quyết chắc không vấn đề gì.

Chúng ta không hề biết thông tin gì về giá trị của biến pad, tuy nhiên nó nên mang một đặc tính quan trọng, đó là sau khi decrypt bằng nó thì dữ liệu trả về phải ở dạng plain text gồm chỉ những ký tự printable. Theo hướng này, chúng ta sẽ dò từng byte của pad, tìm những byte thỏa mãn điều kiện. Trường hợp tìm được chỉ 1 byte, thì đơn giản là chọn nó, còn nếu có nhiều hơn, thì sẽ cần một chút năng lực về English emo_popo_embarrassed

[python]ciphers = [
‘794d630169441dbdb788337d40fe245daa63c30e6c80151d4b055c18499a8ac3e5f3b3a8752e95cb36a90f477eb8d7aa7809427dde0f00dc11ab1f78cdf64da55cb75924a2b837d7a239639d89fe2b7bc1415f3542dba748dd40’.decode(‘hex’),
’14a60bb3afbca7da0e8e337de5a3a47ae763a20e8e18695f39450353a2c6a26a6d8635694cbdc34b7d1a543af546b94b6671e67d0c5a8b64db12fe32e275′.decode(‘hex’),
‘250d83a7ed103faaca9d786f23a82e8e4473a5938eabd9bd03c3393b812643ea5df835b14c8e5a4b36cdcfd210a82e2c3c71d27d3c47091bdb391f2952b261fde94a4b23238137a4897d1631b4e18d63’.decode(‘hex’),
’68a90beb191f13b621747ab46321a491e71c536b71800b8f5f08996bb433838fe56587f171a759cf1c160b4733a3465f5509ad7d1a89d4b41f631f3c600347a8762141095dad3714027dfc7c894d69fd896b810313259b1a0e941ecb43d6ae1857a465b4ddcdf102b7297763acb0281144b0598c326e871c3a1ad047ad4fea2093a1b734d589b8998175b3′.decode(‘hex’),
‘0fc304048469137d0e2f3a71885a5a78e749145510cf2d56157939548bfd5dd7e59dcebc75b678cfeac4cf408fce5dda32c9bfcbfd578bdcb801df32ebf64da365df4b285d5068975137990134bd69991695989b322b0849’.decode(‘hex’),
‘254c0bb31453badaca9d060ce5faa45fa66378a6716915473579d3743e315dbedf4d8cf78b93c3267d579247e32c8c7cd3e71e7dda6138a2ab015166fa03f2ce6ab74b89ce561eb16a65990189e169f1c457d9af622ba119a66acedb108fae18825bf3efc0428b9dae250791cb0ea018966e257d601a87f9914d646026eeab5c45cbaedd27e4c47643ab4e25193aa64f79’.decode(‘hex’),
’41cd1c01c62883b2ca71e671dce57e5f96b1610e29507b6c03c38211653284576d4d8cdc967764147d1a0578102cb05f32a73065f11009041fa3cc5f60b24d8c7098598627df37322f814525966acabc99be5303c2322b43ecf358ac8b8541bd82214d1cc042cac3869c54e2964fa376229c2563ba3fd03e2d4d4d441721c60b6d817e034965be28b7d463cf2b97baebfe2729ed2aa41ffe’.decode(‘hex’),
’68c50bd5197bfdbdfa887883783d2455a673a685436915bd72d1af74dffdd2b89df335daee93c36d5f57e147e9a35913d3b3bf33′.decode(‘hex’)]

def test_decrypt(pad):
for cipher in ciphers:
cipher_part = cipher[:len(pad)]
print decrypt(pad, cipher_part)

pad = ”
index = len(pad)
for i in range(index, index + 1):
for c in [chr(j) for j in range(1, 256)]:
valid = True
for cipher in ciphers:
cipher_char = cipher[i]
plain_char = decrypt(c, cipher_char)

if (len(plain_char) == 0):
continue

if (ord(plain_char) not in range(0x20, 0x7E)):
valid = False
break

if (valid):
print ‘nndecrypt with next char = 0x’ + c.encode(‘hex’)
test_decrypt(pad + c)[/python]

Sau vài ba phút cặm cụi, ta tìm được:

[python]pad = ‘xdfx47x28x8bxd4xeax6fx68x39xa4xe4x86x71x2bxbex9bx8fx61x7fx40xe7x72xf8x66x73x3bx0fx74xe5xafx7cx56xa9x45x77x1exbfxebxc3x4bx10xa7xf6xfexa6x81xf7x68x4cxefx5a'[/python]

dù chưa đủ để có được toàn bộ nội dung các dòng text, nhưng cái cần là flag thì đã xuất hiện:

[sh]decrypt with next char = 0xe5
The difference between stupidity and genius is that
Go to Heaven for the climate, Hell for the company-
I am not a member of any organized political party.
My definition of an intellectual is someone who can
Republicans want less government for the same reason
If there are no stupid questions, then what kind of
And now, in the interest of equal time, here is a me
MY key for you is {And yes the nsa can read this to}[/sh]

flag = And yes the nsa can read this to

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *