wmap 2.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +141 -0
  3. data/LICENSE.txt +15 -0
  4. data/README.rdoc +98 -0
  5. data/TODO +13 -0
  6. data/bin/deprime +21 -0
  7. data/bin/distrust +38 -0
  8. data/bin/googleBot +23 -0
  9. data/bin/prime +21 -0
  10. data/bin/refresh +26 -0
  11. data/bin/run_tests +16 -0
  12. data/bin/spiderBot +26 -0
  13. data/bin/trust +38 -0
  14. data/bin/updateAll +57 -0
  15. data/bin/wadd +25 -0
  16. data/bin/wadds +26 -0
  17. data/bin/wcheck +28 -0
  18. data/bin/wdel +25 -0
  19. data/bin/wdump +21 -0
  20. data/bin/wmap +151 -0
  21. data/bin/wscan +32 -0
  22. data/data/cidrs +2 -0
  23. data/data/deactivated_sites +1 -0
  24. data/data/domains +2 -0
  25. data/data/hosts +1 -0
  26. data/data/prime_hosts +1 -0
  27. data/data/sites +2 -0
  28. data/data/sub_domains +2 -0
  29. data/demos/bruter.rb +27 -0
  30. data/demos/dns_brutes.rb +28 -0
  31. data/demos/filter_cidr.rb +18 -0
  32. data/demos/filter_crawls.rb +5 -0
  33. data/demos/filter_domain.rb +25 -0
  34. data/demos/filter_geoip.rb +26 -0
  35. data/demos/filter_known_services.rb +59 -0
  36. data/demos/filter_netinfo.rb +23 -0
  37. data/demos/filter_prime.rb +25 -0
  38. data/demos/filter_profiler.rb +3 -0
  39. data/demos/filter_redirection.rb +19 -0
  40. data/demos/filter_site.rb +40 -0
  41. data/demos/filter_siteip.rb +31 -0
  42. data/demos/filter_status.rb +17 -0
  43. data/demos/filter_timestamp.rb +23 -0
  44. data/demos/filter_url.rb +19 -0
  45. data/demos/new_fnd.rb +66 -0
  46. data/demos/nmap_parser.pl +138 -0
  47. data/demos/site_format.rb +18 -0
  48. data/demos/whois_domain.rb +78 -0
  49. data/dicts/GeoIP.dat +0 -0
  50. data/dicts/GeoIPASNum.dat +0 -0
  51. data/dicts/GeoLiteCity.dat +0 -0
  52. data/dicts/ccsld.txt +2646 -0
  53. data/dicts/cctld.txt +243 -0
  54. data/dicts/gtld.txt +25 -0
  55. data/dicts/hostnames-dict.big +1402 -0
  56. data/dicts/hostnames-dict.txt +101 -0
  57. data/lib/wmap/cidr_tracker.rb +327 -0
  58. data/lib/wmap/dns_bruter.rb +308 -0
  59. data/lib/wmap/domain_tracker/sub_domain.rb +142 -0
  60. data/lib/wmap/domain_tracker.rb +342 -0
  61. data/lib/wmap/geoip_tracker.rb +72 -0
  62. data/lib/wmap/google_search_scraper.rb +177 -0
  63. data/lib/wmap/host_tracker/primary_host.rb +130 -0
  64. data/lib/wmap/host_tracker.rb +550 -0
  65. data/lib/wmap/network_profiler.rb +144 -0
  66. data/lib/wmap/port_scanner.rb +208 -0
  67. data/lib/wmap/site_tracker/deactivated_site.rb +85 -0
  68. data/lib/wmap/site_tracker.rb +937 -0
  69. data/lib/wmap/url_checker.rb +314 -0
  70. data/lib/wmap/url_crawler.rb +381 -0
  71. data/lib/wmap/utils/domain_root.rb +184 -0
  72. data/lib/wmap/utils/logger.rb +53 -0
  73. data/lib/wmap/utils/url_magic.rb +343 -0
  74. data/lib/wmap/utils/utils.rb +333 -0
  75. data/lib/wmap/whois.rb +76 -0
  76. data/lib/wmap.rb +227 -0
  77. data/logs/wmap.log +17 -0
  78. data/ruby_whois_patches/base_cocca2.rb +149 -0
  79. data/ruby_whois_patches/kero.yachay.pe.rb +120 -0
  80. data/ruby_whois_patches/whois.PublicDomainRegistry.com.rb +124 -0
  81. data/ruby_whois_patches/whois.above.com.rb +61 -0
  82. data/ruby_whois_patches/whois.adamsnames.tc.rb +107 -0
  83. data/ruby_whois_patches/whois.aeda.net.ae.rb +105 -0
  84. data/ruby_whois_patches/whois.ai.rb +112 -0
  85. data/ruby_whois_patches/whois.arnes.si.rb +121 -0
  86. data/ruby_whois_patches/whois.ascio.com.rb +91 -0
  87. data/ruby_whois_patches/whois.cnnic.cn.rb +123 -0
  88. data/ruby_whois_patches/whois.corporatedomains.com.rb +67 -0
  89. data/ruby_whois_patches/whois.crsnic.net.rb +108 -0
  90. data/ruby_whois_patches/whois.denic.de.rb +174 -0
  91. data/ruby_whois_patches/whois.dk-hostmaster.dk.rb +120 -0
  92. data/ruby_whois_patches/whois.dns.be.rb +134 -0
  93. data/ruby_whois_patches/whois.dns.lu.rb +129 -0
  94. data/ruby_whois_patches/whois.dns.pl.rb +150 -0
  95. data/ruby_whois_patches/whois.dns.pt.rb +119 -0
  96. data/ruby_whois_patches/whois.domain.kg.rb +126 -0
  97. data/ruby_whois_patches/whois.domainregistry.my.rb +123 -0
  98. data/ruby_whois_patches/whois.domreg.lt.rb +110 -0
  99. data/ruby_whois_patches/whois.dot.tk.rb +140 -0
  100. data/ruby_whois_patches/whois.hkirc.hk.rb +121 -0
  101. data/ruby_whois_patches/whois.isnic.is.rb +130 -0
  102. data/ruby_whois_patches/whois.je.rb +119 -0
  103. data/ruby_whois_patches/whois.jprs.jp.rb +137 -0
  104. data/ruby_whois_patches/whois.kenic.or.ke.rb +140 -0
  105. data/ruby_whois_patches/whois.markmonitor.com.rb +118 -0
  106. data/ruby_whois_patches/whois.melbourneit.com.rb +58 -0
  107. data/ruby_whois_patches/whois.nic.as.rb +96 -0
  108. data/ruby_whois_patches/whois.nic.at.rb +109 -0
  109. data/ruby_whois_patches/whois.nic.ch.rb +141 -0
  110. data/ruby_whois_patches/whois.nic.cl.rb +117 -0
  111. data/ruby_whois_patches/whois.nic.ec.rb +157 -0
  112. data/ruby_whois_patches/whois.nic.im.rb +120 -0
  113. data/ruby_whois_patches/whois.nic.it.rb +170 -0
  114. data/ruby_whois_patches/whois.nic.lv.rb +116 -0
  115. data/ruby_whois_patches/whois.nic.ly.rb +127 -0
  116. data/ruby_whois_patches/whois.nic.mu.rb +27 -0
  117. data/ruby_whois_patches/whois.nic.mx.rb +123 -0
  118. data/ruby_whois_patches/whois.nic.net.sa.rb +111 -0
  119. data/ruby_whois_patches/whois.nic.or.kr.rb +101 -0
  120. data/ruby_whois_patches/whois.nic.tel.rb +129 -0
  121. data/ruby_whois_patches/whois.nic.tr.rb +133 -0
  122. data/ruby_whois_patches/whois.nic.us.rb +129 -0
  123. data/ruby_whois_patches/whois.nic.ve.rb +135 -0
  124. data/ruby_whois_patches/whois.norid.no.rb +127 -0
  125. data/ruby_whois_patches/whois.pandi.or.id.rb +118 -0
  126. data/ruby_whois_patches/whois.psi-usa.info.rb +63 -0
  127. data/ruby_whois_patches/whois.registro.br.rb +109 -0
  128. data/ruby_whois_patches/whois.registrygate.com.rb +55 -0
  129. data/ruby_whois_patches/whois.rrpproxy.net.rb +61 -0
  130. data/ruby_whois_patches/whois.sgnic.sg.rb +130 -0
  131. data/ruby_whois_patches/whois.srs.net.nz.rb +166 -0
  132. data/ruby_whois_patches/whois.tucows.com.rb +70 -0
  133. data/ruby_whois_patches/whois.twnic.net.tw.rb +133 -0
  134. data/settings/discovery_ports +24 -0
  135. data/settings/google_keywords.txt +9 -0
  136. data/settings/google_locator.txt +23 -0
  137. data/test/domain_tracker_test.rb +31 -0
  138. data/test/utils_test.rb +168 -0
  139. data/version.txt +13 -0
  140. data/wmap.gemspec +49 -0
  141. metadata +202 -0
