Browse Source

works

master
arnaucode 7 years ago
parent
commit
f6ff238fb5
8 changed files with 121 additions and 0 deletions
  1. +2
    -0
      .gitignore
  2. +8
    -0
      README.md
  3. BIN
      goNmapTelegramBot
  4. +21
    -0
      main.go
  5. +16
    -0
      nmap.go
  6. +25
    -0
      readConfig.go
  7. BIN
      screenrecording1.gif
  8. +49
    -0
      telegramBot.go

+ 2
- 0
.gitignore

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

+ 8
- 0
README.md

@ -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


+ 21
- 0
main.go

@ -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
- 0
nmap.go

@ -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
- 0
readConfig.go

@ -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

Before After
Width: 600  |  Height: 316  |  Size: 2.3 MiB

+ 49
- 0
telegramBot.go

@ -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)
}
}

Loading…
Cancel
Save