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

Add support for TLS servers #1210

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
62a3bd8
Add support for TLS servers
Feb 5, 2023
97cc7c4
Fixed an issue with the install script failing on mac on the checksum…
richwrightnyc Jan 17, 2023
4d6a635
Fixed no newline at end of file
richwrightnyc Jan 17, 2023
827e2c1
refactor installer script to make it more robust and flexible. Adds o…
richwrightnyc Feb 1, 2023
0e7ddd8
fixed some typos
richwrightnyc Feb 1, 2023
6f66cb4
squashed some bugs, further testing needed
richwrightnyc Feb 20, 2023
2f64f4f
fixed a few typos, should be ready for review
richwrightnyc Feb 20, 2023
5cd121d
removed one additional debug item. ready for review
richwrightnyc Feb 20, 2023
303055b
fix shellcheck SC2076 (warning): Remove quotes from right-hand side o…
richwrightnyc Mar 1, 2023
4f3b888
fixed 2 shellcheck issues:
richwrightnyc Mar 1, 2023
a047b58
fix(deps): bump actions/setup-go from 3.2.0 to 3.5.0
dependabot[bot] Feb 6, 2023
3f47084
fix(deps): bump goreleaser/goreleaser-action from 4.1.1 to 4.2.0
dependabot[bot] Feb 6, 2023
353e98f
fix(deps): bump docker/login-action from 1.14.1 to 2.1.0
dependabot[bot] Feb 13, 2023
5a2f44f
fix(deps): bump actions/setup-python from 4.3.1 to 4.5.0
dependabot[bot] Feb 13, 2023
6a69f5b
fix(deps): bump actions/checkout from 3.0.0 to 3.3.0
dependabot[bot] Feb 20, 2023
1d35c51
docs: install instructions
sundowndev Mar 1, 2023
719bc31
docs: readme
sundowndev Mar 8, 2023
f6fcd89
ci: create homebrew workflow
sundowndev Feb 14, 2023
ae667a8
chore: update makefile
sundowndev Feb 14, 2023
7e303f6
docs: add homebrew installation
sundowndev Mar 10, 2023
bc1e54a
docs: contribute
sundowndev Mar 3, 2023
6d55658
docs: contribute
sundowndev Mar 19, 2023
2820266
fix(deps): bump actions/checkout from 3.3.0 to 3.4.0
dependabot[bot] Mar 20, 2023
d32c5e0
ci: homebrew workflow
sundowndev Mar 23, 2023
7e968e4
fix(deps): bump actions/checkout from 3.4.0 to 3.5.0
dependabot[bot] Mar 27, 2023
0c3842e
fix(deps): bump actions/setup-go from 3.5.0 to 4.0.0
dependabot[bot] Apr 3, 2023
700eb43
fix(deps): bump actions/checkout from 3.5.0 to 3.5.2
dependabot[bot] Apr 17, 2023
892134e
fix(deps): bump actions/setup-python from 4.5.0 to 4.6.0
dependabot[bot] Apr 24, 2023
8969e7b
fix: colored text on windows
Apr 18, 2023
a672534
fix: server logs output
Apr 19, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v3.2.0
uses: actions/setup-go@v4.0.0
with:
go-version: 1.17.8
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v3.0.0
uses: actions/checkout@v3.5.2

- name: Get dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
matrix:
node-version: [15.11.x]
steps:
- uses: actions/checkout@v3.0.0
- uses: actions/checkout@v3.5.2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3.6.0
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3.0.0
uses: actions/checkout@v3.5.2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/dockerimage-next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
if: contains(toJson(github.event.commits), '[action]') == false
steps:
- uses: actions/checkout@v3.0.0
- uses: actions/checkout@v3.5.2
with:
fetch-depth: 0

Expand All @@ -21,7 +21,7 @@ jobs:
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
uses: docker/login-action@v1.14.1
uses: docker/login-action@v2.1.0
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/homebrew.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Homebrew Bump Formula
on:
release:
types: [published]
workflow_dispatch:
jobs:
homebrew:
runs-on: macos-latest
steps:
- uses: dawidd6/action-homebrew-bump-formula@v3
with:
token: ${{ secrets.HOMEBREW_GITHUB_API_TOKEN }}
formula: phoneinfoga
14 changes: 7 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3.0.0
uses: actions/checkout@v3.5.2

- name: Unshallow
run: git fetch --prune --unshallow
Expand All @@ -21,7 +21,7 @@ jobs:
node-version: 15.11.x

- name: Set up Go
uses: actions/setup-go@v3.2.0
uses: actions/setup-go@v4.0.0
with:
go-version: 1.17.8

Expand All @@ -32,7 +32,7 @@ jobs:
run: make install-tools

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4.1.1
uses: goreleaser/goreleaser-action@v4.2.0
with:
version: v1.10.2
args: release --rm-dist
Expand All @@ -42,15 +42,15 @@ jobs:
runs-on: ubuntu-latest
if: contains(toJson(github.event.commits), '[action]') == false
steps:
- uses: actions/checkout@v3.0.0
- uses: actions/checkout@v3.5.2
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v1.14.1
uses: docker/login-action@v2.1.0
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
Expand All @@ -66,9 +66,9 @@ jobs:
publish-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.0.0
- uses: actions/checkout@v3.5.2
- name: Set up Python 3.8
uses: actions/setup-python@v4.3.1
uses: actions/setup-python@v4.6.0
with:
python-version: 3.8

Expand Down
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ GIT_COMMIT=$(shell git rev-parse --short HEAD)
.PHONY: all
all: fmt lint test build go.mod

# Build static assets
# This will create dist directory containing client's static files
.PHONY: static
static:
cd web/client
yarn
yarn build

.PHONY: build
build:
go generate ./...
Expand Down Expand Up @@ -48,14 +56,14 @@ clean:

.PHONY: lint
lint:
@which golangci-lint > /dev/null 2>&1 || (curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- -b $(GOBINPATH) v1.46.2)
golangci-lint run -v --timeout=10m
golangci-lint run -v --timeout=2m

.PHONY: install-tools
install-tools:
$(GOINSTALL) gotest.tools/gotestsum@v1.6.3
$(GOINSTALL) github.com/vektra/mockery/v2@v2.8.0
$(GOINSTALL) github.com/swaggo/swag/cmd/swag@v1.7.0
@which golangci-lint > /dev/null 2>&1 || (curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- -b $(GOBINPATH) v1.46.2)

go.mod: FORCE
$(GOMOD) tidy
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,18 @@
<p align="center">
<a href="https://sundowndev.github.io/phoneinfoga/">Documentation</a> •
<a href="https://petstore.swagger.io/?url=https://raw.githubusercontent.com/sundowndev/phoneinfoga/master/web/docs/swagger.yaml">API documentation</a> •
<a href="https://demo.phoneinfoga.crvx.fr/">Demo instance</a> •
<a href="https://medium.com/@SundownDEV/phone-number-scanning-osint-recon-tool-6ad8f0cac27b">Related blog post</a>
</p>

## About

PhoneInfoga is one of the most advanced tools to scan international phone numbers. It allows you to first gather basic information such as country, area, carrier and line type, then use various techniques to try to find the VoIP provider or identify the owner. It works with a collection of scanners that must be configured in order for the tool to be effective. PhoneInfoga doesn't automate everything, it's just there to help investigating on phone numbers.

![web client screenshot](./docs/images/screenshot.png)

## Current status

This project is stable and production-ready.

**About demo instance**: This is a test service. Kittens will die if you abuse it.
You can try out the web client or REST API on the <a href="https://demo.phoneinfoga.crvx.fr/">demo instance</a>. **This is a test service**. Kittens will die if you abuse it. Most of scanners are not configured so you won't get relevant results.

## Features

Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ func Execute() {
}

func exitWithError(err error) {
fmt.Println(color.RedString(err.Error()))
fmt.Fprintf(color.Error, "%s\n", color.RedString(err.Error()))
os.Exit(1)
}
5 changes: 2 additions & 3 deletions cmd/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/sundowndev/phoneinfoga/v2/lib/number"
"github.com/sundowndev/phoneinfoga/v2/lib/output"
"github.com/sundowndev/phoneinfoga/v2/lib/remote"
"os"
)

type ScanCmdOptions struct {
Expand Down Expand Up @@ -53,7 +52,7 @@ func NewScanCmd(opts *ScanCmdOptions) *cobra.Command {
}

func runScan(opts *ScanCmdOptions) {
fmt.Printf(color.WhiteString("Running scan for phone number %s...\n\n"), opts.Number)
fmt.Fprintf(color.Output, color.WhiteString("Running scan for phone number %s...\n\n"), opts.Number)

if valid := number.IsValid(opts.Number); !valid {
logrus.WithFields(map[string]interface{}{
Expand Down Expand Up @@ -83,7 +82,7 @@ func runScan(opts *ScanCmdOptions) {

result, errs := remoteLibrary.Scan(num)

err = output.GetOutput(output.Console, os.Stdout).Write(result, errs)
err = output.GetOutput(output.Console, color.Output).Write(result, errs)
if err != nil {
exitWithError(err)
}
Expand Down
27 changes: 24 additions & 3 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package cmd

import (
"fmt"
"log"
"net/http"
"os"

"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"github.com/sirupsen/logrus"
Expand All @@ -11,14 +15,14 @@ import (
"github.com/sundowndev/phoneinfoga/v2/lib/remote"
"github.com/sundowndev/phoneinfoga/v2/web"
"github.com/sundowndev/phoneinfoga/v2/web/v2/api/handlers"
"log"
"net/http"
"os"
)

type ServeCmdOptions struct {
HttpPort int
DisableClient bool
Domain string
KeyfilePath string
CertfilePath string
DisabledScanners []string
PluginPaths []string
EnvFiles []string
Expand All @@ -33,11 +37,19 @@ func init() {
// Register flags
cmd.PersistentFlags().IntVarP(&opts.HttpPort, "port", "p", 5000, "HTTP port")
cmd.PersistentFlags().BoolVar(&opts.DisableClient, "no-client", false, "Disable web client (REST API only)")
cmd.PersistentFlags().StringVar(&opts.Domain, "domain", "", "Use a specific domain to host (with tls).")
cmd.PersistentFlags().StringVar(&opts.CertfilePath, "cert", "", "Path to certfile (will use default letsencrypt path for domain if none provided).")
cmd.PersistentFlags().StringVar(&opts.KeyfilePath, "key", "", "Path to keyfile (will use default letsencrypt path for domain if none provided).")
cmd.PersistentFlags().StringArrayVarP(&opts.DisabledScanners, "disable", "D", []string{}, "Scanner to skip for the scans")
cmd.PersistentFlags().StringArrayVar(&opts.PluginPaths, "plugin", []string{}, "Extra scanner plugin to use for the scans")
cmd.PersistentFlags().StringSliceVar(&opts.EnvFiles, "env-file", []string{}, "Env files to parse environment variables from (looks for .env by default)")
}

func fmtLetsEncrypt(sitename string) (string, string) {
return fmt.Sprintf("/etc/letsencrypt/live/%s/fullchain.pem", sitename),
fmt.Sprintf("/etc/letsencrypt/live/%s/privkey.pem", sitename)
}

Comment on lines +48 to +52
Copy link
Owner

@sundowndev sundowndev Feb 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is not windows-compatible. Anyway I think it's not worth to guess the cert and key paths, if the user doesn't specify it, just don't use TLS.

func NewServeCmd(opts *ServeCmdOptions) *cobra.Command {
return &cobra.Command{
Use: "serve",
Expand Down Expand Up @@ -70,6 +82,15 @@ func NewServeCmd(opts *ServeCmdOptions) *cobra.Command {
log.Fatal(err)
}

if len(opts.Domain) != 0 {
if len(opts.CertfilePath) == 0 || len(opts.KeyfilePath) == 0 {
opts.CertfilePath, opts.KeyfilePath = fmtLetsEncrypt(opts.Domain)
}
if err := srv.ListenAndServeTLS(opts.Domain+":443", opts.CertfilePath, opts.KeyfilePath); err != nil && err != http.ErrServerClosed {
log.Fatalf("listen: %s\n", err)
}
}

Comment on lines +85 to +93
Copy link
Owner

@sundowndev sundowndev Feb 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed we don't have a addr flag to listen to a different address. I think it's worth adding a new --addr flag and use it for both TLS and non-TLS.

  • --addr should be empty by default and we should use TLS when --cert or --key is not empty
  • We can use Port option to listen to port 443, instead of hard-coding it

In the Gin's server implementation, it's the same option for both methods.

addr := fmt.Sprintf(":%d", opts.HttpPort)
fmt.Printf("Listening on %s\n", addr)
if err := srv.ListenAndServe(addr); err != nil && err != http.ErrServerClosed {
Expand Down
17 changes: 8 additions & 9 deletions docs/contribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,25 @@ This page describe the project structure and gives you a bit of context to start

**Requirements :**

- Node.js >= v10.x
- Nodejs >= v15
- npm or yarn
- Go >= 1.16
- [swag](https://github.com/swaggo/swag)

**Note:** if you're using npm, just replace `yarn <command>` by `npm run <command>`.

```shell
# Install tools needed to build, creating mocks or running tests
$ make install-tools

# Build static assets
# This will create dist directory containing client's static files
$ (cd web/client && yarn && yarn build)

# Generate in-memory assets
# This will put content of dist directory in memory. It's usually needed to build but
# the design requires you to do it anyway.
# Generate in-memory assets, then build the project.
# This will put content of dist directory in a single binary file.
# It's needed to build but the design requires you to do it anyway.
# This step is needed at each change if you're developing on the client.
$ go generate ./...

# Build the whole project
$ go build -v .
$ make build
```

If you're developing, you don't need to build at each changes, you can compile then run with the `go run` command :
Expand Down
19 changes: 14 additions & 5 deletions docs/getting-started/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ Follow the instructions :

You can also do it from the terminal (UNIX systems only) :

1. Download latest release in the current directory
1. Download the latest release in the current directory

```
curl -sSL https://raw.githubusercontent.com/sundowndev/phoneinfoga/master/support/scripts/install | bash
# Add --help at the end of the command for a list of install options
bash <( curl -sSL https://raw.githubusercontent.com/sundowndev/phoneinfoga/master/support/scripts/install )
```

2. Install phoneinfoga
2. Install it globally
```
sudo install ./phoneinfoga /usr/local/bin/phoneinfoga
```
Expand All @@ -31,7 +32,15 @@ sudo install ./phoneinfoga /usr/local/bin/phoneinfoga

To ensure your system is supported, please check the output of `echo "$(uname -s)_$(uname -m)"` in your terminal and see if it's available on the [GitHub release page](https://github.com/sundowndev/phoneinfoga/releases).

## Using Docker
## Homebrew

PhoneInfoga is now available on Homebrew. Homebrew is a free and open-source package management system for Mac OS X. Install the official phoneinfoga formula from the terminal.

```shell
brew install phoneinfoga
```

## Docker

!!! info
If you want to use the beta channel, you can use the `next` tag, it's updated directly from the master branch. But in most cases we recommend using [`latest`, `v2` or `stable` tags](https://hub.docker.com/r/sundowndev/phoneinfoga/tags) to only get release updates.
Expand Down Expand Up @@ -68,7 +77,7 @@ services:
- "80:5000"
```

### From the source code
### Build from source

You can download the source code, then build the docker images

Expand Down
Loading