Monday, August 24, 2020

Exploiting Golang Unsafe Pointers


There are situations when c interacts with golang for example in a library, and its possible to exploit a golang function writing raw memory using an unsafe.Pointer() parameter.

When golang receive a null terminated string on a *C.Char parameter, can be converted to golang s tring with  s2 := C.GoString(s1) we can do string operations with s2 safelly if the null byte is there.

When golang receives a pointer to a buffer on an unsafe.Pointer() and the length of the buffer on a C.int, if the length is not cheated can be converted to a []byte safelly with b := C.GoBytes(buf,sz)

Buuut what happens if golang receives a pointer to a buffer on an unsafe.Pointer() and is an OUT variable? the golang routine has to write on this pointer unsafelly for example we can create a golangs memcpy in the following way:



We convert to uintptr for indexing the pointer and then convert again to pointer casted to a byte pointer dereferenced and every byte is writed in this way.

If b is controlled, the memory can be written and the return pointer of main.main or whatever function can be modified.

https://play.golang.org/p/HppcVpLfuMf


The return addres can be pinpointed, for example 0x41 buffer 0x42 address:



We can reproduce it simulating the buffer from golang in this way:


we can dump the address of a function and redirect the execution to it:


https://play.golang.org/p/7htJHJp8gUJ

In this way it's possible to build a rop chain using golang runtime to unprotect a shellcode.

More info


  1. Top Pentest Tools
  2. Hack Rom Tools
  3. Termux Hacking Tools 2019
  4. Install Pentest Tools Ubuntu
  5. Hacker Tools
  6. Pentest Tools Linux
  7. Pentest Tools Online
  8. Pentest Tools Review
  9. Pentest Tools Android
  10. Install Pentest Tools Ubuntu
  11. Hacking Tools Free Download
  12. Hacking Tools Windows
  13. Hacking Tools For Pc
  14. Nsa Hack Tools Download
  15. Hacker Tools Github
  16. Usb Pentest Tools
  17. Best Pentesting Tools 2018
  18. Hack Tool Apk
  19. Hack Tools For Windows
  20. Hacking Tools Github
  21. Hacking Tools For Kali Linux
  22. Hack Tools 2019
  23. Kik Hack Tools
  24. Hacking Tools For Windows
  25. Hacker Tools Free Download
  26. Pentest Tools Nmap
  27. Hacker Tools 2019
  28. Hack Tools For Games
  29. Hacker Search Tools
  30. Pentest Tools Nmap
  31. Pentest Tools Apk
  32. Hacking Tools For Windows 7
  33. How To Hack
  34. Pentest Tools Website
  35. Hack Tools 2019
  36. Hak5 Tools
  37. Hacking Tools For Windows
  38. Pentest Tools Windows
  39. Android Hack Tools Github
  40. Pentest Tools Windows
  41. Pentest Tools Port Scanner
  42. Hacking Tools 2019
  43. Hacker Tools For Windows
  44. Pentest Tools Review
  45. Hack Tools
  46. Bluetooth Hacking Tools Kali
  47. Hacker Tools Hardware
  48. Github Hacking Tools
  49. Pentest Tools Nmap
  50. Pentest Tools Github
  51. Pentest Tools Github
  52. Pentest Tools Android
  53. Hacking Tools Free Download
  54. Best Pentesting Tools 2018
  55. Hacker Tools Apk Download
  56. Hacker Tool Kit
  57. Pentest Tools Linux
  58. Pentest Tools Open Source
  59. Hack Tools Mac
  60. Hacking Tools Usb
  61. Android Hack Tools Github
  62. Hacks And Tools
  63. What Are Hacking Tools
  64. Pentest Tools Kali Linux
  65. Hacker Tools Mac
  66. Tools For Hacker
  67. Pentest Automation Tools
  68. Tools Used For Hacking
  69. Best Hacking Tools 2019
  70. Hack Tools For Mac
  71. Pentest Tools List
  72. Hacking Tools For Mac
  73. Hacker Tools Software
  74. Hack Tools For Pc
  75. Hacker Tools For Mac
  76. Underground Hacker Sites
  77. Hack App
  78. Hack Tools 2019
  79. Pentest Tools For Mac
  80. Pentest Recon Tools
  81. Hacking Tools Windows
  82. Hackrf Tools
  83. Hacking Tools For Windows Free Download
  84. Install Pentest Tools Ubuntu
  85. Pentest Tools
  86. Hacker Tools Free
  87. Hacking Tools Kit
  88. Pentest Tools Tcp Port Scanner
  89. Computer Hacker
  90. Hacker
  91. Hack And Tools
  92. Hacker Tools Linux
  93. Hacking Tools Download
  94. Hacking Tools Pc
  95. Nsa Hack Tools
  96. Pentest Tools
  97. Black Hat Hacker Tools
  98. Hacker Tools
  99. Pentest Tools Tcp Port Scanner
  100. Hack Tools For Windows
  101. Hack Tools For Windows
  102. Hack Apps
  103. Pentest Tools Port Scanner
  104. Hack App
  105. Hack Tools 2019
  106. Hacking Tools Github
  107. How To Make Hacking Tools
  108. Install Pentest Tools Ubuntu

No comments: