onsdag 24. januar 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()





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

Ingen kommentarer:

Legg inn en kommentar