| 155 | |
| 156 | |
| 157 | def nmap_sig(target, oport=80, cport=81, ucport=1): |
| 158 | # type: (str, int, int, int) -> Dict |
| 159 | res = {} |
| 160 | |
| 161 | tcpopt = [("WScale", 10), |
| 162 | ("NOP", None), |
| 163 | ("MSS", 256), |
| 164 | ("Timestamp", (123, 0))] |
| 165 | tests = [ |
| 166 | IP(dst=target, id=1) / |
| 167 | TCP(seq=1, sport=5001 + i, dport=oport if i < 4 else cport, |
| 168 | options=tcpopt, flags=flags) |
| 169 | for i, flags in enumerate(["CS", "", "SFUP", "A", "S", "A", "FPU"]) |
| 170 | ] |
| 171 | tests.append(IP(dst=target) / UDP(sport=5008, dport=ucport) / (300 * "i")) |
| 172 | |
| 173 | ans, unans = sr(tests, timeout=2) |
| 174 | ans.extend((x, None) for x in unans) |
| 175 | |
| 176 | for snd, rcv in ans: |
| 177 | if snd.sport == 5008: |
| 178 | res["PU"] = (snd, rcv) |
| 179 | else: |
| 180 | test = "T%i" % (snd.sport - 5000) |
| 181 | if rcv is not None and ICMP in rcv: |
| 182 | warning("Test %s answered by an ICMP", test) |
| 183 | rcv = None # type: ignore |
| 184 | res[test] = rcv |
| 185 | |
| 186 | return nmap_probes2sig(res) |
| 187 | |
| 188 | |
| 189 | def nmap_probes2sig(tests): |