Introduction

In this post, we covered Python programming basics for penetration testers and cyber security specialists. We focused first on covering the basics such as variables, data types, operator types, if statements and loops. In the next section, we covered practical applications of cyber security concepts using Python such as hash cracking, subdomain enumeration, directory enumeration,etc. This was part of TryHackMe walkthrough for two rooms; TryHackMe python basics and TryHackMe Python for pentesters.

OSCP Study Notes

HackTheBox Certified Penetration Testing Specialist Study Notes

Introduction

Walkthrough of TryHackMe rooms focusing on relevant topics.

Overview of the video: Covers Python programming basics and its application in cybersecurity.

Learning Objectives

  • Build foundational Python skills.
  • Apply Python concepts to cybersecurity-related scenarios.
  • Gain familiarity with TryHackMe environments for hands-on learning.

Key Python Concepts Covered

  1. Basic Python Syntax
    • Printing statements: Demonstrating basic print functionality.
    • Example: Printing “Learn security with TryHackMe.”
  2. Mathematical Operations
    • Performing addition, subtraction, multiplication, and exponentiation directly in Python using the print function without variables.
    • Explanation of how Python handles mathematical expressions within print statements.
  3. Variables and Data Types
    • Creating and manipulating variables.
    • Example: Setting height to 200, adding 50, and printing the updated value.
    • Emphasis on understanding integers and avoiding string usage when printing numerical values.
  4. Conditional Statements
    • Developing logic for customer basket costs with if-else conditions.
    • Scenario:
      • If basket cost > 100: Free shipping.
      • Otherwise: Calculate shipping cost as $1.20 per kg of basket weight.
    • Step-by-step explanation of Python syntax and logic implementation.
  5. Loops
    • Introduction to for loops:
      • Example: Iterating from 0 to 50.
      • Explanation of the range() function and its behavior.
    • Adjustments to starting values for customization.
  6. Functions
    • Building reusable code blocks.
    • Example: Creating a function Bitcoin_to_USD to calculate the USD value of a given amount of Bitcoin.
    • Emphasis on parameter passing and return values.
  7. File Handling
  8. Using Python’s open() function to read and print a file’s content.
  9. Example:

Python Projects

  1. Shipping Cost Calculator
    • Program to calculate total basket costs including shipping.
    • Logic:
      • Free shipping for costs over $100.
      • Shipping cost $1.20 per kg for lower basket values.
    • Example: For a basket cost of $34 and weight 44kg, calculate the total cost as $86.80.
  2. Bitcoin Conversion

Function Development

  • The function Bitcoin_to_USD takes two arguments:
    • Bitcoin amount: The number of Bitcoins owned.
    • Bitcoin value in USD: The current market value of Bitcoin.
  • The function calculates the total value of the Bitcoin investment and returns it.

Updating Bitcoin Value

  • Demonstration of updating the Bitcoin market value in code.
  • For instance, setting Bitcoin value in USD to $24,000 to check if the value drops below $30,000.

Conditionals for Monitoring

  • If the Bitcoin value is less than $30,000, an alert is printed.
  • If the value equals $30,000, a message of normalcy is printed.
  • If the value is above $30,000, the script indicates profit.

Subdomain Enumeration

  1. Overview
    • A Python script is used to enumerate possible subdomains of a target domain.
    • Reads a wordlist containing potential subdomain names.
  2. Steps in the Script
    • Libraries imported: requests and sys.
    • The wordlist is read and split line-by-line into a list of potential subdomains.
    • A for loop iterates through the subdomains, forming HTTP requests to verify their existence.
  3. Output and Validation
    • A successful response (e.g., HTTP status 200) confirms the subdomain’s existence.
    • Error handling with try-except ensures robustness.
  4. Alternative Protocol
    • Discussion of DNS as an alternative protocol for subdomain enumeration.

Directory Enumeration

  1. Purpose
    • Identify files and directories on a web server during a penetration testing engagement.
  2. Process
    • Read a wordlist of potential directory names.
    • Use HTTP requests to check for the existence of directories.
    • HTTP status codes:
      • 200 or 301: Valid directory.
      • 404: Directory not found.
  3. Example Results
    • Found directories: index, Appollo, private, and server.
    • Specific findings:
      • Login page under /private.
      • Usernames and passwords under /server.

Network Scanning with Python

  1. Objective
    • Identify live hosts in a network using ARP (Address Resolution Protocol).
  2. Script Details
    • Importing the Scapy library for networking operations.
    • Defining variables:
      • Network interface.
      • IP range.
      • Broadcast MAC address.
    • The script sends ARP packets to scan the network.
  3. Why ARP?
    • ARP is used because ICMP (ping) is often blocked on networks.

Video Walkthrough

About the Author

Mastermind Study Notes is a group of talented authors and writers who are experienced and well-versed across different fields. The group is led by, Motasem Hamdan, who is a Cybersecurity content creator and YouTuber.

View Articles