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}
Task3 Mathematical Operators
1.In the code editor, print the result of 21 + 43. What is the flag?
THM{ADDITI0N}
2.Print the result of 142 - 52. What is the flag?
THM{SUBTRCT}
3.Print the result of 10 * 342. What is the flag?
THM{MULTIPLICATION_PYTHON}
4.Print the result of 5 squared. What is the flag?
THM{EXP0N3NT_POWER}
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}
Task5 Logical and Boolean Operators
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}
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}
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}
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}
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}
Task10 Imports
Read the task and run the Python example code above in the code editor on the right.