Tuesday, May 30, 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. Hacker Techniques Tools And Incident Handling
  2. Termux Hacking Tools 2019
  3. Hacker Search Tools
  4. How To Make Hacking Tools
  5. World No 1 Hacker Software
  6. Hack Tools Mac
  7. Growth Hacker Tools
  8. Android Hack Tools Github
  9. Game Hacking
  10. Usb Pentest Tools
  11. Hacking Tools 2020
  12. New Hack Tools
  13. Tools For Hacker
  14. Hacking Tools Github
  15. Github Hacking Tools
  16. Hak5 Tools
  17. Hack Tools Mac
  18. Easy Hack Tools
  19. Hacks And Tools
  20. Hack Tools Download
  21. Hack Tools Online
  22. Hacker Tools Online
  23. Hacker Security Tools
  24. Wifi Hacker Tools For Windows
  25. Easy Hack Tools
  26. Hacking Tools Kit
  27. Hacking Tools Windows
  28. Hacking Apps
  29. Hacker Search Tools
  30. Hacker Tools 2020
  31. Github Hacking Tools
  32. Termux Hacking Tools 2019
  33. Hacking Tools Mac
  34. Hack Tool Apk
  35. Pentest Tools Github
  36. Hack Tools
  37. Game Hacking
  38. Hacker Search Tools
  39. Hacking Tools For Windows 7
  40. Hacking Tools Software
  41. Hacker Tools Windows
  42. Hack Tool Apk
  43. Hack Tools
  44. Hacker Tools 2020
  45. Hacking Tools For Pc
  46. Hacking Tools And Software
  47. Hacking Tools Hardware
  48. Pentest Tools Online
  49. Pentest Tools Find Subdomains
  50. How To Make Hacking Tools
  51. Pentest Tools
  52. Hacker Tools Linux
  53. Hacker Tools
  54. Pentest Tools For Android
  55. Hack Tools
  56. Hack Tools For Ubuntu
  57. Game Hacking
  58. How To Install Pentest Tools In Ubuntu
  59. Hacker Security Tools
  60. Hack Tool Apk No Root
  61. Pentest Tools Kali Linux
  62. Best Hacking Tools 2019
  63. Nsa Hacker Tools
  64. Pentest Tools Subdomain
  65. Hacker Tools For Windows
  66. Usb Pentest Tools
  67. Pentest Tools Find Subdomains
  68. Hacking Tools Software
  69. Hack Tools 2019
  70. Hack Apps
  71. Pentest Box Tools Download
  72. Hacking Tools
  73. Hack Apps
  74. Termux Hacking Tools 2019
  75. Hack Tools
  76. Hack Tool Apk No Root
  77. Hacking Tools
  78. Hacking Tools 2020
  79. Hacker Tools Hardware
  80. Hacker Hardware Tools
  81. Pentest Tools Url Fuzzer
  82. Hacker Tools Apk Download
  83. Pentest Tools
  84. Pentest Tools Github
  85. Hack Tool Apk
  86. Hacking Tools Software
  87. Hacking Tools Free Download
  88. Game Hacking
  89. Tools For Hacker
  90. Pentest Tools Linux
  91. How To Hack
  92. New Hack Tools
  93. Pentest Tools Free
  94. Hacking Apps
  95. Hacker Tools
  96. Android Hack Tools Github
  97. World No 1 Hacker Software
  98. Nsa Hack Tools Download
  99. Beginner Hacker Tools
  100. How To Hack
  101. Hacker Tools Free Download
  102. Hacks And Tools
  103. Hacking Tools Usb
  104. Hack And Tools
  105. Pentest Tools Download
  106. Hacker Tools Software
  107. Pentest Tools Subdomain
  108. Hack Tool Apk
  109. New Hacker Tools
  110. Pentest Tools Download
  111. Pentest Tools Alternative
  112. Pentest Tools Online
  113. Hacker Tool Kit
  114. Hacking Tools Software
  115. Nsa Hack Tools Download
  116. Pentest Tools For Android
  117. Easy Hack Tools
  118. Usb Pentest Tools
  119. Hacker Tools Windows
  120. Nsa Hack Tools Download
  121. Hack Tools 2019
  122. Pentest Tools Free
  123. Hacking Tools Software
  124. Github Hacking Tools
  125. Nsa Hack Tools
  126. Hacking Tools Windows 10
  127. Hacker Tools 2020
  128. Hacking Tools
  129. Beginner Hacker Tools
  130. Hacking Tools Usb
  131. Hacking Tools 2019
  132. Hack Tools Download
  133. How To Make Hacking Tools

No comments:

Post a Comment