probe_modules.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * ZMap Copyright 2013 Regents of the University of Michigan
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy
  6. * of the License at http://www.apache.org/licenses/LICENSE-2.0
  7. */
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <assert.h>
  11. #include <time.h>
  12. #include <sys/time.h>
  13. #include "../../lib/includes.h"
  14. #include "../../lib/logger.h"
  15. #include "../../lib/xalloc.h"
  16. #include "../fieldset.h"
  17. #include "probe_modules.h"
  18. #include "packet.h"
  19. extern probe_module_t module_tcp_synscan_proberesponse;
  20. extern probe_module_t module_tcp_synscan;
  21. extern probe_module_t module_icmp_echo;
  22. extern probe_module_t module_icmp_echo_time;
  23. extern probe_module_t module_udp;
  24. extern probe_module_t module_udp_dns;
  25. extern probe_module_t module_dns_mx;
  26. extern probe_module_t module_ntp;
  27. extern probe_module_t module_upnp;
  28. // ADD YOUR MODULE HERE
  29. probe_module_t* probe_modules[] = {
  30. &module_tcp_synscan_proberesponse,
  31. &module_tcp_synscan,
  32. &module_icmp_echo,
  33. &module_icmp_echo_time,
  34. &module_udp,
  35. &module_udp_dns,
  36. &module_dns_mx,
  37. &module_ntp,
  38. &module_upnp
  39. // ADD YOUR MODULE HERE
  40. };
  41. probe_module_t* get_probe_module_by_name(const char* name)
  42. {
  43. int len = (int) (sizeof(probe_modules)/sizeof(probe_modules[0]));
  44. for (int i=0; i < len; i++) {
  45. if (!strcmp(probe_modules[i]->name, name)) {
  46. return probe_modules[i];
  47. }
  48. }
  49. return NULL;
  50. }
  51. void print_probe_modules(void)
  52. {
  53. int len = (int) (sizeof(probe_modules)/sizeof(probe_modules[0]));
  54. for (int i=0; i < len; i++) {
  55. printf("%s\n", probe_modules[i]->name);
  56. }
  57. }
  58. void fs_add_ip_fields(fieldset_t *fs, struct ip *ip)
  59. {
  60. // WARNING: you must update fs_ip_fields_len as well
  61. // as the definitions set (ip_fiels) if you
  62. // change the fields added below:
  63. fs_add_string(fs, "saddr", make_ip_str(ip->ip_src.s_addr), 1);
  64. fs_add_uint64(fs, "saddr-raw", (uint64_t) ip->ip_src.s_addr);
  65. fs_add_string(fs, "daddr", make_ip_str(ip->ip_dst.s_addr), 1);
  66. fs_add_uint64(fs, "daddr-raw", (uint64_t) ip->ip_dst.s_addr);
  67. fs_add_uint64(fs, "ipid", ntohs(ip->ip_id));
  68. fs_add_uint64(fs, "ttl", ip->ip_ttl);
  69. }
  70. #define TIMESTR_LEN 55
  71. void fs_add_system_fields(fieldset_t *fs, int is_repeat, int in_cooldown)
  72. {
  73. fs_add_uint64(fs, "repeat", is_repeat);
  74. fs_add_uint64(fs, "cooldown", in_cooldown);
  75. char *timestr = xmalloc(TIMESTR_LEN+1);
  76. char *timestr_ms = xmalloc(TIMESTR_LEN+1);
  77. struct timeval t;
  78. gettimeofday(&t, NULL);
  79. struct tm *ptm = localtime(&t.tv_sec);
  80. strftime(timestr, TIMESTR_LEN, "%Y-%m-%dT%H:%M:%S.%%03d%z", ptm);
  81. snprintf(timestr_ms, TIMESTR_LEN, timestr, t.tv_usec/1000);
  82. free(timestr);
  83. fs_add_string(fs, "timestamp-str", timestr_ms, 1);
  84. fs_add_uint64(fs, "timestamp-ts", (uint64_t) t.tv_sec);
  85. fs_add_uint64(fs, "timestamp-us", (uint64_t) t.tv_usec);
  86. }
  87. int ip_fields_len = 6;
  88. fielddef_t ip_fields[] = {
  89. {.name="saddr", .type="string", .desc="source IP address of response"},
  90. {.name="saddr-raw", .type="int", .desc="network order integer form of source IP address"},
  91. {.name="daddr", .type="string", .desc="destination IP address of response"},
  92. {.name="daddr-raw", .type="int", .desc="network order integer form of destination IP address"},
  93. {.name="ipid", .type="int", .desc="IP identification number of response"},
  94. {.name="ttl", .type="int", .desc="time-to-live of response packet"}
  95. };
  96. int sys_fields_len = 5;
  97. fielddef_t sys_fields[] = {
  98. {.name="repeat", .type="int", .desc="Is response a repeat response from host"},
  99. {.name="cooldown", .type="int", .desc="Was response received during the cooldown period"},
  100. {.name="timestamp-str", .type="string", .desc="timestamp of when response arrived in ISO8601 format."},
  101. {.name="timestamp-ts", .type="int", .desc="timestamp of when response arrived in seconds since Epoch"},
  102. {.name="timestamp-us", .type="int", .desc="microsecond part of timestamp (e.g. microseconds since 'timestamp-ts')"}
  103. };