Skip to content

Commit

Permalink
Added exclusion ports and hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
leech001 committed Dec 25, 2022
1 parent 50dbebe commit f6f9de5
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 16 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
- [ ADD ] Running code;

## [0.0.2] - 2022-12-11
- [ CHANGE ] Delete `bash` from apk;
- [ CHANGE ] Delete `bash` from apk;

## [0.0.2] - 2022-12-25
- [ ADD ] Exclusion hosts and ports in config;
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Telegram bot for organizing constant monitoring of open ports on the network
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/grfc-ru/nmap-telegram-bot/Publish%20Docker%20image?label=BUILD%20AND%20PUBLISH%20APPLICATION&logo=github) [![GitHub](https://img.shields.io/badge/Git-Hub-purple.svg)](https://github.com/grfc-ru/nmap-telegram-bot) [![Docker](https://img.shields.io/badge/Docker-hub-2496ed.svg)](https://hub.docker.com/r/leech001/nmap-telegram-bot) [![License: WTFPL](https://img.shields.io/badge/license-WTFPL-brightgreen)](https://github.com/grfc-ru/nmap-telegram-bot/blob/master/LICENSE)
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/grfc-ru/nmap-telegram-bot/docker-image.yml?label=BUILD%20AND%20PUBLISH%20APPLICATION&logo=GITHUB) [![GitHub](https://img.shields.io/badge/Git-Hub-purple.svg)](https://github.com/grfc-ru/nmap-telegram-bot) [![Docker](https://img.shields.io/badge/Docker-hub-2496ed.svg)](https://hub.docker.com/r/leech001/nmap-telegram-bot) [![License: WTFPL](https://img.shields.io/badge/license-WTFPL-brightgreen)](https://github.com/grfc-ru/nmap-telegram-bot/blob/master/LICENSE)

Application for organizing constant monitoring of open ports on nodes. Used to monitor erroneous configurations on network equipment or hacker activity.

Expand Down Expand Up @@ -28,7 +28,12 @@ scan:
hosts:
- host: 8.8.8.0/24 #scan network
ports:
- 3389 #scan port
- 20-23
exclusion:
hosts:
- 8.8.8.1 #exclusion host
ports:
- 22 #exclusion port
- host: google.com #scan host
ports:
- 80 #scan port
Expand Down
18 changes: 13 additions & 5 deletions app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ type Config struct {
}
Scan struct {
Hosts []struct {
Host string
Ports []uint16
Host string
Ports []string
Exclusion struct {
Hosts []string
Ports []string
}
}
}
}
Expand Down Expand Up @@ -60,16 +64,20 @@ func main() {

// Telegram bot for listening to incoming commands
func botUpdate(bot *tgbotapi.BotAPI, hosts []struct {
Host string
Ports []uint16
Host string
Ports []string
Exclusion struct {
Hosts []string
Ports []string
}
}) {

// Create string for list scanning hosts
listString := ""
for _, host := range hosts {
ports := ""
for _, port := range host.Ports {
ports += strconv.FormatUint(uint64(port), 10) + ","
ports += port + ","
}

listString += host.Host + " ports: " + ports + "\n"
Expand Down
34 changes: 26 additions & 8 deletions app/nmapScan.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,44 @@ package main
import (
"fmt"
"log"
"strconv"
"time"

"github.com/Ullaakut/nmap/v2"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)

// Scanning hosts for open ports
func nmapScan(update uint16, bot *tgbotapi.BotAPI, group int64, host struct {
Host string
Ports []uint16
}) {
func nmapScan(update uint16, bot *tgbotapi.BotAPI, group int64, hosts struct {
Host string
Ports []string
Exclusion struct {
Hosts []string
Ports []string
}
},
) {
ports := ""
for _, port := range host.Ports {
ports += strconv.FormatUint(uint64(port), 10) + ","
for _, port := range hosts.Ports {
ports += port + ","
}

// Create exclusions hosts
ehosts := ""
for _, ehost := range hosts.Exclusion.Hosts {
ehosts += ehost + ","
}

// Create exclusions ports
eports := ""
for _, eport := range hosts.Exclusion.Ports {
eports += eport + ","
}

scanner, err := nmap.NewScanner(
nmap.WithTargets(host.Host),
nmap.WithTargets(hosts.Host),
nmap.WithTargetExclusion(ehosts),
nmap.WithPorts(ports),
nmap.WithPortExclusions(eports),
)
if err != nil {
log.Fatalf("Unable to create nmap scanner: %v", err)
Expand Down
7 changes: 7 additions & 0 deletions conf/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ scan:
hosts:
- host: 8.8.8.0/24
ports:
- 20-23
- 3389
exclusion:
hosts:
- 8.8.8.1
ports:
- 22
- host: google.com
ports:
- 80
- 443

0 comments on commit f6f9de5

Please sign in to comment.