Skip to content

Commit

Permalink
Replace unmaintained caching library with local generic implementation
Browse files Browse the repository at this point in the history
Log API requests
Support JSON logs (`--prettyLog=false`)
Update GitHub Actions
  • Loading branch information
wolveix committed Mar 9, 2024
1 parent 76adb90 commit feb398a
Show file tree
Hide file tree
Showing 13 changed files with 276 additions and 100 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@master
uses: actions/checkout@v4

- name: Build
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: '^1.20.0'
go-version: '^1.22.0'
- run: |
cd cmd/dss
go build -o dss
27 changes: 16 additions & 11 deletions .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
name: Cleanup

on: [pull_request]
on: pull_request

jobs:
prettier:
runs-on: ubuntu-latest
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write

steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
# Make sure the actual branch is checked out when running on pull requests
ref: ${{ github.head_ref }}
# This is important to fetch the changes to the previous commit
fetch-depth: 0
go-version: '^1.22.0' # The Go version to download (if necessary) and use.

- name: Install gofumpt
run: go install mvdan.cc/gofumpt@latest

- name: Format code
uses: iamnotaturtle/auto-gofmt@v2.1.0
run: gofumpt -w .

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
# This part is also where you can pass other options, for example:
only_changed: True
commit_message: Apply gofumpt formatting
52 changes: 30 additions & 22 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
name: Docker

on:
push:
branches:
- main
- dev
on: push

jobs:
push:
name: Build and Release Docker Image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Checkout Repo
uses: actions/checkout@v4

- name: Log into registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Setup Image Name
run: |
echo "IMAGE_ID=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
- name: Build image
run: docker build . --file Dockerfile --tag image
- name: Login to GitHub Packages
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Push image to Github Packages
run: |
IMAGE_ID=ghcr.io/${{ github.repository }}
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
[ "$VERSION" == "main" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag image $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
- name: Docker Metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ env.IMAGE_ID }}
tags: |
type=raw,value=dev
- name: Build and push to GitHub Packages
id: docker_build
uses: docker/build-push-action@v2
with:
push: true
tags: |
ghcr.io/${{ env.IMAGE_ID }}:dev
${{ steps.meta.outputs.tags }}
52 changes: 46 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
name: Release
on: push
on:
release:
types: [published]

jobs:
build:
name: Build and Release
name: Build and Release Binaries
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@master
uses: actions/checkout@v4

- name: Setup Go Environment
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: '^1.20.0'
go-version: '^1.22.0'

- name: Build Binaries
run: |
Expand All @@ -22,7 +24,45 @@ jobs:
gox --output "../../builds/dss-{{.OS}}-{{.Arch}}" -ldflags '-s -w' -osarch 'darwin/amd64 darwin/arm64 linux/amd64 linux/arm freebsd/amd64 windows/amd64'
cd ../../builds
find . -maxdepth 1 -type f -execdir zip 'compressed/{}.zip' '{}' \;
- name: Upload Binaries
run: |
go install github.com/tcnksm/ghr@latest
ghr -t ${{ secrets.GITHUB_TOKEN }} --delete Latest builds/compressed/
ghr -t ${{ secrets.GITHUB_TOKEN }} --delete Latest builds/compressed/
docker:
name: Build and Release Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Setup Image Name
run: |
echo "IMAGE_ID=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
- name: Login to GitHub Packages
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker Metadata
id: meta
uses: docker/metadata-action@v3
with:
images: |
ghcr.io/${{ env.IMAGE_ID }}
tags: |
type=semver,pattern=v{{version}}
type=semver,pattern=v{{major}}.{{minor}}
type=semver,pattern=v{{major}}
flavor: |
latest=true
- name: Build and Push to GitHub Packages
id: docker_build
uses: docker/build-push-action@v2
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,11 @@ You can then email this inbox from any address, and you'll receive an email back
| `--debug` | `-d` | Print debug logs |
| `--dkimSelector` | | Specify a comma seperated list of DKIM selectors (default "") |
| `--dnsBuffer` | | Specify the allocated buffer for DNS responses (default 4096) |
| `--dnsProtocol` | | Use udp, tcp, or tcp-tls for DNS queries (default udp) |
| `--dnsProtocol` | | Protocol to use for DNS queries (udp, tcp, tcp-tls) (default udp) |
| `--format` | `-f` | Format to print results in (yaml, json, csv) (default "yaml") |
| `--nameservers` | `-n` | Use specific nameservers, in host[:port] format; may be specified multiple times |
| `--outputFile` | `-o` | Output the results to a specified file (creates a file with the current unix timestamp if no file is specified) |
| `--prettyLog` | `-p` | Pretty print logs to console (default true) |
| `--timeout` | `-t` | Timeout duration for a DNS query (default 15s) |
| `--zoneFile` | `-z` | Input file/pipe containing an RFC 1035 zone file |

Expand Down
36 changes: 23 additions & 13 deletions cmd/dss/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/csv"
"fmt"
"io"
"os"
"runtime"
"strings"
Expand All @@ -25,12 +26,20 @@ var (
Use: "dss",
Short: "Scan a domain's DNS records.",
Long: "Scan a domain's DNS records.\n/~https://github.com/GlobalCyberAlliance/domain-security-scanner",
Version: "3.0.3",
Version: "3.0.4",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
var logWriter io.Writer

if prettyLog {
logWriter = zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339}
} else {
logWriter = os.Stdout
}

if debug {
log = zerolog.New(zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339}).With().Timestamp().Logger().Level(zerolog.DebugLevel)
log = zerolog.New(logWriter).With().Timestamp().Logger().Level(zerolog.DebugLevel)
} else {
log = zerolog.New(zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339}).With().Timestamp().Logger().Level(zerolog.InfoLevel)
log = zerolog.New(logWriter).With().Timestamp().Logger().Level(zerolog.InfoLevel)
}

configDir, err := os.UserHomeDir()
Expand All @@ -55,15 +64,15 @@ var (
},
}

cfg *Config
log zerolog.Logger
writeToFileCounter int
dnsProtocol, format, outputFile string
dkimSelector, nameservers []string
advise, debug, checkTLS, zoneFile bool
dnsBuffer uint16
cache, timeout time.Duration
concurrent uint16
cfg *Config
log zerolog.Logger
writeToFileCounter int
dnsProtocol, format, outputFile string
dkimSelector, nameservers []string
advise, debug, checkTLS, prettyLog, zoneFile bool
dnsBuffer uint16
cache, timeout time.Duration
concurrent uint16
)

