Saturday, January 20, 2024

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 articles


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

No comments:

Post a Comment