void syscall_proxy(int sockfd) {
	unsigned long remote_sp=0;
	int retval = 0, myfd;
	struct syscall *sysc;

	remote_sp = get_remote_sp(sockfd);
	printf("Got remote stack pointer: 0x%.4lx\n", remote_sp);

	sysc = build_getid(remote_sp, 0);
	retval = send_syscall(sockfd, sysc, 1);
	printf("Got return value of: %d from getid(0)\n", retval);

	sysc = build_umask(remote_sp, 022);
	retval = send_syscall(sockfd, sysc, 1);
	printf("Got return value of: %d from umask(022)\n", retval);
	
	sysc = build_mkdir(remote_sp, "/tmp/syscall", 00700);
	retval = send_syscall(sockfd, sysc, 1);
	printf("Got return value of: %d from mkdir(%s, %o)\n", retval, 
		   "/tmp/syscall", 00700);

	sysc = build_open(remote_sp, "/tmp/syscall/passwd", 
					  O_WRONLY|O_CREAT|O_APPEND);
	retval = send_syscall(sockfd, sysc, 1);
	printf("Got return value of: %d from open(\"/tmp/syscall/passwd\")\n", 
		   retval);

	myfd = retval;

	sysc = build_write(remote_sp, myfd, "root:*:0:0:Charlie &:/root:/bin/csh", 
					   35);
	retval = send_syscall(sockfd, sysc, 1);
	printf("Got return value of: %d from write(%d, ...)\n", retval, myfd);

	sysc = build_close(remote_sp, myfd);
	retval = send_syscall(sockfd, sysc, 1);
	printf("Got return value of: %d from close(%d)\n", retval, myfd);

	sysc = build_chmod(remote_sp, "/tmp/syscall/passwd", 0644);
	retval = send_syscall(sockfd, sysc, 1);
	printf("Got return value of: %d from chmod(%s,%o)\n", retval, 
		   "/tmp/syscall/passwd", 0644);

	sysc = build_unlink(remote_sp, "/tmp/syscall/passwd");
	retval = send_syscall(sockfd, sysc, 1);
	printf("Got return value of: %d from unlink(%s)\n", retval, 
		   "/tmp/syscall/passwd");

	sysc = build_rmdir(remote_sp, "/tmp/syscall");
	retval = send_syscall(sockfd, sysc, 1);
	printf("Got return value of: %d from rmdir(%s)\n", retval, "/tmp/syscall");

	sysc = build_exit(remote_sp, 5);
	retval = send_syscall(sockfd, sysc, 0);
	printf("Sent exit() syscall!\n");
}
Пример #2
0
void	check_exit(t_data *d)
{
	if (d->line != NULL && d->line != '\0')
	{
		if ((ft_strequ("exit", d->line) == 1)
			&& (d->line[4] == '\0' || d->line[4] == ' '))
		{
			d->toexec = ft_strtrim(d->line);
			build_exit(d);
		}
	}
}