# CRYPTOHACK Writeup: General (Author: dpduy123) ## ENCODING ### ASCII ![](https://i.imgur.com/9IQ9EzJ.png) Solution: ```python = 0 ASCII = [99, 114, 121, 112, 116, 111, 123, 65, 83, 67, 73, 73, 95, 112, 114, 49, 110, 116, 52, 98, 108, 51, 125] flag = '' for c in ASCII: flag += chr(c) print(flag) ``` -> Flag: `crypto{ASCII_pr1nt4bl3}` ### Hex ![](https://i.imgur.com/jzuMNWP.png) Solution: ```python = 0 from binascii import unhexlify flag = unhexlify(b'63727970746f7b596f755f77696c6c5f62655f776f726b696e675f776974685f6865785f737472696e67735f615f6c6f747d') print(flag) ``` -> Flag: `crypto{You_will_be_working_with_hex_strings_a_lot}` ### Base64 ![](https://i.imgur.com/hYtfCom.png) Solution: - Đầu tiên ta sẽ decode tất cả các hex, sau đó encode thành base64 là nhận được flag. ```python = 0 import base64 from binascii import unhexlify hex = unhexlify('72bca9b68fc16ac7beeb8f849dca1d8a783e8acf9679bf9269f7bf') flag = base64.b64encode(hex) print(flag) ``` -> Flag: `crypto/Base+64+Encoding+is+Web+Safe/` ### Bytes and Big Integer ![](https://i.imgur.com/Jpua04M.png) Solution: ``` python = 0 from Crypto.Util.number import * data = 11515195063862318899931685488813747395775516287289682636499965282714637259206269 flag = long_to_bytes(data) print(flag) ``` -> Flag: `crypto{3nc0d1n6_4ll_7h3_w4y_d0wn}` ### Encoding Challenge >Now you've got the hang of the various encodings you'll be encountering, let's have a look at automating it. >Can you pass all 100 levels to get the flag? >The 13377.py file attached below is the source code for what's running on the server. The pwntools_example.py file provides the start of a solution. >For more information about connecting to interactive challenges, see the FAQ. Feel free to skip ahead to the cryptography if you aren't in the mood for a coding challenge! >Connect at socket.cryptohack.org 13377 Challenge files: * 13377.py * pwntools_example.py ## XOR ### XOR Starter ![image](https://hackmd.io/_uploads/H1rHRySeA.png) Solution: ### XOR Proporties ![image](https://i.imgur.com/9XXy418.png) Solution: ### Favourite bytes ![image](https://hackmd.io/_uploads/SkN1yeBlC.png) Solution: ### You either know, XOR you don't ![image](https://i.imgur.com/3Q8SMpl.png) Solution: ### Lemur XOR ![image](https://hackmd.io/_uploads/Syw2RyBg0.png) Solution: ## MATHEMATICS ### Greatest Common Divisors ### Extended GCD ### Modular Arithmetic 1 ### Modular Arithmetic 2 ### Modular Inverting ## DATA FORMATS ### Privacy-Enhanced Mail? ![](https://i.imgur.com/SqfpgLA.png) Solution: - tải và lưu PEM file và code chung folder - sử dụng hint để decode. - sử dụng module RSA ``` from Crypto.PublicKey import RSA ``` - mở tệp ``` open(file, mode)``` - đọc file bằng ``` RSA.importKey()``` input: ``` from Crypto.PublicKey import RSA f = open("privacy_enhanced_mail_1f696c053d76a78c2c531bb013a92d4a (4).pem", mode='r') #'r':chi_doc key = RSA.importKey(f.read()) print(key.n) ``` output: `15682700288056331364787171045819973654991149949197959929860861228180021707316851924456205543665565810892674190059831330231436970914474774562714945620519144389785158908994181951348846017432506464163564960993784254153395406799101314760033445065193429592512349952020982932218524462341002102063435489318813316464511621736943938440710470694912336237680219746204595128959161800595216366237538296447335375818871952520026993102148328897083547184286493241191505953601668858941129790966909236941127851370202421135897091086763569884760099112291072056970636380417349019579768748054760104838790424708988260443926906673795975104689` ### CERTainly not: ![](https://i.imgur.com/YvKMCrf.png) Solution: - định dang file der về file pem - lưu file và code cùng folder Script: ```python = 0 from Crypto.PublicKey import RSA f = open("2048b-rsa-example-cert_3220bd92e30015fe4fbeb84a755e7ca5.der", mode='rb') key = RSA.importKey(f.read()) #'rb':dinh_dang_file_ve_dang_nhi_phan print(key.n) ``` Output: ``` 22825373692019530804306212864609512775374171823993708516509897631547513634635856375624003737068034549047677999310941837454378829351398302382629658264078775456838626207507725494030600516872852306191255492926495965536379271875310457319107936020730050476235278671528265817571433919561175665096171189758406136453987966255236963782666066962654678464950075923060327358691356632908606498231755963567382339010985222623205586923466405809217426670333410014429905146941652293366212903733630083016398810887356019977409467374742266276267137547021576874204809506045914964491063393800499167416471949021995447722415959979785959569497 ``` ### SSH Keys ![](https://i.imgur.com/UabXy6Z.png) ![](https://i.imgur.com/1MUx69g.png) note: - đưa file pub về file pem tương tự như đưa der về pem input: ```python = 0 from Crypto.PublicKey import RSA f = open("bruce_rsa_6e7ecd53b443a97013397b1a1ea30e14.pub", mode='rb') key = RSA.importKey(f.read()) print(key.n) ``` output: ``` 3931406272922523448436194599820093016241472658151801552845094518579507815990600459669259603645261532927611152984942840889898756532060894857045175300145765800633499005451738872081381267004069865557395638550041114206143085403607234109293286336393552756893984605214352988705258638979454736514997314223669075900783806715398880310695945945147755132919037973889075191785977797861557228678159538882153544717797100401096435062359474129755625453831882490603560134477043235433202708948615234536984715872113343812760102812323180391544496030163653046931414723851374554873036582282389904838597668286543337426581680817796038711228401443244655162199302352017964997866677317161014083116730535875521286631858102768961098851209400973899393964931605067856005410998631842673030901078008408649613538143799959803685041566964514489809211962984534322348394428010908984318940411698961150731204316670646676976361958828528229837610795843145048243492909 ``` ### Transparency: ![](https://i.imgur.com/BHeGVhD.png) Solution: - Tìm miền phụ của cryptohack.org - ![](https://i.imgur.com/mGWPnAV.png) - Truy cập https://thetransparencyflagishere.cryptohack.org sẽ ra flag -> Flag: ``` crypto{thx_redpwn_for_inspiration} ```