Skip to content

Commit

Permalink
Merge pull request #459 from projectdiscovery/dev
Browse files Browse the repository at this point in the history
v2.1.1
  • Loading branch information
ehsandeep authored Oct 25, 2022
2 parents 03034c5 + 4c657fd commit d5a355b
Show file tree
Hide file tree
Showing 28 changed files with 583 additions and 262 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ jobs:
run: go test ./...
working-directory: v2/

- name: Integration Tests
env:
GH_ACTION: true
run: bash run.sh
working-directory: integration_tests/

- name: Race Condition Tests
run: |
sudo go run -race . -host scanme.sh
Expand Down Expand Up @@ -60,6 +66,12 @@ jobs:
run: go test ./...
working-directory: v2/

- name: Integration Tests
env:
GH_ACTION: true
run: bash run.sh
working-directory: integration_tests/

- name: Race Condition Tests
run: |
sudo go run -race . -host scanme.sh
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
run: sudo apt install libpcap-dev

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3.2.0
uses: golangci/golangci-lint-action@v3.3.0
with:
version: latest
args: --timeout 5m
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/release-binary.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: 🎉 Release Binary

on:
create:
push:
tags:
- v*
workflow_dispatch:
Expand Down Expand Up @@ -48,8 +49,9 @@ jobs:
version: latest
args: release -f .goreleaser/linux.yml --rm-dist
workdir: v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
SLACK_WEBHOOK: "${{ secrets.RELEASE_SLACK_WEBHOOK }}"

build-windows:
runs-on: windows-latest
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM golang:1.18.4-alpine AS builder
FROM golang:1.19.2-alpine AS builder
RUN apk add build-base libpcap-dev
RUN go install -v github.com/projectdiscovery/naabu/v2/cmd/naabu@latest

