Thursday, June 1, 2023

Introduction To Reversing Golang Binaries


Golang binaries are a bit hard to analyze but there are some tricks to locate the things and view what is doing the code.






Is possible to list all the go files compiled in the binary even in an striped binaries, in this case we have only one file gohello.go this is a good clue to guess what is doing the program.


On stripped binaries the runtime functions are not resolved so is more difficult to locate the user algorithms:


If we start from the entry point, we will found this mess:

The golang string initialization are encoded and is not displayed on the strings window.


How to locate main?  if its not stripped just bp on [package name].main for example bp main.main, (you can locate the package-name searching strings with ".main")


And here is our main.main:


The code is:

So in a stripped binary we cant find the string "hello world" neither the initialization 0x1337 nor the comparator 0x1337, all this is obfuscated.

The initialization sequence is:


The procedure for locating main.main in stripped binaries is:
1. Click on the entry point and locate the runtime.mainPC pointer:



2. click on runtime.main function (LAB_0042B030):


3. locate the main.main call after the zero ifs:



4. click on it and here is the main:




The runtime is not obvious for example the fmt.Scanf() call perform several internal calls until reach the syscall, and in a stripped binary there are no function names.



In order to identify the functions one option is compile another binary with symbols and make function fingerprinting.

In Ghidra we have the script golang_renamer.py which is very useful:


After applying this plugin the main looks like more clear:




This script is an example of function fingerprinting, in this case all the opcodes are included on the crc hashing:
# This script fingerprints the functions
#@author: sha0coder
#@category fingerprinting

print "Fingerprinting..."

import zlib


# loop through program functions
function = getFirstFunction()
while function is not None:
name = str(function.getName())
entry = function.getEntryPoint()
body = function.getBody()
addresses = body.getAddresses(True)

if not addresses.hasNext():
# empty function
continue

ins = getInstructionAt(body.getMinAddress())
opcodes = ''
while ins and ins.getMinAddress() <= body.getMaxAddress():
for b in ins.bytes:
opcodes += chr(b & 0xff)
ins = getInstructionAfter(ins)
crchash = zlib.crc32(opcodes) & 0xffffffff

print name, hex(crchash)


function = getFunctionAfter(function)





More articles
  1. Hack Tools Pc
  2. Hacking Tools Kit
  3. Hacker Tools Windows
  4. Hacking Tools Name
  5. Computer Hacker
  6. Hacking App
  7. Pentest Tools List
  8. Pentest Tools Website Vulnerability
  9. Hacker Tools 2019
  10. Hacker Tools Software
  11. Game Hacking
  12. Hacking Tools Free Download
  13. Hacking Tools For Windows 7
  14. Hacker Tools For Windows
  15. Hack Tools 2019
  16. Hacking Tools Free Download
  17. Pentest Tools Windows
  18. Hacker Tools Linux
  19. Physical Pentest Tools
  20. What Are Hacking Tools
  21. What Are Hacking Tools
  22. Usb Pentest Tools
  23. Pentest Box Tools Download
  24. Physical Pentest Tools
  25. Hack Tools Download
  26. Pentest Tools Linux
  27. Pentest Tools Windows
  28. Pentest Tools For Ubuntu
  29. Hacking Tools Windows
  30. Beginner Hacker Tools
  31. Hacker Tools 2019
  32. Easy Hack Tools
  33. Hacker Tool Kit
  34. Computer Hacker
  35. Pentest Tools Free
  36. Hack Tools
  37. Pentest Automation Tools
  38. Physical Pentest Tools
  39. Hacking Tools Pc
  40. Hacker Tools Online
  41. Hacking Tools For Pc
  42. Pentest Tools Tcp Port Scanner
  43. Nsa Hacker Tools
  44. Hacker Tools Online
  45. Hacking Tools For Games
  46. Hacking Tools Github
  47. Hacking Tools For Pc
  48. Bluetooth Hacking Tools Kali
  49. Pentest Automation Tools
  50. Nsa Hacker Tools
  51. Hacker Tools Apk Download
  52. Hacker Tool Kit
  53. How To Hack
  54. Hacker Tools 2019
  55. How To Install Pentest Tools In Ubuntu
  56. New Hack Tools
  57. Hacker Tools For Pc
  58. Hack Tools Pc
  59. Hacker Techniques Tools And Incident Handling
  60. Hack Tools

No comments:

Post a Comment