Sunday, April 29, 2007

XSS on Yaari.com



Lots of friendship network sites are coming up these days following the success of orkut. Another one supposedly originating from the same stanford university is yaari.com targeted at mainly Indian users. The site looks and functionality seems fine but is full of XSS holes (Cross Site Scripting). Almost all the fields can be bugged.

Only thing that amazes me is that the site has used PHP. PHP has such a wonderful list of functions that can take care of the XSS problem. I wonder why no one is using those. I guess people are unaware of the XSS problem or is it that they just under estimate it ????

If anyone from the administrative department of yaari happens to be reading this, please post a comment on "Why have you ignored XSS ??"

Thanx Mr Nobody,
XSS is on DesiMartini.com too

Monday, April 23, 2007

Using PHP for more than HTML

Intro
It is mostly thought that PHP can be used only for making dynamic web pages. No. PHP can also be used to make dynamic images (jpg,gif,bmp,png..), javascript codes (js), Style sheets (css), XML files and in the advanced cases pdf's, docs etc.

So How do we know the php is a different file ?
By default the php file is rendered as a HTML file. The server does not need any recognition for the format of the php file, i.e, server doesn't care what the format is. But the browser does. So we have to notify the browser the content-type of the content we are sending to the browser.

This is done by

<?
header("Content-Type: image/jpeg");
?>

The header function adds or replaces the default headers. Thus here the default content type being html/plain-text is replaced by image/jpeg. Thus on the viewers browser the php file would be rendered as an image. Thus
<img src="http://example.com/images/image.php">

would show an image if the coding is correct and the image format is correctly rendered.

More about returning images
<?
header("Content-Type: image/jpeg");
echo file_get_contents("../images/some.jpg");
?>


The above code returns a jpeg. But this is static everytime we see the some.jpg. The advantage of using php to return image is that you can provide a authentication validation, i.e, the user must have signed in to view the image. Thus automatically hot linking is prevented. (Hot linking is the use of images of other servers, by another server. for eg an image on www.example.com displyed on www.elpmaxe.com)
But precious server resources are also consumed.

Another advantage is by returning a random image :
<?
header("Content-Type: image/jpeg");
$files = array("photo0.jpg","photo1.jpg","photo2.jpg");
$index = rand(0,2);
echo file_get_contents($file[$index]);
?>


Returning an image from scratch
Suppose we want to display an image, say for example a bar graph or a random code or text segment from php. Using 100's of images is inefficient and time consuming. In these cases comes in the use of the GD library.

Returning other formats
Other formats can be returned from php via the same way by changing the Content-Type header and giving the appropriate body.
Example :

<?
header("Content-Type: text/javascript");
?>
function Foo()
{

}
<?
echo "function Rand() { } ";
?>


It is also a good practice to set the content-length header, in case you know the size of the body you are about to send in advance. (In case you are sending an image).

Common Content Types


HTML TEXTtext/html
Plain TEXTtext/plain
Cascading Style Sheetstext/css
GIFimage/gif
JPEGimage/jpeg
TIFFimage/tiff
RGBimage/rgb
PNGimage/x-png
PDFapplication/pdf
RTFapplication/rtf

Sunday, April 22, 2007

Chatting with Self on google talk

How did I do it ?



Have you done this ?
If yes, comment on how you did that ...
If no, challenge .... try doing it...

Have fun :)

Saturday, April 21, 2007

An Introduction to PHP

PHP ?
PHP stands for Hypertext Preprocessor. Well what is it ? In the world wide web we are familiar with the HTML page. The HTML page is static and does not change. What if we want a page that has some parts common and other parts different according to the browser or user that is visiting the site? Say for an example, a user's profile page. It is wasteful and time consuming to make each user a separate HTML page. Here is where Server side scripting comes in. Thus we can program the page in such a way that the common template is stored in a file and all the variable information such as the user's name, address , etc can be fetched from a database or a remote location and be displayed on the site. This is just one scenario where server side scripting is used. There is many other scenario's like the need for a login, displaying dynamic data etc.

