|
@@ -10,20 +10,30 @@ import (
|
|
|
|
|
|
)
|
|
|
|
|
|
-var PORT_LIST = []int{
|
|
|
- 22, 23, 53, 80, 125, 443, 8080, 8081, 8082, 8085, 8090, 8091, 9010, 9012, 10000,
|
|
|
+var PORT_MAP = map[int]string{
|
|
|
+ 22: "ssh", 23: "telnet", 53: "dns", 80: "http", 25: "smtp", 443: "https", 8080: "unknown", 8081: "unknown",
|
|
|
+ 8082: "unknown", 8085: "unknown", 8090: "unknown", 8091: "unknown", 9010: "unknown", 9012: "unknown", 10000: "unknown",
|
|
|
}
|
|
|
|
|
|
type TcpScanHost struct {
|
|
|
- Host string
|
|
|
- Addr netip.Addr
|
|
|
- Ports []TcpScanResult
|
|
|
+ Host string `json:"host"`
|
|
|
+ Ipv4Address netip.Addr `json:"ipv4_address"`
|
|
|
+ PortsScanned []PortScanResult `json:"ports_scanned"`
|
|
|
}
|
|
|
|
|
|
-type TcpScanResult struct {
|
|
|
- PortNumber int
|
|
|
- Protocol string
|
|
|
- Listening bool
|
|
|
+type PortScanResult struct {
|
|
|
+ PortNumber int `json:"port_number"`
|
|
|
+ Service string `json:"service"`
|
|
|
+ Protocol string `json:"protocol"`
|
|
|
+ Listening bool `json:"listening"`
|
|
|
+}
|
|
|
+
|
|
|
+type PortScanDirective struct {
|
|
|
+ Pairs map[int]string
|
|
|
+}
|
|
|
+
|
|
|
+func RetrieveScanDirectives() PortScanDirective {
|
|
|
+ return PortScanDirective{Pairs: PORT_MAP}
|
|
|
}
|
|
|
|
|
|
|
|
@@ -32,34 +42,36 @@ Scans a single host on a single port
|
|
|
:param addr: the address to dial
|
|
|
:param port: the port number to dial
|
|
|
*/
|
|
|
-func singlePortScan(addr string, port int) *TcpScanResult {
|
|
|
+func singlePortScan(addr string, port int, svcs string) *PortScanResult {
|
|
|
//defer wg.Done()
|
|
|
address := fmt.Sprintf("%v:%d", addr, port)
|
|
|
conn, err := net.DialTimeout("tcp", address, 1*time.Second)
|
|
|
if err != nil {
|
|
|
- return &TcpScanResult{PortNumber: port, Protocol: "tcp", Listening: false}
|
|
|
+ return &PortScanResult{PortNumber: port, Protocol: "tcp", Service: svcs, Listening: false}
|
|
|
}
|
|
|
conn.Close()
|
|
|
- return &TcpScanResult{PortNumber: port, Protocol: "tcp", Listening: true}
|
|
|
+ return &PortScanResult{PortNumber: port, Protocol: "tcp", Service: svcs, Listening: true}
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
Perform a TCP scan on the pointers host
|
|
|
:param posts: a list of ports to scan against a host
|
|
|
*/
|
|
|
-func (t *TcpScanHost) ScanPortRange(ports []int) []*TcpScanResult {
|
|
|
+func (t *TcpScanHost) ScanPortRange(ports []int) []*PortScanResult {
|
|
|
wg := &sync.WaitGroup{}
|
|
|
- out := make(chan *TcpScanResult)
|
|
|
- var res []*TcpScanResult
|
|
|
+ out := make(chan *PortScanResult)
|
|
|
+ var res []*PortScanResult
|
|
|
wgOuter := &sync.WaitGroup{}
|
|
|
wgOuter.Add(1)
|
|
|
go func() {
|
|
|
defer wgOuter.Done()
|
|
|
- for p := range ports {
|
|
|
+ ports := RetrieveScanDirectives()
|
|
|
+ for p, s := range ports.Pairs {
|
|
|
wg.Add(1)
|
|
|
- port := ports[p]
|
|
|
+ port := p
|
|
|
+ svcs := s
|
|
|
go func() {
|
|
|
- out <- singlePortScan(t.Addr.String(), port)
|
|
|
+ out <- singlePortScan(t.Ipv4Address.String(), port, svcs)
|
|
|
wg.Done()
|
|
|
}()
|
|
|
}
|