How can I decode multiple layers of encoded php code?

  • PHP
  • Thread starter AliGh
  • Start date
  • Tags
    File Php
In summary, my cousin gave me this file which had several commands that encoded and decoded code. I tried using eval and it caused some weird characters to show up. I then tried decoding it using gzinflate and base64_decode multiple times, but it kept getting the same result. I then wrote a code to do it myself, but it still jumped to the file. Finally, I found a way to decode it without the use of eval.
  • #1
AliGh
64
1
My cousin gave me this file
?temp_hash=8839ed0b6dccd9a22fe9a24b3cb6615e.jpg

The commands eval(gzinflate(base64_decode())); decodes the entered code and run it as a php code .
The problem is that its not the only decoding command there are several of this command in the code .
I used this command for the code and put the result in a variable and commanded to save whatever there is in the variable into .txt file (Couldn't show it in the browser page because its php code it will execute instead of apearing)
Now does anyone know how to write a code in php that decodes this several time until it gets the final code ?
 

Attachments

  • 2015-08-28_164111.jpg
    2015-08-28_164111.jpg
    76.8 KB · Views: 623
Technology news on Phys.org
  • #2
AliGh said:
The commands eval(gzinflate(base64_decode())); decodes the entered code and run it as a php code .
It also means you will run arbitrary code sent by someone - including potential malware. Don't do the eval().

What do you mean with "decode this several times"? It is possible to send the result of base64-encoding through the same algorithm again, but this is quite pointless. It can be reverted by applying the decode function again on the result as often as necessary. The same applies to gzdeflate and gzinflate.
 
  • #3
mfb said:
It also means you will run arbitrary code sent by someone - including potential malware. Don't do the eval().

What do you mean with "decode this several times"? It is possible to send the result of base64-encoding through the same algorithm again, but this is quite pointless. It can be reverted by applying the decode function again on the result as often as necessary. The same applies to gzdeflate and gzinflate.
I have tried removing eval and doing this before but the problem is that it gives a some weird chinese or japanese letters
Its not malware its a shell i think
When i decode it there is another <?php eval(gzinflate(base64_decode("blah blah blah"))); ?> inside
While running on a server it will continue decoding until the main code executed how can i stop it there ?
 
  • #4
Remove the eval, make a loop that applies the gzinflate and base64_decode as often as you like and removes those characters from the decoded string (so only the things in " " gets decoded), print each result and check which one has some readable code.
 
  • #5
I did it about 14 times still needs to decode
I wrote a program to do it but it seems it doesn't work
$thecode=gzinflate(base64_decode('blah blah blah'));
$time=0;
while ($time=0){
$exists1 = strpos($thecode, "?><?phpeval(gzinflate(base64_decode('");
$exists2 = strpos($thecode, "')));?><?");
if ($exists1=== true and $exists2 === true){
str_replace("?><?phpeval(gzinflate(base64_decode('","",$thecode);
str_replace("')));?><?","",$thecode);
$decodedtext = gzinflate(base64_decode($thecode));}
else {$time=1;}
}
$myfile = fopen("text/textfile.txt",w);
fwrite($myfile, $decodedtext);
fclose($myfile);

it just jumps to $myfile's line
 
  • #6
AliGh said:
while ($time=0){
That will set $time to 0 and get always evaluated as true.
strpos returns an integer or false, but never true.
 
  • #7
mfb said:
That will set $time to 0 and get always evaluated as true.
strpos returns an integer or false, but never true.
There is "else {$time=1}" at the end of while loop
I edited my code still jumps to $myfile with only one time passing the while loop
$time=0;
while ($time=0){
$exists1 = strpos($thecode, "?><?phpeval(gzinflate(base64_decode('");
$exists2 = strpos($thecode, "')));?><?");
if ($exists1 == 1 and $exists2 == 1){
str_replace("?><?phpeval(gzinflate(base64_decode('","",$thecode);
str_replace("')));?><?","",$thecode);
$decodedtext = gzinflate(base64_decode($thecode));}
else {$time=1;}
}
$myfile = fopen("text/textfile.txt",w);
fwrite($myfile, $decodedtext);
fclose($myfile);

errors : Notice: Use of undefined constant w - assumed 'w' in C:\wamp\www\autodecode.php on line 15
Notice: Undefined variable: decodedtext in C:\wamp\www\autodecode.php on line 16
 
  • #8
AliGh said:
There is "else {$time=1}" at the end of while loop
Which does not do anything as it gets overwritten again with the while condition.
I don't think you want to check if strpos returns 1.
 
  • #9
mfb said:
Which does not do anything as it gets overwritten again with the while condition.
I don't think you want to check if strpos returns 1.
Sorry I am a begginer ...
Checked and it returns nothing the problem is the command in smaller scales it returns a value but here it returns nothing . The code is a 12 kb text file .
 
  • #10
At last finished
Using this code substr($decodedtext, 39, -10);
It doesn't decode all of these kind of codes automatically but if you give it the exact numbers it will ...
However its not the proper way to do it ... It would be better to use str_replace but whatever i did that code didn't work
 

What is an encoded PHP file?

An encoded PHP file is a file that has been converted from human-readable code into a format that is difficult to understand or modify. This is often done for security purposes to protect the code from being copied or altered.

Why would someone want to decode an encoded PHP file?

There are a few reasons why someone may want to decode an encoded PHP file. One reason could be to better understand the code and make modifications or improvements. Another reason could be to troubleshoot any issues or bugs in the code.

Is it legal to decode an encoded PHP file?

This depends on the specific circumstances and the terms of use set by the creator of the encoded file. In some cases, it may be a violation of copyright laws to decode an encoded file without permission. It is important to always check the terms of use before attempting to decode any file.

What tools are available for decoding an encoded PHP file?

There are various tools and software programs available for decoding an encoded PHP file. Some popular options include IonCube, Zend Guard, and SourceGuardian. These tools typically require a license and may have different capabilities, so it is important to research and choose the best option for your needs.

Is it possible to fully decode an encoded PHP file?

It is not always possible to fully decode an encoded PHP file. The level of success in decoding will depend on the type of encoding used and the tools available. Some encoding methods may be more difficult to decode than others, and some files may have additional layers of protection that make it nearly impossible to fully decode the file.

Similar threads

  • Programming and Computer Science
2
Replies
65
Views
2K
  • Programming and Computer Science
Replies
5
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
275
  • General Math
Replies
3
Views
5K
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • Computing and Technology
Replies
1
Views
7K
Replies
17
Views
5K
Back
Top