Sunday, January 28, 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()





Read more


  1. Hacker Tools For Windows
  2. Pentest Tools For Mac
  3. Hack App
  4. Hack Tools Pc
  5. Hak5 Tools
  6. Hacking Tools For Kali Linux
  7. Hack Tools
  8. Pentest Box Tools Download
  9. Pentest Tools Android
  10. Hacker Tools Software
  11. Pentest Tools Review
  12. Pentest Tools Port Scanner
  13. Hacker Tools For Pc
  14. Hacking Tools For Windows 7
  15. Underground Hacker Sites
  16. Hack App
  17. Hacker Tools Software
  18. Pentest Tools For Mac
  19. Pentest Tools Kali Linux
  20. Hacker Tools List
  21. Hacking Tools Name
  22. Pentest Tools Free
  23. Pentest Tools For Ubuntu
  24. Hack And Tools
  25. Pentest Tools Free
  26. Pentest Tools Kali Linux
  27. Hack Tools Mac
  28. Hacker Tools
  29. Pentest Tools Linux
  30. Tools Used For Hacking
  31. Hacking Tools Github
  32. Hacker Search Tools
  33. Hacking Tools Name
  34. Tools For Hacker
  35. Hack Apps
  36. Pentest Tools Website
  37. What Is Hacking Tools
  38. Hack Tools Github
  39. Hacking Tools For Windows 7
  40. Hak5 Tools
  41. Hacking Tools Online
  42. Pentest Reporting Tools
  43. Hacking Tools For Windows Free Download
  44. Computer Hacker
  45. Pentest Tools Download
  46. Pentest Tools For Windows
  47. Pentest Tools Windows
  48. Pentest Tools Open Source
  49. Hacking Tools Free Download
  50. Pentest Box Tools Download
  51. Hacking Tools 2020
  52. What Are Hacking Tools
  53. Pentest Tools Alternative
  54. Pentest Tools For Android
  55. Growth Hacker Tools
  56. Hacker Tools For Pc
  57. Hacker Tools 2020
  58. Hack App
  59. Hacker Tools Github
  60. Usb Pentest Tools
  61. Hacker Security Tools
  62. Pentest Reporting Tools
  63. Hacking Tools For Kali Linux
  64. Hack App
  65. Hacking Tools Kit
  66. Hack And Tools
  67. Hacking Tools For Kali Linux
  68. Hacker Tools Apk
  69. Hacker
  70. Hack Tools For Windows
  71. Hacker Tools For Ios
  72. Hack Tools For Windows
  73. Pentest Reporting Tools
  74. Hacker Tools For Pc
  75. What Are Hacking Tools
  76. How To Install Pentest Tools In Ubuntu
  77. Pentest Tools For Android
  78. Pentest Tools Review
  79. Pentest Tools For Android
  80. Hack Tools Github
  81. Hacker Tools
  82. Pentest Tools Online
  83. Hack And Tools
  84. Hackers Toolbox
  85. Hackers Toolbox
  86. Hacking Tools Windows 10
  87. Hacks And Tools
  88. Hack Tools For Games
  89. Pentest Reporting Tools
  90. Hacker Tools For Mac
  91. Hacker Tools Github
  92. Hacker Tools Free Download
  93. Hacking Tools Github
  94. Hacker Tools 2019
  95. World No 1 Hacker Software
  96. Underground Hacker Sites
  97. Tools For Hacker
  98. Hack Tools For Pc
  99. Pentest Tools Open Source
  100. Pentest Tools Find Subdomains
  101. Pentest Box Tools Download
  102. Hacking Tools Windows 10
  103. Hack Tools Download
  104. Bluetooth Hacking Tools Kali
  105. Hacker Tools Online
  106. Hacking Tools Name
  107. Pentest Tools For Ubuntu

No comments: