⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 amap-lib.c

📁 Ubuntu packages of security software。 相当不错的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
      if (opt->verbose > 1)        printf("DEBUG: Loaded response %s ...\n", response->id);    }  }  if (count_responses == 0)    amap_error("no responses loaded - responses file is empty");  if (opt->verbose)    printf("loaded %d responses\n", count_responses);  return responses;}// AMAP_ADD_PORT_STRING //amap_struct_ports *amap_add_port_string(amap_struct_ports *port_tmp, char *port, int cmd_proto, amap_struct_options *opt) {  char *ptr;  int pfrom, pto;  if ((ptr = index(port, '-')) == NULL) {    if (atoi(port) < 0 || atoi(port) > 65535)      amap_error("ports to be scanned must be between 0 and 65535 inclusive: %s", port);    port_tmp->port = atoi(port);    port_tmp->ip_prot = cmd_proto;  } else {    *ptr = 0;    ptr++;    pfrom = atoi(port);    pto = atoi(ptr);    if (pto < 1 || pfrom < 1 || pto < pfrom || pto > 65535 || pfrom > 65535)      amap_error("range definition is invalid: %s-%s",port, ptr);    for ( ;  pfrom <= pto; pfrom++) {      port_tmp->port = (unsigned short int) pfrom;      port_tmp->ip_prot = cmd_proto;      if (opt->verbose > 1)        printf("%d/%s ", port_tmp->port, port_tmp->ip_prot == AMAP_PROTO_TCP ? "tcp" : "udp");      if (pto != pfrom) {        if ((/*(amap_struct_ports *)*/ port_tmp->next = /*(amap_struct_ports *)*/ malloc(sizeof(amap_struct_ports))) == NULL)          amap_error("malloc failed");        port_tmp = (amap_struct_ports *) port_tmp->next;        memset(port_tmp, 0, sizeof(amap_struct_ports));      }    }  }  return port_tmp;}// READ_FILE_NMAP //amap_struct_targets *read_file_nmap(char *filename, amap_struct_options *opt) {  amap_struct_targets *targets;  amap_struct_targets *target;  amap_struct_ports   *port_tmp;  FILE *f;  char line[AMAP_BUFSIZE_BIG];  char orig_line[AMAP_BUFSIZE_BIG];  char *ip;  char *portinfo;  char *proto;  char *ptr;  int ip_prot;  int count = 0;  f = amap_open_file(filename, "nmap", "", opt->verbose);  if ((targets = target = (amap_struct_targets*) malloc(sizeof(amap_struct_targets))) == NULL)    amap_error("malloc failed");  memset(target, 0, sizeof(amap_struct_targets));  if ((port_tmp = target->ports = (amap_struct_ports *) malloc(sizeof(amap_struct_ports))) == NULL)    amap_error("malloc failed");  memset(port_tmp, 0, sizeof(amap_struct_ports));  while (fgets(line, AMAP_BUFSIZE_BIG, f) != NULL) {    if (line[strlen(line) - 1] != '\n')      amap_error("line in nmap file is too long or not terminating with \\n: %s", line);    if ((line[0] == 'H') && (index(line, ' ') != NULL) && ((portinfo = strstr(line, "/open/")) != NULL)) { // just care for data lines      if (count != 0) {        if ((/*(amap_struct_targets*)*/ target->next = /*(amap_struct_targets*)*/ malloc(sizeof(amap_struct_targets))) == NULL)          amap_error("malloc failed");        target = (amap_struct_targets*) target->next;        memset(target, 0, sizeof(amap_struct_targets));        if ((port_tmp = target->ports = (amap_struct_ports *) malloc(sizeof(amap_struct_ports))) == NULL)          amap_error("malloc failed");        memset(port_tmp, 0, sizeof(amap_struct_ports));      }      line[strlen(line) - 1] = 0;      if (line[strlen(line) - 1] == '\r')        line[strlen(line) - 1] = 0;      strcpy(orig_line, line);      ip = index(line, ' ');      ip++;      if (opt->ipv6)        ptr = amap_index(ip, ':');      else        ptr = amap_index(ip, '.');      if ((ptr = amap_index(ptr, ' ')) == NULL)        amap_error("nmap data line fucked up (is it ipv6 but you did not use the -6 option?) : %s", orig_line);      *ptr = 0;      target->target = strdup(ip);      if (opt->ipv6 == 0)        if (inet_addr(target->target) == -1)          amap_error("invalid IP address in nmap line: %s : %s", target->target, orig_line);      if (opt->verbose > 1)        printf("DEBUG: Loading ports for %s ... ", target->target);      while (*(portinfo - 1) != ' ')        portinfo--;      ptr = amap_index(portinfo, '/');      proto = amap_index(ptr, '/');      if (proto == NULL)        amap_error("too few number of fields in the following port data in the nmap file: %s", portinfo);      *ptr++ = 0;      *proto++ = 0;      switch (*proto) {        case 't': ip_prot = AMAP_PROTO_TCP; break;        case 'u': ip_prot = AMAP_PROTO_UDP; break;        default:  amap_error("protocol field in nmap file is not tcp or udp : %s : %s", proto, orig_line);      }      port_tmp->port = atoi(portinfo);      port_tmp->ip_prot = ip_prot;      if (opt->verbose > 1)        printf("%d/%s ", port_tmp->port, port_tmp->ip_prot == AMAP_PROTO_TCP ? "tcp" : "udp");      while ((portinfo = strstr(proto + 1, "/open/")) != NULL) {        if ((/*(amap_struct_ports *)*/ port_tmp->next = /*(amap_struct_ports *)*/ malloc(sizeof(amap_struct_ports))) == NULL)          amap_error("malloc failed");        port_tmp = (amap_struct_ports *) port_tmp->next;        memset(port_tmp, 0, sizeof(amap_struct_ports));        while (*(portinfo - 1) != ' ')          portinfo--;        ptr = amap_index(portinfo, '/');        proto = amap_index(ptr, '/');        if (proto == NULL)          amap_error("too few number of fields in the following port data in the nmap file: %s", portinfo);        *ptr++ = 0;        *proto++ = 0;        switch (*proto) {          case 't': ip_prot = AMAP_PROTO_TCP; break;          case 'u': ip_prot = AMAP_PROTO_UDP; break;          default:  amap_error("protocol field in nmap file is not tcp or udp : %s : %s", proto, orig_line);        }        port_tmp->port = atoi(portinfo);        port_tmp->ip_prot = ip_prot;        if (opt->verbose > 1)          printf("%d/%s ", port_tmp->port, port_tmp->ip_prot == AMAP_PROTO_TCP ? "tcp" : "udp");      }      count++;      if (opt->verbose > 1)        printf("\n");    }  }  if (targets->target == NULL) {    printf("\n");    amap_warn("No readable information in file %s found - was it really generated with nmap's -oM option?\n", filename);    free(targets);    targets = NULL;  }  if (opt->verbose)    printf("done\n");  return targets;}// AMAP_SKIP_TRANSLATE //char *amap_skip_translate(int i) {  switch(i) {    case 0:    case 1:      return "open";    case 2:      return "closed";    case 3:      return "timeout";    case 4:      return "timeout";    default:      amap_error("unknown skip value, programmer's error or memory corruption");  }  return "";}// AMAP_BUILD_TIME //char *amap_build_time(char *today, int len) {  time_t t = time(NULL);  struct tm *time = localtime(&t);    snprintf(today, len, "%d-%02d-%02d %02d:%02d:%02d", time->tm_year + 1900, time->tm_mon + 1, time->tm_mday, time->tm_hour, time->tm_min, time->tm_sec);  return today;}// AMAP_PRINTABLE_BANNER_STRING //char *amap_printable_banner_string(unsigned char *string, int slen, char *banner, int blen) {  int i = 0;  int j = 0;  if (slen < 1 || string == NULL || banner == NULL || blen < 1)    return "";    while (i < blen - 2 && j < slen) {    if (string[j] != ':' && (isprint(string[j]) || isspace(string[j]))) {      if ((isspace(string[j]) && string[j] != ' ') || string[j] == '\\') {        banner[i] = '\\';        i++;        switch (string[j]) {          case '\n': banner[i] = 'n'; break;          case '\r': banner[i] = 'r'; break;          case '\t': banner[i] = 't'; break;          case '\v': banner[i] = 'v'; break;          case '\f': banner[i] = 'f'; break;          case '\\': banner[i] = '\\'; break;          default: banner[i] = '?';        }        i++;      } else {        banner[i] = string[j];        i++;      }    }    j++;  }  banner[i] = 0;  return banner;}// AMAP_BANNER_STRING //void amap_banner_string(FILE *f, unsigned char *string, int len) {  int i = 0;  int j = 0;    if (f == NULL || string == NULL || len < 1)    return;    while (j == 0 && i < len) {    if (!isprint(string[i]) && !isspace(string[i]) && string[i] != ':' && string[i] != '"')      j = 1;    i++;  }    if (j) {    fprintf(f, "0x");    for (i = 0; i < len; i++) {      fprintf(f, "%c", string[i] / 16 > 9 ? string[i] / 16 + 87 : string[i] / 16 + 48);      fprintf(f, "%c", string[i] % 16 > 9 ? string[i] % 16 + 87 : string[i] % 16 + 48);    }  } else {    fprintf(f, "\"");    for (i = 0; i < len; i++)      switch(string[i]) {        case '\n': fprintf(f, "\\n"); break;        case '\r': fprintf(f, "\\r"); break;        case '\t': fprintf(f, "\\t"); break;        case '\v': fprintf(f, "\\v"); break;        case '\f': fprintf(f, "\\f"); break;        case '\\': fprintf(f, "\\\\"); break;        default:   fprintf(f, "%c", string[i]);      }    fprintf(f, "\"");  }}// AMAP_DUMP_STRING - partial rip from vh-lib //void amap_dump_string(FILE *f, unsigned char *string, int length, int width) {    unsigned char *p = (unsigned char *) string;    unsigned char lastrow_data[16];    int rows = length / width;    int lastrow = length % width;    int i, j;    for (i = 0; i < rows; i++) {        fprintf(f, "%04hx:  ", i * 16);        for (j = 0; j < width; j++) {            fprintf(f, "%02x", p[(i * 16) + j]);            if (j % 2 == 1)                fprintf(f, " ");        }        fprintf(f, "   [ ");        for (j = 0; j < width; j++) {            if (isprint(p[(i * 16) + j]))                fprintf(f, "%c", p[(i * 16) + j]);            else                fprintf(f, ".");        }        fprintf(f, " ]\n");    }    if (lastrow > 0) {        memset(lastrow_data, 0, sizeof(lastrow_data));        memcpy(lastrow_data, p + length - lastrow, lastrow);        fprintf(f, "%04hx:  ", i * 16);        for (j = 0; j < lastrow; j++) {            fprintf(f, "%02x", p[(i * 16) + j]);            if (j % 2 == 1)                fprintf(f, " ");        }        while(j < width) {            fprintf(f, "  ");            if (j % 2 == 1)                fprintf(f, " ");            j++;        }        fprintf(f, "   [ ");        for (j = 0; j < lastrow; j++) {            if (isprint(p[(i * 16) + j]))                fprintf(f, "%c", p[(i * 16) + j]);            else                fprintf(f, ".");        }        while(j < width) {            fprintf(f, " ");            j++;        }        fprintf(f, " ]\n");    }}// AMAP_LOOKUP_ID //int amap_lookup_id(amap_struct_identifications *ids, char *id) {  while (ids != NULL) {    if (strcmp(ids->id, id) == 0)      return 1;    ids = (amap_struct_identifications*) ids->next;  }  return 0;}// AMAP_ADD_ID //void amap_add_id(amap_struct_ports *port, char *id) {  amap_struct_identifications *ids = port->ids;  if (port->ids == NULL) {    if ((ids = port->ids = malloc(sizeof(amap_struct_identifications))) == NULL)      amap_error("malloc failed");  } else {    while (ids->next != NULL)      ids = (amap_struct_identifications*) ids->next;    if ((/*(char *)*/ ids->next = malloc(sizeof(amap_struct_identifications))) == NULL)      amap_error("malloc failed");    ids = (amap_struct_identifications*) ids->next;  }  ids->next = NULL;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -