åå ã¯ãCè¨èªã¨ã¢ã»ã³ãã©ã§ã·ã§ã«ãèµ·åããããã°ã©ã ãä½ã£ã¦ã¿ã¾ããã
ä»åã¯ãã¢ã»ã³ãã©ã§ä½ã£ãããã°ã©ã ãExploitã³ã¼ãã®é¨åã¨ãªããã㪠Cè¨èªããã·ã§ã«ãèµ·åããããã°ã©ã ãå®è£
ãã¦ã¿ããã¨æãã¾ãã
ããã§ã¯ããã£ã¦ããã¾ãã
åèæç®
ã¯ããã«
ãã»ãã¥ãªãã£ãã®è¨äºä¸è¦§ã§ããè¯ãã£ããåèã«ãã¦ãã ããã
ã»ãã¥ãªãã£ã®è¨äºä¸è¦§
ååã«å¼ãç¶ããä»åã以ä¸ã®ãµã¤ããåèã«ããã¦é ãã¾ãã以ä¸ã¯ x86 ã®è¨äºã§ãã
inaz2.hatenablog.com
以ä¸ã¯ãä¸ã®è¨äºã® ARM32bitçã®è¨äºã§ãã
inaz2.hatenablog.com
ã¾ãã64bitARMï¼Aarch64ï¼ã®ã¢ã»ã³ãã©ã«ã¤ãã¦ã¯ã以ä¸ã®ãµã¤ããåèã«ããã¦é ãã¾ããã
www.mztn.org
ããã§ã¯ããã£ã¦ããã¾ãã
å®è£
ãã¦ãããã°ããã¢ã»ã³ãã©ããã°ã©ã ã確èªãã
ã¾ããååå®è£
ããã¢ã»ã³ãã©ã®ã½ã¼ã¹ã³ã¼ãã§ãã
.global _start
_start:
ldr x8, binsh
mov x2, xzr
mov x0, sp
stp x8, x2, [sp],
mov x1, sp
stp x0, x2, [sp,
mov x8,
svc
binsh:
.asciz "/bin/sh"
次ã¯ãã¢ã»ã³ãã«ã¨éã¢ã»ã³ãã©è¡¨ç¤ºã§ããä»åã¯ãããããã¡ã¤ã«ãåºåãã¦ããã¾ãã
$ gcc -g -Wl,-Map=execve.map -o execve.out -nostdlib execve.s
$ objdump -d execve.out
execve.out: file format elf64-littleaarch64
Disassembly of section .text:
0000000000000244 <_start>:
244: 58000108 ldr x8, 264 <binsh>
248: aa1f03e2 mov x2, xzr
24c: 910003e0 mov x0, sp
250: a8bf0be8 stp x8, x2, [sp],
254: 910003e1 mov x1, sp
258: a9000be0 stp x0, x2, [sp]
25c: d2801ba8 mov x8,
260: d4000001 svc
0000000000000264 <binsh>:
264: 6e69622f .word 0x6e69622f
268: 0068732f .word 0x0068732f
åºåãããããããã¡ã¤ã«ã確èªãã¾ãã以ä¸ã¯ãæç²ã§ãã確ãã«ã244çªå°ããããã¹ãã»ã¯ã·ã§ã³ãå§ã¾ã£ã¦ãã¾ãã0x28ï¼40ï¼byte ã¨ãããã¨ãªã®ã§ãè¨è¿°ããã¢ã»ã³ãã©ã¯å
¨ã¦å
¥ã£ã¦ããããã§ãã
.text 0x0000000000000244 0x28
*(.text.unlikely .text.*_unlikely .text.unlikely.*)
*(.text.exit .text.exit.*)
*(.text.startup .text.startup.*)
*(.text.hot .text.hot.*)
*(SORT_BY_NAME(.text.sorted.*))
*(.text .stub .text.* .gnu.linkonce.t.*)
.text 0x0000000000000244 0x28 /tmp/ccmxWWSK.o
0x0000000000000244 _start
readelf ã§ãELFãããã®å
容ã確èªãã¾ããã¨ã³ããªãã¤ã³ãã¯ã0x244 ã«ãªã£ã¦ãã¾ãã
$ readelf -h execve.out
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Position-Independent Executable file)
Machine: AArch64
Version: 0x1
Entry point address: 0x244
Start of program headers: 64 (bytes into file)
Start of section headers: 66864 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 7
Size of section headers: 64 (bytes)
Number of section headers: 19
Section header string table index: 18
ç¶ãã¦ãããã°ã©ã ãããã§ãã64bitããã°ã©ã ã«ãªã£ã¦ãã¢ãã¬ã¹ãé·ããã¦è¦ã¥ããã§ãï¼ç¬ï¼ã
$ readelf -l execve.out
Elf file type is DYN (Position-Independent Executable file)
Entry point 0x244
There are 7 program headers, starting at offset 64
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flags Align
PHDR 0x0000000000000040 0x0000000000000040 0x0000000000000040 0x0000000000000188 0x0000000000000188 R 0x8
INTERP 0x00000000000001c8 0x00000000000001c8 0x00000000000001c8 0x000000000000001b 0x000000000000001b R 0x1 [Requesting program interpreter: /lib/ld-linux-aarch64.so.1]
LOAD 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x000000000000026c 0x000000000000026c R E 0x10000
LOAD 0x000000000000ff10 0x000000000001ff10 0x000000000001ff10 0x00000000000000f0 0x00000000000000f0 RW 0x10000
DYNAMIC 0x000000000000ff10 0x000000000001ff10 0x000000000001ff10 0x00000000000000d0 0x00000000000000d0 RW 0x8
NOTE 0x00000000000001e4 0x00000000000001e4 0x00000000000001e4 0x0000000000000024 0x0000000000000024 R 0x4
GNU_RELRO 0x000000000000ff10 0x000000000001ff10 0x000000000001ff10 0x00000000000000f0 0x00000000000000f0 R 0x1
Section to Segment mapping:
Segment Sections...
00
01 .interp
02 .interp .note.gnu.build-id .gnu.hash .dynsym .dynstr .text
03 .dynamic .got .got.plt
04 .dynamic
05 .note.gnu.build-id
06 .dynamic .got .got.plt
ã»ã¯ã·ã§ã³ãããã§ãã
$ readelf -S execve.out
There are 19 section headers, starting at offset 0x10530:
Section Headers:
[Nr] Name Type Address Offset Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000 0000000000000000 0000000000000000 0 0 0
[ 1] .interp PROGBITS 00000000000001c8 000001c8 000000000000001b 0000000000000000 A 0 0 1
[ 2] .note.gnu.bu[...] NOTE 00000000000001e4 000001e4 0000000000000024 0000000000000000 A 0 0 4
[ 3] .gnu.hash GNU_HASH 0000000000000208 00000208 000000000000001c 0000000000000000 A 4 0 8
[ 4] .dynsym DYNSYM 0000000000000228 00000228 0000000000000018 0000000000000018 A 5 1 8
[ 5] .dynstr STRTAB 0000000000000240 00000240 0000000000000001 0000000000000000 A 0 0 1
[ 6] .text PROGBITS 0000000000000244 00000244 0000000000000028 0000000000000000 AX 0 0 4
[ 7] .dynamic DYNAMIC 000000000001ff10 0000ff10 00000000000000d0 0000000000000010 WA 5 0 8
[ 8] .got PROGBITS 000000000001ffe0 0000ffe0 0000000000000008 0000000000000008 WA 0 0 8
[ 9] .got.plt PROGBITS 000000000001ffe8 0000ffe8 0000000000000018 0000000000000008 WA 0 0 8
[10] .debug_aranges PROGBITS 0000000000000000 00010000 0000000000000030 0000000000000000 0 0 16
[11] .debug_info PROGBITS 0000000000000000 00010030 0000000000000028 0000000000000000 0 0 1
[12] .debug_abbrev PROGBITS 0000000000000000 00010058 0000000000000014 0000000000000000 0 0 1
[13] .debug_line PROGBITS 0000000000000000 0001006c 000000000000004e 0000000000000000 0 0 1
[14] .debug_str PROGBITS 0000000000000000 000100ba 0000000000000035 0000000000000001 MS 0 0 1
[15] .debug_line_str PROGBITS 0000000000000000 000100ef 0000000000000029 0000000000000001 MS 0 0 1
[16] .symtab SYMTAB 0000000000000000 00010118 00000000000002e8 0000000000000018 17 23 8
[17] .strtab STRTAB 0000000000000000 00010400 0000000000000071 0000000000000000 0 0 1
[18] .shstrtab STRTAB 0000000000000000 00010471 00000000000000bd 0000000000000000 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
L (link order), O (extra OS processing required), G (group), T (TLS),
C (compressed), x (unknown), o (OS specific), E (exclude),
D (mbind), p (processor specific)
ååã¯ããã®ããã°ã©ã ã GDB ã使ã£ã¦åä½ç¢ºèªãã¾ããã
ã¡ã¢ãªã«é
ç½®ã§ããããã«æ©æ¢°èªã§åãè¾¼ã
åèãµã¤ãã§ã¯ããã®æ©æ¢°èªã Linux ã®ã³ãã³ãã使ã£ã¦å å·¥ãã¦ãã¾ããã¡ãã£ã¨é£ããã£ãã®ã§ãããã§ã¯æåã§ä¸¦ã¹ã¾ãï¼ç¬ï¼ã
å
ã»ã©ã®éã¢ã»ã³ãã©ã®ã¯ã4byteãã¤ã10è¡ä¸¦ãã§ãã¾ããããã®4byteã¯ããªãã«ã¨ã³ãã£ã¢ã³ãªã®ã§ããã¤ãåä½ã§ã²ã£ããè¿ãã¾ãããããé£çµãã¾ããã以ä¸ã®ããã«ãªãã¾ããã
main颿°ã®1è¡ã¯ãshellcode ãå®è¡ãã¦ãã¾ããshellcode ã¯é
åã®å
é ã¢ãã¬ã¹ãªã®ã§ãããã颿°ã ã¨æã£ã¦è¦ãã¨ã颿°ã®å
é ã¢ãã¬ã¹ã¨ãè¨ãã¾ãããã®1è¡ã¯é¢æ°ãã¤ã³ã¿ãå®è¡ãã¦ããã³ã¼ãã¨ãããã¨ã«ãªãã¾ãã
颿°ãã¤ã³ã¿ã®ãã£ã¹ãã¯è¦ã«ããã§ãããvoid(*) ã颿°ã®æ»ãå¤ã®åï¼voidï¼ã¨é¢æ°ãã¤ã³ã¿ãã颿°ã«ããããã®ã¢ã¹ã¿ãªã¹ã¯ã§ããæ¬¡ã® () ã¯å¼æ°ã§ããã¤ã¾ãã弿°ç¡ããæ»ãå¤ç¡ãã®é¢æ°ã¸ã®ãã£ã¹ãã§ããå
é ã®ã¢ã¹ã¿ãªã¹ã¯ã¯ããªãä»ãã¦ãã®ãåããã¾ããããã®ã¢ã¹ã¿ãªã¹ã¯ã¯ç¡ãã¦ãã³ã³ãã¤ã«ãéãã¾ãããå®è¡ã«ã¤ãã¦ãå¤åã¯ããã¾ããããã¶ãããããªãããããªããã¨æã£ã¦ãã¾ãã
char shellcode[] = "\x08\x01\x00\x58\xe2\x03\x1f\xaa\xe0\x03\x00\x91\xe8\x0b\xbf\xa8\xe1\x03\x00\x91\xe0\x0b\x00\xa9\xa8\x1b\x80\xd2\x01\x00\x00\xd4\x2f\x62\x69\x6e\x2f\x73\x68\x00";
int main()
{
( *(void (*)())shellcode )();
}
ãããã³ã³ãã¤ã«ãã¦ãå®è¡ãã¦ã¿ã¾ããSegmentation Fault ãåºã¾ããã
$ gcc -g -Wl,-Map=execve_str.map -static -o execve_str.out execve_str.c
$ ./execve_str.out
Segmentation fault
æ©æ¢°èªã§åãè¾¼ãã ããã°ã©ã ãGDBã§ç¢ºèªãã
GDB ã§ç¢ºèªãã¾ããé·ãã®ã§ãããã¤ãçç¥ãã¾ãã0x490000 ã« 0x50 ãå ããã¢ãã¬ã¹ã«åå²ããããã§ãã
$ gdb execve_str.out
Reading symbols from execve_str.out...
(gdb) start
Temporary breakpoint 1 at 0x4006dc: file execve_str.c, line 7.
Starting program: /home/daisuke/svn/experiment/c/execve_str.out
Temporary breakpoint 1, main () at execve_str.c:7
7 (*(void (*)())shellcode)();
(gdb) disassemble
Dump of assembler code for function main:
0x00000000004006d4 <+0>: stp x29, x30, [sp, #-16]!
0x00000000004006d8 <+4>: mov x29, sp
=> 0x00000000004006dc <+8>: adrp x0, 0x490000
0x00000000004006e0 <+12>: add x0, x0,
0x00000000004006e4 <+16>: blr x0
0x00000000004006e8 <+20>: mov w0,
0x00000000004006ec <+24>: ldp x29, x30, [sp],
0x00000000004006f0 <+28>: ret
End of assembler dump.
åå²ããå¾ã§ããå®è£
ããéãã®ã³ã¼ãã並ãã§ãã¾ããã©ãã§è½ã¡ãã®ãã¨è¨ãã¨ãæåã® ldrå½ä»¤ãå®è¡ããã¨ããã§è½ã¡ã¾ããä¸ã¯ 40ä¸çªå°ä»è¿ã§ããããããããã¯ã49ä¸çªå°ã¨ãªã£ã¦ãã¾ãã
(gdb) disassemble
Dump of assembler code for function shellcode:
=> 0x0000000000490050 <+0>: ldr x8, 0x490070 <shellcode+32>
0x0000000000490054 <+4>: mov x2, xzr
0x0000000000490058 <+8>: mov x0, sp
0x000000000049005c <+12>: stp x8, x2, [sp],
0x0000000000490060 <+16>: mov x1, sp
0x0000000000490064 <+20>: stp x0, x2, [sp]
0x0000000000490068 <+24>: mov x8,
0x000000000049006c <+28>: svc
0x0000000000490070 <+32>: rsubhn2 v15.8h, v17.4s, v9.4s
0x0000000000490074 <+36>: .inst 0x0068732f ; undefined
0x0000000000490078 <+40>: udf
End of assembler dump.
ããããã¡ã¤ã«ãè¦ã¦ã¿ã¾ããã¾ããåå²åã® 40ä¸çªå°ä»è¿ã§ããæ®éã® textã»ã¯ã·ã§ã³ã§ãã
*(.text.startup .text.startup.*)
*fill* 0x0000000000400524 0xc 1f2003d5
.text.startup 0x0000000000400530 0x24 /usr/lib/gcc/aarch64-linux-gnu/12/libgcc.a(lse-init.o)
*(.text.hot .text.hot.*)
*(SORT_BY_NAME(.text.sorted.*))
*(.text .stub .text.* .gnu.linkonce.t.*)
*fill* 0x0000000000400554 0x2c 1f2003d5
.text 0x0000000000400580 0x44 /usr/lib/gcc/aarch64-linux-gnu/12/../../../aarch64-linux-gnu/crt1.o
0x0000000000400580 _start
0x00000000004005c0 _dl_relocate_static_pie
.text 0x00000000004005c4 0x14 /usr/lib/gcc/aarch64-linux-gnu/12/../../../aarch64-linux-gnu/crti.o
*fill* 0x00000000004005d8 0x8 1f2003d5
.text 0x00000000004005e0 0xf4 /usr/lib/gcc/aarch64-linux-gnu/12/crtbeginT.o
.text 0x00000000004006d4 0x20 /tmp/ccG8mGtX.o
0x00000000004006d4 main
*fill* 0x00000000004006f4 0xc 1f2003d5
.text 0x0000000000400700 0x42c /usr/lib/gcc/aarch64-linux-gnu/12/../../../aarch64-linux-gnu/libc.a(libc-start.o)
0x00000000004007e4 __libc_start_main_impl
0x00000000004007e4 __libc_start_main
*fill* 0x0000000000400b2c 0x4 1f2003d5
ç¶ãã¦ãåå²å¾ã®æ©æ¢°èªãåãè¾¼ãã æ¹ãè¦ã¦ã¿ã¾ããdataã»ã¯ã·ã§ã³ã«ãªã£ã¦ãã¾ãããããã¯å®è¡å¯è½ãªã¨ããã§ã¯ãªããã ã¨æãã¾ãã
.data 0x0000000000490040 0x1948
[!provide] PROVIDE (__data_start = .)
*(.data .data.* .gnu.linkonce.d.*)
.data 0x0000000000490040 0x4 /usr/lib/gcc/aarch64-linux-gnu/12/../../../aarch64-linux-gnu/crt1.o
0x0000000000490040 data_start
0x0000000000490040 __data_start
.data 0x0000000000490044 0x0 /usr/lib/gcc/aarch64-linux-gnu/12/../../../aarch64-linux-gnu/crti.o
*fill* 0x0000000000490044 0x4
.data 0x0000000000490048 0x8 /usr/lib/gcc/aarch64-linux-gnu/12/crtbeginT.o
0x0000000000490048 __dso_handle
.data 0x0000000000490050 0x29 /tmp/ccG8mGtX.o
0x0000000000490050 shellcode
ã»ã¯ã·ã§ã³ããããè¦ã¦ã¿ã¾ããtextã»ã¯ã·ã§ã³ã¯ X ãä»ãã¦ãã®ã§ãå®è¡å¯è½ãªé åã§ãã䏿¹ãdataã»ã¯ã·ã§ã³ã¯ X ãä»ãã¦ãã¾ããããããåå ã ã¨æããã¾ãã
$ readelf -S execve_str.out
There are 35 section headers, starting at offset 0xab428:
Section Headers:
[Nr] Name Type Address Offset Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000 0000000000000000 0000000000000000 0 0 0
[ 1] .note.gnu.bu[...] NOTE 0000000000400190 00000190 0000000000000024 0000000000000000 A 0 0 4
[ 2] .note.ABI-tag NOTE 00000000004001b4 000001b4 0000000000000020 0000000000000000 A 0 0 4
[ 3] .rela.plt RELA 00000000004001d8 000001d8 00000000000000a8 0000000000000018 AI 32 18 8
[ 4] .init PROGBITS 0000000000400280 00000280 0000000000000018 0000000000000000 AX 0 0 4
[ 5] .plt PROGBITS 00000000004002a0 000002a0 0000000000000070 0000000000000000 AX 0 0 16
[ 6] .text PROGBITS 0000000000400340 00000340 0000000000056394 0000000000000000 AX 0 0 64
[ 7] __libc_freeres_fn PROGBITS 00000000004566e0 000566e0 0000000000000b04 0000000000000000 AX 0 0 16
[ 8] .fini PROGBITS 00000000004571e4 000571e4 0000000000000014 0000000000000000 AX 0 0 4
[ 9] .rodata PROGBITS 0000000000457200 00057200 000000000001a320 0000000000000000 A 0 0 16
[10] .eh_frame PROGBITS 0000000000471520 00071520 000000000000ba84 0000000000000000 A 0 0 8
[11] .gcc_except_table PROGBITS 000000000047cfa4 0007cfa4 00000000000000dc 0000000000000000 A 0 0 1
[12] .tdata PROGBITS 000000000048c710 0008c710 0000000000000018 0000000000000000 WAT 0 0 8
[13] .tbss NOBITS 000000000048c728 0008c728 0000000000000048 0000000000000000 WAT 0 0 8
[14] .init_array INIT_ARRAY 000000000048c728 0008c728 0000000000000010 0000000000000008 WA 0 0 8
[15] .fini_array FINI_ARRAY 000000000048c738 0008c738 0000000000000008 0000000000000008 WA 0 0 8
[16] .data.rel.ro PROGBITS 000000000048c740 0008c740 0000000000003498 0000000000000000 WA 0 0 16
[17] .got PROGBITS 000000000048fbd8 0008fbd8 0000000000000408 0000000000000008 WA 0 0 8
[18] .got.plt PROGBITS 000000000048ffe8 0008ffe8 0000000000000050 0000000000000008 WA 0 0 8
[19] .data PROGBITS 0000000000490040 00090040 0000000000001948 0000000000000000 WA 0 0 16
[20] __libc_subfreeres PROGBITS 0000000000491988 00091988 0000000000000048 0000000000000000 WAR 0 0 8
[21] __libc_IO_vtables PROGBITS 00000000004919d0 000919d0 0000000000000690 0000000000000000 WA 0 0 8
[22] __libc_atexit PROGBITS 0000000000492060 00092060 0000000000000008 0000000000000000 WAR 0 0 8
[23] .bss NOBITS 0000000000492070 00092068 00000000000054f8 0000000000000000 WA 0 0 16
[24] __libc_freer[...] NOBITS 0000000000497568 00092068 0000000000000020 0000000000000000 WA 0 0 8
[25] .comment PROGBITS 0000000000000000 00092068 000000000000001f 0000000000000001 MS 0 0 1
[26] .debug_aranges PROGBITS 0000000000000000 00092087 0000000000000030 0000000000000000 0 0 1
[27] .debug_info PROGBITS 0000000000000000 000920b7 0000000000000088 0000000000000000 0 0 1
[28] .debug_abbrev PROGBITS 0000000000000000 0009213f 0000000000000068 0000000000000000 0 0 1
[29] .debug_line PROGBITS 0000000000000000 000921a7 000000000000004f 0000000000000000 0 0 1
[30] .debug_str PROGBITS 0000000000000000 000921f6 0000000000000070 0000000000000001 MS 0 0 1
[31] .debug_line_str PROGBITS 0000000000000000 00092266 000000000000002d 0000000000000001 MS 0 0 1
[32] .symtab SYMTAB 0000000000000000 00092298 0000000000012318 0000000000000018 33 1953 8
[33] .strtab STRTAB 0000000000000000 000a45b0 0000000000006cfe 0000000000000000 0 0 1
[34] .shstrtab STRTAB 0000000000000000 000ab2ae 0000000000000178 0000000000000000 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
L (link order), O (extra OS processing required), G (group), T (TLS),
C (compressed), x (unknown), o (OS specific), E (exclude),
R (retain), D (mbind), p (processor specific)
æ©æ¢°èªãåãè¾¼ãã ããã°ã©ã ãå®è¡ã§ããããã«å¯¾çãã
åèãµã¤ãã§ã¯ãã¹ã¿ãã¯ã«é
ç½®ãããã®ã§ãã¹ã¿ãã¯é åãå®è¡å¯è½ã«ãã対çãè¡ã£ã¦ãã¾ããããã¡ãã¯ãdataã»ã¯ã·ã§ã³ã«é
ç½®ããã¦ããã®ã§ãå¥ã®å¯¾çãå¿
è¦ã§ãã
ãããã調ã¹ãã¨ãããCè¨èªã® mprotect ã¨ãã颿°ãããããã§ããã¡ã¢ãªã®ã¢ãã¬ã¹ã¨ãµã¤ãºãæå®ãã¦ãRead/Write/Exec ã®å±æ§ã夿´ãããã¨ãåºæ¥ãããã§ãããããã¿ã¤ãã¯ãint mprotect(void *addr, size_t len, int prot); ã§ãã
注æç¹ã¨ãã¦ã¯ã第1弿°ã® addr ã¯ããã¼ã¸å¢çã§ãªããã°ãªããªãã¨ãããã¨ã§ãã
以ä¸ã®ããã«ãªãã¾ããããã¼ã¸å¢çã¨ããããããã¼ã¸ãµã¤ãºã表示ãã¦ãã¾ãããã®å¾ã
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
char shellcode[] = "\x08\x01\x00\x58\xe2\x03\x1f\xaa\xe0\x03\x00\x91\xe8\x0b\xbf\xa8\xe1\x03\x00\x91\xe0\x0b\x00\xa9\xa8\x1b\x80\xd2\x01\x00\x00\xd4\x2f\x62\x69\x6e\x2f\x73\x68\x00";
int main()
{
long page_size = sysconf( _SC_PAGESIZE );
printf( "page_size=0x%x\n", page_size );
if( mprotect((void *)0x490000, 0x1940, PROT_READ | PROT_WRITE | PROT_EXEC) == -1 ){
perror( "mprotect failed" );
return 1;
}
( (void (*)())shellcode )();
}
ã³ã³ãã¤ã«ãã¦ãå®è¡ãã¦ã¿ã¾ããã·ã§ã«ã®èµ·åã«æåãã¾ããï¼
$ gcc -g -Wl,-Map=execve_str_fixed.map -static -o execve_str_fixed.out execve_str_fixed.c
$ ./execve_str_fixed.out
page_size=0x1000
$ ls
execve.map execve_chatgpt2.map execve_objdump.s execve_x86.txt
execve.out execve_chatgpt2.out execve_str.c k_and_r_org.c
execve.s execve_chatgpt2.s execve_str.map main_execve.s
execve_c.c execve_chatgpt2_objdump.s execve_str.out memorymap.c
execve_c.out execve_chatgpt_fixed.map execve_str_fixed.c memorymap.out
execve_chatgpt.map execve_chatgpt_fixed.out execve_str_fixed.map
execve_chatgpt.out execve_chatgpt_fixed.s execve_str_fixed.out
execve_chatgpt.s execve_chatgpt_objdump.s execve_str_fixed_objdump.s
$ exit
ä»åã¯ããã¾ã§ã§ãã
ãããã«
ä»åã¯ãåèãµã¤ããè¦ãªãããexecve ã使ã£ãã·ã§ã«ãèµ·åããããã°ã©ã ããæ©æ¢°èªãåãè¾¼ãã ããã°ã©ã ã«å¤æ´ãã¦åä½ã確èªãã¾ããã
çµæ§æéããããã¾ããããä½ã¬ã¤ã¤ã®ããã°ã©ã ã«ã¤ãã¦ãããããå¨è¾ºã®ç¥èãæ·±ã¾ãã¾ããã
æå¾ã«ãªãã¾ããããã¨ã³ã¸ãã¢ã°ã«ã¼ãã®ã©ã³ãã³ã°ã«åå ä¸ã§ãã
æ°æ¥½ã«ãããã¨ãããããé¡ããããã¾ãð
ä»åã¯ä»¥ä¸ã§ãï¼
æå¾ã¾ã§ãèªã¿ããã ãããããã¨ããããã¾ããã