mirror of
https://github.com/arnaucube/flock-botnet.git
synced 2026-02-06 19:16:39 +01:00
streaming keywords implemented, replying from the flock (botnet) to tweets with text generated with Markov chains
This commit is contained in:
@@ -1,15 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/dghubble/go-twitter/twitter"
|
||||
)
|
||||
|
||||
func replyTweet(client *twitter.Client, text string, inReplyToStatusID int64) {
|
||||
tweet, httpResp, err := client.Statuses.Update(text, &twitter.StatusUpdateParams{
|
||||
InReplyToStatusID: inReplyToStatusID,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
if httpResp.Status != "200 OK" {
|
||||
c.Red("error: " + httpResp.Status)
|
||||
c.Purple("maybe twitter has blocked the account, CTRL+C, wait 15 minutes and try again")
|
||||
}
|
||||
fmt.Print("tweet posted: ")
|
||||
c.Green(tweet.Text)
|
||||
}
|
||||
|
||||
func postTweet(client *twitter.Client, text string) {
|
||||
tweet, httpResp, err := client.Statuses.Update(text, nil)
|
||||
if err != nil {
|
||||
@@ -33,27 +45,3 @@ func tweetFromFlock(flock Flock, text string) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func optionTweetFromFlock(flock Flock) {
|
||||
|
||||
fmt.Print("entry tweet content: ")
|
||||
newcommand := bufio.NewReader(os.Stdin)
|
||||
text, _ := newcommand.ReadString('\n')
|
||||
text = strings.TrimSpace(text)
|
||||
fmt.Print("tweet content: ")
|
||||
c.Purple(text)
|
||||
|
||||
c.Red("Are you sure? [y/n]")
|
||||
newcommand = bufio.NewReader(os.Stdin)
|
||||
answer, _ := newcommand.ReadString('\n')
|
||||
answer = strings.TrimSpace(answer)
|
||||
switch answer {
|
||||
case "y":
|
||||
fmt.Println("ok, you are sure")
|
||||
tweetFromFlock(flock, text)
|
||||
break
|
||||
default:
|
||||
fmt.Println("Operation cancelled")
|
||||
break
|
||||
}
|
||||
}
|
||||
31
main.go
31
main.go
@@ -10,26 +10,22 @@ import (
|
||||
const version = "0.1-dev"
|
||||
|
||||
func main() {
|
||||
c.Yellow("twFlock")
|
||||
c.Yellow("projectFlock")
|
||||
fmt.Println("---------------")
|
||||
c.Cyan("twFlock initialized")
|
||||
c.Purple("https://github.com/arnaucode/twFlock")
|
||||
c.Cyan("projectFlock initialized")
|
||||
c.Purple("https://github.com/arnaucode/projectFlock")
|
||||
fmt.Println("version " + version)
|
||||
fmt.Println("Reading flockConfig.json file")
|
||||
flock := readConfigTokensAndConnect()
|
||||
|
||||
c.Yellow("generating markov chains (may take some seconds)")
|
||||
text, _ := readTxt("text.txt")
|
||||
states := markov.train(text)
|
||||
c.Green("markov chains generated")
|
||||
|
||||
//var flock Flock
|
||||
fmt.Println("---------------")
|
||||
newcommand := bufio.NewReader(os.Stdin)
|
||||
fmt.Print("Please select command number")
|
||||
options := `
|
||||
1 - Tweet from flock of bots
|
||||
2 - Markov
|
||||
1 - Manual tweet from flock of bots
|
||||
2 - Markov manual text generator
|
||||
3 - Markov's Flock Botnet
|
||||
0 - Exit script
|
||||
option to select: `
|
||||
for {
|
||||
@@ -40,13 +36,22 @@ option to select: `
|
||||
|
||||
switch option {
|
||||
case "1":
|
||||
fmt.Println("selected 1 - Tweet from flock of bots")
|
||||
optionTweetFromFlock(flock)
|
||||
fmt.Println("selected 1 - Manual tweet from flock of bots")
|
||||
optionManualTweetFromFlock(flock)
|
||||
break
|
||||
case "2":
|
||||
fmt.Println("selected 2 - Markov")
|
||||
fmt.Println("selected 2 - Markov manual text generator")
|
||||
c.Yellow("generating markov chains (may take some seconds)")
|
||||
text, _ := readTxt("text.txt")
|
||||
states := markov.train(text)
|
||||
c.Green("markov chains generated")
|
||||
|
||||
optionTweetMarkov(states)
|
||||
break
|
||||
case "3":
|
||||
fmt.Println("selected 3 - Markov Flock Botnet")
|
||||
optionMarkovFlockBotnet(flock)
|
||||
break
|
||||
case "0":
|
||||
fmt.Println("selected 0 - exit script")
|
||||
os.Exit(3)
|
||||
|
||||
@@ -26,7 +26,7 @@ func printLoading(n int, total int) {
|
||||
bar = append(bar, "█")
|
||||
}
|
||||
progressBar := strings.Join(bar, "")
|
||||
fmt.Printf("\r " + progressBar + " - " + strconv.Itoa(tantPerCent) + "%")
|
||||
fmt.Printf("\r " + progressBar + " - " + strconv.Itoa(tantPerCent) + "")
|
||||
}
|
||||
|
||||
func addWordToStates(states []State, word string) ([]State, int) {
|
||||
@@ -70,7 +70,7 @@ func calcMarkovStates(words []string) []State {
|
||||
states[i].NextStates[j].Prob = (float64(states[i].NextStates[j].Count) / float64(len(words)) * 100)
|
||||
}
|
||||
}
|
||||
fmt.Println("total words computed: " + strconv.Itoa(len(words)))
|
||||
fmt.Println("\ntotal words computed: " + strconv.Itoa(len(words)))
|
||||
//fmt.Println(states)
|
||||
return states
|
||||
}
|
||||
@@ -116,9 +116,12 @@ func (markov Markov) generateText(states []State, initWord string, count int) st
|
||||
generatedText = append(generatedText, word)
|
||||
for i := 0; i < count; i++ {
|
||||
word = getNextMarkovState(states, word)
|
||||
if word == "word no exist on the memory" {
|
||||
return "word no exist on the memory"
|
||||
}
|
||||
generatedText = append(generatedText, word)
|
||||
}
|
||||
generatedText = append(generatedText, ".")
|
||||
//generatedText = append(generatedText, ".")
|
||||
text := strings.Join(generatedText, " ")
|
||||
return text
|
||||
}
|
||||
|
||||
32
optionManualTweetFromFlock.go
Normal file
32
optionManualTweetFromFlock.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func optionManualTweetFromFlock(flock Flock) {
|
||||
|
||||
fmt.Print("entry tweet content: ")
|
||||
newcommand := bufio.NewReader(os.Stdin)
|
||||
text, _ := newcommand.ReadString('\n')
|
||||
text = strings.TrimSpace(text)
|
||||
fmt.Print("tweet content: ")
|
||||
c.Purple(text)
|
||||
|
||||
c.Red("Are you sure? [y/n]")
|
||||
newcommand = bufio.NewReader(os.Stdin)
|
||||
answer, _ := newcommand.ReadString('\n')
|
||||
answer = strings.TrimSpace(answer)
|
||||
switch answer {
|
||||
case "y":
|
||||
fmt.Println("ok, you are sure")
|
||||
tweetFromFlock(flock, text)
|
||||
break
|
||||
default:
|
||||
fmt.Println("Operation cancelled")
|
||||
break
|
||||
}
|
||||
}
|
||||
111
optionMarkovFlockBotnet.go
Normal file
111
optionMarkovFlockBotnet.go
Normal file
@@ -0,0 +1,111 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/dghubble/go-twitter/twitter"
|
||||
)
|
||||
|
||||
func isRT(text string) bool {
|
||||
tweetWords := strings.Split(text, " ")
|
||||
for i := 0; i < len(tweetWords); i++ {
|
||||
if tweetWords[i] == "RT" {
|
||||
c.Red(text)
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
func generateMarkovResponse(states []State, word string) string {
|
||||
generatedText := markov.generateText(states, word, 15)
|
||||
return generatedText
|
||||
}
|
||||
func processTweet(states []State, flockUser *twitter.Client, botScreenName string, keywords []string, tweet *twitter.Tweet) {
|
||||
c.Yellow("bot @" + botScreenName + " - New tweet detected:")
|
||||
fmt.Println(tweet.Text)
|
||||
|
||||
tweetWords := strings.Split(tweet.Text, " ")
|
||||
generatedText := "word no exist on the memory"
|
||||
for i := 0; i < len(tweetWords) && generatedText == "word no exist on the memory"; i++ {
|
||||
fmt.Println(strconv.Itoa(i) + " - " + tweetWords[i])
|
||||
generatedText = generateMarkovResponse(states, tweetWords[i])
|
||||
}
|
||||
c.Yellow("bot @" + botScreenName + " posting response")
|
||||
fmt.Println(tweet.ID)
|
||||
replyTweet(flockUser, "@"+tweet.User.ScreenName+" "+generatedText, tweet.ID)
|
||||
waitTime(1)
|
||||
}
|
||||
func startStreaming(states []State, flockUser *twitter.Client, botScreenName string, keywords []string) {
|
||||
// Convenience Demux demultiplexed stream messages
|
||||
demux := twitter.NewSwitchDemux()
|
||||
demux.Tweet = func(tweet *twitter.Tweet) {
|
||||
if isRT(tweet.Text) == false {
|
||||
processTweet(states, flockUser, botScreenName, keywords, tweet)
|
||||
}
|
||||
}
|
||||
demux.DM = func(dm *twitter.DirectMessage) {
|
||||
fmt.Println(dm.SenderID)
|
||||
}
|
||||
demux.Event = func(event *twitter.Event) {
|
||||
fmt.Printf("%#v\n", event)
|
||||
}
|
||||
|
||||
fmt.Println("Starting Stream...")
|
||||
// FILTER
|
||||
filterParams := &twitter.StreamFilterParams{
|
||||
Track: keywords,
|
||||
StallWarnings: twitter.Bool(true),
|
||||
}
|
||||
stream, err := flockUser.Streams.Filter(filterParams)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
// Receive messages until stopped or stream quits
|
||||
demux.HandleChan(stream.Messages)
|
||||
|
||||
// Wait for SIGINT and SIGTERM (HIT CTRL-C)
|
||||
/*ch := make(chan os.Signal)
|
||||
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
|
||||
log.Println(<-ch)
|
||||
|
||||
fmt.Println("Stopping Stream...")
|
||||
stream.Stop()*/
|
||||
}
|
||||
func optionMarkovFlockBotnet(flock Flock) {
|
||||
c.Green("Starting Markov's Flock botnet")
|
||||
fmt.Println("generating Markov chains")
|
||||
inputText, _ := readTxt("text.txt")
|
||||
states := markov.train(inputText)
|
||||
|
||||
//getting the keywords
|
||||
c.Purple("entry words to stream tweets (separated by comma): ")
|
||||
newcommand := bufio.NewReader(os.Stdin)
|
||||
text, _ := newcommand.ReadString('\n')
|
||||
text = strings.TrimSpace(text)
|
||||
text = strings.Replace(text, " ", "", -1)
|
||||
keywords := strings.Split(text, ",")
|
||||
c.Purple("total keywords: " + strconv.Itoa(len(keywords)))
|
||||
fmt.Print("keywords to follow: ")
|
||||
fmt.Println(keywords)
|
||||
|
||||
c.Red("Are you sure? [y/n]")
|
||||
newcommand = bufio.NewReader(os.Stdin)
|
||||
answer, _ := newcommand.ReadString('\n')
|
||||
answer = strings.TrimSpace(answer)
|
||||
switch answer {
|
||||
case "y":
|
||||
fmt.Println("ok, you are sure")
|
||||
for i := 0; i < len(flock.Clients); i++ {
|
||||
go startStreaming(states, flock.Clients[i], flock.ScreenNames[i], keywords)
|
||||
}
|
||||
break
|
||||
default:
|
||||
fmt.Println("Operation cancelled")
|
||||
break
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user