-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
589 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.DS_Store | ||
*.ini | ||
*.swp | ||
bin/ | ||
dist/ | ||
*.tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
builds: | ||
- main: . | ||
binary: emissary | ||
env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
- darwin | ||
- windows | ||
goarch: | ||
- 386 | ||
- amd64 | ||
- arm | ||
- arm64 | ||
|
||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- balls | ||
- docs | ||
- Merge pull request | ||
- Merge branch | ||
|
||
archives: | ||
- format: tar.gz | ||
format_overrides: | ||
- goos: windows | ||
format: zip | ||
files: | ||
- LICENSE | ||
- README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,52 @@ | ||
# Emissary | ||
Send notifications on different channels such as Slack, Telegram, Discord etc. | ||
Send notifications via different channels such as Slack, Telegram, Discord etc. | ||
|
||
## Motivation | ||
The idea is to hook Emissary into https://github.com/BountyStrike/Bountystrike-sh which will notify me on Telegram when new domains have been found. | ||
|
||
## Usage | ||
|
||
**Create a configuration file:** | ||
``` | ||
[Telegram] | ||
chat_id=xxxxxx | ||
api_key=xxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | ||
[Slack] | ||
webhook=https://hooks.slack.com/services/xxxxxxxxxx/xxxxxxxxxx/xxxxxxxxxx | ||
``` | ||
|
||
**Pipe data via stdin:** | ||
``` | ||
$ cat domains.txt | emissary -telegram -stdin | ||
``` | ||
|
||
**Specify a message as an argument:** | ||
``` | ||
$ emissary -telegram -message "This is a very cool message" | ||
``` | ||
|
||
**Send to multiple channels:** | ||
``` | ||
$ cat domains.txt | emissary -telegram -slack -stdin | ||
``` | ||
|
||
Right now the Emissary will only deliver 20 rows, to protect against accidentally sending a gazillion domains :) | ||
|
||
## Todo | ||
Some stuff that I plan to implement: | ||
- [X] Slack | ||
- [X] Telegram | ||
- [ ] Discord | ||
- [ ] Let user decide max rows to be sent | ||
- [ ] Place config file in ~/.config/emissary.ini | ||
|
||
## Contributing | ||
Any feedback or ideas are welcome! Want to improve something? Create a pull request! | ||
|
||
1. Fork it! | ||
2. Create your feature branch: `git checkout -b my-new-feature` | ||
3. Commit your changes: `git commit -am 'Add some feature'` | ||
4. Push to the branch: `git push origin my-new-feature` | ||
5. Submit a pull request :D |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"strings" | ||
"time" | ||
) | ||
|
||
// Telegram Send messages via telegram | ||
func Telegram(chatID string, apiKey string, message string) (*http.Response, error) { | ||
|
||
jayson := map[string]interface{}{ | ||
"chat_id": chatID, | ||
"text": message, | ||
} | ||
js, _ := json.Marshal(jayson) | ||
endpoint := "https://api.telegram.org/bot" + apiKey + "/sendMessage" | ||
|
||
return request(endpoint, string(js)) | ||
} | ||
|
||
// Slack Send messages via Slack | ||
func Slack(message string, webhook string) (*http.Response, error) { | ||
js := `{"text":"` + message + `"}` | ||
return request(webhook, js) | ||
} | ||
|
||
func request(endpoint string, data string) (*http.Response, error) { | ||
|
||
tr := &http.Transport{ | ||
MaxIdleConns: 10, | ||
IdleConnTimeout: 30 * time.Second, | ||
DisableCompression: true, | ||
} | ||
|
||
var resp *http.Response | ||
var err error | ||
|
||
client := &http.Client{Transport: tr} | ||
|
||
resp, err = client.Post(endpoint, "application/json", strings.NewReader(data)) | ||
|
||
if err != nil { | ||
return resp, err | ||
} | ||
|
||
defer resp.Body.Close() | ||
|
||
return resp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module github.com/BountyStrike/emissary | ||
|
||
go 1.13 | ||
|
||
require ( | ||
github.com/goreleaser/goreleaser v0.124.1 // indirect | ||
github.com/smartystreets/goconvey v1.6.4 // indirect | ||
gopkg.in/ini.v1 v1.51.1 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"flag" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
"os" | ||
"strings" | ||
|
||
"gopkg.in/ini.v1" | ||
) | ||
|
||
type cliOptions struct { | ||
telegram bool | ||
discord bool | ||
slack bool | ||
version bool | ||
stdin bool | ||
message string | ||
} | ||
|
||
func checkResponse(httpResponse *http.Response, err error) { | ||
if httpResponse.StatusCode > 201 { | ||
body, respErr := ioutil.ReadAll(httpResponse.Body) | ||
if respErr != nil { | ||
log.Println("Error reading response body") | ||
os.Exit(1) | ||
} | ||
log.Println("HTTP Status code: ", httpResponse.StatusCode) | ||
log.Println("HTTP Body: ", string(body)) | ||
} | ||
|
||
if err != nil { | ||
log.Println("Something went wrong sending your message: ", err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func main() { | ||
opts := cliOptions{} | ||
flag.BoolVar(&opts.telegram, "telegram", false, "Send via telegram") | ||
flag.BoolVar(&opts.discord, "discord", false, "Send via discord") | ||
flag.BoolVar(&opts.slack, "slack", false, "Send via slack") | ||
flag.BoolVar(&opts.version, "v", false, "Show version number") | ||
flag.BoolVar(&opts.version, "version", false, "Show version number") | ||
flag.BoolVar(&opts.stdin, "stdin", false, "Take input from stdin") | ||
flag.StringVar(&opts.message, "message", "", "The message you want to send") | ||
flag.Parse() | ||
|
||
if opts.version { | ||
fmt.Printf("Emissary version: %s\n", "1.0") | ||
os.Exit(0) | ||
} | ||
if len(os.Args) <= 1 { | ||
flag.Usage() | ||
os.Exit(0) | ||
} | ||
|
||
cfg, err := ini.Load("emissary.ini") | ||
if err != nil { | ||
log.Fatal("Fail to read configuration file: ", err) | ||
os.Exit(1) | ||
} | ||
|
||
if len(opts.message) > 0 && opts.stdin { | ||
fmt.Println("[-] Please take input from either STDIN or cli argument, not both.") | ||
os.Exit(1) | ||
} | ||
|
||
if opts.message == "" && !opts.stdin { | ||
fmt.Println("[-] You forgot to set message...") | ||
os.Exit(1) | ||
} | ||
|
||
messages := make([]string, 21) | ||
|
||
if opts.stdin { | ||
count := 0 | ||
sc := bufio.NewScanner(os.Stdin) | ||
for sc.Scan() { | ||
msg := sc.Text() | ||
if msg != "" { | ||
if count < 20 { | ||
messages[count] = msg | ||
count++ | ||
} else { | ||
messages[count] = "Sent 20 domains, there are more on the server." | ||
break | ||
} | ||
|
||
} else { | ||
break | ||
} | ||
} | ||
|
||
opts.message = strings.Join(messages[:], "\n") | ||
} | ||
|
||
if opts.telegram { | ||
telegramAPIKey := cfg.Section("Telegram").Key("api_key").String() | ||
telegramUser := cfg.Section("Telegram").Key("chat_id").String() | ||
|
||
resp, err := Telegram(telegramUser, telegramAPIKey, opts.message) | ||
|
||
checkResponse(resp, err) | ||
} | ||
|
||
if opts.slack { | ||
slackWebhook := cfg.Section("Slack").Key("webhook").String() | ||
|
||
resp, err := Slack(opts.message, slackWebhook) | ||
|
||
checkResponse(resp, err) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
# nothing to see here, just a utility i use to create new releases ^_^ | ||
|
||
CURRENT_VERSION=$(cat version.go | grep VERSION | cut -d '"' -f 2) | ||
|
||
echo -n "Current version is $CURRENT_VERSION, select new version: " | ||
read NEW_VERSION | ||
echo "Creating version $NEW_VERSION ..." | ||
|
||
echo "Updating version.go" | ||
sed -i "s/$CURRENT_VERSION/$NEW_VERSION/g" version.go | ||
|
||
git add version.go | ||
git commit -m "Releasing v$NEW_VERSION" | ||
git push | ||
|
||
git tag -a v$NEW_VERSION -m "Release v$NEW_VERSION" | ||
git push origin v$NEW_VERSION | ||
|
||
rm -rf dist | ||
|
||
echo "All done, just run goreleaser now ^_^" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package main | ||
|
||
// VERSION Emissary version | ||
const VERSION = "0.8" |