Friday, 2 June 2023

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.

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

0 comments:

Post a Comment