There are many server side scripting languages. One of it is PHP. Other common languages are ASP (Active Server Pages),ASP.net,CFM (Cold Fusion Template),etc...

PHP is different from other conventional languages like C,C++ used to make desktop applications.

PHP file is an ordinary text file and does not need any compiler. The language is interpreted as it is and executed by the server. In desktop applications the data is entered through the keyboard and displayed on the monitor. In web applications that make use of the PHP, data is sent by HTTP methods in the browser. 2 most common ways to input data is via the GET and POST. Similarly the output of a PHP file can be in the form of an HTML file, JPG file, XML file or any format as you wish (Yes!!)

The PHP Language
As mentioned above, PHP files are ordinary text files with the extension PHP. Suppose you want a dynamic page that shows say todays date.


<html>
<head>
<title>Today's date</title>
</head>
<body>
Todays date is : <? //PHP code begin
echo date("M d Y H:i:s");
//PHP code end
?>

</body>
</HTML>


The <? tag marks the beginning of the PHP code segment and the ?> marks the ending of the code segment. There can be any number of PHP code segments in a file. Text outside the code segment is by default interpreted as HTML and send back to the browser as it is. The code within the segement is evaluated and executed and the output of the code replaces the <? ?> The PHP code is executed and replaced in the server itself and no PHP source code is sent to the browser. Thus the HTML recieved by the browser is


<html>
<head>
<title>Today's date</title>
</head>
<body>
Todays date is : Apr 22 2007 09:15:00
</body>
</HTML>


echo is something like the printf. It prints whatever that follows it until the ;. date is a function that returns the formatted date and time according to the argument passed to it.

The code segment is broken up into statements. Each statement ends with a ; as in C / C++.

Variables in PHP
All variables in PHP start with $. eg: $variable = 10;
Unlike C/C++ no data type needs to be mentioned in PHP.

$variable = 10;
$var2 = "arun";
$var3 = array("asd","gfh");
$var4 = false;


To read more about the language, built-in functions and syntax visit www.php.net.

Inputing to PHP

Now you have seen how the PHP outputs the DATA. Now lets see how to push data into the PHP code. Data can be pushed in two common ways :

1. GET : In get method, the data to be passed to the php page can be encoded in the URL in the following format :
http://www.example.com/some/test.php?variable1=something&variable2=something else
These variables are automatically filled into the $_GET array. Therefore $_GET["variable1"] has the value "something" and $_GET["variable2"] has the value "somethingelse".

2. POST : In the POST method the data is not send with the URL but with the HTTP request. An HTML form with action="the destination php file" is used in this case. All POST variables appear in the $_POST similarly as with the GET.

That's all for Part 1
Stay tuned....

Tuesday, April 17, 2007

Freeing up more disk space

Disk Clean Up
Right Click the drive -> Properties -> Click on the Disk Clean Up -> Press OK


Obsolete Restore Files
Right Click the drive -> Properties -> Click on the Disk Clean Up -> More Options Tab -> System Restore Frame -> Click Clean Up -> OK

Disable Hibernation
If you do not use hibernate feature, disable it.
Control Panel -> Power Options -> Hibernate Tab -> Uncheck Enable Hibernation -> OK


Removing .tmp , .log
.tmp and .log are temporary or log files that simply clog up valuable disk space on your system, Its safe to delete them.

Clean the TEMP directories
X:\Windows\TEMP
X:\Documents and Settings\User\Local Settings\TEMP

Remove unused User Accounts
Delete any users that no longer exists

Change the pagefiling quota on the disk
Control Panel -> Click System -> Advanced Tab -> Performance Frame -> Click Settings -> Advanced Tab -> Virtual Memory Frame -> Click Change Button -> ...


Remove DMP file
Sometimes a RAM image may be saved to your X:\Windows\ folder after a crash. You can remove that files. Normally X:\Windows\memory.dmp

Empty the Trash Bin
Right Click the Recycle Bin and Click empty Recycle Bin.

Related :

Run the Disk Defragmenter to increase performance.
Pressing PrintScreen takes the screen shot of the entire screen.
Pressing Alt+PrintScreen takes the screen shot of the active window only.