Are there any methods to catch the php commands instead of executing them?
There's a backdoor which is encoded in my server, I was able to get declared classes and methods names, of the backdoor, but I need to find out the real code.
I can think of 2 things.
1. Use a profiler tool.
2. In your own code define a class with the same name. Then when the backdoor class is loaded, it will give a fatal error ('class name already defined') and tell you where the other class resides. Do enable stacktraces in case the backdoor is obfuscated/eval'd/remote included.
Related
I'm trying to wrap a test class around a pre-existing PHP class file that does not adhere to any PSR standard.
The PHP object I'm trying to test has a constructor that accepts 1 argument.
When prepping my object in setUp, my test correctly fails because there is a constructor argument missing. Because of this, I feel good that my object is being correctly resolved.
protected function setUp() {
$this->object = new HierarchyChange();
}
However, when I do add a value:
$this->object = new HierarchyChange('username');
NetBeans throws a "Perhaps error occurred, verify in Output window" message when I run the tests. And the output window has no information.
Executing "phpunit . -v" from the command line simply outputs the PHPUnit version I'm working with, but does not show any exception information.
I've tracked the failing line in my HierarchyChange class to this line in the class constructor:
public function __construct($agent_manager)
{
/* require contracting base class */
require_once($_SERVER['DOCUMENT_ROOT'] . '/_inc/oc.class.php');
I've tried a number of different ways to add this file, thinking that the server variable was causing the problem, but even removing it and hardcoding the path in the constructor cause the test suite to crash.
It DOES, however, work when I comment out the require_once line completely.
It doesn't make sense to me why this fails, but I am grasping at straws with this. Thanks.
The issue stemmed from a few things:
incorrect configuration of PHP.ini (error messages were not being raised), but more importantly:
incorrectly setting server vars; I ended up modifying the phpunit.xml configuration file to include:
Since the tests were being executed via CLI, these server variables are not available, so they needed to be set. And when phpunit encountered this as an error, NetBeans didn't know how to report it in the output window because the local INI configuration was not set to do so.
I'm new to php and i'm using log4php with laravel.
My project structure is
->Root
->Laravel
->app
->folderx
->abc.php
->otherfolders
.
.
->vendor
->composer.json (contains log4php and laravel)
->logconfig.xml
I'm trying to initialize the logger from inside abc.php,
Logger::configure('../../../logconfig.xml');
but it gives the error message
Class 'Apache\Log4php\Hierarchy' not found
I verified that the class Hierarchy.php exists in the vendor/apache/log4php/src under Root folder. Also, if I open Logger.php and go to the line where Hierarchy in initialized and ctrl+click(in eclipse) on Hierarchy, it takes me to Hierarchy.php.
I'm trying to figure out why php is not able to find that class.
Any help/suggestions would be greatly appreciated.
Thanks
That error message shows that your PHP is looking for a namespaced class. Log4PHP has never been released until now with namespaces (up to version 2.3.0), so this is definitely weird.
If you accidentially use the development branch of the 3.0 version, I must currently suggest not to use it. It barely got any significant commits in the last year, and should be considered work in progress (very slow progress unfortunately).
I'm using PHP 5.4, and have a PSR-0 class structure similar to the following.
A\Library\Session.php:
namespace A\Library;
class Session { ... }
My\Application\Session.php:
namespace My\Application;
class Session { ... }
My\Application\Facebook.php:
namespace My\Application;
use A\Library\Session;
class Facebook { ... }
When I try to run the application, I get the following error:
Cannot use A\Library\Session as Session because the name is already in use in My\Application\Facebook.php
Even though it's not, at least not in this file. The Facebook.php file declares only the Facebook class, and imports exactly one Session class, the A\Library one.
The only problem I can see is that another Session class exists in the same namespace as the Facebook class, but as it was never imported in the Facebook.php file, I thought it did not matter at all.
Am I wrong (in that case please point to the relevant documentation), or is this a bug?
There is a bug confirmed in PHP that may affect the behavior you see. It is supposed to fatal error, but with opcache enabled, it may still execute flawlessly.
https://bugs.php.net/bug.php?id=66773
If it still concerns you, please vote for the bug.
No, this is not a bug. As mentioned in Using namespaces: Aliasing/Importing
use A\Library\Session;
is the same as:
use A\Library\Session as Session;
So try using something like:
use A\Library\Session as AnotherSessionClassName;
The only problem I can see is that another Session class exists in the
same namespace as the Facebook class, but as it was never imported in
the Facebook.php file, I thought it did not matter at all.
Yes, it does matter. This is why you don't need to "import" classes from the same namespace. If you have conflicting names from different namespaces, you need to alias the class.
namespace My\Application;
use A\Library\Session as ASession; // choose a proper alias name here
class Facebook { ... }
I've read the thread about the issue, but I tested on many PHP versions (php 5.5, 5.6, 7.*, x32, x64, vc11, vc14, vc5). I'm using Laravel with Laragon. But, when I build up the server with php artisan serve (and open the server at http://localhost:8000) I have the problem of "the namespace that some Class was already used" and stuff.
I tested with and without opcache extension and nothing works, then I tested the virtual domain that Laragon provides and... voila, the error just disappeared and now I can work OK. I don't know what was happening, my namespaces were OK, I had an alias but the same code works in many machine without problem (AWS, local, prod, dev, etc) but only in my machine I had the problem just as I described it.
So, if someone is working with Laravel (5.1) and is having this issue, try the virtual host of Laragon.
I am learning how to use SWIG, and I am writing a php wrapper for a C library. The extension successfully compiles, but when I try to call the function I get this error:
php: symbol lookup error: /usr/lib/php5/20090626+lfs/fact.so: undefined symbol: fact
Your problem is probably due to a mismatch in the name of the module (see %module, or passed on the command line) and the name of the .so file you are generating.
PHP, or any system that accepts loadable binary modules, is going to make certain assumptions about the name of the entry point into the library it is trying to load. PHP seems to be assuming that the file name (fact.so) is going to contain a function called "fact".
When you run SWIG, explicitly setting the module name to "fact" will probably solve your problem. If not, posting the generated SWIG source file could help us debug your problem.
I want to use php in console mode and create an environment to test my functions.
I do not want to be forced to use a web browser and create a new file each time I want to test a function.
I want to access the function in the console and then it return the result.
How do I do this?
Update:
Perhaps I have explained this badly. I only want to see what result the function's return.
Maybe I have to learn unit testing but for the moment I only want an interactive console which allows me to test all functions one by one.
In my case I have to load the wordpress functions (I know how do it with a regular .php file and then a browser to parse the file) but i don't if it is possible to do it with php from the command line.
I have used phpsh in the past and found it very useful. Once you start it you will need to chdir() to where your files are and then obviously require() any files containing functions you need to test. You can then just test your function calls by typing them into the shell e.g. var_dump(some_function(1, 2));
I guess you've to be more specific what kind of functions exactly. Wordpress does not provide something like that out of the box, most PHP apps won't.
I also think you're calling for trouble here when such apps aren't developed in mind for such environments.
Here's an example trying to call "current_time()" from functions.php and the attempts I had to do just to realize it won't work that way:
php -r 'require "functions.php"; var_dump(current_time("mysql"));'
gives
Fatal error: Call to undefined function apply_filters() in functions.php on line 346
Trying
php -r 'require "functions.php"; require "plugin.php"; var_dump(current_time("mysql"));'
gives
Fatal error: Call to undefined function wp_cache_get() in functions.php on line 351
Trying
php -r 'require "functions.php"; require "plugin.php"; require "cache.php"; var_dump(current_time("mysql"));'
gives
Fatal error: Call to a member function get() on a non-object in cache.php on line 93
Looking at the last error in the source I see
function wp_cache_get($id, $flag = '') {
global $wp_object_cache;
return $wp_object_cache->get($id, $flag);
}
Using global variables makes testing in other environments a PITA if not impossible.
If this is not what you're trying to do, you've to be more specific/detailed in your question.
You are going to want to read up on "Unit Testing" in a generic sense and then try and apply them to PHP.
The framework you are using (if any), the style of code, and the tests you want to run are going to determine the exact methods you need to use. Only by first understanding the concept of Unit Tests and implementing them into your coding best-practices will you be able to make progress in this regard.
How about:
php -a
And if you compile php with readline support it'll be more fancy.