Categories
PHP

Using Memcached with PHP

Memcached could be a very efficient way to scale your web applications. Memcached lets you store data into the cache of your memory and quickly retrieve data when you need. So, it is usually very fast for data storage. But the darker side is that it’s extremely volatile. Your machine crashes or restarts and all the data are gone. Still, memcached is widely used as a caching device to store temporary data for decreasing the load on mysql database.

Memcached is supported by many of the scripting languages. PHP has excellent support it. They have a PECL extension for interacting with Memcached.

=====================
Setting Things Up
=====================

1) Install Memcached on your machine.
2) Install Memcached PECL extension for PHP.
3) Activate Memcache.

1) Installing Memcached:

To install memcached on your Ubuntu type the following command on your terminal and press enter:

To install on Windows:

1. Download memcache from code.jellycan.com/memcached/ [grab the ‘win32 binary’ version]
2. Install memcache as a service:
* Unzip and copy the binaries to your desired directory (eg. c:\memcached) [you should see one file, memcached.exe] – thanks to Stephen for the heads up on the new version
* If you’re running Vista, right click on memcached.exe and click Properties. Click the Compatibility tab. Near the bottom you’ll see Privilege Level, check “Run this program as an administrator”.
* Install the service using the command: c:\memcached\memcached.exe -d install from the command line
* Start the server from the Microsoft Management Console or by running one of the following commands: c:\memcached\memcached.exe -d start, or net start “memcached Server”

2) Installing The PECL Extension:

On Ubuntu, use the command on terminal:

On windows, you need to get the memcached PECL extension, put it into the PHP’s extension directory. You might get the file at: http://downloads.php.net/pierre/

Add the extension to php.ini.

On Linux:

On Windows:

3) Activate:

Make sure that Memcached is running as a daemon/service. If not, use the command:

Now start using memcached 🙂

Memcached Demo: How to store an array ?

The Memcached PECL extension has a built in class “Memcache” which we will use to work with Memcached.

Pretty easy… Isn’t it?

Categories
PHP

LavaLair SQL Injection Vulnerability: Looking Inside

Lavalair is the name of a very popular mobile chat community software developed using PHP MySQL and WML front end. I was once a serious mobile web developer and worked with mobile web apps a lot.

A few days ago, a Indian boy asked for some help with a wapdesire clone of LavaLair. His site was getting hacked by some so-called “hackers”. My experience with LavaLair told me it was some sort of nasty SQL Injection. After having a look at the script, I found out a intensive SQL Injection vulnerability in the registration page. I wrote a CLI php script to inject some SQL codes.

Here is the tool I used to crack into the target site:

The easiest explanation is that LavaLair by default requires magic_quotes_gpc() to be off and it’s insert SQLs are in the format:

So, it becomes easy to inject some single quotes and hash sign to terminate the script and modify it the way you wish.

My suggestion would be to use Insert SQLs in this way:

And now a little rant about these so called hackers… I have heard lots of stories about AyOn and some other freaks terrorizing the LL community… It’s really funny the way the developers never bothered to learn how these scrip kiddies or so-called hackers managed their way in… From the very beginning, I have used J21Community with magic_quotes_gpc turned on and secure SQL queries. That’s one of the important reasons why no J21Community site has been hacked yet by SQL Injection… 😀

Categories
PHP

Reflection API in PHP

The reflection API works in a similar way of Python’s dir() function. The API provides a rich set of classes to reverse engineer classes, methods, parameters and functions.

Suppose, we want to explore and reverse engineer a class, then use the following code:

For example:

Outputs:

Cool, isn’t it? I loved it ! Thanks to Hasin Hayder for referring me to this API.

Read more at: http://www.php.net/language.oop5.reflection 😉