Monday, August 24, 2020

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

No comments:

Post a Comment