Skip to content

Commit 938dcc1

Browse files
committed
update gitignore
0 parents  commit 938dcc1

File tree

8 files changed

+252
-0
lines changed

8 files changed

+252
-0
lines changed

.gitignore

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/scripts/initgit.sh
2+
# Binaries for programs and plugins
3+
*.exe
4+
*.exe~
5+
*.dll
6+
*.so
7+
*.dylib
8+
main
9+
10+
# Test binary, built with `go test -c`
11+
*.test
12+
13+
# Output of the go coverage tool, specifically when used with LiteIDE
14+
*.out
15+
16+
# Dependency directories (remove the comment below to include it)
17+
# vendor/

.replit

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
run="go build && ./main"
2+
onBoot="./scripts/initgit.sh"

github.go

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package main
2+
3+
import (
4+
"github.com/google/go-github/github"
5+
"github.com/bradleyfalzon/ghinstallation"
6+
"net/http"
7+
"os"
8+
"context"
9+
// "strconv"
10+
"fmt"
11+
"time"
12+
)
13+
14+
func githubInit() *github.Client {
15+
// Wrap the shared transport for use with the integration ID 1 authenticating with installation ID 99.
16+
itr, err := ghinstallation.New(http.DefaultTransport, 115168, 16900202, []byte(os.Getenv("GITHUB_PRIVATE_KEY")))
17+
if err != nil {
18+
handleError(err)
19+
}
20+
fmt.Println(itr.BaseURL)
21+
client := github.NewClient(&http.Client{Transport: itr})
22+
return client
23+
}
24+
25+
func pushToken(client *github.Client, message string, token string) error {
26+
committerName := "Token Scanner Bot"
27+
committerEmail := "[email protected]"
28+
commitMessage := "Push token from message " + message
29+
contResp, _, err := client.Repositories.CreateFile(context.Background(), "RoBlockHead", "TokenDisabler", "tokens/" + message + ".txt", &github.RepositoryContentFileOptions{
30+
Content: []byte(fmt.Sprintf("Hey there, this file was created automatically because a bot found your token in public. By creating this file, the Discord bots will immediately reset the token.\nHopefully, we caught it in time to make sure that you weren't compromised.\nThis is a dangerous thing to leak, as your bot can be controlled by anyone if they have the token! Please keep your token safe. \nReporter: %s\nTime Detected: %s\n\n%s", "Token Scanner Bot (replit/@RoBlockHead)", (time.Now()).String, token)),
31+
Message: &commitMessage,
32+
Author: &github.CommitAuthor{
33+
Name: &committerName,
34+
Email: &committerEmail,
35+
},
36+
Committer: &github.CommitAuthor{
37+
Name: &committerName,
38+
Email: &committerEmail,
39+
},
40+
})
41+
if err != nil{
42+
fmt.Println(err)
43+
return err
44+
} else {
45+
fmt.Printf("Token Pushed: %v\n", contResp.Commit.SHA)
46+
return nil
47+
}
48+
}

go.mod

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module main
2+
3+
go 1.14
4+
5+
require (
6+
github.com/bradleyfalzon/ghinstallation v1.1.1
7+
github.com/bwmarrin/discordgo v0.23.2
8+
github.com/google/go-github v17.0.0+incompatible
9+
)

go.sum

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
github.com/bradleyfalzon/ghinstallation v1.1.1 h1:pmBXkxgM1WeF8QYvDLT5kuQiHMcmf+X015GI0KM/E3I=
2+
github.com/bradleyfalzon/ghinstallation v1.1.1/go.mod h1:vyCmHTciHx/uuyN82Zc3rXN3X2KTK8nUTCrTMwAhcug=
3+
github.com/bwmarrin/discordgo v0.23.2 h1:BzrtTktixGHIu9Tt7dEE6diysEF9HWnXeHuoJEt2fH4=
4+
github.com/bwmarrin/discordgo v0.23.2/go.mod h1:c1WtWUGN6nREDmzIpyTp/iD3VYt4Fpx+bVyfBG7JE+M=
5+
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
6+
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
7+
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
8+
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
9+
github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY=
10+
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
11+
github.com/google/go-github/v29 v29.0.2 h1:opYN6Wc7DOz7Ku3Oh4l7prmkOMwEcQxpFtxdU8N8Pts=
12+
github.com/google/go-github/v29 v29.0.2/go.mod h1:CHKiKKPHJ0REzfwc14QMklvtHwCveD0PxlMjLlzAM5E=
13+
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
14+
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
15+
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
16+
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
17+
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16 h1:y6ce7gCWtnH+m3dCjzQ1PCuwl28DDIc3VNnvY29DlIA=
18+
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
19+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
20+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
21+
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
22+
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
23+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
24+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
25+
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=

