diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 43f59e1..58eaddc 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -29,7 +29,7 @@ jobs: id: meta uses: docker/metadata-action@v4 with: - images: leech001/telegram-site-monitor + images: leech001/nmap-telegram-bot tags: | type=ref,event=tag diff --git a/README.md b/README.md index 609230d..f122a84 100644 --- a/README.md +++ b/README.md @@ -23,10 +23,10 @@ telegram: scan: hosts: - - host: 8.8.8.0/24 #Scan network + - host: 8.8.8.0/24 #scan network ports: - 3389 #scan port - - host: google.com #Scan host + - host: google.com #scan host ports: - 80 #scan port - 443 #scan port diff --git a/app/main.go b/app/main.go index f220bc9..1224d1a 100644 --- a/app/main.go +++ b/app/main.go @@ -64,10 +64,15 @@ func botUpdate(bot *tgbotapi.BotAPI, hosts []struct { Ports []uint16 }) { - // Create string for HTTP(s) monitoring sites - hostString := "" + // Create string for list scanning hosts + listString := "" for _, host := range hosts { - hostString += host.Host + "\n" + ports := "" + for _, port := range host.Ports { + ports += strconv.FormatUint(uint64(port), 10) + "," + } + + listString += host.Host + " ports: " + ports + "\n" } // Telegram bot listener @@ -89,7 +94,7 @@ func botUpdate(bot *tgbotapi.BotAPI, hosts []struct { case "start": msg.Text = "Hi, I am a NMAP scanner bot! Your (group) ID = " + strconv.FormatInt(update.Message.Chat.ID, 10) case "list": - msg.Text = "Scanned hosts:\n" + hostString + msg.Text = "Scanned hosts:\n" + listString default: msg.Text = "I don't know that command" } diff --git a/app/nmapScan.go b/app/nmapScan.go index 100a625..51aaf18 100644 --- a/app/nmapScan.go +++ b/app/nmapScan.go @@ -10,7 +10,7 @@ import ( tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" ) -// Checking the open ports +// Scanning hosts for open ports func nmapScan(update uint16, bot *tgbotapi.BotAPI, group int64, host struct { Host string Ports []uint16 @@ -28,29 +28,32 @@ func nmapScan(update uint16, bot *tgbotapi.BotAPI, group int64, host struct { log.Fatalf("Unable to create nmap scanner: %v", err) } - result, warnings, err := scanner.Run() - if err != nil { - log.Fatalf("Unable to run nmap scan: %v", err) - } - - if warnings != nil { - log.Printf("Warnings: \n %v", warnings) - } + // Infinity scan loop + for { + result, warnings, err := scanner.Run() + if err != nil { + log.Fatalf("Unable to run nmap scan: %v", err) + } - for _, host := range result.Hosts { - if len(host.Ports) == 0 || len(host.Addresses) == 0 { - continue + if warnings != nil { + log.Printf("Warnings: \n %v", warnings) } - for _, port := range host.Ports { - if port.State.State == "open" { - fmt.Printf("Host %q has %d/%s %s %s\n", host.Addresses[0], port.ID, port.Protocol, port.State, port.Service.Name) + for _, host := range result.Hosts { + if len(host.Ports) == 0 || len(host.Addresses) == 0 { + continue + } + + for _, port := range host.Ports { + if port.State.State == "open" { + fmt.Printf("Host %q has %d/%s %s %s port\n", host.Addresses[0], port.ID, port.Protocol, port.State, port.Service.Name) - msg := tgbotapi.NewMessage(group, fmt.Sprintf("Host %q has %d/%s %s %s\n", host.Addresses[0], port.ID, port.Protocol, port.State, port.Service.Name)) - bot.Send(msg) + msg := tgbotapi.NewMessage(group, fmt.Sprintf("Host %q has %d/%s %s %s port\n", host.Addresses[0], port.ID, port.Protocol, port.State, port.Service.Name)) + bot.Send(msg) + time.Sleep(time.Second) + } } } + time.Sleep(time.Duration(update) * time.Second) } - - time.Sleep(time.Duration(update) * time.Second) } diff --git a/docker-compose.yml b/docker-compose.yml index 1dc65ac..1a9040b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: "3.9" services: app: - image: leech001/... + image: leech001/nmap-telegram-bot restart: always volumes: - ./conf:/app/conf:ro