styx/graph/main.go
Christopher Talib 9fa5d13bf6 Full text search and indexing some keywords
Some of keywords are indexed and open for full text search, please refer
to the README for more details.

CertStream, Pastebin and Shodan are running as services and can be
searched.

Next steps: building the matcher and creating edges.
2020-05-20 10:03:28 +02:00

195 lines
2.9 KiB
Go

package graph
import (
"context"
"github.com/dgraph-io/dgo/v2"
"github.com/dgraph-io/dgo/v2/protos/api"
"google.golang.org/grpc"
)
func ConnectToDgraph() (*dgo.Dgraph, error) {
conn, err := grpc.Dial("localhost:9080", grpc.WithInsecure())
if err != nil {
return nil, err
}
dgraphClient := dgo.NewDgraphClient(api.NewDgraphClient(conn))
err = setupDgraphSchema(dgraphClient)
if err != nil {
return nil, err
}
return dgraphClient, nil
}
func setupDgraphSchema(c *dgo.Dgraph) error {
err := c.Alter(context.Background(), &api.Operation{
DropOp: api.Operation_ALL,
})
if err != nil {
return err
}
err = c.Alter(context.Background(), &api.Operation{
Schema: `
id: string @index(term) .
type: string @index(term) .
ndata: string .
nodeOne: uid .
nodeTwo: uid .
subNode: uid .
sourceName: string @index(term) .
timestamp: string .
created: string .
modified: string .
certNode: uid .
shodanNode: uid .
pasteNode: uid .
type Node {
id: string
type: string
ndata: string
created: string
modified: string
certNode: CertNode
shodanNode: ShodanNode
pasteNode: PasteNode
}
type Edge {
id: string
nodeOne: uid
nodeTwo: uid
timestamp: string
sourceName: string
}
fingerprint: string @index(exact, term) .
notBefore: string .
notAfter: string .
cn: string @index(term) .
sourceName: string @index(term) .
serialNumber: string @index(term) .
basicConstraints: string .
chain: [uid].
csdata: uid .
raw: uid .
type CertNode {
id: string
fingerprint: string
notBefore: string
notAfter: string
cn: string
sourceName: string
serialNumber: string
basicConstraints: string
raw: CertRaw
chain: CertNode
}
type CertRaw {
id: string
type: string
created: string
modified: string
csdata: string
}
hostData: uid .
type ShodanNode {
id: string
type: string
created: string
modified: string
hostData: uid
}
product: string @index(term) .
hostnames: [string] @index(term) .
version: string .
title: string @index(term) .
ip: string @index(term) .
os: string .
organization: string @index(term) .
isp: string .
cpe: [string] .
asn: string .
port: int .
html: string .
banner: string .
transport: string .
domains: [string] .
timestamp: string .
type Hostdata {
product: string
hostnames: [string]
version: string
title: string
ip: string
os: string
organization: string
isp: string
cpe: [string]
asn: string
port: int
html: string
banner: string
transport: string
domains: [string]
timestamp: string
}
fullPaste: uid .
meta: uid .
full: string @index(term) .
scrape_url: string .
full_url: string .
date: string .
key: string .
size: string .
expire: string .
title: string @index(term) .
syntax: string .
user: string @index(term) .
type PasteMeta {
scrape_url: string
full_url: string
date: string
key: string
size: string
expire: string
title: string
syntax: string
user: string
}
type FullPaste {
meta: PasteMeta
full: string
type: string
}
type PasteNode {
id: string
type: string
created: string
modified: string
fullPaste: FullPaste
}
`})
if err != nil {
return err
}
return nil
}