All pastes #126302 Raw Edit

Anonymous

public c v1 · immutable
·published 2006-08-11 09:45 UTC
rendered paste body
/* * Vortex Labs * Your goal is to connect to port 5842 on vortex.labs.pulltheplug.org  * and read in 4 unsigned integers. Add these integers together  * and send back the results to get a username and password for level 1. * Note that vortex is on an x86 machine (meaning, a little endian  * architecture). * * Vortex.c Version 0.0.3 by francois @ www.xploiting.org * */#include <stdio.h>#include <stdlib.h>#include <errno.h>#include <netdb.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>int main(int argc, char *argv[]){	struct hostent *h;		/* Error check command line */	if (argc <= 2){		fprintf(stderr,"Usage: %s <target> <port>\n",argv[0]);		exit(1);	}				/* Change domain name into ip 	 * This value get parsed as a ip 	 * even if ip get issued */	if ((h=gethostbyname(argv[1])) == NULL) {		herror("gethostbyname");		exit(1);	}		/* atoi port number and check for errors */	if(atoi(argv[2]) == 0){		fprintf(stderr,"Please give the valid port number\n");		exit(1);	}		/* Make IP and PORT available for usage */	char *dest_ip = inet_ntoa(*((struct in_addr *)h->h_addr));	int dest_port = atoi(argv[2]);		/* Show results & details */	//printf("Host name : %s\n", H->h_name);	printf("\n");	printf("IP Address: %s\n", dest_ip);	printf("Port Num  : %d\n", atoi(argv[2]));		/* Contruct the connection information */ 	int sockfd;	struct sockaddr_in dest_addr;	/* Check if creating a socket fails */	if((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1)	{		perror("socket");		return EXIT_FAILURE;	}	dest_addr.sin_family = AF_INET;	dest_addr.sin_port = htons(dest_port);	dest_addr.sin_addr.s_addr = inet_addr(dest_ip);	memset(&(dest_addr.sin_zero), '\0', 8);	/* Start connection and check for errors */ 	if (connect(sockfd, (struct sockaddr *)&dest_addr, 				sizeof(struct sockaddr)) == -1)	{		fprintf(stderr,"No Connection to %s\n", dest_ip);		exit(1);	}		/* Make space in stack *safe? :S */	unsigned long recvd[4];	unsigned long total_val = 0;	char recv_answ[50];	memset(recv_answ, 0, 50);	/* Recieve loop */	int i = 0;	for (i = 0; i < 4; i++)	{		if(recv(sockfd, &recvd[i], sizeof(recvd[i]), 0) == -1)		{			fprintf(stderr,"Error recieving %d\n",i);			exit(1);		}				printf("Recieve %d : %d\n",i,recvd[i]);				/* Add all the values together */	        total_val = total_val + recvd[i]; 	}	printf("RecvTotal : %d\n",total_val);	/* Send answer back */	if (send(sockfd, &total_val, sizeof(total_val), 0) == -1)	{		fprintf(stderr,"Error Sending data back to %s\n", dest_ip);		exit(1);	}	/* Retrieve the information back */	recv(sockfd, &recv_answ, sizeof(recv_answ), 0);	printf("____________________________________\n");	printf("%s\n", &recv_answ);	return(0);}