Skip to main content

THM — RUST — [task 13] challenge - writeup


Before starting this you must get familiar with all the previous tasks and run some code in the tasks and get familiar with error handling and using crates.

If you have difficulty completing the previous tasks here is a walkthrough video of them.

TryHackMe — learn Rust — [Task 13]:

So as given the string is already encrypted and all you have to do is to decrypt in the order of rot13 -> base64 -> ROT13 -> plaintext and find the flag.

To do that you can head to https://crates.io/ to find external packages which will decrypt the text for you out of the box, so search for packages such as base64 and rot13 to make use of them to use them in our code.

So here are some packages which I used


cipher-crypt = “0.17.0”
base64 = “0.12.3”


will use cipher-crypt for rot13 and base64 for base 64 decryption.

So now you can add them to your dependencies in Cargo.toml file(as below)



Now you are all set to use the packages it in your code. Then you can import these packages in your code as below

extern crate cipher_crypt;
extern crate base64;
use base64::{decode};
use cipher_crypt::{Rot13};


Here is the complete code to get decrypt.

extern crate cipher_crypt;
extern crate base64;
use base64::{decode};
use cipher_crypt::{Rot13};use std::str;fn main(){
let in_string = "M3I6r2IbMzq9";
let rot13_decrypt1 = Rot13::decrypt(in_string);
let unicode_decrypt = decode(rot13_decrypt1).unwrap();
let bytes_to_string = str::from_utf8(&unicode_decrypt).unwrap();
let final_string = Rot13::decrypt(bytes_to_string);
println!("{:?}",final_string);
}



Rust always recommends using snakecase so all the variables must be initialized in such format.

As Rot13::decrypt(“xxx”) returns a string we can directly pass it to base64 decode but the return type fo base64~decode is bytes we have to convert that to a string so we are using str::from_utf8. This could be done in several different ways I suppose I would be glad if could share with me your way of approaching the same in the comments.


Finally, you could use cargo run to run the code.



There you get the flag 🤩.

Comments

Popular posts from this blog

Reasons not to buy Akaso action camera if you are from india

Recently I made a full review of the action camera I brought after doing a ton of research and time. Having used it for a couple of months I feel extremely glad that it meets up to my expectations. But recently, I accidentally tipped off the camera without an external case and it cracked my lens. This, in turn, added a shady spot on my phone or video and I cannot use that anymore (Some phones of the cracked lens below)     I immediately mailed the akaso team to ask if there is anything they could do but unfortunately, this was their response. Oops, that was not what I was expecting and then I asked them I could get any details of the replacement parts or anything like that so that I can order it online. But that didn't happen it took a lot of time for them to respond me back(I have been bugging them on Facebook and email).  But after some time they left me with this response which I had no other choice but to accept. After getting the 50%re...

Best and free NTFS tool for mac

Early recently I had my internal memory of my mac stocked up and I had to rely on storing my excess data onto my external hard disk which most have to do as we do not have an option otherwise to increase the internal storage of the machine itself. I pulled up my external hard disk and boom to my wonder it doesn't have the write permissions as it's of `NTFS` format. So after a quick search, it was evident that there are a lot of software that can mount my NTFS drive namely Microsoft NTFS for Mac by Paragon Software Microsoft NTFS for Mac by Tuxera But there all are restricted and you can use it for a limited period of time and they had hefty prices to pay for, So instead after a long search and trying out various tools here are my list of best picks for the free software available that will definitely help you out. easyuefi ~ ntfs-for-mac  ~ I myself been using it for a while now. mounty I will be updating the list every time when I find new software availabl...

Changing python version in gitpod

I have always had this problem modifying using a particular version of python on gitpod. Until I knew this simple trick to switch between the python versions. If you have not heard of gitpod its time for you to use it as running code online instead of local machine helps you when you have a CPU intensive processes and there are a lot of free to use online web apps that enable you to start with using powerful CPU and extends to GPU and TPU as well. I will be sharing a blog post soon on all the free tools you could use to boost up your productivity. So if you are already using gitpod and want to switch between python versions its simpler than you think Run this to check all the python versions available:    pyenv versions So to install a new version of python you simply have to run this:   pyenv install 3.7.6 (Or whatever version you want) That will basically download and install. Now you need to make sure to configure it for the existing workspace, t...