Tryhackme-Scripting for Pentesters

Scripting for Pentesters

Python Basic

Task1 Introduction to Python

Run what’s currently in the code editor by clicking the green “Run Code” button (on the right-hand side of your screen), and move onto the next task.

Task2 Hello World

On the code editor, print “Hello World”. What is the flag?

THM{PRINT_STATEMENTS}

image-20210818165955645

Task3 Mathematical Operators

1.In the code editor, print the result of 21 + 43. What is the flag?

THM{ADDITI0N}

image-20210818170144799

2.Print the result of 142 - 52. What is the flag?

THM{SUBTRCT}

image-20210818170219858

3.Print the result of 10 * 342. What is the flag?

THM{MULTIPLICATION_PYTHON}

image-20210818170309135

4.Print the result of 5 squared. What is the flag?

THM{EXP0N3NT_POWER}

image-20210818170415264

Task4 Variables and Data Types

1.In the code editor, create a variable called height and set its initial value to 200.

2.On a new line, add 50 to the height variable

3.On another new line, print out the value of height. What is the flag that appears?\

THM{VARIABL3S}

image-20210818170646337

Task5 Logical and Boolean Operators

image-20210818170742432

image-20210818170753956

Read the above section

Task6 Introduction to If Statements

1.In this exercise, we will code a small application that calculates and outputs the shipping cost for a customer based on how much they’ve spent.

In the code editor, click on the “shipping.py” tab and follow the instructions to complete this task.

2.Once you’ve written the application in the code editor’s shipping.py tab, a flag will appear, which is the answer to this question

shipping_cost_per_kg = 1.20
customer_basket_cost = 34
customer_basket_weight = 44

if(customer_basket_cost >= 100):
  print('Free shipping!')
else:
  shipping_cost = customer_basket_weight * shipping_cost_per_kg
  customer_basket_cost = customer_basket_cost+shipping_cost

print("Total basket cost including shipping is " + str(customer_basket_cost))

THM{IF_STATEMENT_SHOPPING}

image-20210818172014017

3.In shipping.py, on line 12 (when using the Code Editor’s Hint), change the customer_basket_cost variable to 101 and re-run your code. You will get a flag (if the total cost is correct based on your code); the flag is the answer to this question.

THM{MY_FIRST_APP}

image-20210818172212051

Task7 Loops

On the code editor, click back on the “script.py” tab and code a loop that outputs every number from 0 to 50.

THM{L00PS_WHILE_FOR}

image-20210818172335342

Task8 Introduction to Functions

investment_in_bitcoin = 1.2
bitcoin_to_usd = 40000

# 1) write a function to calculate bitcoin to usd
def bitcoinToUSD(bitcoin_amount,bitcoin_value_usd):
  usd_value = investment_in_bitcoin * bitcoin_to_usd
  return usd_value

investment_in_usd = bitcoinToUSD(investment_in_bitcoin, bitcoin_to_usd)
if investment_in_usd <= 30000:
  print("Investment below $30,000! SELL!")
else:

1.Once you’ve written the bitcoinToUSD function, use it to calculate the value of your Bitcoin in USD, and then create an if statement to determine if the value falls below $30,000; if it does, output a message to alert you (via a print statement).

THM{BITC0IN_INVESTOR}

image-20210818173515215

2.1 Bitcoin is now worth $25,000. In the code editor on line 14, update the bitcoin_to_usd variable value to 25000 and see if your Python program recognises that your investment is below the $30,000 threshold.

Task9 Files

In the code editor, write Python code to read the flag.txt file. What is the flag in this file?

THM{F1LE_R3AD}

image-20210818173746403

Task10 Imports

Read the task and run the Python example code above in the code editor on the right.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值