main.go

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"regexp"
6+
"github.com/bwmarrin/discordgo"
7+
"os"
8+
"os/signal"
9+
"syscall"
10+
"strings"
11+
// "github.com/google/go-github/github"
12+
// "net/http"
13+
)
14+
func main() {
15+
16+
discord, err := discordgo.New("Bot " + os.Getenv("DISCORD_SECRET"), )
17+
if err != nil {
18+
fmt.Println("Error while connecting to discord: ", err)
19+
return
20+
}
21+
discord.Identify.Properties.Browser = "Discord iOS"
22+
discord.AddHandler(messageCreateHandler)
23+
discord.AddHandler(connectHandler)
24+
discord.Identify.Intents = discordgo.IntentsGuildMessages
25+
26+
// Open a websocket connection to Discord and begin listening.
27+
err = discord.Open()
28+
if err != nil {
29+
fmt.Println("error opening connection,", err)
30+
return
31+
}
32+
33+
// Wait here until CTRL-C or other term signal is received.
34+
fmt.Println("Bot is now running. Press CTRL-C to exit.")
35+
sc := make(chan os.Signal, 1)
36+
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
37+
<-sc
38+
39+
// Cleanly close down the Discord session.
40+
discord.Close()
41+
42+
}
43+
44+
// runs on connection to Discord
45+
func connectHandler(s *discordgo.Session, c *discordgo.Connect) {
46+
s.UpdateGameStatus(0, "token watcher 2021")
47+
s.UpdateStatusComplex(discordgo.UpdateStatusData{
48+
Activities: []*discordgo.Activity{&discordgo.Activity{
49+
Name: "for tokens ts$help",
50+
Type: 3,
51+
URL: "https://replit.com/@RoBlockHead",
52+
}},
53+
})
54+
}
55+
56+
57+
func messageCreateHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
58+
// git
59+
content := m.Content
60+
if len(m.Embeds) > 0 {
61+
for _, em := range m.Embeds {
62+
content += fmt.Sprint(em)
63+
}
64+
}
65+
if strings.HasPrefix(m.Message.Content, "ts$"){
66+
commandHandler(s, m)
67+
} else {
68+
tokens := findTokens(content)
69+
if(len(tokens) > 0){
70+
formattedTokens := ""
71+
for _, tok := range tokens {
72+
formattedTokens += tok + "\n"
73+
}
74+
fmt.Println(formattedTokens)
75+
err := pushToken(githubInit(), m.ID, formattedTokens)
76+
if err != nil {
77+
s.ChannelMessageSendComplex(m.ChannelID, &discordgo.MessageSend{
78+
Content: "Hey! You leaked a token! I ran into an error while trying to reset it, so please reset it!",
79+
Reference: &discordgo.MessageReference{
80+
MessageID: m.ID,
81+
ChannelID: m.ChannelID,
82+
GuildID: m.GuildID,
83+
},
84+
})
85+
} else{
86+
_, err = s.ChannelMessageSendComplex(m.ChannelID, &discordgo.MessageSend{
87+
Content: "Hey! You leaked a token! Don't worry though, as I've had it reset!",
88+
Reference: &discordgo.MessageReference{
89+
MessageID: m.ID,
90+
ChannelID: m.ChannelID,
91+
GuildID: m.GuildID,
92+
},
93+
})
94+
if err != nil {
95+
fmt.Println(err)
96+
}
97+
}
98+
}
99+
}
100+
if m.Author.ID == s.State.User.ID {
101+
return
102+
}
103+
}
104+
105+
func commandHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
106+
command := m.Content[3:]
107+
fmt.Printf("Command %v run\n", command)
108+
if strings.HasPrefix(command, "help") {
109+
110+
s.ChannelMessageSendEmbed(m.ChannelID, &discordgo.MessageEmbed{
111+
Title: "Token Scanner Help",
112+
Description: "Hi! I'm Token Scanner, a bot made to protect your Discord tokens! If you accidentally send a token in the chat, I'll make sure to reset it so that you don't have to worry about people using it for evil!",
113+
Color: 4449000,
114+
Footer: &discordgo.MessageEmbedFooter{
115+
IconURL: "https://cdn.discordapp.com/avatars/156126755646734336/5179ad095e5ad4a07a8f5b3c32c57375.png",
116+
Text: "Token Scanner written by @miro#7551",
117+
},
118+
Fields: []*discordgo.MessageEmbedField{
119+
&discordgo.MessageEmbedField{
120+
Name: "How do you detect tokens?",
121+
Inline: true,
122+
Value: "I use Regular Expressions (regex) to detect the format of a Discord token. If I find a match to this format, I have the token reset!",
123+
},
124+
&discordgo.MessageEmbedField{
125+
Name: "How do you reset tokens?",
126+
Inline: true,
127+
Value: "Token resetting is done via GitHub Secret Scanning. With GitHub Secret Scanning, we can just send your token up to GitHub and it will be caught by automated systems designed to find tokens. Once it's found, it's sent to Discord to be reset.",
128+
},
129+
&discordgo.MessageEmbedField{
130+
Name: "My Code",
131+
Inline: true,
132+
Value: "https://replit.com/@RoBlockHead/token-go",
133+
},
134+
},
135+
})
136+
}
137+
}
138+
139+
func findTokens(content string) []string {
140+
re := regexp.MustCompile(`[M-Z][A-Za-z\d]{23}\.[\w-]{6}\.[\w-]{27}`)
141+
return re.FindAllString(content, -1)
142+
}

scripts/initgit.template.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
git config user.name First Last
2+
git config user.email [email protected]

util.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func handleError(err error) {
6+
fmt.Errorf("err: ", err)
7+
}

0 commit comments

Comments
 (0)