@ -1,57 +0,0 @@ |
|||||
package main |
|
||||
|
|
||||
import "fmt" |
|
||||
|
|
||||
//Color struct, defines the color
|
|
||||
type Color struct{} |
|
||||
|
|
||||
var c Color |
|
||||
|
|
||||
//DarkGray color
|
|
||||
func (c Color) DarkGray(t string) { |
|
||||
fmt.Print("\x1b[30;1m") //dark gray
|
|
||||
fmt.Println(t) |
|
||||
fmt.Print("\x1b[0m") //defaultColor
|
|
||||
} |
|
||||
|
|
||||
//Red color
|
|
||||
func (c Color) Red(t string) { |
|
||||
fmt.Print("\x1b[31;1m") //red
|
|
||||
fmt.Println(t) |
|
||||
fmt.Print("\x1b[0m") //defaultColor
|
|
||||
} |
|
||||
|
|
||||
//Green color
|
|
||||
func (c Color) Green(t string) { |
|
||||
fmt.Print("\x1b[32;1m") //green
|
|
||||
fmt.Println(t) |
|
||||
fmt.Print("\x1b[0m") //defaultColor
|
|
||||
} |
|
||||
|
|
||||
//Yellow color
|
|
||||
func (c Color) Yellow(t string) { |
|
||||
fmt.Print("\x1b[33;1m") //yellow
|
|
||||
fmt.Println(t) |
|
||||
fmt.Print("\x1b[0m") //defaultColor
|
|
||||
} |
|
||||
|
|
||||
//Blue color
|
|
||||
func (c Color) Blue(t string) { |
|
||||
fmt.Print("\x1b[34;1m") //blue
|
|
||||
fmt.Println(t) |
|
||||
fmt.Print("\x1b[0m") //defaultColor
|
|
||||
} |
|
||||
|
|
||||
//Purple color
|
|
||||
func (c Color) Purple(t string) { |
|
||||
fmt.Print("\x1b[35;1m") //purple
|
|
||||
fmt.Println(t) |
|
||||
fmt.Print("\x1b[0m") //defaultColor
|
|
||||
} |
|
||||
|
|
||||
//Cyan color
|
|
||||
func (c Color) Cyan(t string) { |
|
||||
fmt.Print("\x1b[36;1m") //cyan
|
|
||||
fmt.Println(t) |
|
||||
fmt.Print("\x1b[0m") //defaultColor
|
|
||||
} |
|
@ -0,0 +1,9 @@ |
|||||
|
package main |
||||
|
|
||||
|
import "log" |
||||
|
|
||||
|
func check(err error) { |
||||
|
if err != nil { |
||||
|
log.Println(err) |
||||
|
} |
||||
|
} |
@ -0,0 +1,19 @@ |
|||||
|
package main |
||||
|
|
||||
|
import ( |
||||
|
"io" |
||||
|
"log" |
||||
|
"os" |
||||
|
"time" |
||||
|
) |
||||
|
|
||||
|
func savelog() { |
||||
|
timeS := time.Now().String() |
||||
|
_ = os.Mkdir("logs", os.ModePerm) |
||||
|
logFile, err := os.OpenFile("logs/log-"+timeS+".log", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666) |
||||
|
if err != nil { |
||||
|
panic(err) |
||||
|
} |
||||
|
mw := io.MultiWriter(os.Stdout, logFile) |
||||
|
log.SetOutput(mw) |
||||
|
} |
@ -1,28 +1,52 @@ |
|||||
package main |
package main |
||||
|
|
||||
import "fmt" |
|
||||
|
import ( |
||||
|
"fmt" |
||||
|
"log" |
||||
|
"strconv" |
||||
|
"time" |
||||
|
|
||||
|
"github.com/fatih/color" |
||||
|
) |
||||
|
|
||||
const version = "0.1-dev" |
const version = "0.1-dev" |
||||
|
|
||||
func main() { |
func main() { |
||||
c.Yellow("echo-botnet") |
|
||||
|
savelog() |
||||
|
color.Blue("echo-botnet") |
||||
fmt.Println("---------------") |
fmt.Println("---------------") |
||||
c.Cyan("echo-botnet initialized") |
|
||||
c.Purple("https://github.com/arnaucode/echo-botnet") |
|
||||
fmt.Println("version " + version) |
|
||||
|
color.Cyan("echo-botnet initialized") |
||||
|
color.Green("https://github.com/arnaucode/echo-botnet") |
||||
|
log.Println("version " + version) |
||||
|
|
||||
keywords := readKeywordsConfig() |
|
||||
c.Cyan("keywords configured: ") |
|
||||
|
readKeywordsConfig() |
||||
|
color.Cyan("keywords configured: ") |
||||
fmt.Println(keywords) |
fmt.Println(keywords) |
||||
replies := readRepliesConfig() |
|
||||
c.Cyan("replies configured: ") |
|
||||
|
readRepliesConfig() |
||||
|
color.Cyan("replies configured: ") |
||||
fmt.Println(replies) |
fmt.Println(replies) |
||||
|
|
||||
fmt.Println("Reading botsConfig.json file") |
fmt.Println("Reading botsConfig.json file") |
||||
botnet := readConfigTokensAndConnect() |
|
||||
c.Cyan("[list of configured bots]:") |
|
||||
for _, v := range botnet.ScreenNames { |
|
||||
c.Cyan(v) |
|
||||
|
readConfigTokensAndConnect() |
||||
|
color.Cyan("[list of configured bots]:") |
||||
|
for _, bot := range botnet { |
||||
|
color.Cyan(bot.Title) |
||||
|
} |
||||
|
var i int |
||||
|
for { |
||||
|
color.Red(strconv.Itoa(i)) |
||||
|
sinceTweeted := time.Unix(botnet[i].SinceTweeted, 0) |
||||
|
elapsed := time.Since(sinceTweeted) |
||||
|
fmt.Println(elapsed) |
||||
|
if elapsed.Seconds() > 60 { |
||||
|
log.Println("starting to use bot: " + botnet[i].Title) |
||||
|
startStreaming(botnet[i]) |
||||
|
} else { |
||||
|
log.Println("bot: " + botnet[i].Title + " not used due bot is in waiting time") |
||||
|
} |
||||
|
i++ |
||||
|
if i > len(botnet)-1 { |
||||
|
i = 0 |
||||
|
} |
||||
} |
} |
||||
streamTweets(botnet, keywords, replies) |
|
||||
} |
} |
@ -1,54 +0,0 @@ |
|||||
package main |
|
||||
|
|
||||
import ( |
|
||||
"encoding/json" |
|
||||
"fmt" |
|
||||
"io/ioutil" |
|
||||
|
|
||||
"github.com/dghubble/go-twitter/twitter" |
|
||||
"github.com/dghubble/oauth1" |
|
||||
) |
|
||||
|
|
||||
//Config stores the data from json botsConfig.json file
|
|
||||
type Config struct { |
|
||||
Title string `json:"title"` |
|
||||
ConsumerKey string `json:"consumer_key"` |
|
||||
ConsumerSecret string `json:"consumer_secret"` |
|
||||
AccessTokenKey string `json:"access_token_key"` |
|
||||
AccessTokenSecret string `json:"access_token_secret"` |
|
||||
} |
|
||||
|
|
||||
//Botnet stores each bot configured
|
|
||||
type Botnet struct { |
|
||||
ScreenNames []string |
|
||||
Clients []*twitter.Client |
|
||||
} |
|
||||
|
|
||||
func readConfigTokensAndConnect() (botnet Botnet) { |
|
||||
var config []Config |
|
||||
var clients []*twitter.Client |
|
||||
|
|
||||
file, e := ioutil.ReadFile("botsConfig.json") |
|
||||
if e != nil { |
|
||||
fmt.Println("error:", e) |
|
||||
} |
|
||||
content := string(file) |
|
||||
json.Unmarshal([]byte(content), &config) |
|
||||
fmt.Println("botnetConfig.json read comlete") |
|
||||
|
|
||||
fmt.Print("connecting to twitter api --> ") |
|
||||
for i := 0; i < len(config); i++ { |
|
||||
configu := oauth1.NewConfig(config[i].ConsumerKey, config[i].ConsumerSecret) |
|
||||
token := oauth1.NewToken(config[i].AccessTokenKey, config[i].AccessTokenSecret) |
|
||||
httpClient := configu.Client(oauth1.NoContext, token) |
|
||||
// twitter client
|
|
||||
client := twitter.NewClient(httpClient) |
|
||||
clients = append(clients, client) |
|
||||
botnet.ScreenNames = append(botnet.ScreenNames, config[i].Title) |
|
||||
} |
|
||||
botnet.Clients = clients |
|
||||
|
|
||||
fmt.Println("connection successful") |
|
||||
|
|
||||
return botnet |
|
||||
} |
|
@ -0,0 +1,61 @@ |
|||||
|
package main |
||||
|
|
||||
|
import ( |
||||
|
"encoding/json" |
||||
|
"io/ioutil" |
||||
|
"log" |
||||
|
|
||||
|
"github.com/dghubble/go-twitter/twitter" |
||||
|
"github.com/dghubble/oauth1" |
||||
|
) |
||||
|
|
||||
|
//Bot stores the data from json botsConfig.json file
|
||||
|
type Bot struct { |
||||
|
Title string `json:"title"` |
||||
|
ConsumerKey string `json:"consumer_key"` |
||||
|
ConsumerSecret string `json:"consumer_secret"` |
||||
|
AccessTokenKey string `json:"access_token_key"` |
||||
|
AccessTokenSecret string `json:"access_token_secret"` |
||||
|
Client *twitter.Client |
||||
|
SinceTweeted int64 `json:"sincetweeted"` |
||||
|
Blocked bool `json:"blocked"` |
||||
|
SinceBlocked int64 `json:"sinceblocked"` |
||||
|
} |
||||
|
|
||||
|
var botnet []Bot |
||||
|
var keywords []string |
||||
|
var replies []string |
||||
|
|
||||
|
func readConfigTokensAndConnect() { |
||||
|
file, err := ioutil.ReadFile("botsConfig.json") |
||||
|
check(err) |
||||
|
content := string(file) |
||||
|
json.Unmarshal([]byte(content), &botnet) |
||||
|
log.Println("botnetConfig.json read comlete") |
||||
|
log.Print("connecting to twitter api") |
||||
|
for k, _ := range botnet { |
||||
|
configu := oauth1.NewConfig(botnet[k].ConsumerKey, botnet[k].ConsumerSecret) |
||||
|
token := oauth1.NewToken(botnet[k].AccessTokenKey, botnet[k].AccessTokenSecret) |
||||
|
httpClient := configu.Client(oauth1.NoContext, token) |
||||
|
// twitter client
|
||||
|
client := twitter.NewClient(httpClient) |
||||
|
botnet[k].Client = client |
||||
|
botnet[k].Blocked = false |
||||
|
} |
||||
|
|
||||
|
log.Println("connection successful") |
||||
|
} |
||||
|
|
||||
|
func readKeywordsConfig() { |
||||
|
file, err := ioutil.ReadFile("keywordsConfig.json") |
||||
|
check(err) |
||||
|
content := string(file) |
||||
|
json.Unmarshal([]byte(content), &keywords) |
||||
|
} |
||||
|
|
||||
|
func readRepliesConfig() { |
||||
|
file, err := ioutil.ReadFile("repliesConfig.json") |
||||
|
check(err) |
||||
|
content := string(file) |
||||
|
json.Unmarshal([]byte(content), &replies) |
||||
|
} |
@ -1,19 +0,0 @@ |
|||||
package main |
|
||||
|
|
||||
import ( |
|
||||
"encoding/json" |
|
||||
"fmt" |
|
||||
"io/ioutil" |
|
||||
) |
|
||||
|
|
||||
func readKeywordsConfig() []string { |
|
||||
var keywords []string |
|
||||
file, e := ioutil.ReadFile("keywordsConfig.json") |
|
||||
if e != nil { |
|
||||
fmt.Println("error:", e) |
|
||||
} |
|
||||
content := string(file) |
|
||||
json.Unmarshal([]byte(content), &keywords) |
|
||||
|
|
||||
return keywords |
|
||||
} |
|
@ -1,19 +0,0 @@ |
|||||
package main |
|
||||
|
|
||||
import ( |
|
||||
"encoding/json" |
|
||||
"fmt" |
|
||||
"io/ioutil" |
|
||||
) |
|
||||
|
|
||||
func readRepliesConfig() []string { |
|
||||
var replies []string |
|
||||
file, e := ioutil.ReadFile("repliesConfig.json") |
|
||||
if e != nil { |
|
||||
fmt.Println("error:", e) |
|
||||
} |
|
||||
content := string(file) |
|
||||
json.Unmarshal([]byte(content), &replies) |
|
||||
|
|
||||
return replies |
|
||||
} |
|