The Dutch Hacker
Intro to Python Tryhackme

Intro to Python on Tryhackme

This is the write up for the room Intro to Python on Tryhackme and it is part of the Web Fundamentals Path

Make connection with VPN or use the attackbox on Tryhackme site to connect to the Tryhackme lab environment.

Tasks Intro to Python

For all the task in this room I’ll be using gedit to create a .py file. You can install gedit by typing

apt install gedit

Task 1

Read all that is in the task and press complete

Task 2

Read all that is in the task and press complete

Task 3

Read all that is in the task. All answer can exactly be found in this task

3.1 What is the name of >

Answer: Greater than

3.2 What is the name of !=

Answer: Not Equal to

3.3 1 != 0 will this return true or false (T or F)

Answer: T

3.4 What is the name of <=

Answer: Less than or equal

3.5 Will this sample code return truee or false    

a= 15
if <= 15:

The statement is saying if less then or equal to. In this case it is equal

Answer: True

Task 4

Read all that is in the task and press complete. DO note the IN operator 😀

Task 5

Read allt hat is in the task and learn the diffence

5.1 What data type is 13

Answer: Interger

5.2 What data type is “65”

Notice the ” around the 65. This means it is an string

Answer: String

5.3 What data type is 62.193

Answer: Float

Task 6

Read all that is in the task and press complete

Task 7

Read all that is in the task and press complete

Task 8

Read all that is in the task and press complete

Task 9

Read all that is in the task and press complete

Task 10

Read all that is in the task then Install the virtual enviroment by typing

sudo apt install virtualenv

Create virtual environment

virtualenv --python=python3 introduction

Activate the environment

source introduction/bin/activate

Notice the name in

Activate env

We can deactivate by tyiping

deactivate

Press complete when done

Task 11

Install pip by typing in

sudo apt install python3-pip

Task 12

Download the file that is attached to this task and save it to a directory where we can read it.

We need to decode

  • 5 times encoded using base 64
  • 5 times encoded using base 32
  • 5 times encoded using base 16!

We use the module from base64 import *

Type inside the directory where you save the file and in the terminal

gedit task12.py

Let;s start writing the code

Forst we do the import

import base64

Now we need to read the file

encodedflag  = open("encodedflag.txt","r")
print(encodedflag.read())

We see the utput

Intro to Python on Tryhackme

So we know that we can read the file and output it to screen.

Now start the encoding part

Because we are going to use multiple times the same code, we are going to use a funtions

Type in the following 3 functions

def b16d(encoded):
decoded = base64.b16decode(encoded)
return decoded

def b32d(encoded):
decoded = base64.b32decode(encoded)
return decoded
def b64d(encoded):

decoded = base64.b64decode(encoded)
return decoded

And we are going to use the IF statement to loop trough each function to decode the flag

encodedflag = open("encodedflag.txt","rb").read()

for i in range(5):
encodedflag = b16d(encodedflag)

for i in range(5):
encodedflag = b32d(encodedflag)

for i in range(5):
if i != 4:
encodedflag = b64d(encodedflag)
else:
encodedflag = b64d(encodedflag)
print("The flag is:",encodedflag)

The complete code

Intro to Python on Tryhackme

Run this by typing in

python task12.py

Remember if you use the same code over and over again create a function

Most Popular Post

Sign Up

Signup today for free and be the first to get notified on new updates.
* indicates required

Follow Me

Most Popular Post

Contact Us