This commit is contained in:
arnaucode
2017-05-23 23:19:02 +02:00
parent d1888e421a
commit f6ff238fb5
8 changed files with 121 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
temp
*.json

8
README.md Normal file
View File

@@ -0,0 +1,8 @@
# goNmapTelegramBot
This is a simple telegram bot, that gets an ip, performs a nmap port scan, and returns the result to the telegram user.
Warning: is not recommended to leave the Bot running, a possible attack to the Bot (and the server where is the Bot running) could be insect command lines outside the nmap
![goNmapTelegramBot](https://raw.githubusercontent.com/arnaucode/goNmapTelegramBot/master/screenrecording1.gif "goNmapTelegramBot")

BIN
goNmapTelegramBot Executable file

Binary file not shown.

21
main.go Normal file
View File

@@ -0,0 +1,21 @@
package main
import (
"strings"
)
func checkIp(text string) bool {
if len(strings.Split(text, ".")) != 4 {
return false
}
if len(strings.Split(text, "")) > 16 {
return false
}
return true
}
func main() {
readConfig()
telegramBot()
}

16
nmap.go Normal file
View File

@@ -0,0 +1,16 @@
package main
import (
"fmt"
"os/exec"
)
func nmap(ip string) string {
out, err := exec.Command("nmap", "-T4", "F", ip).Output()
if err != nil {
fmt.Println(err)
}
fmt.Println(string(out))
return string(out)
}

25
readConfig.go Normal file
View File

@@ -0,0 +1,25 @@
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
)
//Config stores the data from json twitterConfig.json file
type Config struct {
TelegramBotToken string `json:"telegramBotToken"`
}
var config Config
func readConfig() {
file, e := ioutil.ReadFile("config.json")
if e != nil {
fmt.Println("error:", e)
}
content := string(file)
json.Unmarshal([]byte(content), &config)
fmt.Println("config.json read comlete, Telegram bot ready")
}

BIN
screenrecording1.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

49
telegramBot.go Normal file
View File

@@ -0,0 +1,49 @@
package main
import (
"fmt"
"log"
"gopkg.in/telegram-bot-api.v4"
)
func telegramBot() {
bot, err := tgbotapi.NewBotAPI(config.TelegramBotToken)
if err != nil {
log.Panic(err)
}
//bot.Debug = true
//log.Printf("Authorized on account %s", bot.Self.UserName)
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
updates, err := bot.GetUpdatesChan(u)
for update := range updates {
if update.Message == nil {
continue
}
//log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
fmt.Println("new ip to scan: " + update.Message.Text)
var result string
ok := checkIp(update.Message.Text)
if update.Message.Text == "/start" {
result = "welcome to nmap telegram bot, written in Go lang"
} else {
if ok {
result = nmap(update.Message.Text)
} else {
result = "ip not valid"
}
}
msg := tgbotapi.NewMessage(update.Message.Chat.ID, result)
msg.ReplyToMessageID = update.Message.MessageID
bot.Send(msg)
}
}