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 example library import #20

Merged
merged 1 commit into from
Jul 17, 2023
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<a href="#installation">Installation</a> •
<a href="#usage">Usage</a> •
<a href="#running-fingerprintx">Running fingerprintx</a> •
<a href="#using-as-a-library">Using as a library</a> •
<a href="#why-not-nmap">Why not nmap?</a> •
<a href="#notes">Notes</a> •
<a href="#acknowledgements">Acknowledgements</a>
Expand Down Expand Up @@ -169,6 +170,9 @@ $ cat input.txt | fingerprintx --json
{"host":"telehack.com","ip":"64.13.139.230","port":23,"service":"telnet","transport":"tcp","metadata":{"serverData":"fffb03"}}
```

# Using as a library
`fingerprintx` can be imported into your project to scan for services on open ports. Example code on how one might do this is provided [here in the examples directory](examples/scan.go). Build with `go build scan.go`. Another file that might be of use as a reference when importing `fingerprintx` into your own project is the [command line runner](pkg/runner/root.go).

# Why Not Nmap?
[Nmap](https://nmap.org/) is the standard for network scanning. Why use `fingerprintx` instead of nmap? The main two reasons are:

Expand Down
41 changes: 41 additions & 0 deletions examples/scan.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"fmt"
"log"
"net/netip"
"time"

"github.com/praetorian-inc/fingerprintx/pkg/plugins"
"github.com/praetorian-inc/fingerprintx/pkg/scan"
)

func main() {
// setup the scan config (mirrors command line options)
fxConfig := scan.Config{
DefaultTimeout: time.Duration(2) * time.Second,
FastMode: false,
Verbose: false,
UDP: false,
}

// create a target list to scan
ip, _ := netip.ParseAddr("146.148.61.165")
target := plugins.Target{
Address: netip.AddrPortFrom(ip, 443),
Host: "praetorian.com",
}
targets := make([]plugins.Target, 1)
targets = append(targets, target)

// run the scan
results, err := scan.ScanTargets(targets, fxConfig)
if err != nil {
log.Fatalf("error: %s\n", err)
}

// process the results
for _, result := range results {
fmt.Printf("%s:%d (%s/%s)\n", result.Host, result.Port, result.Transport, result.Protocol)
}
}
Loading