⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sendip.c.txt

📁 经过修改的sendip结构
💻 TXT
📖 第 1 页 / 共 2 页
字号:
/* sendip.c - main program code for sendip * Copyright 2001 Mike Ricketts <mike@earth.li> * Distributed under the GPL.  See LICENSE. * Bug reports, patches, comments etc to mike@earth.li * ChangeLog since 2.0 release: * 27/11/2001 compact_string() moved to compact.c * 27/11/2001 change search path for libs to include <foo>.so * 23/01/2002 make random fields more random (Bryan Croft <bryan@gurulabs.com>) * 10/08/2002 detect attempt to use multiple -d and -f options */#define _SENDIP_MAIN/* socket stuff */#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <netdb.h>/* everything else */#include <unistd.h>#include <stdlib.h>#include <dlfcn.h>#include <string.h>#include <time.h>#include <sys/stat.h>#include <sys/mman.h>#include <fcntl.h>#include <ctype.h> /* isprint */#include "sendip_module.h"#ifdef __sun__  /* for EVILNESS workaround */#include "ipv4.h"#endif /* __sun__ *//* Use our own getopt to ensure consistant behaviour on all platforms */#include "gnugetopt.h"typedef struct _s_m {	struct _s_m *next;	struct _s_m *prev;	char *name;	char optchar;	sendip_data * (*initialize)(void);	bool (*do_opt)(const char *optstring, const char *optarg, 						sendip_data *pack);	bool (*set_addr)(char *hostname, sendip_data *pack);	bool (*finalize)(char *hdrs, sendip_data *headers[], sendip_data *data, 						  sendip_data *pack);	sendip_data *pack;	void *handle;	sendip_option *opts;	int num_opts;} sendip_module;/* sockaddr_storage struct is not defined everywhere, so here is our own	nasty version*/typedef struct {	unsigned short int ss_family;	char ss_padding[126];} _sockaddr_storage;static int num_opts=0;static sendip_module *first;static sendip_module *last;static int num_modules=0;static bool verbosity=FALSE;static char *progname;typedef struct paralist_t{	int para_num;       char* list[25];}paralist;static paralist mylist[]={{16,{"-p","ipv4","-is","192.168.1.111","-id","192.168.1.114",	"-p","tcp","-ts","1606","-td","6969","-tn","1694480794","-tfs","1","192.168.1.107"}},{20,{"-p","ipv4","-is","192.168.1.114","-id","192.168.1.111","-p","tcp","-ts","6969","-td","1606","-tn","183968251","-ta","1694480795","-tfa","1","-tfs","1","192.168.1.107"}},{18,{"-p","ipv4","-is","192.168.1.111","-id","192.168.1.114",  "-p","tcp","-ts","1606","-td","6969","-tn","1694480795","-ta","183968252","-tfa","1","192.168.1.107"}},{22,{"-f","http1","-p","ipv4","-is","192.168.1.111","-id","192.168.1.114",  "-p","tcp","-ts","1606","-td","6969","-tn","1694480795","-ta","183968252","-tfa","1","-tfp","1","192.168.1.107"}},{18,{"-p","ipv4","-is","192.168.1.114","-id","192.168.1.111",  "-p","tcp","-ts","6969","-td","1606","-tn","183968252","-ta","1694481172","-tfa","1","192.168.1.107"}},{22,{"-f","http2","-p","ipv4","-is","192.168.1.114","-id","192.168.1.111","-p","tcp","-ts","6969","-td","1606","-tn","183968252","-ta","1694481172","-tfa","1","-tfp","1","192.168.1.107"}}, {20, {"-p","ipv4","-is","192.168.1.114","-id","192.168.1.111",  "-p","tcp","-ts","6969","-td","1606","-tn","183968377","-ta","1694481172","-tfa","1","-tff","1","192.168.1.107"}}, {18,{"-p","ipv4","-is","192.168.1.111","-id","192.168.1.114",  "-p","tcp","-ts","1606","-td","6969","-tn","1694481172","-ta","183968378","-tfa","1","192.168.1.107"}}, {20,{"-p","ipv4","-is","192.168.1.111","-id","192.168.1.114",  "-p","tcp","-ts","1606","-td","6969","-tn","1694481172","-ta","183968378","-tfa","1","-tff","1","192.168.1.107"}},{18,{"-p","ipv4","-is","192.168.1.114","-id","192.168.1.111",  "-p","tcp","-ts","6969","-td","1606","-tn","183968378","-ta","1694481173","-tfa","1","192.168.1.107"}}  };static int sendpacket(sendip_data *data, char *hostname, int af_type,							 bool verbose) {	_sockaddr_storage *to = malloc(sizeof(_sockaddr_storage));	int tolen;	/* socket stuff */	int s;                            /* socket for sending       */	/* hostname stuff */	struct hostent *host = NULL;      /* result of gethostbyname2 */	/* casts for specific protocols */	struct sockaddr_in *to4 = (struct sockaddr_in *)to; /* IPv4 */	struct sockaddr_in6 *to6 = (struct sockaddr_in6 *)to; /* IPv6 */	int sent;                         /* number of bytes sent */	memset(to, 0, sizeof(_sockaddr_storage));	if ((host = gethostbyname2(hostname, af_type)) == NULL) {		perror("Couldn't get destination host: gethostbyname2()");		return -1;	};	switch (af_type) {	case AF_INET:		to4->sin_family = host->h_addrtype;		memcpy(&to4->sin_addr, host->h_addr, host->h_length);		tolen = sizeof(struct sockaddr_in);		break;	case AF_INET6:		to6->sin6_family = host->h_addrtype;		memcpy(&to6->sin6_addr, host->h_addr, host->h_length);		tolen = sizeof(struct sockaddr_in6);		break;	default:		return -2;		break;	}	if(verbose) { 		int i, j;  		printf("Final packet data:\n");		for(i=0; i<data->alloc_len; ) {			for(j=0; j<4 && i+j<data->alloc_len; j++)				printf("%02X ", (unsigned char)(data->data[i+j])); 			printf("  ");			for(j=0; j<4 && i+j<data->alloc_len; j++)				printf("%c", isprint((int)data->data[i+j])?data->data[i+j]:'.'); 			printf("\n");			i+=j;		}	}	if ((s = socket(af_type, SOCK_RAW, IPPROTO_RAW)) < 0) {		perror("Couldn't open RAW socket");		return -1;	}	/* Need this for OpenBSD, shouldn't cause problems elsewhere */	/* TODO: should make it a command line option */	if(af_type == AF_INET) { 		const int on=1;		if (setsockopt(s, IPPROTO_IP,IP_HDRINCL,(const void *)&on,sizeof(on)) <0) { 			perror ("Couldn't setsockopt IP_HDRINCL");			return -2;		}	}	/* On Solaris, it seems that the only way to send IP options or packets		with a faked IP header length is to:		setsockopt(IP_OPTIONS) with the IP option data and size		decrease the total length of the packet accordingly		I'm sure this *shouldn't* work.  But it does.	*/#ifdef __sun__	if((*(data->data)&0x0F) != 5) {		ip_header *iphdr = (ip_header *)data->data;		int optlen = iphdr->header_len*4-20;		if(verbose) 			printf("Solaris workaround enabled for %d IP option bytes\n", optlen);		iphdr->tot_len = htons(ntohs(iphdr->tot_len)-optlen);		if(setsockopt(s,IPPROTO_IP,IP_OPTIONS,						  (void *)((data->data)+20),optlen)) {			perror("Couldn't setsockopt IP_OPTIONS");			return -2;		}	}#endif /* __sun__ */	/* Send the packet */	sent = sendto(s, (char *)data->data, data->alloc_len, 0, (void *)to, tolen);	if (sent == data->alloc_len) {		if(verbose) printf("Sent %d bytes to %s\n",sent,hostname);	} else {		if (sent < 0)			perror("sendto");		else {			if(verbose) fprintf(stderr, "Only sent %d of %d bytes to %s\n", 									  sent, data->alloc_len, hostname);		}	}	close(s);	return sent;}static void unload_modules(bool freeit, int verbosity) {	sendip_module *mod, *p;	p = NULL;	for(mod=first;mod!=NULL;mod=mod->next) {		if(verbosity) printf("Freeing module %s\n",mod->name);		if(p) free(p);		p = mod;		free(mod->name);		if(freeit) free(mod->pack->data);		free(mod->pack);		(void)dlclose(mod->handle);		/* Do not free options - TODO should we? */	}	if(p) free(p);}static bool load_module(char *modname) {	sendip_module *newmod = malloc(sizeof(sendip_module));	sendip_module *cur;	int (*n_opts)(void);	sendip_option * (*get_opts)(void);	char (*get_optchar)(void);	for(cur=first;cur!=NULL;cur=cur->next) {		if(!strcmp(modname,cur->name)) {			memcpy(newmod,cur,sizeof(sendip_module));			newmod->num_opts=0;			goto out;		}	}	newmod->name=malloc(strlen(modname)+strlen(SENDIP_LIBS)+strlen(".so")+2);	strcpy(newmod->name,modname);	if(NULL==(newmod->handle=dlopen(newmod->name,RTLD_NOW))) {		char *error0=strdup(dlerror());		sprintf(newmod->name,"./%s.so",modname);		if(NULL==(newmod->handle=dlopen(newmod->name,RTLD_NOW))) {			char *error1=strdup(dlerror());			sprintf(newmod->name,"%s/%s.so",SENDIP_LIBS,modname);			if(NULL==(newmod->handle=dlopen(newmod->name,RTLD_NOW))) {				char *error2=strdup(dlerror());				sprintf(newmod->name,"%s/%s",SENDIP_LIBS,modname);				if(NULL==(newmod->handle=dlopen(newmod->name,RTLD_NOW))) {					char *error3=strdup(dlerror());					fprintf(stderr,"Couldn't open module %s, tried:\n",modname);					fprintf(stderr,"  %s\n  %s\n  %s\n  %s\n", error0, error1,							  error2, error3);					free(newmod);					free(error3);					return FALSE;				}				free(error2);			}			free(error1);		}		free(error0);	}	if(NULL==(newmod->initialize=dlsym(newmod->handle,"initialize"))) {		fprintf(stderr,"%s doesn't have an initialize function: %s\n",modname,				  dlerror());		dlclose(newmod->handle);		free(newmod);		return FALSE;	}	if(NULL==(newmod->do_opt=dlsym(newmod->handle,"do_opt"))) {		fprintf(stderr,"%s doesn't contain a do_opt function: %s\n",modname,				  dlerror());		dlclose(newmod->handle);		free(newmod);		return FALSE;	}	newmod->set_addr=dlsym(newmod->handle,"set_addr"); // don't care if fails	if(NULL==(newmod->finalize=dlsym(newmod->handle,"finalize"))) {		fprintf(stderr,"%s\n",dlerror());		dlclose(newmod->handle);		free(newmod);		return FALSE;	}	if(NULL==(n_opts=dlsym(newmod->handle,"num_opts"))) {		fprintf(stderr,"%s\n",dlerror());		dlclose(newmod->handle);		free(newmod);		return FALSE;	}	if(NULL==(get_opts=dlsym(newmod->handle,"get_opts"))) {		fprintf(stderr,"%s\n",dlerror());		dlclose(newmod->handle);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -