diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..944718d --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +ko_fi: dwisiswant0 +custom: ["https://paypal.me/dw1s", "https://saweria.co/dwisiswant0"] diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..689f7bb --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,22 @@ +name: Build +on: + push: + branches: + - master + pull_request: + +jobs: + build: + name: Dependencies + runs-on: ubuntu-latest + steps: + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.11 + + - name: Check out code + uses: actions/checkout@v2 + + - name: Build + run: go build . \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..6b62aaa --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,27 @@ +name: Release +on: + create: + tags: + - v* + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: "Check out code" + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: "Set up Go" + uses: actions/setup-go@v2 + with: + go-version: 1.13 + + - name: "Create release on GitHub" + uses: goreleaser/goreleaser-action@v2 + env: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + with: + args: "release --rm-dist" + version: latest diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..d5e666f --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,21 @@ +builds: + - binary: discat + main: main.go + goos: + - linux + - windows + - darwin + goarch: + - amd64 + - 386 + - arm + - arm64 + +archives: + - id: tgz + format: tar.gz + replacements: + darwin: macOS + format_overrides: + - goos: windows + format: zip diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..af3ac66 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 dwisiswant0 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..c5db03a --- /dev/null +++ b/README.md @@ -0,0 +1,66 @@ +# discat + +A simple way of sending messages from the CLI output to your Discord channel with webhook. +> Actually, this is a fork version of [slackcat](https://github.com/dwisiswant0/slackcat) that I made too! + +## Installation + +- Download a prebuilt binary from [releases page](https://github.com/dwisiswant0/discat/releases/latest), unpack and run! or +- If you have go1.13+ compiler installed: `go get dw1.みんな/discat`. + +## Configuration + +**Step 1:** Get yours Discord channel webhook URL [here](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks). + +**Step 2** _(optional)_**:** Set `DISCORD_WEBHOOK_URL` environment variable. +```bash +export DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/xnxx/xxx-xxx" +``` + +## Usage + +It's very simple! + +```bash +▶ echo -e "Hello,\nworld!" | discat +``` + +### Flags + +``` +Usage of discat: + -1 Send message line-by-line + -u string + Discord Webhook URL + -v Verbose mode +``` + +### Workaround + +The goal is to get automated alerts for interesting stuff! + +```bash +▶ assetfinder twitter.com | anew | discat -u https://hooks.discord.com/services/xxx/xxx/xxx +``` + +The `-u` flag is optional if you've defined `DISCORD_WEBHOOK_URL` environment variable. + +Discat also strips the ANSI colors from stdin to send messages, so you'll receive a clean message on your Discord! + +```bash +▶ nuclei -l urls.txt -t cves/ | discat +``` + +![Proof](https://user-images.githubusercontent.com/25837540/108782401-1571e380-759e-11eb-8d20-dfcc9294a30a.png) + +### Line-by-line + +Instead of have to wait for previously executed program to finish, use the `-1` flag if you want to send messages on a line by line _(default: false)_. + +```bash +▶ amass track -d domain.tld | discat -1 +``` + +## License + +`discat` is distributed under MIT License. \ No newline at end of file diff --git a/discat b/discat new file mode 100755 index 0000000..867e955 Binary files /dev/null and b/discat differ diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..300dd04 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module dw1.みんな/discat + +go 1.13 + +require github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..51f6dd9 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8= +github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo= diff --git a/main.go b/main.go new file mode 100644 index 0000000..7fda227 --- /dev/null +++ b/main.go @@ -0,0 +1,86 @@ +package main + +import ( + "bufio" + "encoding/json" + "flag" + "fmt" + "net/http" + "os" + "strings" + "sync" + + "github.com/acarl005/stripansi" +) + +var wg sync.WaitGroup + +func main() { + var oneLine, verboseMode bool + var webhookURL, lines string + + flag.StringVar(&webhookURL, "u", "", "Discord Webhook URL") + flag.BoolVar(&oneLine, "1", false, "Send message line-by-line") + flag.BoolVar(&verboseMode, "v", false, "Verbose mode") + flag.Parse() + + webhookEnv := os.Getenv("DISCORD_WEBHOOK_URL") + if webhookEnv != "" { + webhookURL = webhookEnv + } else { + if webhookURL == "" { + if verboseMode { + fmt.Println("Discord Webhook URL not set!") + } + } + } + + if !isStdin() { + os.Exit(1) + } + + sc := bufio.NewScanner(os.Stdin) + for sc.Scan() { + line := sc.Text() + + fmt.Println(line) + if oneLine { + if webhookURL != "" { + wg.Add(1) + go disCat(webhookURL, line) + } + } else { + lines += line + lines += "\n" + } + } + + if !oneLine { + wg.Add(1) + go disCat(webhookURL, lines) + } + wg.Wait() +} + +func isStdin() bool { + f, e := os.Stdin.Stat() + if e != nil { + return false + } + + if f.Mode()&os.ModeNamedPipe == 0 { + return false + } + + return true +} + +type data struct { + Content string `json:"content"` +} + +func disCat(url string, line string) { + data, _ := json.Marshal(data{Content: stripansi.Strip(line)}) + http.Post(url, "application/json", strings.NewReader(string(data))) + wg.Done() +}