diff --git a/cmds/exp/tcpdump/gen.go b/cmds/exp/tcpdump/gen.go new file mode 100644 index 0000000000..be79d8b726 --- /dev/null +++ b/cmds/exp/tcpdump/gen.go @@ -0,0 +1,63 @@ +// Copyright 2024 the u-root Authors. All rights reserved +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build ignore + +package main + +import ( + "log" + "os" + "os/exec" + "regexp" + "strings" +) + +func main() { + data, err := os.ReadFile("/etc/services") + if err != nil { + log.Fatalf("Error opening /etc/services: %v", err) + } + + re := regexp.MustCompile(`^(\S+)\s+(\d+)/\S+`) + + ports := make(map[string]string) + + for _, line := range strings.Split(string(data), "\n") { + if strings.HasPrefix(line, "#") || len(strings.TrimSpace(line)) == 0 { + continue + } + matches := re.FindStringSubmatch(line) + if len(matches) == 3 { + service := matches[1] + port := matches[2] + ports[port] = service + } + } + + // Generate the content for the Go file + content := `// Copyright 2024 the u-root Authors. All rights reserved +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +var wellKnownPortsMap = map[string]string{ +` + + // Append the ports to the content + for port, service := range ports { + content += `"` + port + `":"` + service + `",` + "\n" + } + content += "}" + + // Write the content to the Go file + if err := os.WriteFile("well_known_ports.go", []byte(content), 0644); err != nil { + log.Fatalf("Error writing file: %v", err) + } + + if err := exec.Command("gofmt", "-w", "well_known_ports.go").Run(); err != nil { + log.Fatalf("Error running gofmt: %v", err) + } +} diff --git a/cmds/exp/tcpdump/util.go b/cmds/exp/tcpdump/util.go index ecd61294ae..bd80f360b7 100644 --- a/cmds/exp/tcpdump/util.go +++ b/cmds/exp/tcpdump/util.go @@ -11,27 +11,7 @@ import ( "github.com/vishvananda/netlink" ) -var wellKnownPortsMap = map[string]string{ - "20": "ftp-data", - "21": "ftp", - "22": "ssh-scp", - "23": "telnet", - "25": "smtp", - "53": "domain", - "80": "http", - "88": "kerberos", - "110": "pop3", - "119": "nntp", - "123": "ntp", - "143": "imap", - "443": "https", - "465": "smtps", - "563": "nntps", - "989": "ftps-data", - "990": "ftps", - "993": "imaps", - "995": "pop3s", -} +//go:generate go run gen.go // wellKnownPorts returns the well-known name of the port or the port number itself. func (cmd cmd) wellKnownPorts(port string) string { diff --git a/cmds/exp/tcpdump/util_test.go b/cmds/exp/tcpdump/util_test.go index 906e760881..7d37b839be 100644 --- a/cmds/exp/tcpdump/util_test.go +++ b/cmds/exp/tcpdump/util_test.go @@ -44,8 +44,8 @@ func TestWellKnownPorts(t *testing.T) { { name: "Unknown port without numerical", cmd: cmd{Opts: flags{Numerical: false}}, - port: "8080", - expected: "8080", + port: "666", + expected: "666", }, } diff --git a/cmds/exp/tcpdump/well_known_ports.go b/cmds/exp/tcpdump/well_known_ports.go new file mode 100644 index 0000000000..e8c18f3d34 --- /dev/null +++ b/cmds/exp/tcpdump/well_known_ports.go @@ -0,0 +1,272 @@ +// Copyright 2024 the u-root Authors. All rights reserved +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +var wellKnownPortsMap = map[string]string{ + "7008": "afs3-update", + "538": "gdomap", + "3306": "mysql", + "1094": "rootd", + "3260": "iscsi-target", + "4500": "ipsec-nat-t", + "4": "echo", + "30865": "csync2", + "137": "netbios-ns", + "487": "saft", + "8080": "http-alt", + "2605": "bgpd", + "5353": "mdns", + "7002": "afs3-prserver", + "10081": "kamanda", + "445": "microsoft-ds", + "554": "rtsp", + "2602": "ripd", + "199": "smux", + "3632": "distcc", + "1127": "supfiledbg", + "1210": "predict", + "515": "printer", + "2086": "gnunet", + "1812": "radius", + "777": "moira-update", + "88": "kerberos", + "111": "sunrpc", + "17004": "sgi-cad", + "1645": "datametrics", + "7001": "afs3-callback", + "6347": "gnutella-rtr", + "7000": "afs3-fileserver", + "1314": "xtelw", + "4559": "hylafax", + "371": "clearcase", + "992": "telnets", + "3690": "svn", + "751": "kerberos-master", + "443": "https", + "3493": "nut", + "607": "nqs", + "6": "zip", + "370": "codaauth2", + "444": "snpp", + "2049": "nfs", + "6002": "x11-2", + "17003": "sgi-gcd", + "2583": "mon", + "6001": "x11-1", + "7003": "afs3-vlserver", + "5680": "canna", + "6003": "x11-3", + "7007": "afs3-bos", + "871": "supfilesrv", + "2601": "zebra", + "8081": "tproxy", + "27374": "asp", + "4353": "f5-iquery", + "4460": "ntske", + "17002": "sgi-crsd", + "11": "systat", + "10809": "nbd", + "6004": "x11-4", + "10050": "zabbix-agent", + "2431": "venus-se", + "4691": "mtn", + "6667": "ircd", + "6006": "x11-6", + "6445": "sge-execd", + "2628": "dict", + "990": "ftps", + "2401": "cvspserver", + "8088": "omniorb", + "2119": "gsigatekeeper", + "752": "passwd-server", + "655": "tinc", + "5672": "amqp", + "389": "ldap", + "631": "ipp", + "2603": "ripngd", + "5667": "nsca", + "37": "time", + "80": "http", + "427": "svrloc", + "13": "daytime", + "22": "ssh", + "17001": "sgi-cmsd", + "60177": "tfido", + "4569": "iax", + "6007": "x11-7", + "517": "talk", + "2000": "cisco-sccp", + "2433": "codasrv-se", + "4094": "sysrqd", + "21": "fsp", + "23": "telnet", + "7009": "afs3-rmtsys", + "162": "snmp-trap", + "993": "imaps", + "2432": "codasrv", + "5269": "xmpp-server", + "3130": "icpv2", + "5060": "sip", + "543": "klogin", + "1524": "ingreslock", + "53": "domain", + "5666": "nrpe", + "2608": "isisd", + "10082": "amandaidx", + "5222": "xmpp-client", + "6444": "sge-qmaster", + "1649": "kermit", + "7004": "afs3-kaserver", + "19": "chargen", + "164": "cmip-agent", + "1813": "radius-acct", + "512": "biff", + "520": "route", + "779": "moira-ureg", + "9": "discard", + "11112": "dicom", + "2792": "f5-globalsite", + "6446": "mysql-proxy", + "8140": "puppet", + "1236": "rmtcfg", + "43": "whois", + "1099": "rmiregistry", + "587": "submission", + "2103": "zephyr-clt", + "60179": "fido", + "163": "cmip-man", + "548": "afpovertcp", + "7005": "afs3-volser", + "9098": "xinetd", + "546": "dhcpv6-client", + "2811": "gsiftp", + "1194": "openvpn", + "6696": "babel", + "22125": "dcap", + "1178": "skkserv", + "6514": "syslog-tls", + "119": "nntp", + "345": "pawserv", + "1677": "groupwise", + "2104": "zephyr-hm", + "79": "finger", + "464": "kpasswd", + "989": "ftps-data", + "4369": "epmd", + "5556": "freeciv", + "6346": "gnutella-svc", + "7": "echo", + "67": "bootps", + "754": "krb-prop", + "9102": "bacula-fd", + "9667": "xmms2", + "320": "ptp-general", + "706": "silc", + "873": "rsync", + "2947": "gpsd", + "10080": "amanda", + "22273": "wnn6", + "15": "netstat", + "174": "mailq", + "783": "spamd", + "2604": "ospfd", + "5555": "rplay", + "623": "asf-rmcp", + "1646": "sa-msg-port", + "1313": "xtel", + "465": "submissions", + "646": "ldp", + "6000": "x11", + "9103": "bacula-sd", + "25": "smtp", + "179": "bgp", + "3689": "daap", + "57000": "dircproxy", + "69": "tftp", + "123": "ntp", + "10083": "amidxtape", + "4190": "sieve", + "750": "kerberos4", + "2121": "iprop", + "513": "who", + "518": "ntalk", + "2600": "zebrasrv", + "143": "imap2", + "2430": "venus", + "2135": "gris", + "3050": "gds-db", + "4899": "radmin-port", + "775": "moira-db", + "138": "netbios-dgm", + "346": "zserv", + "749": "kerberos-adm", + "4949": "munin", + "70": "gopher", + "139": "netbios-ssn", + "3205": "isns", + "5308": "cfengine", + "22128": "gsidcap", + "68": "bootpc", + "563": "nntps", + "10000": "webmin", + "1080": "socks", + "11371": "hkp", + "540": "uucp", + "17500": "db-lsp", + "106": "poppassd", + "8021": "zope-ftp", + "102": "iso-tsap", + "514": "syslog", + "6697": "ircs-u", + "210": "z3950", + "4031": "suucp", + "319": "ptp-event", + "1093": "proofd", + "3389": "ms-wbt-server", + "5671": "amqps", + "6005": "x11-5", + "9418": "git", + "20": "ftp-data", + "213": "ipx", + "544": "kshell", + "6379": "redis", + "9101": "bacula-dir", + "10051": "zabbix-trapper", + "2607": "ospfapi", + "24554": "binkp", + "1": "rtmp", + "113": "auth", + "49": "tacacs", + "995": "pop3s", + "636": "ldaps", + "1352": "lotusnote", + "9673": "zope", + "135": "epmap", + "547": "dhcpv6-server", + "161": "snmp", + "853": "domain-s", + "1433": "ms-sql-s", + "1701": "l2f", + "5061": "sip-tls", + "6566": "sane-port", + "104": "acr-nema", + "110": "pop3", + "2101": "rtcm-sc104", + "7100": "font-service", + "4557": "fax", + "8990": "clc-build-daemon", + "500": "isakmp", + "628": "qmqp", + "209": "qmtp", + "4373": "remctl", + "2102": "zephyr-srv", + "17": "qotd", + "177": "xdmcp", + "5432": "postgresql", + "2": "nbp", + "2606": "ospf6d", + "369": "rpc2portmap", + "1434": "ms-sql-m", +}