Reference Online article: http://www.freebuf.com/articles/system/6388.html
According to the article, the dynamic injection of code, that is, a running process, without restarting the implementation of the code is not within the original program.
My lab Environment:
Ubuntu 14.10 System
1.Makefile Compilation:
All:
Gcc-g-wall Dynlib.c-fpic-shared-o libdynlib.so
GCC app.c-g-o app-ldynlib-l./
Gcc-wall injection.c-c-O INJECTION.O
Clean:
Rm-f libdynlib.so
2. My experiment records:
GDB) Call Open ("INJECTION.O", 2)
$ = 3
(GDB) Call Mmap (0, 1056, 1|2|4, 1, 3, 0)
$1216774144
(GDB) P &print
$4 = (void (*) ()) 0xb7782575 <print>
(GDB) p/x *0x0804a010
$ $ = 0xb7782575
(GDB) p/x *0x08
Cannot access memory at address 0x8
(GDB) p/x *0x0804a010
$6 = 0xb7782575
(GDB) p/x *0x0804a010
$7 = 0xb7782575
(GDB) Set *0x0804a010 = 0xb7798000 + 0x000034
(GDB) P &system
$8 = (<text variable, no debug info> *) 0xb7612770 <__libc_system>
(GDB) p * (0xb7798000 + 0x000034 + 0x00000014)
$9 =-4
(GDB) Set * (0xb7798000 + 0x000034 + 0x00000014) = 0xb7612770-(0xb7798000 + 0x000034 + 0x00000014)-4
(GDB) P &print
$ = (void (*) ()) 0xb7782575 <print>
(GDB) p * (0xb7798000 + 0x000034 + 00000007)
$11 =-4
(GDB) Set * (0xb7798000 + 0x000034 + 00000007) = 0xb7782575-(0xb7798000 + 0x000034 + 00000007)-4
(GDB) p * (0xb7798000 + 0x000034 + 0x0000000f)
$0
(GDB) Set * (0xb7798000 + 0x000034 + 0x0000000f) = 0xb7798000 + 0x000051
(GDB)
Linux Dynamic Code Injection