hp ux에서 시스템 콜 가로채기 질문입니다.
글쓴이: iceru / 작성시간: 월, 2008/02/04 - 3:29오후
HP UX 11i v2 (11.23) 에서 시스템콜을 가로채는 모듈을 만들고 있습니다.
후킹해서.. 메세지만 출력하는 단순한 프로그램인데 워낙 이쪽 자료가 희귀하다보니 혼자 삽질하는게
너무 어렵네요.
아래는 코드 내용입니다.
// sysent structures, function pointer for hooking
extern struct sysent sysent[];
static int (* old_mkdir)(char *, mode_t);
// dynamic loading function
static int
mymodule_load(void *arg) {
printf("mymodule_load running...\n");
old_mkdir = (int (*)())(sysent[SYS_MKDIR].sy_call);
sysent[SYS_MKDIR].sy_call = (void (*)())new_mkdir;
printf("mymodule_load exiting...\n");
return 0;
}
// dynamic unloading function
static int
mymodule_unload(void *arg) {
printf("mymodule_unload running...\n");
sysent[SYS_MKDIR].sy_call = (void (*)())old_mkdir;
printf("mymodule_unload exiting...\n");
return 0;
}
// hooking function
int
new_mkdir(char *path, mode_t mode) {
printf("new_mkdir called!!!!!!\n");
return old_mkdir(path, mode);
}컴파일하면 출력되는 에러가...
Error 249: "mymodule.c", line 57 # Subscript operator must have pointer to object and integral operands; 'sysent [][int]' was found.
old_mkdir = (int (*)())(sysent[SYS_MKDIR].sy_call);
^^^^^^^^^
Error 249: "mymodule.c", line 58 # Subscript operator must have pointer to object and integral operands; 'sysent [][int]' was found.
sysent[SYS_MKDIR].sy_call = (void (*)())new_mkdir;
^^^^^^^^^
Error 249: "mymodule.c", line 67 # Subscript operator must have pointer to object and integral operands; 'sysent [][int]' was found.
sysent[SYS_MKDIR].sy_call = (void (*)())old_mkdir;
^^^^^^^^^이렇네요..
뭔가 sysent에 접근하는 방법이 잘못된 것 같은데..
많은 분들의 조언 부탁드립니다. ㅠ_ㅠ/
Forums:


HP/UX 에도 LD_PRELOAD 나
HP/UX 에도 LD_PRELOAD 나 그 비스무리한게 있을 듯 싶은데요 ?
google 이 이런 답을 내놓는군요.
LD_PRELOAD 를 사용한 라이브러리 수준의 함수 가로채기입니다.
http://kldp.org/node/87850
OTL
lib.c #include #include
lib.c #include <stdio.h> #include <stdlib.h> #if defined(__GNUC__) # define __USE_GNU # include <dlfcn.h> #else # include <dlfcn.h> #endif typedef void*(*fp_libcmalloc_t)(size_t); void *malloc(size_t size) { void *handle; static fp_libcmalloc_t fp_libcmalloc = NULL; void *buf; char *error; fprintf ( stderr, " [DEBUG] ## %s: %s: %d\n", __FILE__, "__FUNCTION__", __LINE__ ); fp_libcmalloc = (fp_libcmalloc_t) dlsym(RTLD_NEXT, "malloc"); if ((error = dlerror()) != NULL) { fprintf (stderr, "%s\n", error); exit(1); } buf = (void *)fp_libcmalloc( size ); fprintf ( stderr, " [DEBUG] ## %s: %s: %d\n", __FILE__, "__FUNCTION__", __LINE__ ); return buf; }malloc_test.c #include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char *argv[]) { char *p = NULL; printf( " p = [%s][%p]\n", p, p ); p = (char *)malloc( 16 ); strcpy( p, "aaa" ); printf( " p = [%s][%p]\n", p, p ); return 0; }위 내용과 첨부 파일이 도움이 되시길 바랍니다.
<어떠한 역경에도 굴하지 않는 '하양 지훈'>
#include
do { if (com) hacking(); if (money) drinking(); if (women) loving(); } while (1);
#include <com.h> <C2H5OH.h> <woman.h>
do { if (com) hacking(); if (money) drinking(); if (women) loving(); } while (1);
감사합니다. ^^
도움 주신 분들 대단히 감사합니다. ^-^
제가 아직 미숙해서.. 정확히 이해한 것이 맞는지는 모르겠지만..
application에서 시스템 콜을 호출했을 때, 원래의 시스템 콜을 실행하는 대신,
직접 만든 라이브러리를 우선 링크시켜 그 라이브러리의 함수를 호출하도록 하는 걸로 이해했는데요,
문제는.. 어플리케이션이 아니라 커널 레벨에서의 후킹을 원한다는 거지요 ㅠ_ㅠ;;
뭐 다음주면 hp ux internal 책이 배송된다니.. 지금은 그거 믿고 기다리는 수밖에 없네요.
변변찮은 질문에 도움 주신 분들 다시한번 감사합니다. 복받으실 거에요 >_
댓글 달기