Thursday, January 18, 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. Hacking Tools For Kali Linux
  2. Pentest Tools Nmap
  3. Usb Pentest Tools
  4. Hacker Tools Apk Download
  5. Hack Tools For Pc
  6. New Hack Tools
  7. Pentest Tools Bluekeep
  8. Hack Tools Github
  9. Hacking Tools Pc
  10. Hack Tools Mac
  11. Usb Pentest Tools
  12. Hack Tools Online
  13. Game Hacking
  14. Hacker Tool Kit
  15. Pentest Tools For Mac
  16. Pentest Tools Online
  17. Hack Rom Tools
  18. Pentest Tools Website
  19. Hacker Tools 2020
  20. Free Pentest Tools For Windows
  21. Pentest Tools Kali Linux
  22. Hack Website Online Tool
  23. Hacker Tools Free Download
  24. Pentest Tools Website Vulnerability
  25. Hack Tools For Windows
  26. Hacking Tools Pc
  27. Pentest Tools Bluekeep
  28. Hacker Tools Software
  29. Best Pentesting Tools 2018
  30. Pentest Tools
  31. Pentest Tools For Ubuntu
  32. Bluetooth Hacking Tools Kali
  33. Hack Tool Apk No Root
  34. Pentest Tools For Ubuntu
  35. Hack Apps
  36. Hack Tools Online
  37. Hacker Tools For Mac
  38. Hacking Tools For Games
  39. How To Hack
  40. New Hack Tools
  41. New Hacker Tools
  42. Hacker
  43. Hack Website Online Tool
  44. Pentest Tools Website
  45. Top Pentest Tools
  46. Hacking Tools
  47. Hacking App
  48. Pentest Tools For Windows
  49. Pentest Tools Subdomain
  50. Tools 4 Hack
  51. Nsa Hack Tools Download
  52. Hacker
  53. Kik Hack Tools
  54. Hacking Tools Github
  55. Pentest Tools Website
  56. Pentest Tools For Ubuntu
  57. Hack Tools For Mac
  58. New Hacker Tools
  59. Hack Website Online Tool
  60. Hacking Tools Usb
  61. Hacking Tools Download
  62. Hacking Tools For Kali Linux
  63. Hacking Tools For Windows
  64. Hak5 Tools
  65. Pentest Tools Subdomain
  66. Hack Tool Apk No Root
  67. Easy Hack Tools
  68. Nsa Hack Tools Download
  69. Hack Tools Pc
  70. Hacker Tools Mac
  71. Hacker Tools For Ios
  72. Hack App
  73. Wifi Hacker Tools For Windows
  74. Pentest Tools Port Scanner
  75. Hacker Tools Online
  76. Hacker Tool Kit
  77. How To Install Pentest Tools In Ubuntu
  78. Hacker Tools Hardware
  79. Hack Tools Pc
  80. Hacking Tools
  81. Game Hacking
  82. Hack Tools Github
  83. Hacking Tools Free Download
  84. Hacking Tools Usb
  85. Hack And Tools
  86. Easy Hack Tools
  87. Hack Tool Apk
  88. Best Hacking Tools 2020
  89. Hacking Tools Name
  90. Pentest Tools Free
  91. Hack Rom Tools
  92. Tools For Hacker
  93. Hacker Hardware Tools
  94. Hack Tools Pc
  95. Growth Hacker Tools
  96. Hacking Tools Pc
  97. Pentest Tools Framework
  98. Hacker Tools Free Download
  99. Tools For Hacker
  100. Hacker Tools Free
  101. Hacking Tools Windows
  102. Hacking Tools For Pc
  103. World No 1 Hacker Software
  104. Hack Tools Mac
  105. Hacker Tools Free Download
  106. What Is Hacking Tools
  107. Hack Tools Github
  108. Hacking Tools Hardware
  109. Best Hacking Tools 2019
  110. Pentest Tools Online
  111. Hacker Tools For Windows
  112. Usb Pentest Tools
  113. Pentest Recon Tools
  114. Hack Tools Online
  115. Pentest Tools Review
  116. Hacker Tools Apk Download

No comments: