舊站 POP3 驗證程式逆向工程 - ntouind/sites.ind.ntou.edu.tw GitHub Wiki

這是舊站用來進行 POP3 驗證的程式

**更新:**已經找到來源碼

字串

luit -encoding BIG5 strings --encoding=S pop3.cgi

(stripped)
錯誤: 參數不正確(host, name, password).
錯誤: 找不到郵件主機(%s).
錯誤: 無法辯認主機回應 (%s)
QUIT
USER %s
錯誤: 使用者不正確(%s).
PASS %s
錯誤: 密碼錯誤(%s).
錯誤: 連線失敗(%s).
正確: 認證通過
(stripped)

反編譯結果

//
// This file was generated by the Retargetable Decompiler
// Website: https://retdec.com
// Copyright (c) 2016 Retargetable Decompiler <[email protected]>
//

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

// ------------------------ Structures ------------------------

// FILE {
//     int32_t e0;
// };

// struct hostent {
//     char * e0;
//     char ** e1;
//     int32_t e2;
//     int32_t e3;
//     char ** e4;
// };

// struct sockaddr {
//     int32_t e0;
//     char e1[14];
// };

// ------------------- Function Prototypes --------------------

int32_t name_resolve(char * cp, int32_t a2);

// --------------------- Global Variables ---------------------

char * error_message_wrong_arg = "錯誤: 參數不正確(host, name, password)."; // 0x8048b10
int32_t g2 = 0x7ebbf9bf; // 0x8048b39
int32_t g3 = 0x7ebbf9bf; // 0x8048b58
int32_t g4 = 0x7ebbf9bf; // 0x8048b86
int32_t g5 = 0x7ebbf9bf; // 0x8048ba9
int32_t g6 = 0x7ebbf9bf; // 0x8048bbe
int32_t g7 = 0x54bdbfa5; // 0x8048bd3
struct sockaddr * g8 = NULL; // 0x8049d20

// ------------------------ Functions -------------------------

// Address range: 0x80486a8 - 0x8048709
int32_t name_resolve(char * cp, int32_t a2) {
    int32_t result = inet_addr(cp); // 0x80486b2
    int32_t data = result; // bp-8
    if (result != -1) {
        // 0x8048708
        return result;
    }
    struct hostent * v1 = gethostbyname(cp); // 0x80486ca
    int32_t v2 = (int32_t)v1; // 0x80486ca_3
    if (v1 != NULL) {
        int32_t n = *(int32_t *)(v2 + 12); // 0x80486e7
        int32_t str = *(int32_t *)(v2 + 16); // 0x80486f2
        bcopy((char *)*(int32_t *)str, (char *)&data, n);
        // branch -> 0x8048708
    } else {
        data = 0;
    }
    // 0x8048708
    return data;
}

// Address range: 0x804870c - 0x8048b07
int main(int argc, char ** argv) {
    int32_t buf = 0; // bp-1156
    int32_t v1;
    memset((char *)&v1, 0, 1023);
    if (argc <= 3) {
        // 0x804873d
        fprintf(stdout, error_message_wrong_arg);
        // branch -> 0x8048b04
        // 0x8048b04
        return -1;
    }
    int32_t sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_IP); // 0x8048762
    int32_t addr;
    memset((char *)&addr, 0, 16);
    int32_t v2 = (int32_t)argv; // 0x804879a_0
    if (name_resolve((char *)*(int32_t *)(v2 + 4), addr) == 0) {
        // 0x80487bc
        fprintf(stdout, (char *)&g2);
        close(sock_fd);
        // branch -> 0x8048b04
        // 0x8048b04
        return -1;
    }
    // 0x80487f0
    if (connect(sock_fd, (struct sockaddr *)&addr, 16) != 0) {
        // 0x8048ac4
        fprintf(stdout, (char *)&g6);
        // branch -> 0x8048b04
        // 0x8048b04
        return -1;
    }
    // 0x8048812
    recv(sock_fd, (char *)&buf, 1024, 0);
    int32_t result; // 0x8048b05_2
    if (strncmp((char *)&buf, "+OK", 3) == 0) {
        // 0x80488b0
        buf = 0;
        int32_t v3 = *(int32_t *)(v2 + 8); // 0x80488bd
        int32_t str;
        snprintf((char *)&str, 128, "USER %s\r\n", (char *)v3);
        int32_t len = strlen((char *)&str); // 0x80488dc
        int32_t len2; // 0x80489d0
        int32_t v4; // 0x80489b1
        if (send(sock_fd, (char *)&str, len, 0) != 0) {
            // 0x8048904
            recv(sock_fd, (char *)&buf, 1024, 0);
            if (strncmp((char *)&buf, "+OK", 3) == 0) {
                // 0x80489a4
                buf = 0;
                // branch -> 0x80489ab
                // 0x80489ab
                v4 = *(int32_t *)(v2 + 12);
                snprintf((char *)&str, 128, "PASS %s\r\n", (char *)v4);
                len2 = strlen((char *)&str);
                if (send(sock_fd, (char *)&str, len2, 0) != 0) {
                    // 0x80489f8
                    recv(sock_fd, (char *)&buf, 1024, 0);
                    if (strncmp((char *)&buf, "+OK", 3) == 0) {
                        // 0x8048a94
                        buf = 0;
                        // branch -> 0x8048a9b
                        // 0x8048a9b
                        send(sock_fd, "QUIT\r\n", 6, 0);
                        close(sock_fd);
                        fprintf(stdout, (char *)&g7);
                        result = 1;
                        // branch -> 0x8048b04
                    } else {
                        // 0x8048a4a
                        fprintf(stdout, (char *)&g5);
                        send(sock_fd, "QUIT\r\n", 6, 0);
                        close(sock_fd);
                        result = -1;
                        // branch -> 0x8048b04
                    }
                    // 0x8048b04
                    return result;
                }
                // 0x8048a9b
                send(sock_fd, "QUIT\r\n", 6, 0);
                close(sock_fd);
                fprintf(stdout, (char *)&g7);
                result = 1;
                // branch -> 0x8048b04
            } else {
                // 0x8048956
                fprintf(stdout, (char *)&g4);
                send(sock_fd, "QUIT\r\n", 6, 0);
                close(sock_fd);
                result = -1;
                // branch -> 0x8048b04
            }
            // 0x8048b04
            return result;
        }
        // 0x80489ab
        v4 = *(int32_t *)(v2 + 12);
        snprintf((char *)&str, 128, "PASS %s\r\n", (char *)v4);
        len2 = strlen((char *)&str);
        if (send(sock_fd, (char *)&str, len2, 0) != 0) {
            // 0x80489f8
            recv(sock_fd, (char *)&buf, 1024, 0);
            if (strncmp((char *)&buf, "+OK", 3) == 0) {
                // 0x8048a94
                buf = 0;
                // branch -> 0x8048a9b
                // 0x8048a9b
                send(sock_fd, "QUIT\r\n", 6, 0);
                close(sock_fd);
                fprintf(stdout, (char *)&g7);
                result = 1;
                // branch -> 0x8048b04
            } else {
                // 0x8048a4a
                fprintf(stdout, (char *)&g5);
                send(sock_fd, "QUIT\r\n", 6, 0);
                close(sock_fd);
                result = -1;
                // branch -> 0x8048b04
            }
            // 0x8048b04
            return result;
        }
        // 0x8048a9b
        send(sock_fd, "QUIT\r\n", 6, 0);
        close(sock_fd);
        fprintf(stdout, (char *)&g7);
        result = 1;
        // branch -> 0x8048b04
    } else {
        // 0x8048864
        fprintf(stdout, (char *)&g3);
        send(sock_fd, "QUIT\r\n", 6, 0);
        close(sock_fd);
        result = -1;
        // branch -> 0x8048b04
    }
    // 0x8048b04
    return result;
}

// --------------- Dynamically Linked Functions ---------------

// void bcopy(const void * src, void * dest, size_t n);
// int close(int fd);
// int connect(int fd, __CONST_SOCKADDR_ARG addr, socklen_t len);
// int fprintf(FILE * restrict stream, const char * restrict format, ...);
// struct hostent * gethostbyname(const char * name);
// in_addr_t inet_addr(const char * cp);
// void * memset(void * s, int c, size_t n);
// ssize_t recv(int fd, void * buf, size_t n, int flags);
// ssize_t send(int fd, const void * buf, size_t n, int flags);
// int snprintf(char * restrict s, size_t maxlen, const char * restrict format, ...);
// int socket(int domain, int type, int protocol);
// size_t strlen(const char * s);
// int strncmp(const char * s1, const char * s2, size_t n);

// --------------------- Meta-Information ---------------------

// Detected compiler/packer: gcc (bsd) (4.2.1)
// Detected functions: 2
// Decompiler release: v2.2.1 (2016-09-07)
// Decompilation date: 2016-12-27 07:36:13
⚠️ **GitHub.com Fallback** ⚠️