Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.1.0 #2

Merged
merged 4 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
if: steps.git_diff.outputs.diff_exists == 'true'
id: get_tag
run: |
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1) 2>/dev/null || echo "v0.0.0")
LATEST_TAG=$(make get-version)
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT

- name: Calculate new tag
Expand Down
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Define LATEST_TAG to get the latest Git tag, or fallback to "v0.0.0" if no tag exists
LATEST_TAG=$(shell git describe --tags $$(git rev-list --tags --max-count=1) 2>/dev/null || echo "v0.0.0")

# Define VERSION to remove the "v" prefix from LATEST_TAG
VERSION=$(shell echo $(LATEST_TAG) | sed 's/^v//')

.PHONY: all
all: lint generate pre-build build test

Expand All @@ -19,8 +25,12 @@ pre-build: generate

.PHONY: build
build: pre-build generate
go build -o ./bin/cli ./cmd/cli/*.go
go build -ldflags="-X main.version=$(VERSION)" -o ./bin/cli ./cmd/cli/*.go

.PHONY: test
test:
go test ./...

.PHONY: get-version
get-version:
@echo $(VERSION)
115 changes: 98 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,109 @@
# cloudfinder

Detect the cloud / hosting provider of a given IP. Fast, static & offline.
Detect the cloud / hosting provider of a given host. Fast, static & offline.
Cloudfinder offers both a cli and a golang package.

## CLI Usage

Installing the binary:
TODO
### Installation

From url:
TODO
Run install script: `curl -sSL https://raw.githubusercontent.com/Escape-Technologies/cloudfinder/main/install.sh | sh`
Or directly download a [release](https://github.com/Escape-Technologies/cloudfinder/releases/latest).

From cloned repository:
`go run cmd/cli/cli.go cmd/cli/dial.go <domain, ip, url, ...>`
### Usage

## PKG Usage
```bash
cloudfinder [flags] <ip, host, domain, url> <ip, host, domain, url> ...
Flags:
-debug
enable debug mode
-h print help
-help
print help
-json
output json
-raw
output raw provider string
-v print version number
-version
print version number
```

## Examples

```bash
cloudfinder escape.tech
[15:06:39.755] INFO: escape.tech (13.39.28.216): Aws
[15:06:39.756] INFO: escape.tech (13.37.196.127): Aws
[15:06:39.756] INFO: escape.tech (13.36.180.15): Aws
```

You can provide multiple inputs:

```bash
cloudfinder escape.tech jobs.escape.tech
[15:31:34.602] INFO: escape.tech (13.39.28.216): Aws
[15:31:34.603] INFO: escape.tech (13.37.196.127): Aws
[15:31:34.603] INFO: escape.tech (13.36.180.15): Aws
[15:31:34.623] INFO: jobs.escape.tech (52.6.1.219): Aws
[15:31:34.623] INFO: jobs.escape.tech (44.212.166.106): Aws
[15:31:34.623] INFO: jobs.escape.tech (52.55.10.55): Aws
```

Or take the input from stdin:

```bash
echo "escape.tech" | cloudfinder
[15:07:43.573] INFO: escape.tech (13.39.28.216): Aws
[15:07:43.573] INFO: escape.tech (13.37.196.127): Aws
[15:07:43.573] INFO: escape.tech (13.36.180.15): Aws
```

Output can also be raw text:

```bash
cloudfinder --raw escape.tech
escape.tech,13.37.196.127,Aws
escape.tech,13.39.28.216,Aws
escape.tech,13.36.180.15,Aws
```

Add dependency:
TODO
Or JSON:

```bash
cloudfinder --json escape.tech
{"input":"escape.tech","ip":"13.37.196.127","provider":"Aws"}
{"input":"escape.tech","ip":"13.36.180.15","provider":"Aws"}
{"input":"escape.tech","ip":"13.39.28.216","provider":"Aws"}
```

### Example: using with subfinder

You can pipe the output of external tools into cloudfinder. Here is an example using [subfinder](https://github.com/projectdiscovery/subfinder) to enumerate all subdomains of a given domain, and then finding their cloud providers.

```bash
# run subfinder pipe to cloudfinder and use jq to collect into a single json
subfinder -d "escape.tech" | cloudfinder --json | jq -s '.'

# You'll get errors on stderr for domains that are not exposed and you'll get on stdout:
[
{
"input": "www.jobs.escape.tech",
"ip": "52.6.1.219",
"provider": "Aws"
},
# ...
{
"input": "www.docs.escape.tech",
"ip": "76.76.21.123",
"provider": "Vercel"
}
]
```

## Go Package Usage

Add dependency: `go get github.com/Escape-Technologies/cloudfinder@latest`

Use cloudfinder:

Expand All @@ -27,8 +113,8 @@ package main
import (
"net"

"escape.tech/cloudfinder/pkg/cloud"
"escape.tech/cloudfinder/pkg/provider"
"github.com/Escape-Technologies/cloudfinder/pkg/cloud"
"github.com/Escape-Technologies/cloudfinder/pkg/provider"
)

func main() {
Expand All @@ -52,9 +138,4 @@ func main() {
}
}
}

```

## pre build

`go run cmd/pre-build/pre-build.go`
25 changes: 18 additions & 7 deletions cmd/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ import (
"net"
"os"

"escape.tech/cloudfinder/internal/log"
"escape.tech/cloudfinder/pkg/cloud"
"escape.tech/cloudfinder/pkg/provider"
"github.com/Escape-Technologies/cloudfinder/internal/log"
"github.com/Escape-Technologies/cloudfinder/pkg/cloud"
"github.com/Escape-Technologies/cloudfinder/pkg/provider"
)

// Version is injected during build
var version string

type args struct {
inputs chan string
debug bool
Expand Down Expand Up @@ -77,7 +80,9 @@ func parseArgs() args {
a.mode = outputDefault
flag.BoolVar(&a.debug, "debug", false, "enable debug mode")

var json, raw, help bool
var showVersion, json, raw, help bool
flag.BoolVar(&showVersion, "version", false, "print version number")
flag.BoolVar(&showVersion, "v", false, "print version number")
flag.BoolVar(&json, "json", false, "output json")
flag.BoolVar(&raw, "raw", false, "output raw provider string")

Expand All @@ -91,6 +96,11 @@ func parseArgs() args {
os.Exit(0)
}

if showVersion {
fmt.Printf("%s\n", version)
os.Exit(0)
}

switch {
case json:
a.mode = outputJson
Expand Down Expand Up @@ -118,7 +128,6 @@ func main() {
ips, err := getIPsForURL(context.Background(), i)
if err != nil {
log.Error("Failed to get ips, verify input", err)
os.Exit(1)
}

for _, ip := range ips {
Expand Down Expand Up @@ -158,8 +167,10 @@ func printOutput(input string, ip net.IP, p provider.Provider, mode outputMode)
case outputDefault:
log.Info("%s (%s): %s", input, ip.String(), p.String())
case outputJson:
println(marshallOutput(input, ip, p))
// Print to stdout
fmt.Println(marshallOutput(input, ip, p))
case outputRaw:
println(p.String())
// Print to stdout
fmt.Printf("%s,%s,%s\n", input, ip.String(), p.String())
}
}
6 changes: 3 additions & 3 deletions cmd/pre-build/pre-build.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

"crypto/sha256"

"escape.tech/cloudfinder/internal/log"
"escape.tech/cloudfinder/internal/source"
"escape.tech/cloudfinder/internal/tree"
"github.com/Escape-Technologies/cloudfinder/internal/log"
"github.com/Escape-Technologies/cloudfinder/internal/source"
"github.com/Escape-Technologies/cloudfinder/internal/tree"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions examples/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import (
"net"

"escape.tech/cloudfinder/pkg/cloud"
"escape.tech/cloudfinder/pkg/provider"
"github.com/Escape-Technologies/cloudfinder/pkg/cloud"
"github.com/Escape-Technologies/cloudfinder/pkg/provider"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module escape.tech/cloudfinder
module github.com/Escape-Technologies/cloudfinder

go 1.22
2 changes: 1 addition & 1 deletion internal/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func NewLogger(level slog.Level) *slog.Logger {
return slog.New(
handler{
slog.NewTextHandler(
os.Stdout,
os.Stderr,
&slog.HandlerOptions{
Level: level,
ReplaceAttr: replaceAttr,
Expand Down
2 changes: 1 addition & 1 deletion internal/log/pretty.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func newPretty(handlerOptions *slog.HandlerOptions, options ...Option) *prettyHa
}

func newPrettyHandler(opts *slog.HandlerOptions) *prettyHandler {
return newPretty(opts, WithDestinationWriter(os.Stdout), WithColor(), WithOutputEmptyAttrs())
return newPretty(opts, WithDestinationWriter(os.Stderr), WithColor())
}

type Option func(h *prettyHandler)
Expand Down
2 changes: 1 addition & 1 deletion internal/source/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net"
"sync"

"escape.tech/cloudfinder/pkg/provider"
"github.com/Escape-Technologies/cloudfinder/pkg/provider"
)

type IPCat int
Expand Down
4 changes: 2 additions & 2 deletions internal/source/source_alibaba.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package source

import (
"escape.tech/cloudfinder/internal/log"
"escape.tech/cloudfinder/pkg/provider"
"github.com/Escape-Technologies/cloudfinder/internal/log"
"github.com/Escape-Technologies/cloudfinder/pkg/provider"
)

type Alibaba struct{}
Expand Down
4 changes: 2 additions & 2 deletions internal/source/source_aws.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package source

import (
"escape.tech/cloudfinder/internal/log"
"escape.tech/cloudfinder/pkg/provider"
"github.com/Escape-Technologies/cloudfinder/internal/log"
"github.com/Escape-Technologies/cloudfinder/pkg/provider"
)

type Aws struct{}
Expand Down
4 changes: 2 additions & 2 deletions internal/source/source_azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"net/http"
"regexp"

"escape.tech/cloudfinder/internal/log"
"escape.tech/cloudfinder/pkg/provider"
"github.com/Escape-Technologies/cloudfinder/internal/log"
"github.com/Escape-Technologies/cloudfinder/pkg/provider"
)

type Azure struct{}
Expand Down
4 changes: 2 additions & 2 deletions internal/source/source_cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package source
import (
"strings"

"escape.tech/cloudfinder/internal/log"
"escape.tech/cloudfinder/pkg/provider"
"github.com/Escape-Technologies/cloudfinder/internal/log"
"github.com/Escape-Technologies/cloudfinder/pkg/provider"
)

type Cloudflare struct{}
Expand Down
4 changes: 2 additions & 2 deletions internal/source/source_digitalocean.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"encoding/csv"
"strings"

"escape.tech/cloudfinder/internal/log"
"escape.tech/cloudfinder/pkg/provider"
"github.com/Escape-Technologies/cloudfinder/internal/log"
"github.com/Escape-Technologies/cloudfinder/pkg/provider"
)

type Digitalocean struct{}
Expand Down
4 changes: 2 additions & 2 deletions internal/source/source_fastly.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package source

import (
"escape.tech/cloudfinder/internal/log"
"escape.tech/cloudfinder/pkg/provider"
"github.com/Escape-Technologies/cloudfinder/internal/log"
"github.com/Escape-Technologies/cloudfinder/pkg/provider"
)

type Fastly struct{}
Expand Down
4 changes: 2 additions & 2 deletions internal/source/source_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package source
import (
"errors"

"escape.tech/cloudfinder/internal/log"
"escape.tech/cloudfinder/pkg/provider"
"github.com/Escape-Technologies/cloudfinder/internal/log"
"github.com/Escape-Technologies/cloudfinder/pkg/provider"
)

type Gcp struct{}
Expand Down
4 changes: 2 additions & 2 deletions internal/source/source_ibm.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package source

import (
"escape.tech/cloudfinder/internal/log"
"escape.tech/cloudfinder/pkg/provider"
"github.com/Escape-Technologies/cloudfinder/internal/log"
"github.com/Escape-Technologies/cloudfinder/pkg/provider"
)

type Ibm struct{}
Expand Down
4 changes: 2 additions & 2 deletions internal/source/source_linode.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package source

import (
"escape.tech/cloudfinder/internal/log"
"escape.tech/cloudfinder/pkg/provider"
"github.com/Escape-Technologies/cloudfinder/internal/log"
"github.com/Escape-Technologies/cloudfinder/pkg/provider"
)

type Linode struct{}
Expand Down
Loading
Loading