Skip to content

A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol

10.6 KB
Raw Blame
#pragma once
#include <stdint.h>

#define TOP_100_TCP_PORTS {7,9,13,21,22,23,25,26,37,53,79,80,81,88,106,110,111,113,119,135,139,143,144,179,199,389,427,443,444,445,465,513,514,515,543,544,548,554,587,631,646,873,990,993,995,1025,1026,1027,1028,1029,1110,1433,1720,1723,1755,1900,2000,2001,2049,2121,2717,3000,3128,3306,3389,3986,4899,5000,5009,5051,5060,5101,5190,5357,5432,5631,5666,5800,5900,6000,6001,6646,7070,8000,8008,8009,8080,8081,8443,8888,9100,9999,10000,32768,49152,49153,49154,49155,49156,49157};
#define TOP_100_UDP_PORTS {7,9,17,19,49,53,67,68,69,80,88,111,120,123,135,136,137,138,139,158,161,162,177,427,443,445,497,500,514,515,518,520,593,623,626,631,996,997,998,999,1022,1023,1025,1026,1027,1028,1029,1030,1433,1434,1645,1646,1701,1718,1719,1812,1813,1900,2000,2048,2049,2222,2223,3283,3456,3703,4444,4500,5000,5060,5353,5632,9200,10000,17185,20031,30718,31337,32768,32769,32771,32815,33281,49152,49153,49154,49156,49181,49182,49185,49186,49188,49190,49191,49192,49193,49194,49200,49201,65024};

enum nmap_rc_enum
{
    OTHER = -1,
    TCP_OPEN = 0,
    TCP_CLOSED = 1,
    TCP_FILTERED = 2,
    UDP_OPEN = 10,
    UDP_CLOSED = 11,
    UDP_OPEN_FILTERED = 12
};

struct NmapOptions {
    bool tcp = true;        // -t sets TCP only (default)
    bool udp = false;       // -u sets UDP only
    int verbosity = 0;      // -v/-vv
    bool hasPort = false;   // Did user pass `-p` ?
    std::string ports;      // "80", "22,80-90"
    bool hasTrash = false;  // Did user pass non-option tokens?
    bool help = false;      // -h or --help
    bool pingOnly = false;  // -sn
};

enum class Layer4Protocol
{
    TCP,
    UDP
};

struct PortService {
    uint16_t   port;
    Layer4Protocol proto;
    const char* service;   // nullptr when unknown/ambiguous
};


static const int CONNECT_TIMEOUT_MS = 600;
static const int SMALL_DELAY_MS = 5;

static constexpr PortService TOP100_TCP_MAP[] = {
    {7,    Layer4Protocol::TCP, "echo"},
    {9,    Layer4Protocol::TCP, "discard"},
    {13,   Layer4Protocol::TCP, "daytime"},
    {21,   Layer4Protocol::TCP, "ftp"},
    {22,   Layer4Protocol::TCP, "ssh"},
    {23,   Layer4Protocol::TCP, "telnet"},
    {25,   Layer4Protocol::TCP, "smtp"},
    {26,   Layer4Protocol::TCP, "rsftp"},
    {37,   Layer4Protocol::TCP, "time"},
    {53,   Layer4Protocol::TCP, "domain"},
    {79,   Layer4Protocol::TCP, "finger"},
    {80,   Layer4Protocol::TCP, "http"},
    {81,   Layer4Protocol::TCP, "hosts2-ns"},
    {88,   Layer4Protocol::TCP, "kerberos-sec"},
    {106,  Layer4Protocol::TCP, "poppassd"},
    {110,  Layer4Protocol::TCP, "pop3"},
    {111,  Layer4Protocol::TCP, "rpcbind"},
    {113,  Layer4Protocol::TCP, "ident"},
    {119,  Layer4Protocol::TCP, "nntp"},
    {135,  Layer4Protocol::TCP, "msrpc"},
    {139,  Layer4Protocol::TCP, "netbios-ssn"},
    {143,  Layer4Protocol::TCP, "imap"},
    {144,  Layer4Protocol::TCP, "news"},
    {179,  Layer4Protocol::TCP, "bgp"},
    {199,  Layer4Protocol::TCP, "smux"},
    {389,  Layer4Protocol::TCP, "ldap"},
    {427,  Layer4Protocol::TCP, "slp"},
    {443,  Layer4Protocol::TCP, "https"},
    {444,  Layer4Protocol::TCP, "snpp"},
    {445,  Layer4Protocol::TCP, "microsoft-ds"},
    {465,  Layer4Protocol::TCP, "smtps"},
    {513,  Layer4Protocol::TCP, "rlogin"},
    {514,  Layer4Protocol::TCP, "shell"},
    {515,  Layer4Protocol::TCP, "printer"},
    {543,  Layer4Protocol::TCP, "klogin"},
    {544,  Layer4Protocol::TCP, "kshell"},
    {548,  Layer4Protocol::TCP, "afp"},
    {554,  Layer4Protocol::TCP, "rtsp"},
    {587,  Layer4Protocol::TCP, "submission"},
    {631,  Layer4Protocol::TCP, "ipp"},
    {646,  Layer4Protocol::TCP, "ldp"},
    {873,  Layer4Protocol::TCP, "rsync"},
    {990,  Layer4Protocol::TCP, "ftps"},
    {993,  Layer4Protocol::TCP, "imaps"},
    {995,  Layer4Protocol::TCP, "pop3s"},
    {1025, Layer4Protocol::TCP, "NFS-or-IIS"},
    {1026, Layer4Protocol::TCP, "LSA-or-nterm"},
    {1027, Layer4Protocol::TCP, "IIS"},
    {1028, Layer4Protocol::TCP, "ms-lsa"},
    {1029, Layer4Protocol::TCP, "solid-mux"},
    {1110, Layer4Protocol::TCP, "nfsd-status"},
    {1433, Layer4Protocol::TCP, "ms-sql-s"},
    {1720, Layer4Protocol::TCP, "h323q931"},
    {1723, Layer4Protocol::TCP, "pptp"},
    {1755, Layer4Protocol::TCP, "mms"},
    {1900, Layer4Protocol::TCP, "upnp"},
    {2000, Layer4Protocol::TCP, "cisco-sccp"},
    {2001, Layer4Protocol::TCP, "dc"},
    {2049, Layer4Protocol::TCP, "nfs"},
    {2121, Layer4Protocol::TCP, "ftp"},
    {2717, Layer4Protocol::TCP, nullptr},
    {3000, Layer4Protocol::TCP, nullptr},
    {3128, Layer4Protocol::TCP, "http-proxy"},
    {3306, Layer4Protocol::TCP, "mysql"},
    {3389, Layer4Protocol::TCP, "ms-wbt-server"},
    {3986, Layer4Protocol::TCP, "mapper-ws-ethd"},
    {4899, Layer4Protocol::TCP, "radmin"},
    {5000, Layer4Protocol::TCP, "upnp"},
    {5009, Layer4Protocol::TCP, "airport-admin"},
    {5051, Layer4Protocol::TCP, "ida-agent"},
    {5060, Layer4Protocol::TCP, "sip"},
    {5101, Layer4Protocol::TCP, "admdog"},
    {5190, Layer4Protocol::TCP, "aol"},
    {5357, Layer4Protocol::TCP, "wsdapi"},
    {5432, Layer4Protocol::TCP, "postgresql"},
    {5631, Layer4Protocol::TCP, "pcanywheredata"},
    {5666, Layer4Protocol::TCP, "nrpe"},
    {5800, Layer4Protocol::TCP, "vnc-http"},
    {5900, Layer4Protocol::TCP, "rfb"},
    {6000, Layer4Protocol::TCP, "x11"},
    {6001, Layer4Protocol::TCP, "x11-1"},
    {6646, Layer4Protocol::TCP, nullptr},
    {7070, Layer4Protocol::TCP, "realserver"},
    {8000, Layer4Protocol::TCP, "http-alt"},
    {8008, Layer4Protocol::TCP, "http-alt"},
    {8009, Layer4Protocol::TCP, "ajp13"},
    {8080, Layer4Protocol::TCP, "http-proxy"},
    {8081, Layer4Protocol::TCP, "http-alt"},
    {8443, Layer4Protocol::TCP, "https-alt"},
    {8888, Layer4Protocol::TCP, "http-alt"},
    {9100, Layer4Protocol::TCP, "jetdirect"},
    {9999, Layer4Protocol::TCP, "abyss"},
    {10000,Layer4Protocol::TCP, "webmin"},
    {32768,Layer4Protocol::TCP, nullptr},
    {49152,Layer4Protocol::TCP, "msrpc"},
    {49153,Layer4Protocol::TCP, "msrpc"},
    {49154,Layer4Protocol::TCP, "msrpc"},
    {49155,Layer4Protocol::TCP, "msrpc"},
    {49156,Layer4Protocol::TCP, "msrpc"},
    {49157,Layer4Protocol::TCP, "msrpc"},
};
static constexpr size_t TOP100_TCP_MAP_COUNT = sizeof(TOP100_TCP_MAP)/sizeof(TOP100_TCP_MAP[0]);

