Skip to content

Commit d5a355b

Browse files
authored
Merge pull request #459 from projectdiscovery/dev
v2.1.1
2 parents 03034c5 + 4c657fd commit d5a355b

File tree

28 files changed

+583
-262
lines changed

28 files changed

+583
-262
lines changed

.github/workflows/build-test.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ jobs:
3030
run: go test ./...
3131
working-directory: v2/
3232

33+
- name: Integration Tests
34+
env:
35+
GH_ACTION: true
36+
run: bash run.sh
37+
working-directory: integration_tests/
38+
3339
- name: Race Condition Tests
3440
run: |
3541
sudo go run -race . -host scanme.sh
@@ -60,6 +66,12 @@ jobs:
6066
run: go test ./...
6167
working-directory: v2/
6268

69+
- name: Integration Tests
70+
env:
71+
GH_ACTION: true
72+
run: bash run.sh
73+
working-directory: integration_tests/
74+
6375
- name: Race Condition Tests
6476
run: |
6577
sudo go run -race . -host scanme.sh

.github/workflows/lint-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
run: sudo apt install libpcap-dev
2222

2323
- name: Run golangci-lint
24-
uses: golangci/golangci-lint-action@v3.2.0
24+
uses: golangci/golangci-lint-action@v3.3.0
2525
with:
2626
version: latest
2727
args: --timeout 5m

.github/workflows/release-binary.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: 🎉 Release Binary
2+
23
on:
3-
create:
4+
push:
45
tags:
56
- v*
67
workflow_dispatch:
@@ -48,8 +49,9 @@ jobs:
4849
version: latest
4950
args: release -f .goreleaser/linux.yml --rm-dist
5051
workdir: v2
51-
env:
52-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
env:
53+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
54+
SLACK_WEBHOOK: "${{ secrets.RELEASE_SLACK_WEBHOOK }}"
5355

5456
build-windows:
5557
runs-on: windows-latest

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
FROM golang:1.18.4-alpine AS builder
1+
FROM golang:1.19.2-alpine AS builder
22
RUN apk add build-base libpcap-dev
33
RUN go install -v github.com/projectdiscovery/naabu/v2/cmd/naabu@latest
44

5-
FROM alpine:3.16.1
5+
FROM alpine:3.16.2
66
RUN apk add nmap libpcap-dev bind-tools ca-certificates nmap-scripts
77
COPY --from=builder /go/bin/naabu /usr/local/bin/naabu
88
ENTRYPOINT ["naabu"]

README.md

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ all ports that return a reply.
4141
- **Passive** Port enumeration using Shodan [Internetdb](https://internetdb.shodan.io)
4242
- **Host Discovery** scan (**experimental**)
4343
- **NMAP** integration for service discovery
44-
- Multiple input support - **STDIN/HOST/IP/CIDR**
44+
- Multiple input support - **STDIN/HOST/IP/CIDR/ASN**
4545
- Multiple output format support - **JSON/TXT/STDOUT**
4646

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

@@ -98,7 +99,8 @@ CONFIGURATION:
9899
-no-stdin Disable Stdin processing
99100

100101
HOST-DISCOVERY:
101-
-sn, -host-discovery Run Host Discovery scan
102+
-sn, -host-discovery Perform Only Host Discovery
103+
-Pn, -skip-host-discovery Skip Host discovery
102104
-ps, -probe-tcp-syn string[] TCP SYN Ping (host discovery needs to be enabled)
103105
-pa, -probe-tcp-ack string[] TCP ACK Ping (host discovery needs to be enabled)
104106
-pe, -probe-icmp-echo ICMP echo request Ping (host discovery needs to be enabled)
@@ -197,7 +199,20 @@ To run the naabu on a list of hosts, `-list` option can be used.
197199
```sh
198200
naabu -list hosts.txt
199201
```
202+
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.
200203

204+
```console
205+
echo AS14421 | naabu -p 80,443
206+
207+
216.101.17.249:80
208+
216.101.17.249:443
209+
216.101.17.248:443
210+
216.101.17.252:443
211+
216.101.17.251:80
212+
216.101.17.251:443
213+
216.101.17.250:443
214+
216.101.17.250:80
215+
```
201216
You can also get output in json format using `-json` switch. This switch saves the output in the JSON lines format.
202217

203218
```console
@@ -269,7 +284,7 @@ hackerone.com:80
269284

270285
# Host Discovery
271286

272-
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.
287+
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.
273288

274289
Available options to perform host discovery:
275290

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

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

347+
# Using naabu as library
348+
The following sample program scan the port `80` of `scanme.sh`. The results are returned via the `OnResult` callback:
349+
350+
```go
351+
package main
352+
353+
import (
354+
"log"
355+
356+
"github.com/projectdiscovery/goflags"
357+
"github.com/projectdiscovery/naabu/v2/pkg/result"
358+
"github.com/projectdiscovery/naabu/v2/pkg/runner"
359+
)
360+
361+
func main() {
362+
options := runner.Options{
363+
ResumeCfg: &runner.ResumeCfg{},
364+
Retries: 1,
365+
Host: goflags.StringSlice{"scanme.sh"},
366+
OnResult: func(hr *result.HostResult) {
367+
log.Println(hr.Host, hr.Ports)
368+
},
369+
Ports: "80",
370+
}
371+
372+
naabuRunner, err := runner.NewRunner(&options)
373+
if err != nil {
374+
log.Fatal(err)
375+
}
376+
defer naabuRunner.Close()
377+
378+
naabuRunner.RunEnumeration()
379+
}
380+
```
381+
332382
# Notes
333383

334384
- Naabu allows arbitrary binary execution as a feature to support [nmap integration](https://github.com/projectdiscovery/naabu#nmap-integration).

integration_tests/run.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
echo "::group::Build naabu"
4+
rm integration-test naabu 2>/dev/null
5+
cd ../v2/cmd/naabu
6+
go build
7+
mv naabu ../../../integration_tests/naabu
8+
echo "::endgroup::"
9+
10+
echo "::group::Build naabu integration-test"
11+
cd ../integration-test
12+
go build
13+
mv integration-test ../../../integration_tests/integration-test
14+
cd ../../../integration_tests
15+
echo "::endgroup::"
16+
17+
./integration-test
18+
if [ $? -eq 0 ]
19+
then
20+
exit 0
21+
else
22+
exit 1
23+
fi

v2/.goreleaser/linux.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,10 @@ archives:
2121

2222
checksum:
2323
name_template: "{{ .ProjectName }}-linux-checksums.txt"
24+
25+
announce:
26+
slack:
27+
enabled: true
28+
channel: '#release'
29+
username: GoReleaser
30+
message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}'

v2/cmd/functional-test/main.go

Lines changed: 71 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,83 @@
11
package main
22

3-
import (
4-
"bufio"
5-
"flag"
6-
"fmt"
7-
"log"
8-
"os"
9-
"strings"
3+
import (
4+
"bufio"
5+
"flag"
6+
"fmt"
7+
"log"
8+
"os"
9+
"strings"
1010

11-
"github.com/logrusorgru/aurora"
12-
"github.com/pkg/errors"
11+
"github.com/logrusorgru/aurora"
12+
"github.com/pkg/errors"
1313

14-
"github.com/projectdiscovery/naabu/v2/cmd/internal/testutils"
15-
)
14+
"github.com/projectdiscovery/naabu/v2/internal/testutils"
15+
)
1616

17-
var (
18-
debug = os.Getenv("DEBUG") == "true"
19-
success = aurora.Green("[✓]").String()
20-
failed = aurora.Red("[✘]").String()
21-
errored = false
17+
var (
18+
debug = os.Getenv("DEBUG") == "true"
19+
success = aurora.Green("[✓]").String()
20+
failed = aurora.Red("[✘]").String()
21+
errored = false
2222

23-
mainNaabuBinary = flag.String("main", "", "Main Branch Naabu Binary")
24-
devNaabuBinary = flag.String("dev", "", "Dev Branch Naabu Binary")
25-
testcases = flag.String("testcases", "", "Test cases file for Naabu functional tests")
26-
)
23+
mainNaabuBinary = flag.String("main", "", "Main Branch Naabu Binary")
24+
devNaabuBinary = flag.String("dev", "", "Dev Branch Naabu Binary")
25+
testcases = flag.String("testcases", "", "Test cases file for Naabu functional tests")
26+
)
2727

28-
func main() {
29-
flag.Parse()
28+
func main() {
29+
flag.Parse()
3030

31-
if err := runFunctionalTests(); err != nil {
32-
log.Fatalf("Could not run functional tests: %s\n", err)
33-
}
34-
if errored {
35-
os.Exit(1)
36-
}
37-
}
31+
if err := runFunctionalTests(); err != nil {
32+
log.Fatalf("Could not run functional tests: %s\n", err)
33+
}
34+
if errored {
35+
os.Exit(1)
36+
}
37+
}
3838

39-
func runFunctionalTests() error {
40-
file, err := os.Open(*testcases)
41-
if err != nil {
42-
return errors.Wrap(err, "could not open test cases")
43-
}
44-
defer file.Close()
39+
func runFunctionalTests() error {
40+
file, err := os.Open(*testcases)
41+
if err != nil {
42+
return errors.Wrap(err, "could not open test cases")
43+
}
44+
defer file.Close()
4545

46-
scanner := bufio.NewScanner(file)
47-
for scanner.Scan() {
48-
text := strings.TrimSpace(scanner.Text())
49-
if text == "" {
50-
continue
51-
}
52-
if err := runIndividualTestCase(text); err != nil {
53-
errored = true
54-
fmt.Fprintf(os.Stderr, "%s Test \"%s\" failed: %s\n", failed, text, err)
55-
} else {
56-
fmt.Printf("%s Test \"%s\" passed!\n", success, text)
57-
}
58-
}
59-
return nil
60-
}
46+
scanner := bufio.NewScanner(file)
47+
for scanner.Scan() {
48+
text := strings.TrimSpace(scanner.Text())
49+
if text == "" {
50+
continue
51+
}
52+
if err := runIndividualTestCase(text); err != nil {
53+
errored = true
54+
fmt.Fprintf(os.Stderr, "%s Test \"%s\" failed: %s\n", failed, text, err)
55+
} else {
56+
fmt.Printf("%s Test \"%s\" passed!\n", success, text)
57+
}
58+
}
59+
return nil
60+
}
6161

62-
func runIndividualTestCase(testcase string) error {
63-
parts := strings.Fields(testcase)
62+
func runIndividualTestCase(testcase string) error {
63+
parts := strings.Fields(testcase)
6464

65-
var finalArgs []string
66-
var target string
67-
if len(parts) > 1 {
68-
finalArgs = parts[2:]
69-
target = parts[0]
70-
}
71-
mainOutput, err := testutils.RunNaabuBinaryAndGetResults(target, *mainNaabuBinary, debug, finalArgs)
72-
if err != nil {
73-
return errors.Wrap(err, "could not run naabu main test")
74-
}
75-
devOutput, err := testutils.RunNaabuBinaryAndGetResults(target, *devNaabuBinary, debug, finalArgs)
76-
if err != nil {
77-
return errors.Wrap(err, "could not run naabu dev test")
78-
}
79-
if len(mainOutput) == len(devOutput) {
80-
return nil
81-
}
82-
return fmt.Errorf("%s main is not equal to %s dev", mainOutput, devOutput)
83-
}
65+
var finalArgs []string
66+
var target string
67+
if len(parts) > 1 {
68+
finalArgs = parts[2:]
69+
target = parts[0]
70+
}
71+
mainOutput, err := testutils.RunNaabuBinaryAndGetResults(target, *mainNaabuBinary, debug, finalArgs)
72+
if err != nil {
73+
return errors.Wrap(err, "could not run naabu main test")
74+
}
75+
devOutput, err := testutils.RunNaabuBinaryAndGetResults(target, *devNaabuBinary, debug, finalArgs)
76+
if err != nil {
77+
return errors.Wrap(err, "could not run naabu dev test")
78+
}
79+
if len(mainOutput) == len(devOutput) {
80+
return nil
81+
}
82+
return fmt.Errorf("%s main is not equal to %s dev", mainOutput, devOutput)
83+
}

0 commit comments

Comments
 (0)