FROM alpine:3.16.1
FROM alpine:3.16.2
RUN apk add nmap libpcap-dev bind-tools ca-certificates nmap-scripts
COPY --from=builder /go/bin/naabu /usr/local/bin/naabu
ENTRYPOINT ["naabu"]
56 changes: 53 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ all ports that return a reply.
- **Passive** Port enumeration using Shodan [Internetdb](https://internetdb.shodan.io)
- **Host Discovery** scan (**experimental**)
- **NMAP** integration for service discovery
- Multiple input support - **STDIN/HOST/IP/CIDR**
- Multiple input support - **STDIN/HOST/IP/CIDR/ASN**
- Multiple output format support - **JSON/TXT/STDOUT**

# Usage
Expand All @@ -67,6 +67,7 @@ PORT:
-top-ports, -tp string top ports to scan (default 100)
-exclude-ports, -ep string ports to exclude from scan (comma-separated)
-ports-file, -pf string list of ports to scan (file)
-port-threshold, -pts int port threshold to skip port scan for the host
-exclude-cdn, -ec skip full port scans for CDN's (only checks for 80,443)
-display-cdn, -cdn display cdn in use

Expand Down Expand Up @@ -98,7 +99,8 @@ CONFIGURATION:
-no-stdin Disable Stdin processing

HOST-DISCOVERY:
-sn, -host-discovery Run Host Discovery scan
-sn, -host-discovery Perform Only Host Discovery
-Pn, -skip-host-discovery Skip Host discovery
-ps, -probe-tcp-syn string[] TCP SYN Ping (host discovery needs to be enabled)
-pa, -probe-tcp-ack string[] TCP ACK Ping (host discovery needs to be enabled)
-pe, -probe-icmp-echo ICMP echo request Ping (host discovery needs to be enabled)
Expand Down Expand Up @@ -197,7 +199,20 @@ To run the naabu on a list of hosts, `-list` option can be used.
```sh
naabu -list hosts.txt
```
To run the naabu on a ASN, AS input can be used. It takes the IP address available for given ASN and runs the enumeration on them.

```console
echo AS14421 | naabu -p 80,443

216.101.17.249:80
216.101.17.249:443
216.101.17.248:443
216.101.17.252:443
216.101.17.251:80
216.101.17.251:443
216.101.17.250:443
216.101.17.250:80
```
You can also get output in json format using `-json` switch. This switch saves the output in the JSON lines format.

```console
Expand Down Expand Up @@ -269,7 +284,7 @@ hackerone.com:80

# Host Discovery

Naabu optionally supports multiple options to perform host discovery, as outlined below. `-sn` flag is required to perform host discovery; when used, host discovery is performed using multiple methods selected internally; one can also specify the desired method to perform host discovery by specifying available options.
Naabu optionally supports multiple options to perform host discovery, as outlined below. Host discovery is completed automatically before beginning a connect/syn scan if the process has enough privileges. `-sn` flag instructs the toll to perform host discovery only. `-Pn` flag skips the host discovery phase. Host discovery is completed using multiple internal methods; one can specify the desired approach to perform host discovery by setting available options.

Available options to perform host discovery:

Expand Down Expand Up @@ -329,6 +344,41 @@ Naabu also supports excluding CDN IPs being port scanned. If used, only `80` and

Currently `cloudflare`, `akamai`, `incapsula` and `sucuri` IPs are supported for exclusions.

# Using naabu as library
The following sample program scan the port `80` of `scanme.sh`. The results are returned via the `OnResult` callback:

```go
package main

import (
"log"

"github.com/projectdiscovery/goflags"
"github.com/projectdiscovery/naabu/v2/pkg/result"
"github.com/projectdiscovery/naabu/v2/pkg/runner"
)

func main() {
options := runner.Options{
ResumeCfg: &runner.ResumeCfg{},
Retries: 1,
Host: goflags.StringSlice{"scanme.sh"},
OnResult: func(hr *result.HostResult) {
log.Println(hr.Host, hr.Ports)
},
Ports: "80",
}

naabuRunner, err := runner.NewRunner(&options)
if err != nil {
log.Fatal(err)
}
defer naabuRunner.Close()

naabuRunner.RunEnumeration()
}
```

# Notes

- Naabu allows arbitrary binary execution as a feature to support [nmap integration](https://github.com/projectdiscovery/naabu#nmap-integration).
Expand Down
23 changes: 23 additions & 0 deletions integration_tests/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

echo "::group::Build naabu"
rm integration-test naabu 2>/dev/null
cd ../v2/cmd/naabu
go build
mv naabu ../../../integration_tests/naabu
echo "::endgroup::"

echo "::group::Build naabu integration-test"
cd ../integration-test
go build
mv integration-test ../../../integration_tests/integration-test
cd ../../../integration_tests
echo "::endgroup::"

./integration-test
if [ $? -eq 0 ]
then
exit 0
else
exit 1
fi
7 changes: 7 additions & 0 deletions v2/.goreleaser/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,10 @@ archives:

checksum:
name_template: "{{ .ProjectName }}-linux-checksums.txt"

announce:
slack:
enabled: true
channel: '#release'
username: GoReleaser
message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}'
142 changes: 71 additions & 71 deletions v2/cmd/functional-test/main.go
Original file line number Diff line number Diff line change
@@ -1,83 +1,83 @@
package main

import (
"bufio"
"flag"
"fmt"
"log"
"os"
"strings"
import (
"bufio"
"flag"
"fmt"
"log"
"os"
"strings"

"github.com/logrusorgru/aurora"
"github.com/pkg/errors"
"github.com/logrusorgru/aurora"
"github.com/pkg/errors"

"github.com/projectdiscovery/naabu/v2/cmd/internal/testutils"
)
"github.com/projectdiscovery/naabu/v2/internal/testutils"
)

var (
debug = os.Getenv("DEBUG") == "true"
success = aurora.Green("[✓]").String()
failed = aurora.Red("[✘]").String()
errored = false
var (
debug = os.Getenv("DEBUG") == "true"
success = aurora.Green("[✓]").String()
failed = aurora.Red("[✘]").String()
errored = false

mainNaabuBinary = flag.String("main", "", "Main Branch Naabu Binary")
devNaabuBinary = flag.String("dev", "", "Dev Branch Naabu Binary")
testcases = flag.String("testcases", "", "Test cases file for Naabu functional tests")
)
mainNaabuBinary = flag.String("main", "", "Main Branch Naabu Binary")
devNaabuBinary = flag.String("dev", "", "Dev Branch Naabu Binary")
testcases = flag.String("testcases", "", "Test cases file for Naabu functional tests")
)

func main() {
flag.Parse()
func main() {
flag.Parse()

if err := runFunctionalTests(); err != nil {
log.Fatalf("Could not run functional tests: %s\n", err)
}
if errored {
os.Exit(1)
}
}
if err := runFunctionalTests(); err != nil {
log.Fatalf("Could not run functional tests: %s\n", err)
}
if errored {
os.Exit(1)
}
}

func runFunctionalTests() error {
file, err := os.Open(*testcases)
if err != nil {
return errors.Wrap(err, "could not open test cases")
}
defer file.Close()
func runFunctionalTests() error {
file, err := os.Open(*testcases)
if err != nil {
return errors.Wrap(err, "could not open test cases")
}
defer file.Close()

scanner := bufio.NewScanner(file)
for scanner.Scan() {
text := strings.TrimSpace(scanner.Text())
if text == "" {
continue
}
if err := runIndividualTestCase(text); err != nil {
errored = true
fmt.Fprintf(os.Stderr, "%s Test \"%s\" failed: %s\n", failed, text, err)
} else {
fmt.Printf("%s Test \"%s\" passed!\n", success, text)
}
}
return nil
}
scanner := bufio.NewScanner(file)
for scanner.Scan() {
text := strings.TrimSpace(scanner.Text())
if text == "" {
continue
}
if err := runIndividualTestCase(text); err != nil {
errored = true
fmt.Fprintf(os.Stderr, "%s Test \"%s\" failed: %s\n", failed, text, err)
} else {
fmt.Printf("%s Test \"%s\" passed!\n", success, text)
}
}
return nil
}

func runIndividualTestCase(testcase string) error {
parts := strings.Fields(testcase)
func runIndividualTestCase(testcase string) error {
parts := strings.Fields(testcase)

var finalArgs []string
var target string
if len(parts) > 1 {
finalArgs = parts[2:]
target = parts[0]
}
mainOutput, err := testutils.RunNaabuBinaryAndGetResults(target, *mainNaabuBinary, debug, finalArgs)
if err != nil {
return errors.Wrap(err, "could not run naabu main test")
}
devOutput, err := testutils.RunNaabuBinaryAndGetResults(target, *devNaabuBinary, debug, finalArgs)
if err != nil {
return errors.Wrap(err, "could not run naabu dev test")
}
if len(mainOutput) == len(devOutput) {
return nil
}
return fmt.Errorf("%s main is not equal to %s dev", mainOutput, devOutput)
}
var finalArgs []string
var target string
if len(parts) > 1 {
finalArgs = parts[2:]
target = parts[0]
}
mainOutput, err := testutils.RunNaabuBinaryAndGetResults(target, *mainNaabuBinary, debug, finalArgs)
if err != nil {
return errors.Wrap(err, "could not run naabu main test")
}
devOutput, err := testutils.RunNaabuBinaryAndGetResults(target, *devNaabuBinary, debug, finalArgs)
if err != nil {
return errors.Wrap(err, "could not run naabu dev test")
}
if len(mainOutput) == len(devOutput) {
return nil
}
return fmt.Errorf("%s main is not equal to %s dev", mainOutput, devOutput)
}
Loading

0 comments on commit d5a355b

Please sign in to comment.