diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index e22614c..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,88 +0,0 @@ -version: 2 -jobs: - build: - docker: - - image: circleci/golang:1.13 - working_directory: /go/src/github.com/alphasoc/flightsim - steps: - - checkout - - run: go install -mod vendor -v ./... - - run: go test -mod vendor -race -v ./... - - run: - name: build - command: | - GOARCH=amd64 GOOS=windows go build -mod vendor -o flightsim-windows-amd64.exe -ldflags "-X main.Version=$(git describe)" - GOARCH=amd64 GOOS=linux go build -mod vendor -o flightsim-linux-amd64 -ldflags "-X main.Version=$(git describe)" - GOARCH=amd64 GOOS=darwin go build -mod vendor -o flightsim-darwin-amd64 -ldflags "-X main.Version=$(git describe)" - - persist_to_workspace: - root: . - paths: - - flightsim-windows-amd64.exe - - flightsim-linux-amd64 - - flightsim-darwin-amd64 - # lint: - # docker: - # - image: circleci/golang:1.13 - # working_directory: /go/src/github.com/alphasoc/flightsim - # steps: - # - checkout - # - restore_cache: - # key: gometalinter-tools-{{ checksum "/go/bin/gometalinter" }} - # - run: go get github.com/alecthomas/gometalinter - # - run: gometalinter --install - # - save_cache: - # key: gometalinter-tools-{{ checksum "/go/bin/gometalinter" }} - # paths: - # - /go/bin/ - # - run: go install ./... - # - run: - # name: run linters - # command: | - # gometalinter \ - # --vendor \ - # --disable-all \ - # --enable=gofmt \ - # --enable=golint \ - # --enable=goimports \ - # --enable=vetshadow \ - # --enable=misspell \ - # --enable=vet ./... - - publish: - docker: - - image: circleci/golang:1.13 - working_directory: /go/src/github.com/alphasoc/flightsim - steps: - - attach_workspace: - at: . - - run: - name: publish - command: | - go get github.com/aktau/github-release - github-release release --draft --user alphasoc --repo flightsim --tag $CIRCLE_TAG - github-release upload --user alphasoc --repo flightsim --tag $CIRCLE_TAG --name flightsim-windows-amd64.exe --file flightsim-windows-amd64.exe - github-release upload --user alphasoc --repo flightsim --tag $CIRCLE_TAG --name flightsim-linux-amd64 --file flightsim-linux-amd64 - github-release upload --user alphasoc --repo flightsim --tag $CIRCLE_TAG --name flightsim-darwin-amd64 --file flightsim-darwin-amd64 - -workflows: - version: 2 - build_and_deploy: - jobs: - - build: - filters: - tags: - only: /^v[0-9]+[.].*$/ - # - lint: - # filters: - # tags: - # only: /^v[0-9]+[.].*$/ - - publish: - context: github-alphasoc-deploy - requires: - - build - # - lint - filters: - tags: - only: /^v[0-9]+[.].*$/ - branches: - ignore: /.*/ diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..21222b7 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,51 @@ +name: builder-releaser + +on: + push: + pull_request: + +permissions: + contents: write + +jobs: + build-test-vet-release: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v2 + - + name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.16 + - + name: Build + run: go build -v ./... + - + name: Test + run: go test -v ./... + - + name: Vet + run: go vet -v ./... + - + if: startsWith(github.ref, 'refs/tags/v') == true + name: Import GPG key + id: import_gpg + uses: crazy-max/ghaction-import-gpg@v3 + with: + gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} + passphrase: ${{ secrets.GPG_PRIVATE_KEY_PASSPHRASE }} + - + if: startsWith(github.ref, 'refs/tags/v') == true + name: GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + # either 'goreleaser' (default) or 'goreleaser-pro' + distribution: goreleaser + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution + # GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..ca1331a --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,64 @@ +builds: + # You can have multiple builds defined as a yaml list. + - + goos: + - linux + - freebsd + - darwin + - windows + # GOARCH to build for. + # For more info refer to: https://golang.org/doc/install/source#environment + # Defaults are 386, amd64 and arm64. + goarch: + - amd64 + +nfpms: + # note that this is an array of nfpm configs + - + # Replacements for GOOS and GOARCH in the package name. + # Keys should be valid GOOSs or GOARCHs. + # Values are the respective replacements. + # Default is empty. + replacements: + amd64: 64-bit + darwin: macOS + vendor: alphasoc + homepage: https://alphasoc.com/ + maintainer: AlphaSOC + description: A lightweight utility used to generate malicious network traffic and help + security teams to evaluate security controls and network visibility. + license: CCPL + # Formats to be generated. + formats: + - deb + - rpm + - apk + +release: + # If set to auto, will mark the release as not ready for production + # in case there is an indicator for this in the tag e.g. v1.0.0-rc1 + # If set to true, will mark the release as not ready for production. + # Default is false. + prerelease: auto + # If set to true, will not auto-publish the release. + # Default is false. + draft: true + # Header template for the release body. + header: | + ## Flightsim Release - {{ time "2006-02-01" }} + + Welcome to this new release! + + # Footer template for the release body. + footer: | + ## Enjoy! + + Those were the changes on {{ .Tag }}! + + # You can change the name of the release. + # Default is `{{.Tag}}` on OSS and `{{.PrefixedTag}}` on Pro. + name_template: "{{.ProjectName}}-v{{.Version}}" + +# Sign all artifacts. +signs: + - artifacts: all diff --git a/simulator/scan.go b/simulator/scan.go index 6b467c5..a37d66d 100644 --- a/simulator/scan.go +++ b/simulator/scan.go @@ -109,7 +109,8 @@ func (s *PortScan) Simulate(ctx context.Context, dst string) error { // TODO: allow for multiple connection in parallel and hence a longer deadline for _, port := range scanPorts { - ctx, _ := context.WithTimeout(ctx, callTimeout) + ctx, cancelFn := context.WithTimeout(ctx, callTimeout) + defer cancelFn() err := s.tcp.Simulate(ctx, fmt.Sprintf("%s:%d", dst, port)) if err != nil { return err diff --git a/simulator/tunnel-dns.go b/simulator/tunnel-dns.go index 5ef7346..fa83797 100644 --- a/simulator/tunnel-dns.go +++ b/simulator/tunnel-dns.go @@ -50,7 +50,8 @@ func (s *Tunnel) Simulate(ctx context.Context, host string) error { label := strings.ToLower(utils.RandString(30)) - ctx, _ := context.WithTimeout(ctx, 200*time.Millisecond) + ctx, cancelFn := context.WithTimeout(ctx, 200*time.Millisecond) + defer cancelFn() _, err := r.LookupTXT(ctx, fmt.Sprintf("%s.%s", label, host)) // ignore timeout and "no such host" @@ -61,8 +62,6 @@ func (s *Tunnel) Simulate(ctx context.Context, host string) error { // wait until context expires so we don't flood <-ctx.Done() } - - return nil } // Hosts returns random generated hosts to alphasoc sandbox.