U E D R , A S I H C RSS

��호/미니프로�트#1

~cpp 
소규모 프로�트를 진행 하려 한다.
예� ��수는 2000~3000 �� 정��며 프로�트를 � 커질수� ��수� 가변성 �한 존재한다.

// 한가지 웃긴것� C++로 짜면 C와 ��한 기능� 가졌��� ��� 수가 3배 �� 늘어난다는 것�다.
// 6000~9000�� 정� �려나...
// 그런� � 웃긴것� C++� 숙달�면 C보다 0.8배 정�로 시간� 단축�다는 것�다.
// �래스� ��성으로 �해 기존� �래스를 고치지 않아서 �것 같다.

만들것 : IRC bot
목� : irc� 접�해 있는 유저들� ���으로 공격하는 프로그램. & 차후 AI(�할 엉터리 AI 패러다임) bot�나 타�봇� 집어넣� 예정
OS : Linux 체제
Language : C & Linux System Function

방법론 : 프로세스를 여러개 만들어 비�� 프로그램� 쉬워지게 만든다.
주�� : Zombie Process를 만들지 않�� System Call � 잘 관리한다.

1. Client Console� 메세지를 입력하면 IRC Server로 문�열� 전송한다. -> Main Process
2. 서버로부터 메세지 중 PING 부분 처리 -> 1번째 Child Process
3. 서버� 메세지 중 타유저들� 명령하는 것 처리 -> 2번째 Chile Process
 (3번�서 Master가 누군지 알아보게 하는 것 -> Private 메세지로 패스워드를 넘겨 IP를 �� 받는 방�.)


main.c -> IRC Server로 메세지를 보내는 역할� 하고 �� 프로세스를 �성한다.
parse.c -> IRC Server로 부터 오는 메세지를 파싱한다.
file.c -> 파� 입출력� 다루는 함수와 메세지들� Log하는 부분� 담당한다. �단 프로그램� 어� 정� 만들고 구현하��한다.
request.c -> IRC Server로 부터 날아오는 PING� 대한 PONG 처리.
bot.c -> 봇� 관한 함수. 
attack_#.c(# == 임�� 숫�) -> 공격 함수. 요즘 보안홀들� 체�하여 보안홀들� 공격하는 함수들� 집어넣�.
// 향후 프로그램� 커지면 네트워� 부분� 따로 모듈� 만들어 낸다.
connect.c -> 네트워� 부분.    // 아마 커진것 같다.


(2�� 한번씩 컴퓨터를 사용하므로...)
우선 구현할 부분 : main� �부, parse� PING 처리부분, request 부분


나중� 아랫부분만 컴파� 해보�. 컴파�러가 없다! �러가 나올지 모른다.
// signal� 나중�.
// fork 부분만 구현한다.


~cpp 
// 구분하지 않� 파�. � 파�� � 파�로 나눈다.
// 심심해서 짜본걸 여기� ��.
// ��으로 #linux 채�까지 접� �.
// �파�로 나눈 차후 채�로� privmsg와 process call� mirc처럼 분리해서 넣어야함.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <unistd.h>
#include <arpa/inet.h>

#define MSG_MAX 1024
#define NICK    "whoami_"
#define HOST    "irc.hanirc.org"
#define PORT    "6667"

void error_handling(char *msg);
void handler(int sig);

typedef struct _info{
        char *nick;
        char *host;
        char *port;
        char *user_name;
        char *user_whois1;
        char *user3;
        char *user_whois2;
} INFO;

INFO info = {NICK, HOST, PORT, "a", "b", "c", "d"};

int main(int argc, char *argv[])
{
        int sockfd;
        struct sockaddr_in ina;
        struct sigaction act;
        struct hostent *h;
        pid_t pid;
        char msg[MSG_MAX];
        int msg_len;
        char check_ping[7];
        char pong[11];
        int join_flag = 0;

        sockfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
        if(sockfd == -1)
                error_handling("socket() error: sockfd");

        h = gethostbyname(info.host);

        memset(&ina, 0, sizeof(ina));
        ina.sin_family = AF_INET;
        ina.sin_addr = *(struct in_addr *)h->h_addr_list[0];
        ina.sin_port = htons(atoi(info.port));

        if(connect(sockfd, (struct sockaddr *)&ina, sizeof(ina)) == -1)
                error_handling("connect() error: ");

        act.sa_handler = handler;
        sigemptyset(&act.sa_mask);
        act.sa_flags = 0;

        sigaction(SIGCHLD, &act, 0);

        pid = fork();

        if(pid == -1)
                error_handling("fork() error: ");
        else if(pid == 0){
                while(1){
                        msg_len = recv(sockfd, msg, MSG_MAX-1, 0);
                        if(msg_len > 0){
                                                                msg[msg_len] = '';
                                printf(msg);
                                                }

                        if(strstr(msg, "NOTICE AUTH :*** Checking Ident") != NULL){
                                sleep(1);
                                sprintf(msg, "user %s %s %s %sn", info.user_name, info.user_whois1, info.user3, info.user_whois2);
                                send(sockfd, msg, strlen(msg), 0);
                                sprintf(msg, "NICK %sn", info.nick);
                                send(sockfd, msg, strlen(msg), 0);
                                printf("Connect Initialization Succeed!n");
                        }
                        else{
                                sscanf(msg, "%6c%s",check_ping, pong);

                                if(strncmp(check_ping, "PING :", 6) == 0){
                                        sprintf(msg, "PONG %sn", pong);
                                        send(sockfd, msg, strlen(msg), 0);

                                        if(join_flag == 0){
                                                sleep(1);
                                                join_flag = 1;
                                                send(sockfd, "join #linuxn", 12, 0);
                                        }
                                }
                        }

                        msg[0] = '';
                }

                exit(0);
        }
        else{
                fprintf(stderr, "Child Process Created!: pid = %dn", pid);
        }

        while(1){
                fgets(msg, MSG_MAX, stdin);
                send(sockfd, msg, strlen(msg), 0);

                if(strcmp(msg, "quitn") == 0)
                        break;
        }

        kill(0, SIGKILL);                // 부모가 종료하면 �� 프로세스 모� 종료한다.

        return 0;
}


void error_handling(char *msg)
{
        fprintf(stderr, "%sn", msg);
        exit(-1);
}

void handler(int sig)
{
        pid_t pid;
        int last;

        pid = waitpid(-1, &last, WNOHANG);
        fprintf(stderr, "Child Process Closed!: pid = %d, WEXITSTATUS = %Xn", pid, WEXITSTATUS(last));
}

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:30:32
Processing time 0.0088 sec