|
|
|
@ -467,50 +467,91 @@ func (mc *MachoContext) ReworkForObjc() {
|
|
|
|
|
ldr x9, [x8, #8]
|
|
|
|
|
br x9
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// TODO: fix to work with offset larger than 0xffff
|
|
|
|
|
shellcode := []uint32{
|
|
|
|
|
0x10000008,
|
|
|
|
|
0, // x9 = (offset end of __DATA) - (offset shellcode)
|
|
|
|
|
0x8B090108,
|
|
|
|
|
0xA8BF23FE,
|
|
|
|
|
0xA8BF0BE3,
|
|
|
|
|
0xA8BF03E1,
|
|
|
|
|
0xF9400109,
|
|
|
|
|
0xD63F0120,
|
|
|
|
|
0xA9C103E1,
|
|
|
|
|
0xA9C10BE3,
|
|
|
|
|
0xA9C123FE,
|
|
|
|
|
0xF9400509,
|
|
|
|
|
0xD61F0120,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shellcode := []uint32{}
|
|
|
|
|
ins_size_byte := 4
|
|
|
|
|
shellcode_offset := text_start - (ins_size_byte * len(shellcode))
|
|
|
|
|
main_offset := int(mc.entryoff)
|
|
|
|
|
var shellcode_offset int
|
|
|
|
|
|
|
|
|
|
if mc.header.cputype == 12{
|
|
|
|
|
shellcode := []uint32{
|
|
|
|
|
0x10000008,
|
|
|
|
|
0, // x9 = (offset end of __DATA) - (offset shellcode)
|
|
|
|
|
0x8B090108,
|
|
|
|
|
0xA8BF23FE,
|
|
|
|
|
0xA8BF0BE3,
|
|
|
|
|
0xA8BF03E1,
|
|
|
|
|
0xF9400109,
|
|
|
|
|
0xD63F0120,
|
|
|
|
|
0xA9C103E1,
|
|
|
|
|
0xA9C10BE3,
|
|
|
|
|
0xA9C123FE,
|
|
|
|
|
0xF9400509,
|
|
|
|
|
0xD61F0120,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shellcode_offset = text_start - (ins_size_byte * len(shellcode))
|
|
|
|
|
|
|
|
|
|
encode_movz := func(v int) uint32 {
|
|
|
|
|
return uint32(uint32(v)<<5 | uint32(0x694)<<21 | uint32(0x09))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// movz_shellcode_offset := encode_movz(shellcode_offset)
|
|
|
|
|
// movz_main_offset := encode_movz(main_offset)
|
|
|
|
|
// movz_data_end_offset := encode_movz(data_end)
|
|
|
|
|
movz_calculate_offset := encode_movz(data_end - shellcode_offset)
|
|
|
|
|
|
|
|
|
|
shellcode[1] = movz_calculate_offset
|
|
|
|
|
// shellcode[10] = movz_data_end_offset
|
|
|
|
|
// shellcode[19] = movz_main_offset
|
|
|
|
|
|
|
|
|
|
fmt.Printf("// shellcode_offset=%x\n", shellcode_offset)
|
|
|
|
|
fmt.Printf("// main_offset=%x\n", main_offset)
|
|
|
|
|
fmt.Printf("// data_end=%x\n", data_end)
|
|
|
|
|
fmt.Printf("// movz_calculate_offset=%x\n", movz_calculate_offset)
|
|
|
|
|
// fmt.Printf("// movz_shellcode_offset=%x\n", movz_shellcode_offset)
|
|
|
|
|
// fmt.Printf("// movz_main_offset=%x\n", movz_main_offset)
|
|
|
|
|
// fmt.Printf("// movz_data_end_offset=%x\n", movz_data_end_offset)
|
|
|
|
|
fmt.Printf("// lc_main_offset=%x\n", lc_main_offset)
|
|
|
|
|
} else {
|
|
|
|
|
// TODO: fix to work with offset larger than 0xffff
|
|
|
|
|
shellcode := []uint32{
|
|
|
|
|
0x00058d4c,
|
|
|
|
|
0x66000000,
|
|
|
|
|
0, // offset
|
|
|
|
|
0x57c8014d,
|
|
|
|
|
0x41515256,
|
|
|
|
|
0x088b4d50,
|
|
|
|
|
0x41d1ff41,
|
|
|
|
|
0x5e5a5958,
|
|
|
|
|
0x488b4d5f,
|
|
|
|
|
0xe1ff4108,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
encode_movz := func(v int) uint32 {
|
|
|
|
|
return uint32(uint32(v)<<5 | uint32(0x694)<<21 | uint32(0x09))
|
|
|
|
|
shellcode_offset = text_start - (ins_size_byte * len(shellcode))
|
|
|
|
|
|
|
|
|
|
encode_movz := func(v int) uint32 {
|
|
|
|
|
return uint32(uint32(v-7)<<16 | uint32(0xb941))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// movz_shellcode_offset := encode_movz(shellcode_offset)
|
|
|
|
|
// movz_main_offset := encode_movz(main_offset)
|
|
|
|
|
// movz_data_end_offset := encode_movz(data_end)
|
|
|
|
|
movz_calculate_offset := encode_movz(data_end - shellcode_offset)
|
|
|
|
|
|
|
|
|
|
shellcode[2] = movz_calculate_offset
|
|
|
|
|
// shellcode[10] = movz_data_end_offset
|
|
|
|
|
// shellcode[19] = movz_main_offset
|
|
|
|
|
|
|
|
|
|
fmt.Printf("// shellcode_offset=%x\n", shellcode_offset)
|
|
|
|
|
fmt.Printf("// main_offset=%x\n", main_offset)
|
|
|
|
|
fmt.Printf("// data_end=%x\n", data_end)
|
|
|
|
|
// fmt.Printf("// movz_calculate_offset=%x\n", movz_calculate_offset)
|
|
|
|
|
// fmt.Printf("// movz_shellcode_offset=%x\n", movz_shellcode_offset)
|
|
|
|
|
// fmt.Printf("// movz_main_offset=%x\n", movz_main_offset)
|
|
|
|
|
// fmt.Printf("// movz_data_end_offset=%x\n", movz_data_end_offset)
|
|
|
|
|
fmt.Printf("// lc_main_offset=%x\n", lc_main_offset)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// movz_shellcode_offset := encode_movz(shellcode_offset)
|
|
|
|
|
// movz_main_offset := encode_movz(main_offset)
|
|
|
|
|
// movz_data_end_offset := encode_movz(data_end)
|
|
|
|
|
movz_calculate_offset := encode_movz(data_end - shellcode_offset)
|
|
|
|
|
|
|
|
|
|
shellcode[1] = movz_calculate_offset
|
|
|
|
|
// shellcode[10] = movz_data_end_offset
|
|
|
|
|
// shellcode[19] = movz_main_offset
|
|
|
|
|
|
|
|
|
|
fmt.Printf("// shellcode_offset=%x\n", shellcode_offset)
|
|
|
|
|
fmt.Printf("// main_offset=%x\n", main_offset)
|
|
|
|
|
fmt.Printf("// data_end=%x\n", data_end)
|
|
|
|
|
fmt.Printf("// movz_calculate_offset=%x\n", movz_calculate_offset)
|
|
|
|
|
// fmt.Printf("// movz_shellcode_offset=%x\n", movz_shellcode_offset)
|
|
|
|
|
// fmt.Printf("// movz_main_offset=%x\n", movz_main_offset)
|
|
|
|
|
// fmt.Printf("// movz_data_end_offset=%x\n", movz_data_end_offset)
|
|
|
|
|
fmt.Printf("// lc_main_offset=%x\n", lc_main_offset)
|
|
|
|
|
|
|
|
|
|
offset := int64(shellcode_offset)
|
|
|
|
|
{
|
|
|
|
|
// fix main to point to our newly created shellcode
|
|
|
|
|