data/bin/wdel ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+ # Executable to delete a new site into the tracking data repository
3
+ # This is useful as a self-correction mechanism to flag out unique website in a constant way
4
+ require "wmap"
5
+
6
+ def print_usage
7
+ puts "Program to delete an entry from the local data repository. Usage: wdel [site]"
8
+ end
9
+
10
+ puts Wmap.banner
11
+ print_usage
12
+ Log_dir=File.dirname(__FILE__)+'/../logs/'
13
+ Wmap.wlog("Execute the command: wdel #{ARGV[0]}","wdel",Log_dir+"wmap.log")
14
+
15
+ st=Wmap::SiteTracker.instance
16
+ abort "Incorrect program argument!" unless ARGV.length==1
17
+
18
+ # Evaluate the argument and update the data store accordingly
19
+ if st.is_site?(ARGV[0])
20
+ st.delete(ARGV[0])
21
+ st.save!
22
+ st=nil
23
+ else
24
+ abort "Unknown argument format: #{ARGV[0]}"
25
+ end
data/bin/wdump ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ # Wmap data repository Dump - Dump out a list of unique websites stored in the current tracking data repository.
3
+ # Usage: wdump <output file>
4
+ require "wmap"
5
+
6
+ def print_usage
7
+ puts "Program to dump out unique website assets from the local repository. Usage: wdump <output file>"
8
+ end
9
+
10
+ puts Wmap.banner
11
+ Log_dir=File.dirname(__FILE__)+'/../logs/'
12
+ Wmap.wlog("Execute the command: wdump #{ARGV[0]}","wdump",Log_dir+"wmap.log")
13
+
14
+ unless ARGV.length==1
15
+ print_usage
16
+ abort "Program argument error. Please check your input and try again. "
17
+ end
18
+ # dump out the unique target list in .csv format
19
+ continue=Wmap.dump(ARGV[0]+".csv")
20
+ # continue to dump out the list in the .xml format if previous step is successful
21
+ Wmap.dump_xml(ARGV[0]+".xml") if continue
data/bin/wmap ADDED
@@ -0,0 +1,151 @@
1
+ #!/usr/bin/env ruby
2
+ # Wmap main executable - intelligent enough to handle most command argument inputs from the user.
3
+ # The discovery result is automatically compared and saved into the the tracking data repository.
4
+ #
5
+ # Usage: wmap <Target Host | URL | IP | CIDR | or a seed file with any of the above combo> <Optional Discovery Result Directory>
6
+ require "wmap"
7
+
8
+ def print_usage
9
+ abort "Program to perform website asset discovery and tracking. \nUsage: wmap <Target Host | URL | IP | CIDR | or a seed file with any of the above combo> <Optional Discovery Result Directory>"
10
+ end
11
+
12
+ # preparing - spit out the program banner
13
+ puts Wmap.banner
14
+ if ARGV.length == 1
15
+ # Log the command entry
16
+ Log_dir=File.dirname(__FILE__)+'/../logs/'
17
+ elsif ARGV.length == 2
18
+ # Log to the instance running directory
19
+ Log_dir=ARGV[1] + '/logs/'
20
+ Dir.mkdir(Log_dir) unless Dir.exist?(Log_dir)
21
+ end
22
+
23
+ Wmap.wlog("Execute the command: wmap #{ARGV[0]}","wmap",Log_dir+"wmap.log")
24
+ print_usage unless (ARGV.length==1 or ARGV.length==2)
25
+ urls = Array.new
26
+ # first step - construct the host list
27
+ scanner = Wmap::PortScanner.new(:verbose=>false, :socket_timeout=>600) # default time-out of 600 milliseconds
28
+ hosts=Array.new
29
+ if File.exist?(ARGV[0])
30
+ puts "Parsing the discovery seed file: \"#{ARGV[0]}\" "
31
+ seeds=scanner.file_2_list(ARGV[0])-[nil,""]
32
+ domains=Array.new
33
+ cidrs=Array.new
34
+ raise "Error: empty seed file or no legal entry found!" if seeds.nil? or seeds.empty?
35
+ seeds.map do |x|
36
+ x=x.split(%r{(,|\s+)})[0]
37
+ urls.push(x) if scanner.is_url?(x)
38
+ domains.push(x) if scanner.is_domain_root?(x) or Wmap.sub_domain_known?(x)
39
+ # invoke bruter if the hostname contains a numeric number.
40
+ domains.push(x) if scanner.is_fqdn?(x) and (x.split('.')[0] =~ /\d+/)
41
+ hosts.push(x) if scanner.is_fqdn?(x) or scanner.is_ip?(x)
42
+ cidrs.push(x) if scanner.is_cidr?(x)
43
+ end
44
+ puts "Parsing done. "
45
+ hosts+=Wmap::DnsBruter.new(:verbose=>false).dns_brute_workers(domains.uniq).values.flatten if domains.size > 0
46
+ cidrs.map { |x| hosts+= scanner.cidr_2_ips(x) } if cidrs.size > 0
47
+ elsif scanner.is_url?(ARGV[0])
48
+ puts "Processing the URL: #{ARGV[0]}"
49
+ urls.push(ARGV[0])
50
+ elsif Wmap.domain_known?(ARGV[0]) or Wmap.sub_domain_known?(ARGV[0])
51
+ puts "Processing the domain: #{ARGV[0]}"
52
+ hosts+=Wmap::DnsBruter.new(:verbose=>false).dns_brute_worker(ARGV[0]).values.flatten
53
+ elsif scanner.is_fqdn?(ARGV[0])
54
+ puts "Processing the host: #{ARGV[0]}"
55
+ hosts.push(ARGV[0])
56
+ my_hosts=Wmap::DnsBruter.new(:verbose=>false).dns_brute_worker(ARGV[0]).values.flatten if (ARGV[0].split('.')[0] =~ /\d+/)
57
+ hosts+=my_hosts unless my_hosts.nil?
58
+ elsif scanner.is_cidr?(ARGV[0])
59
+ puts "Processing the network block: #{ARGV[0]}"
60
+ hosts+=scanner.cidr_2_ips(ARGV[0])
61
+ elsif scanner.is_ip?(ARGV[0])
62
+ hosts.push(ARGV[0])
63
+ else
64
+ print_usage
65
+ end
66
+
67
+ # second step - update the hosts repository
68
+ if ARGV.length == 1
69
+ puts puts "Invoke the HostTracker."
70
+ host_tracker = Wmap::HostTracker.new(:verbose=>true)
71
+ elsif ARGV.length == 2
72
+ puts "Invoke the HostTracker with optional directory setter."
73
+ host_tracker = Wmap::HostTracker.new(:verbose=>true, :data_dir => ARGV[1])
74
+ else
75
+ aborts "Error firing up HostTracker instance!"
76
+ end
77
+ hosts.uniq!
78
+ if hosts.size > 0
79
+ hostnames=hosts.dup.delete_if { |h| host_tracker.is_ip?(h) }
80
+ if hostnames.size > 0
81
+ puts "Update the local hosts data repository."
82
+ new_hosts=host_tracker.adds(hostnames)
83
+ host_tracker.save! if new_hosts.size>0
84
+ end
85
+ end
86
+ host_tracker=nil
87
+
88
+ # third step - port discovery on the above host list, and to build the URL seeds
89
+ puts "Build up URL list for the web crawler ..."
90
+ urls0=scanner.scans(hosts)
91
+ urls+=urls0
92
+ urls.uniq!
93
+ scanner=nil
94
+
95
+ # fourth step - crawling on the URL seeds
96
+ if ARGV.length == 1
97
+ puts "Fire up the crawler."
98
+ crawler = Wmap::UrlCrawler.new(:verbose=>false)
99
+ elsif ARGV.length == 2
100
+ puts "Fire up the crawler with the optional directory setter."
101
+ crawler = Wmap::UrlCrawler.new(:data_dir => ARGV[1])
102
+ else
103
+ aborts "Error firing up UrlCrawler instance!"
104
+ end
105
+ Wmap.wlog(urls, "wmap", Log_dir+"url_seeds.log") if urls.size > 0 # save port scan results for debugging
106
+ crawler.crawls(urls) if urls.size>0
107
+ dis_urls=crawler.discovered_urls_by_crawler
108
+ #c_start=crawler.crawl_start
109
+ #c_done=crawler.crawl_done
110
+ dis_sites=Hash.new
111
+ unless dis_urls.empty?
112
+ dis_urls.keys.map do |url|
113
+ site=crawler.url_2_site(url)
114
+ dis_sites[site]=true unless dis_sites.key?(site)
115
+ end
116
+ end
117
+ puts "Discovered sites: "
118
+
119
+ if dis_sites.empty?
120
+ puts "No web site is discovered. "
121
+ else
122
+ dis_sites.keys.map {|x| puts x}
123
+ end
124
+
125
+ # fifth step - trace the discovery results into a local log file for debugging and other purposes
126
+ Wmap.wlog(dis_urls.keys, "wmap", Log_dir+"discovered_urls.log") unless dis_urls.empty?
127
+ Wmap.wlog(dis_sites.keys, "wmap", Log_dir+"discovered_sites.log") unless dis_sites.empty?
128
+ #crawler.wlog(c_start.keys,Log_dir+"crawler.log")
129
+ #crawler.wlog(c_done.keys,Log_dir+"crawler.log")
130
+ crawler=nil
131
+
132
+ # sixth step - save discovery results into the inventory data repository
133
+ case dis_sites.keys
134
+ when nil,[]
135
+ puts "No new site found. There is no change to the site tracking data repository. "
136
+ else
137
+ puts "Automatically save the discovery results into the site tracking data repository: "
138
+ if ARGV.length == 1
139
+ puts "Start the SiteTracker. "
140
+ inventory=Wmap::SiteTracker.new
141
+ elsif ARGV.length == 2
142
+ puts "Start the SiteTracker with the optional directory setter. "
143
+ inventory=Wmap::SiteTracker.new(:data_dir => ARGV[1])
144
+ else
145
+ aborts "Error firing up SiteTracker instance!"
146
+ end
147
+ new_sites=inventory.adds(dis_sites.keys)
148
+ inventory.save! if new_sites.size>0
149
+ inventory=nil
150
+ puts "Done! New found sites are successfully saved. " if new_sites.size > 0
151
+ end
data/bin/wscan ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+ # Executable to perform port scanning by using build-in tcp port scanner
3
+ # This is useful to detect the web service
4
+ require "wmap"
5
+
6
+ def print_usage
7
+ puts "Program to port scanning remote hops(s) or IP(s). Usage: wscan [IP | File with list of IPs]"
8
+ end
9
+
10
+ puts Wmap.banner
11
+ print_usage
12
+ Log_dir=File.dirname(__FILE__)+'/../logs/'
13
+ Wmap.wlog("Execute the command: wscan #{ARGV[0]}","wscan",Log_dir+"wmap.log")
14
+
15
+ sites=Array.new
16
+ ps=Wmap::PortScanner.new
17
+ abort "Incorrect program argument!" unless ARGV.length==1
18
+
19
+ # Evaluate the argument and update the data psore accordingly
20
+ if File.exist?(ARGV[0])
21
+ targets=ps.file_2_list(ARGV[0])
22
+ sites=ps.scans(targets)
23
+ elsif ps.is_ip?(ARGV[0]) or ps.is_fqdn?(ARGV[0])
24
+ sites=ps.scan(ARGV[0])
25
+ else
26
+ print_usage and abort "Unknown argument format: #{ARGV[0]}."
27
+ end
28
+ ps=nil
29
+ if sites.count>0
30
+ puts "Done. Discovered sites:"
31
+ sites.map {|x| puts x}
32
+ end
data/data/cidrs ADDED
@@ -0,0 +1,2 @@
1
+ # Local cidrs file created by Wmap::CidrTracker.save method at: 2015-07-07 12:23:56 -0400
2
+ Network CIDR, CIDR RIPE Reference Text, CIDR NETNAME
@@ -0,0 +1 @@
1
+ # Local site store created by class Wmap::SiteTracker::DeactivatedSite method save_sites_to_file! at: 2015-04-27 08:43:06 -0400
data/data/domains ADDED
@@ -0,0 +1,2 @@
1
+ # Local domains file created by class Wmap::DomainTracker method save_domains_to_file! at: 2015-07-07 12:24:49 -0400
2
+ # domain name, free zone transfer detected?
data/data/hosts ADDED
@@ -0,0 +1 @@
1
+ # local hosts file created by the Wmap::HostTracker class save_known_hosts_to_file! method at: 2015-04-21 08:59:33 -0400
data/data/prime_hosts ADDED
@@ -0,0 +1 @@
1
+ # local hosts file created by the Wmap::HostTracker::PrimaryHost class save_known_hosts_to_file! method at: 2015-07-07 12:25:34 -0400
data/data/sites ADDED
@@ -0,0 +1,2 @@
1
+ # Local site store created by class Wmap::SiteTracker method save_sites_to_file! at: 2015-04-22 14:03:45 -0400
2
+ # Website,Primary IP,Port,Hosting Status,Server,Response Code,Site MD5 Finger-print,Site Redirection,Timestamp
data/data/sub_domains ADDED
@@ -0,0 +1,2 @@
1
+ # Local domains file created by class Wmap::DomainTracker::SubDomain method save_sub_domains_to_file! at: 2018-01-08 10:18:24 -0500
2
+ # domain name, free zone transfer detected?
data/demos/bruter.rb ADDED
@@ -0,0 +1,27 @@
1
+ # Brute-forcing multiple domains at the same time, the purpose is to extract a valid host list
2
+ # Usage: ruby dns_brute.rb [file with list of domains]
3
+ require "wmap"
4
+
5
+ f_rpt=".rpt.txt"
6
+ # Step 1 - obtain list of domains to be brute-forced on
7
+ host_tracker=Wmap::HostTracker.new
8
+ root_domains=host_tracker.dump_root_domains
9
+ sub_domains=host_tracker.instance.dump_sub_domains
10
+ # Step 2 - multi-thread brute forcer works on known domains and sub-domains
11
+ k=Wmap::DnsBruter.new(:verbose=>true, :max_parallel=>50)
12
+ #hosts=k.dns_brute_file(ARGV[0])
13
+ results=k.dns_brute_workers(sub_domains+root_domains)
14
+ k=nil
15
+ #hosts=hosts1+hosts2
16
+ # Step 3 - save results to a local file for debugging
17
+ f=File.open(f_rpt,"w")
18
+ results.each_pair do |key,value|
19
+ f.write("#{value}\n")
20
+ end
21
+ f.close
22
+ puts "Brute force results are saved successfully: #{f_rpt}"
23
+
24
+ # Step 4 - now update the local hosts table accordingly
25
+ host_tracker.bulk_add(results.values.flatten)
26
+ host_tracker.instance.save!
27
+ host_tracker=nil
@@ -0,0 +1,28 @@
1
+ # Brute-forcing multiple domains at the same time, the purpose is to extract a valid host list
2
+ # Usage: ruby dns_brute.rb [file with list of domains]
3
+ require "wmap"
4
+
5
+ f_rpt=".rpt.txt"
6
+ # Step 1 - obtain list of domains to be brute-forced on
7
+ tracker=Wmap::HostTracker.new
8
+ root_domains=tracker.dump_root_domains
9
+ sub_domains=tracker.dump_sub_domains
10
+ # Step 2 - multi-thread brute forcer works on known domains and sub-domains
11
+ k=Wmap::DnsBruter.new(:verbose=>false, :max_parallel=>50)
12
+ #hosts=k.dns_brute_file(ARGV[0])
13
+ #hosts = k.dns_brute_domains(root_domains)
14
+ hosts=k.dns_brute_domains(sub_domains)
15
+ k=nil
16
+ #hosts=hosts1+hosts2
17
+ # Step 3 - save results to a local file for debugging
18
+ f=File.open(f_rpt,"w")
19
+ hosts.map do |x|
20
+ f.write("#{x}\n")
21
+ end
22
+ f.close
23
+ puts "Brute force results are saved successfully: #{f_rpt}"
24
+
25
+ # Step 4 - now update the local hosts table accordingly
26
+ tracker.bulk_add(hosts)
27
+ tracker.save!
28
+ tracker=nil
@@ -0,0 +1,18 @@
1
+ # Sample CIDR Tracker - Given a trusted IP, print out all tracked CIDR information
2
+ # Usage: ruby filter_cidr.rb [file_web_hosts]
3
+ require "wmap"
4
+
5
+ puts "IP, CIDR, CIDR Netname, CIDR Reference"
6
+ myDis = Wmap::CidrTracker.new(:verbose=>false)
7
+
8
+ f_ips = File.open(ARGV[0], 'r:iso-8859-1')
9
+ f_ips.each do |line|
10
+ ip=line.chomp.split(',')[1]
11
+ if myDis.is_ip?(ip)
12
+ tracker=myDis.track(ip)
13
+ puts "#{line.chomp},#{tracker['cidr']},#{tracker['netname']},#{tracker['ref']}"
14
+ else
15
+ puts "#{line.chomp},,,"
16
+ end
17
+ end
18
+ f_ips.close
@@ -0,0 +1,5 @@
1
+ require "wmap"
2
+
3
+ k=Wmap::UrlCrawler.new(:verbose=>true)
4
+ sites=k.crawls(k.file_2_list(ARGV[0]))
5
+ k.wlog(sites,".crawl_sites")
@@ -0,0 +1,25 @@
1
+ # Input file is a list of hosts or domains, output is a list of unknown hosts / domains
2
+ # Usage: ruby filter_domain_x.rb [file_host]
3
+ require "wmap"
4
+
5
+ puts Wmap.banner
6
+ puts "Host,Domain,IP,Trusted CIDR,Trusted CIDR Netname"
7
+ myD = Wmap::DomainTracker.new
8
+ f_urls = File.open(ARGV[0], 'r')
9
+ f_urls.each do |line|
10
+ url=line.chomp
11
+ host=myD.url_2_host(url)
12
+ next if host.nil?
13
+ domain=myD.domain_root(host)
14
+ next if domain.nil?
15
+ if myD.domain_known?(domain)
16
+ #puts url
17
+ next
18
+ else
19
+ #next
20
+ tracker=Wmap.track(host)
21
+ puts "#{host}, #{domain}, #{tracker['ip']}, #{tracker['cidr']}, #{tracker['netname']}"
22
+ end
23
+ end
24
+
25
+ f_urls.close
@@ -0,0 +1,26 @@
1
+ # Perform GEOIP info lookup, based on Maxmind GeoIP database
2
+ # Usage: ruby filter_geoip.rb [file_wdump_csv]
3
+ require "wmap"
4
+
5
+ verbose=false
6
+ tracker = Wmap::GeoIPTracker.new(:verbose=>false)
7
+
8
+ #puts "IP, GeoIP Location"
9
+ f_ips = File.open(ARGV[0], 'r')
10
+ f_ips.each do |line|
11
+ ip=line.chomp.split(',')[1]
12
+ info=String.new
13
+ if tracker.is_ip?(ip)
14
+ puts "IP: #{ip}" if verbose
15
+ ctr=tracker.country(ip)
16
+ info = info + " " + ctr.country_code3 unless ctr.country_code3.nil?
17
+ citi=tracker.city(ip)
18
+ info=info+" "+citi.region_name unless citi.nil? or citi.region_name.nil?
19
+ info=info+" "+citi.city_name unless citi.nil? or citi.city_name.nil?
20
+ info=info+" "+citi.postal_code unless citi.nil? or citi.postal_code.nil?
21
+ puts "#{line.chomp}, #{info}"
22
+ else
23
+ puts "#{line.chomp},"
24
+ end
25
+ end
26
+ f_ips.close
@@ -0,0 +1,59 @@
1
+ # Compare the scan lists and flag out the new site
2
+ # Usage: filter_known_@services.rb [last quarter list] [this quarter list]
3
+
4
+ require "wmap"
5
+
6
+
7
+ # Create a known service map by parsing last quarter scan list
8
+ def parse_old
9
+ host_tracker=Wmap::HostTracker.new
10
+ @services=Hash.new
11
+ f_site=File.open(ARGV[0],'r')
12
+ f_site.each do |line|
13
+ site=line.chomp.strip
14
+ site=host_tracker.url_2_site(site)
15
+ abort "Error on processing site: #{site}" if site.nil?
16
+ host=host_tracker.url_2_host(site)
17
+ abort "Error on processing host: #{host}" if host.nil?
18
+ ip=host_tracker.local_host_2_ip(host)
19
+ ip=host_tracker.host_2_ip(host) if ip.nil?
20
+ next if ip.nil?
21
+ next unless host_tracker.is_ip?(ip)
22
+ port=host_tracker.url_2_port(site)
23
+ key=ip+":"
24
+ key+=port.to_s
25
+ @services[key]=true unless @services.key?(key)
26
+ end
27
+ f_site.close
28
+ host_tracker=nil
29
+ end
30
+
31
+ # Go through the new scan list and look up for known service from last quarter
32
+ def diff
33
+ host_tracker=Wmap::HostTracker.new
34
+ f_new = File.open(ARGV[1],'r')
35
+ f_new.each do |line|
36
+ site=line.chomp.strip
37
+ site1=host_tracker.url_2_site(site)
38
+ abort "Error on processing site: #{site}" if site1.nil?
39
+ host=host_tracker.url_2_host(site1)
40
+ abort "Error on processing host: #{host}" if host.nil?
41
+ ip=host_tracker.local_host_2_ip(host)
42
+ ip=host_tracker.host_2_ip(host) if ip.nil?
43
+ abort "Error resolve host: #{host}" if ip.nil?
44
+ port=host_tracker.url_2_port(site1)
45
+ abort "Error retrieve service port on site: #{site}" if port.nil?
46
+ key=ip+":"
47
+ key+=port.to_s
48
+ if @services.key?(key)
49
+ puts "No"
50
+ else
51
+ puts "Yes"
52
+ end
53
+ end
54
+ f_new.close
55
+ host_tracker=nil
56
+ end
57
+
58
+ parse_old
59
+ diff
@@ -0,0 +1,23 @@
1
+ # Exact netname and description from the whois query on an IP
2
+ # Usage: ruby filter_netinfo.rb [file_ip]
3
+ require "wmap"
4
+
5
+
6
+ puts Wmap.banner
7
+ whois = Wmap::Whois.new(:verbose=>false)
8
+ #tracker = Wmap::CidrTracker.new
9
+
10
+ #puts "IP ; Netname ; Net Reference"
11
+ f_ips = File.open(ARGV[0], 'r:iso-8859-1')
12
+ f_ips.each do |line|
13
+ ip=line.chomp.split(',')[1]
14
+ if whois.is_ip?(ip) or whois.is_cidr?(ip)
15
+ netname=whois.get_netname(ip)
16
+ desc=whois.get_net_desc(ip)
17
+ #tr=tracker.track(ip)
18
+ puts "#{line.chomp};#{netname};#{desc}"
19
+ else
20
+ puts "#{line.chomp};;"
21
+ end
22
+ end
23
+ f_ips.close
@@ -0,0 +1,25 @@
1
+ # Replace the embedded hostname within the url, based on the prime host table
2
+ # Usage: ruby filter_prime.rb [file_host]
3
+ require "wmap"
4
+
5
+ puts "URL | Prime URL"
6
+ my_tracker=Wmap::HostTracker::PrimaryHost.new
7
+ f_urls = File.open(ARGV[0], 'r')
8
+ f_urls.each do |line|
9
+ url=line.chomp
10
+ if my_tracker.is_url?(url)
11
+ host=my_tracker.url_2_host(url)
12
+ ip=my_tracker.host_2_ip(host)
13
+ if my_tracker.ip_known?(ip)
14
+ p_host=my_tracker.local_ip_2_host(ip)
15
+ url_new=url.sub(host,p_host)
16
+ else
17
+ url_new=url
18
+ end
19
+ puts "#{url} | #{url_new}"
20
+ else
21
+ puts "#{url} | #{url}"
22
+ end
23
+ end
24
+ f_urls.close
25
+ my_tracker=nil
@@ -0,0 +1,3 @@
1
+ require "wmap"
2
+ k=Wmap::NetworkProfiler.new(:verbose=>true)
3
+ k.profile(ARGV[0])
@@ -0,0 +1,19 @@
1
+ # Internet domain fingerprint technique - print the redirection location if any
2
+ # Usage: ruby filter_redirection.rb [file_urls]
3
+ require "wmap"
4
+
5
+ puts "List of URLs with Redirection:"
6
+ puts "URL, Reponse Code, Redirection Location"
7
+ myDis = Wmap::UrlChecker.new
8
+ myDis.http_timeout=5000
9
+ f_urls = File.open(ARGV[0], 'r')
10
+ f_urls.each do |line|
11
+ url=line.chomp
12
+ host=myDis.url_2_host(url)
13
+ code=myDis.response_code(url)
14
+ if code >= 300 && code < 400
15
+ location=myDis.redirect_location(url)
16
+ end
17
+ puts "#{url}, #{code}, #{location}"
18
+ end
19
+ f_urls.close
@@ -0,0 +1,40 @@
1
+ # filter to select findings for the list of sites
2
+ # Usage: ruby filter_site.rb [file targets] [file finding keys]
3
+ # Input A is a list of target sites, input B is a list of site index keys for the finding summary
4
+ # Output is a list of key for the matching purpose
5
+
6
+ require "wmap"
7
+ @map=Hash.new
8
+
9
+ def build_map (file)
10
+ k=Wmap::SiteTracker.new
11
+ f=File.open(file,'r')
12
+ f.each do |line|
13
+ url=line.chomp.strip.downcase
14
+ if k.is_url?(url)
15
+ @map[k.url_2_site(url)]=true
16
+ else
17
+ #puts url
18
+ end
19
+ end
20
+ f.close
21
+ k=nil
22
+ end
23
+
24
+
25
+ build_map(ARGV[0])
26
+ s=Wmap::SiteTracker.new
27
+ f=File.open(ARGV[1],'r')
28
+ f.each do |line|
29
+ url=line.chomp.strip.downcase
30
+ if s.is_url?(url)
31
+ site=s.url_2_site(url)
32
+ if @map.key?(site)
33
+ puts "yes"
34
+ else
35
+ puts "no"
36
+ end
37
+ else
38
+ puts "Invalid Internet URL"
39
+ end
40
+ end
@@ -0,0 +1,31 @@
1
+ # Sample Site IP Tracker - Given a IP, flag it if not found in the site data repository
2
+ # Usage: ruby filter_siteip.rb [file_web_hosts]
3
+ require "wmap"
4
+
5
+ def known?(ip)
6
+ ip=ip.chomp.strip
7
+ myDis = Wmap::SiteTracker.new
8
+ known=false
9
+ if myDis.is_ip?(ip)
10
+ if myDis.siteip_known?(ip)
11
+ myDis=nil
12
+ return true
13
+ end
14
+ end
15
+ myDis=nil
16
+ return known
17
+ end
18
+
19
+ puts "Site IP, Status"
20
+
21
+
22
+ f_ips = File.open(ARGV[0], 'r')
23
+ f_ips.each do |line|
24
+ ip=line.chomp.strip
25
+ if known?(ip)
26
+ # do nothing
27
+ else
28
+ puts "#{ip}, unknown"
29
+ end
30
+ end
31
+ f_ips.close
@@ -0,0 +1,17 @@
1
+ # Print the URL of a site if it response to the HTTP request
2
+ # Usage: ruby filter_status.rb [file_url_links]
3
+ require "wmap"
4
+
5
+ puts "List of URLs with the Valid Response Code:"
6
+ puts "URL, Reponse Code, URL Finger Print, IP, Trusted CIDR, Trusted CIDR Netname"
7
+ myDis = Wmap::UrlChecker.new(:verbose=>false, :http_timeout=>5000)
8
+
9
+ f_urls = File.open(ARGV[0], 'r')
10
+ f_urls.each do |line|
11
+ next if url.nil?
12
+ checker=myDis.check(url)
13
+ host=line.chomp
14
+ tracker=Wmap.track(host)
15
+ puts "#{url}, #{checker['code']}, #{checker['md5']}, #{tracker['ip']}, #{tracker['cidr']}, #{tracker['netname']}"
16
+ end
17
+ f_urls.close
@@ -0,0 +1,23 @@
1
+ # print out the timestamp for the sites
2
+ # Usage: ruby filter_timestamp.rb [file_sites]
3
+ require "wmap"
4
+
5
+ tracker = Wmap::SiteTracker.instance
6
+
7
+ puts "Site | Timestamp"
8
+ f_urls = File.open(ARGV[0], 'r')
9
+ f_urls.each do |line|
10
+ url=line.chomp
11
+ if tracker.is_url?(url)
12
+ site=tracker.url_2_site(url)
13
+ if tracker.site_known?(site)
14
+ ts=tracker.known_sites[site]['timestamp']
15
+ puts "#{site}|#{ts}"
16
+ else
17
+ puts site
18
+ end
19
+ else
20
+ puts url
21
+ end
22
+ end
23
+ f_urls.close
@@ -0,0 +1,19 @@
1
+ # filter to detect unknown internet domain
2
+ # Input is a list of URLs
3
+ # Output is an internet domain list that not currently tracked by the domain tracker
4
+
5
+ require "wmap"
6
+
7
+ k=Wmap::DomainTracker.new
8
+ #k.verbose=true
9
+ f=File.open(ARGV[0],'r')
10
+ f.each do |line|
11
+ url=line.chomp.strip.downcase
12
+ host=k.url_2_host(url)
13
+ root=k.get_domain_root(host)
14
+ unless k.domain_known?(root)
15
+ puts root
16
+ end
17
+ end
18
+ f.close
19
+ k=nil