static constexpr PortService TOP100_UDP_MAP[] = {
    {7,     Layer4Protocol::UDP, "echo"},
    {9,     Layer4Protocol::UDP, "discard"},
    {17,    Layer4Protocol::UDP, "qotd"},
    {19,    Layer4Protocol::UDP, "chargen"},
    {49,    Layer4Protocol::UDP, "tacacs"},
    {53,    Layer4Protocol::UDP, "domain"},
    {67,    Layer4Protocol::UDP, "bootps"},
    {68,    Layer4Protocol::UDP, "bootpc"},
    {69,    Layer4Protocol::UDP, "tftp"},
    {80,    Layer4Protocol::UDP, nullptr},
    {88,    Layer4Protocol::UDP, "kerberos-sec"},
    {111,   Layer4Protocol::UDP, "rpcbind"},
    {120,   Layer4Protocol::UDP, "cfdp"},
    {123,   Layer4Protocol::UDP, "ntp"},
    {135,   Layer4Protocol::UDP, "msrpc"},
    {136,   Layer4Protocol::UDP, "profile"},
    {137,   Layer4Protocol::UDP, "netbios-ns"},
    {138,   Layer4Protocol::UDP, "netbios-dgm"},
    {139,   Layer4Protocol::UDP, nullptr},
    {158,   Layer4Protocol::UDP, "pcmail-srv"},
    {161,   Layer4Protocol::UDP, "snmp"},
    {162,   Layer4Protocol::UDP, "snmptrap"},
    {177,   Layer4Protocol::UDP, "xdmcp"},
    {427,   Layer4Protocol::UDP, "slp"},
    {443,   Layer4Protocol::UDP, "quic"},
    {445,   Layer4Protocol::UDP, "microsoft-ds"},
    {497,   Layer4Protocol::UDP, "retrospect"},
    {500,   Layer4Protocol::UDP, "isakmp"},
    {514,   Layer4Protocol::UDP, "syslog"},
    {515,   Layer4Protocol::UDP, "printer"},
    {518,   Layer4Protocol::UDP, "ntalk"},
    {520,   Layer4Protocol::UDP, "rip"},
    {593,   Layer4Protocol::UDP, "http-rpc-epmap"},
    {623,   Layer4Protocol::UDP, "ipmi-rmcp"},
    {626,   Layer4Protocol::UDP, nullptr},
    {631,   Layer4Protocol::UDP, "ipp"},
    {996,   Layer4Protocol::UDP, nullptr},
    {997,   Layer4Protocol::UDP, nullptr},
    {998,   Layer4Protocol::UDP, nullptr},
    {999,   Layer4Protocol::UDP, nullptr},
    {1022,  Layer4Protocol::UDP, nullptr},
    {1023,  Layer4Protocol::UDP, nullptr},
    {1025,  Layer4Protocol::UDP, nullptr},
    {1026,  Layer4Protocol::UDP, nullptr},
    {1027,  Layer4Protocol::UDP, nullptr},
    {1028,  Layer4Protocol::UDP, nullptr},
    {1029,  Layer4Protocol::UDP, nullptr},
    {1030,  Layer4Protocol::UDP, nullptr},
    {1433,  Layer4Protocol::UDP, nullptr},
    {1434,  Layer4Protocol::UDP, "ms-sql-m"},
    {1645,  Layer4Protocol::UDP, "radius-old"},
    {1646,  Layer4Protocol::UDP, "radius-acct-old"},
    {1701,  Layer4Protocol::UDP, "l2tp"},
    {1718,  Layer4Protocol::UDP, "h323gatedisc"},
    {1719,  Layer4Protocol::UDP, "h323gatestat"},
    {1812,  Layer4Protocol::UDP, "radius"},
    {1813,  Layer4Protocol::UDP, "radius-acct"},
    {1900,  Layer4Protocol::UDP, "upnp"},
    {2000,  Layer4Protocol::UDP, "cisco-sccp"},
    {2048,  Layer4Protocol::UDP, "dls-monitor"},
    {2049,  Layer4Protocol::UDP, "nfs"},
    {2222,  Layer4Protocol::UDP, nullptr},
    {2223,  Layer4Protocol::UDP, nullptr},
    {3283,  Layer4Protocol::UDP, "net-assistant"},
    {3456,  Layer4Protocol::UDP, nullptr},
    {3703,  Layer4Protocol::UDP, nullptr},
    {4444,  Layer4Protocol::UDP, "krb524"},
    {4500,  Layer4Protocol::UDP, "ipsec-nat-t"},
    {5000,  Layer4Protocol::UDP, "upnp"},
    {5060,  Layer4Protocol::UDP, "sip"},
    {5353,  Layer4Protocol::UDP, "mdns"},
    {5632,  Layer4Protocol::UDP, "pcanywherestat"},
    {9200,  Layer4Protocol::UDP, nullptr},
    {10000, Layer4Protocol::UDP, nullptr},
    {17185, Layer4Protocol::UDP, nullptr},
    {20031, Layer4Protocol::UDP, nullptr},
    {30718, Layer4Protocol::UDP, nullptr},
    {31337, Layer4Protocol::UDP, "backorifice"},
    {32768, Layer4Protocol::UDP, "sunrpc"},
    {32769, Layer4Protocol::UDP, "sunrpc"},
    {32771, Layer4Protocol::UDP, "sunrpc"},
    {32815, Layer4Protocol::UDP, nullptr},
    {33281, Layer4Protocol::UDP, nullptr},
    {49152, Layer4Protocol::UDP, nullptr},
    {49153, Layer4Protocol::UDP, nullptr},
    {49154, Layer4Protocol::UDP, nullptr},
    {49156, Layer4Protocol::UDP, nullptr},
    {49181, Layer4Protocol::UDP, nullptr},
    {49182, Layer4Protocol::UDP, nullptr},
    {49185, Layer4Protocol::UDP, nullptr},
    {49186, Layer4Protocol::UDP, nullptr},
    {49188, Layer4Protocol::UDP, nullptr},
    {49190, Layer4Protocol::UDP, nullptr},
    {49191, Layer4Protocol::UDP, nullptr},
    {49192, Layer4Protocol::UDP, nullptr},
    {49193, Layer4Protocol::UDP, nullptr},
    {49194, Layer4Protocol::UDP, nullptr},
    {49200, Layer4Protocol::UDP, nullptr},
    {49201, Layer4Protocol::UDP, nullptr},
    {65024, Layer4Protocol::UDP, nullptr},
};
static constexpr size_t TOP100_UDP_MAP_COUNT = sizeof(TOP100_UDP_MAP)/sizeof(TOP100_UDP_MAP[0]);