Friday, January 26, 2024

Defcon 2015 Coding Skillz 1 Writeup

Just connecting to the service, a 64bit cpu registers dump is received, and so does several binary code as you can see:



The registers represent an initial cpu state, and we have to reply with the registers result of the binary code execution. This must be automated becouse of the 10 seconds server socket timeout.

The exploit is quite simple, we have to set the cpu registers to this values, execute the code and get resulting registers.

In python we created two structures for the initial state and the ending state.

cpuRegs = {'rax':'','rbx':'','rcx':'','rdx':'','rsi':'','rdi':'','r8':'','r9':'','r10':'','r11':'','r12':'','r13':'','r14':'','r15':''}
finalRegs = {'rax':'','rbx':'','rcx':'','rdx':'','rsi':'','rdi':'','r8':'','r9':'','r10':'','r11':'','r12':'','r13':'','r14':'','r15':''}

We inject at the beginning several movs for setting the initial state:

for r in cpuRegs.keys():
    code.append('mov %s, %s' % (r, cpuRegs[r]))

The 64bit compilation of the movs and the binary code, but changing the last ret instruction by a sigtrap "int 3"
We compile with nasm in this way:

os.popen('nasm -f elf64 code.asm')
os.popen('ld -o code code.o ')

And use GDB to execute the code until the sigtrap, and then get the registers

fd = os.popen("gdb code -ex 'r' -ex 'i r' -ex 'quit'",'r')
for l in fd.readlines():
    for x in finalRegs.keys():
           ...

We just parse the registers and send the to the server in the same format, and got the key.


The code:

from libcookie import *
from asm import *
import os
import sys

host = 'catwestern_631d7907670909fc4df2defc13f2057c.quals.shallweplayaga.me'
port = 9999

cpuRegs = {'rax':'','rbx':'','rcx':'','rdx':'','rsi':'','rdi':'','r8':'','r9':'','r10':'','r11':'','r12':'','r13':'','r14':'','r15':''}
finalRegs = {'rax':'','rbx':'','rcx':'','rdx':'','rsi':'','rdi':'','r8':'','r9':'','r10':'','r11':'','r12':'','r13':'','r14':'','r15':''}
fregs = 15

s = Sock(TCP)
s.timeout = 999
s.connect(host,port)

data = s.readUntil('bytes:')


#data = s.read(sz)
#data = s.readAll()

sz = 0

for r in data.split('\n'):
    for rk in cpuRegs.keys():
        if r.startswith(rk):
            cpuRegs[rk] = r.split('=')[1]

    if 'bytes' in r:
        sz = int(r.split(' ')[3])



binary = data[-sz:]
code = []

print '[',binary,']'
print 'given size:',sz,'bin size:',len(binary)        
print cpuRegs


for r in cpuRegs.keys():
    code.append('mov %s, %s' % (r, cpuRegs[r]))


#print code

fd = open('code.asm','w')
fd.write('\n'.join(code)+'\n')
fd.close()
Capstone().dump('x86','64',binary,'code.asm')

print 'Compilando ...'
os.popen('nasm -f elf64 code.asm')
os.popen('ld -o code code.o ')

print 'Ejecutando ...'
fd = os.popen("gdb code -ex 'r' -ex 'i r' -ex 'quit'",'r')
for l in fd.readlines():
    for x in finalRegs.keys():
        if x in l:
            l = l.replace('\t',' ')
            try:
                i = 12
                spl = l.split(' ')
                if spl[i] == '':
                    i+=1
                print 'reg: ',x
                finalRegs[x] = l.split(' ')[i].split('\t')[0]
            except:
                print 'err: '+l
            fregs -= 1
            if fregs == 0:
                #print 'sending regs ...'
                #print finalRegs
                
                buff = []
                for k in finalRegs.keys():
                    buff.append('%s=%s' % (k,finalRegs[k]))


                print '\n'.join(buff)+'\n'

                print s.readAll()
                s.write('\n'.join(buff)+'\n\n\n')
                print 'waiting flag ....'
                print s.readAll()

                print '----- yeah? -----'
                s.close()
                



fd.close()
s.close()





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

No comments:

Post a Comment