• Browse by Tags

C++ Std::String Buffer Overflow And Integer Overflow

Interators are usually implemented using signed integers like the typical "for (int i=0; ..." and in fact is the type used indexing "cstr[i]", most of methods use the signed int, int by default is signed.
Nevertheless, the "std::string::operator[]" index is size_t which is unsigned, and so does size(), and same happens with vectors.
Besides the operator[] lack of negative index control, I will explain this later.

Do the compilers doesn't warn about this?


If his code got a large input it would index a negative numer, let see g++ and clang++ warnings:



No warnings so many bugs out there...

In order to reproduce the crash we can load a big string or vector from file, for example:


I've implemented a loading function, getting the file size with tellg() and malloc to allocate the buffer, then in this case used as a string.
Let see how the compiler write asm code based on this c++ code.



So the string constructor, getting size and adding -2 is clear. Then come the operator<< to concat the strings.
Then we see the operator[] when it will crash with the negative index.
In assembly is more clear, it will call operator[] to get the value, and there will hapen the magic dereference happens. The operator[] will end up returning an invalid address that will crash at [RAX]



In gdb the operator[] is a  allq  0x555555555180 <_znst7__cxx1112basic_stringicst11char_traitsicesaiceeixem plt="">

(gdb) i r rsi
rsi            0xfffffffffffefffe  -65538


The implmementation of operator ins in those functions below:

(gdb) bt
#0  0x00007ffff7feebf3 in strcmp () from /lib64/ld-linux-x86-64.so.2
#1  0x00007ffff7fdc9a5 in check_match () from /lib64/ld-linux-x86-64.so.2
#2  0x00007ffff7fdce7b in do_lookup_x () from /lib64/ld-linux-x86-64.so.2
#3  0x00007ffff7fdd739 in _dl_lookup_symbol_x () from /lib64/ld-linux-x86-64.so.2
#4  0x00007ffff7fe1eb7 in _dl_fixup () from /lib64/ld-linux-x86-64.so.2
#5  0x00007ffff7fe88ee in _dl_runtime_resolve_xsavec () from /lib64/ld-linux-x86-64.so.2
#6  0x00005555555554b3 in main (argc=2, argv=0x7fffffffe118) at main.cpp:29

Then crashes on the MOVZX EAX, byte ptr [RAX]

Program received signal SIGSEGV, Segmentation fault.
0x00005555555554b3 in main (argc=2, argv=0x7fffffffe118) at main.cpp:29
29     cout << "penultimate byte is " << hex << s[i] << endl;
(gdb)


What about negative indexing in std::string::operator[] ?
It's exploitable!

In a C char array is known that having control of the index, we can address memory.
Let's see what happens with C++ strings:






The operator[] function call returns the address of string plus 10, and yes, we can do abitrary writes.



Note that gdb displays by default with at&t asm format wich the operands are in oposite order:


And having a string that is in the stack, controlling the index we can perform a write on the stack.



To make sure we are writing outside the string, I'm gonna do 3 writes:


 See below the command "i r rax" to view the address where the write will be performed.


The beginning of the std::string object is 0x7fffffffde50.
Write -10 writes before the string 0x7fffffffde46.
And write -100 segfaults because is writting in non paged address.



So, C++ std::string probably is not vulnerable to buffer overflow based in concatenation, but the std::string::operator[] lack of negative indexing control and this could create vulnerable and exploitable situations, some times caused by a signed used of the unsigned std::string.size()










Related word


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

0 comments on "C++ Std::String Buffer Overflow And Integer Overflow"



Post a Comment