Saturday, June 03, 2023

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()





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

No comments: