Monday, January 22, 2024

NcN 2015 CTF - theAnswer Writeup


1. Overview

Is an elf32 static and stripped binary, but the good news is that it was compiled with gcc and it will not have shitty runtimes and libs to fingerprint, just the libc ... and libprhrhead
This binary is writed by Ricardo J Rodrigez

When it's executed, it seems that is computing the flag:


But this process never ends .... let's see what strace say:


There is a thread deadlock, maybe the start point can be looking in IDA the xrefs of 0x403a85
Maybe we can think about an encrypted flag that is not decrypting because of the lock.

This can be solved in two ways:

  • static: understanding the cryptosystem and programming our own decryptor
  • dynamic: fixing the the binary and running it (hard: antidebug, futex, rands ...)


At first sight I thought that dynamic approach were quicker, but it turned more complex than the static approach.


2. Static approach

Crawling the xrefs to the futex, it is possible to locate the main:



With libc/libpthread function fingerprinting or a bit of manual work, we have the symbols, here is the main, where 255 threads are created and joined, when the threads end, the xor key is calculated and it calls the print_flag:



The code of the thread is passed to the libc_pthread_create, IDA recognize this area as data but can be selected as code and function.

This is the thread code decompiled, where we can observe two infinite loops for ptrace detection and preload (although is static) this antidebug/antihook are easy to detect at this point.


we have to observe the important thing, is the key random?? well, with the same seed the random sequence will be the same, then the key is "hidden" in the predictability of the random.

If the threads are not executed on the creation order, the key will be wrong because is xored with the th_id which is the identify of current thread.

The print_key function, do the xor between the key and the flag_cyphertext byte by byte.


And here we have the seed and the first bytes of the cypher-text:



With radare we can convert this to a c variable quickly:


And here is the flag cyphertext:


And with some radare magics, we have the c initialized array:


radare, is full featured :)

With a bit of rand() calibration here is the solution ...



The code:
https://github.com/NocONName/CTF_NcN2k15/blob/master/theAnswer/solution.c





3. The Dynamic Approach

First we have to patch the anti-debugs, on beginning of the thread there is two evident anti-debugs (well anti preload hook and anti ptrace debugging) the infinite loop also makes the anti-debug more evident:



There are also a third anti-debug, a bit more silent, if detects a debugger trough the first available descriptor, and here comes the fucking part, don't crash the execution, the execution continues but the seed is modified a bit, then the decryption key will not be ok.





Ok, the seed is incremented by one, this could be a normal program feature, but this is only triggered if the fileno(open("/","r")) > 3 this is a well known anti-debug, that also can be seen from a traced execution.

Ok, just one byte patch,  seed+=1  to  seed+=0,   (add eax, 1   to add eax, 0)

before:


after:



To patch the two infinite loops, just nop the two bytes of each jmp $-0



Ok, but repairing this binary is harder than building a decryptor, we need to fix more things:

  •  The sleep(randInt(1,3)) of the beginning of the thread to execute the threads in the correct order
  •  Modify the pthread_cond_wait to avoid the futex()
  • We also need to calibrate de rand() to get the key (just patch the sleep and add other rand() before the pthread_create loop
Adding the extra rand() can be done with a patch because from gdb is not possible to make a call rand() in this binary.

With this modifications, the binary will print the key by itself. 

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

No comments: