Defcon 2015 Coding Skillz 1 Writeup

quinta-feira, 1 de junho de 2023

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

0 comentários: