|
123 | 123 |
|
124 | 124 | expect(result.host_results.first.up).to be(false) |
125 | 125 | end |
| 126 | + |
| 127 | + { |
| 128 | + syn: { tcp_reply: { reply: :syn_ack, window: 0 }, expected_state: :open }, |
| 129 | + ack: { tcp_reply: { reply: :rst, window: 0 }, expected_state: :unfiltered }, |
| 130 | + fin: { tcp_reply: { reply: :timeout, window: 0 }, expected_state: :open_filtered }, |
| 131 | + null: { tcp_reply: { reply: :rst, window: 0 }, expected_state: :closed }, |
| 132 | + xmas: { tcp_reply: { reply: :timeout, window: 0 }, expected_state: :open_filtered }, |
| 133 | + window: { tcp_reply: { reply: :rst, window: 1024 }, expected_state: :open }, |
| 134 | + maimon: { tcp_reply: { reply: :timeout, window: 0 }, expected_state: :open_filtered } |
| 135 | + }.each do |scan_type, config| |
| 136 | + it "runs #{scan_type} through the scan engine with #{config[:expected_state]} semantics" do |
| 137 | + typed_tcp_prober = instance_double( |
| 138 | + ASRFacet::Scanner::Probes::TCPProber, |
| 139 | + send_probe: config[:tcp_reply], |
| 140 | + fingerprint: { ttl: 64, window: 29_200, tcp_options: %i[mss sack timestamp], ip_id_sequence: [1, 2, 3], rst_behavior: :rst } |
| 141 | + ) |
| 142 | + |
| 143 | + result = described_class.new( |
| 144 | + scan_type: scan_type, |
| 145 | + timing: 3, |
| 146 | + verbosity: 0, |
| 147 | + version_detection: false, |
| 148 | + os_detection: false, |
| 149 | + version_intensity: 7, |
| 150 | + ports: "80", |
| 151 | + logger: logger, |
| 152 | + probe_db: probe_db, |
| 153 | + tcp_prober: typed_tcp_prober, |
| 154 | + udp_prober: udp_prober, |
| 155 | + icmp_prober: icmp_prober |
| 156 | + ).scan("example.com") |
| 157 | + |
| 158 | + expect(result.host_results.first.ports.first.state).to eq(config[:expected_state]) |
| 159 | + end |
| 160 | + end |
| 161 | + |
| 162 | + it "runs a UDP scan through the scan engine with UDP semantics" do |
| 163 | + typed_udp_prober = instance_double(ASRFacet::Scanner::Probes::UDPProber, send_probe: { reply: :icmp_port_unreachable, data: nil }) |
| 164 | + |
| 165 | + result = described_class.new( |
| 166 | + scan_type: :udp, |
| 167 | + timing: 3, |
| 168 | + verbosity: 0, |
| 169 | + version_detection: false, |
| 170 | + os_detection: false, |
| 171 | + version_intensity: 7, |
| 172 | + ports: "53", |
| 173 | + logger: logger, |
| 174 | + probe_db: probe_db, |
| 175 | + tcp_prober: tcp_prober, |
| 176 | + udp_prober: typed_udp_prober, |
| 177 | + icmp_prober: icmp_prober |
| 178 | + ).scan("example.com") |
| 179 | + |
| 180 | + expect(result.host_results.first.ports.first.state).to eq(:closed) |
| 181 | + expect(result.host_results.first.ports.first.proto).to eq(:udp) |
| 182 | + end |
| 183 | + |
| 184 | + it "runs a ping scan through the scan engine as host discovery" do |
| 185 | + result = described_class.new( |
| 186 | + scan_type: :ping, |
| 187 | + timing: 3, |
| 188 | + verbosity: 0, |
| 189 | + version_detection: false, |
| 190 | + os_detection: false, |
| 191 | + version_intensity: 7, |
| 192 | + ports: "80", |
| 193 | + logger: logger, |
| 194 | + probe_db: probe_db, |
| 195 | + tcp_prober: tcp_prober, |
| 196 | + udp_prober: udp_prober, |
| 197 | + icmp_prober: icmp_prober |
| 198 | + ).scan("example.com") |
| 199 | + |
| 200 | + host = result.host_results.first |
| 201 | + expect(host.up).to be(true) |
| 202 | + expect(host.ports.first.port).to eq(0) |
| 203 | + expect(host.ports.first.proto).to eq(:icmp) |
| 204 | + expect(host.ports.first.state).to eq(:open) |
| 205 | + end |
126 | 206 | end |
0 commit comments