func main() {
Expand All @@ -74,10 +83,11 @@ func main() {
cmd.PersistentFlags().BoolVarP(&debug, "debug", "d", false, "Print debug logs")
cmd.PersistentFlags().StringSliceVar(&dkimSelector, "dkimSelector", []string{}, "Specify a DKIM selector")
cmd.PersistentFlags().Uint16Var(&dnsBuffer, "dnsBuffer", 4096, "Specify the allocated buffer for DNS responses")
cmd.PersistentFlags().StringVar(&dnsProtocol, "dnsProtocol", "udp", "Use udp, tcp, or tcp-tls for DNS queries")
cmd.PersistentFlags().StringVar(&dnsProtocol, "dnsProtocol", "udp", "Protocol to use for DNS queries (udp, tcp, tcp-tls)")
cmd.PersistentFlags().StringVarP(&format, "format", "f", "yaml", "Format to print results in (yaml, json)")
cmd.PersistentFlags().StringSliceVarP(&nameservers, "nameservers", "n", nil, "Use specific nameservers, in `host[:port]` format; may be specified multiple times")
cmd.PersistentFlags().StringVarP(&outputFile, "outputFile", "o", "", "Output the results to a specified file (creates a file with the current unix timestamp if no file is specified)")
cmd.PersistentFlags().BoolVar(&prettyLog, "prettyLog", true, "Pretty print logs to console")
cmd.PersistentFlags().DurationVarP(&timeout, "timeout", "t", 15*time.Second, "Timeout duration for queries")
cmd.PersistentFlags().BoolVarP(&zoneFile, "zoneFile", "z", false, "Input file/pipe containing an RFC 1035 zone file")

Expand Down
11 changes: 5 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ module github.com/GlobalCyberAlliance/domain-security-scanner
go 1.22.0

require (
github.com/danielgtaylor/huma/v2 v2.6.0
github.com/danielgtaylor/huma/v2 v2.7.0
github.com/emersion/go-imap v1.2.1
github.com/go-chi/chi/v5 v5.0.12
github.com/go-chi/cors v1.2.1
github.com/go-chi/httprate v0.9.0
github.com/goccy/go-json v0.10.2
github.com/miekg/dns v1.1.58
github.com/panjf2000/ants/v2 v2.9.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.32.0
github.com/spf13/cast v1.6.0
Expand All @@ -34,10 +33,10 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/x448/float16 v0.8.4 // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.18.0 // indirect
golang.org/x/tools v0.19.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)
24 changes: 12 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/danielgtaylor/casing v1.0.0 h1:uX+PewTv0zbXeTluwRwlyPMRQEduVP9svLHpbDsQYkw=
github.com/danielgtaylor/casing v1.0.0/go.mod h1:eFdYmNxcuLDrRNW0efVoxSaApmvGXfHZ9k2CT/RSUF0=
github.com/danielgtaylor/huma/v2 v2.6.0 h1:pSENofc3vLr/48RHzgt48xwxdGFTK8hv1AkL0zch5EE=
github.com/danielgtaylor/huma/v2 v2.6.0/go.mod h1:DHyK1k2u/UqSLgsO5dG1focxyeHg3UUkfB7tti0ZRwc=
github.com/danielgtaylor/huma/v2 v2.7.0 h1:OmDvHqu4IWd/9Yk/si9D6k/YnBVdqlVsPn+6pfrpsdk=
github.com/danielgtaylor/huma/v2 v2.7.0/go.mod h1:0CHjhhZd2ApZfj74Fd4esGaSMXcCK2Y9qoYPU0Cltis=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -33,6 +33,8 @@ github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MG
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
Expand All @@ -52,8 +54,6 @@ github.com/miekg/dns v1.1.58 h1:ca2Hdkz+cDg/7eNF6V56jjzuZ4aCAE+DbVkILdQWG/4=
github.com/miekg/dns v1.1.58/go.mod h1:Ypv+3b/KadlvW9vJfXOTf300O4UqaHFzFCuHz+rPkBY=
github.com/panjf2000/ants/v2 v2.9.0 h1:SztCLkVxBRigbg+vt0S5QvF5vxAbxbKt09/YfAJ0tEo=
github.com/panjf2000/ants/v2 v2.9.0/go.mod h1:7ZxyxsqE4vvW0M7LSD8aI3cKwgFhBHbxnlN8mDqHa1I=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down Expand Up @@ -83,25 +83,25 @@ github.com/wneessen/go-mail v0.4.1 h1:m2rSg/sc8FZQCdtrV5M8ymHYOFrC6KJAQAIcgrXvqo
github.com/wneessen/go-mail v0.4.1/go.mod h1:zxOlafWCP/r6FEhAaRgH4IC1vg2YXxO0Nar9u0IScZ8=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic=
golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ=
golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg=
golang.org/x/tools v0.19.0 h1:tfGCXNR1OsFG+sVdLAitlpjAvD/I6dHDKnYrpEZUHkw=
golang.org/x/tools v0.19.0/go.mod h1:qoJWxmGSIBmAeriMx19ogtrEPrGtDbPK634QFIcLAhc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
Loading

0 comments on commit feb398a

Please sign in to comment.