-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
completed and tested windows + linux agents
- Loading branch information
Showing
39 changed files
with
1,490 additions
and
129 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
.PHONY: build run | ||
.PHONY: build build-agent build-gen | ||
build: | ||
docker build -t siphon . | ||
go build cmd/siphon/siphon.go | ||
|
||
run: | ||
docker run --rm -it siphon | ||
build-agent: | ||
go build cmd/agent/siphon_agent.go | ||
|
||
build-gen: | ||
go build cmd/generator/siphon_gen.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/pygrum/siphon/internal/agent" | ||
"github.com/pygrum/siphon/internal/logger" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var ( | ||
AgentID string | ||
Interface string | ||
Port string | ||
ClientCertData string // Base64 Encoded certificate data | ||
cfgFile string | ||
|
||
rootCmd = &cobra.Command{ | ||
Use: "siphon_agent", | ||
Short: "A Honeypot-Resident Sample Curator", | ||
Long: ``, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
viper.SetConfigFile(cfgFile) | ||
if err := viper.ReadInConfig(); err != nil { | ||
logger.Fatalf("reading configuration file failed: %v", err) | ||
} | ||
agent.Initialize(AgentID, Interface, Port, ClientCertData) | ||
}, | ||
} | ||
) | ||
|
||
func init() { | ||
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "agent configuration file") | ||
_ = cobra.MarkFlagRequired(rootCmd.PersistentFlags(), "config") | ||
} | ||
|
||
func main() { | ||
if err := rootCmd.Execute(); err != nil { | ||
logger.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package generator | ||
|
||
import ( | ||
"crypto/rand" | ||
"encoding/base64" | ||
"fmt" | ||
"github.com/pygrum/siphon/internal/db" | ||
"github.com/pygrum/siphon/internal/logger" | ||
"github.com/spf13/viper" | ||
"math/big" | ||
"net" | ||
"os" | ||
) | ||
|
||
const ( | ||
AgentIDLength = 16 | ||
AgentIDPrefix = "AA" | ||
) | ||
|
||
var charSet = []byte("0123456789ABCDEF") | ||
|
||
func RandID() string { | ||
ret := make([]byte, AgentIDLength-len(AgentIDPrefix)) | ||
for i := 0; i < AgentIDLength-len(AgentIDPrefix); i++ { | ||
num, _ := rand.Int(rand.Reader, big.NewInt(int64(len(charSet)))) | ||
ret[i] = charSet[num.Int64()] | ||
} | ||
return AgentIDPrefix + string(ret) | ||
} | ||
|
||
func IsAgentID(s string) bool { | ||
return len(s) == AgentIDLength && s[:2] == "AA" | ||
} | ||
|
||
func Generate() error { | ||
name := viper.GetString("name") | ||
goos := viper.GetString("os") | ||
arch := viper.GetString("arch") | ||
iFace := viper.GetString("host") | ||
port := viper.GetString("port") | ||
outFile := viper.GetString("outfile") | ||
siphonCert := viper.GetString("cert_file") | ||
|
||
certData, err := os.ReadFile(siphonCert) | ||
if err != nil { | ||
logger.Fatalf("could not read siphon certificate from %s: %v", siphonCert, err) | ||
} | ||
agentID := RandID() | ||
if len(name) == 0 { | ||
name = agentID | ||
} | ||
mainPath := viper.GetString("src_path") | ||
|
||
builder := NewBuilder("go", goos, arch) | ||
builder.AddSrcPath(mainPath) | ||
builder.SetFlags( | ||
Flag{"main.AgentID", agentID}, | ||
Flag{"main.Interface", iFace}, | ||
Flag{"main.Port", port}, | ||
// Add certificate data base64 encoded to agent, so it is added to its rootCAs | ||
Flag{"main.ClientCertData", base64.StdEncoding.EncodeToString(certData)}, | ||
) | ||
builder.SetOutFile(outFile) | ||
// Exits if unsuccessful | ||
builder.Build() | ||
|
||
conn := db.Initialize() | ||
agent := &db.Agent{ | ||
AgentID: agentID, | ||
Name: name, | ||
Endpoint: fmt.Sprintf("https://%s/api", net.JoinHostPort(iFace, port)), | ||
} | ||
return conn.Add(agent) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package generator | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"github.com/pygrum/siphon/internal/logger" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
type Builder struct { | ||
CC string | ||
GOOS string | ||
GOARCH string | ||
SrcPaths []string | ||
outFile string | ||
flags []Flag | ||
} | ||
|
||
type Flag struct { | ||
Name string | ||
Value string | ||
} | ||
|
||
const ( | ||
outFileOption = "-o" | ||
flagsOption = "-ldflags" | ||
flagPrefix = "-X" | ||
) | ||
|
||
func NewBuilder(cc, goos, goarch string) *Builder { | ||
return &Builder{ | ||
CC: cc, | ||
GOOS: goos, | ||
GOARCH: goarch, | ||
} | ||
} | ||
|
||
func (b *Builder) AddSrcPath(path string) { | ||
b.SrcPaths = append(b.SrcPaths, path) | ||
} | ||
|
||
func (b *Builder) SetFlags(flags ...Flag) { | ||
b.flags = flags | ||
} | ||
|
||
func (b *Builder) SetOutFile(name string) { | ||
b.outFile = name | ||
} | ||
|
||
func (b *Builder) Build() { | ||
var buildCmd []string | ||
buildCmd = append(buildCmd, "build") | ||
buildCmd = append(buildCmd, outFileOption) | ||
buildCmd = append(buildCmd, b.outFile) | ||
buildCmd = append(buildCmd, flagsOption) | ||
var flags []string | ||
for _, f := range b.flags { | ||
flags = append(flags, flagPrefix) | ||
formatString := "'%s=%s'" | ||
flags = append(flags, fmt.Sprintf(formatString, f.Name, f.Value)) | ||
} | ||
buildCmd = append(buildCmd, strings.Join(flags, " ")) | ||
for _, s := range b.SrcPaths { | ||
buildCmd = append(buildCmd, s) | ||
} | ||
fmt.Println(b.CC, strings.Join(buildCmd, " ")) | ||
var cerr bytes.Buffer | ||
cmd := exec.Command(b.CC, buildCmd...) | ||
// Set arch and os environment vars | ||
cmd.Env = os.Environ() | ||
cmd.Env = append(cmd.Env, fmt.Sprintf("GOOS=%s", b.GOOS), fmt.Sprintf("GOARCH=%s", b.GOARCH)) // go-sqlite3 requires cgo | ||
cmd.Stderr = &cerr | ||
if err := cmd.Run(); err != nil { | ||
logger.Fatalf("%v: %s", err, cerr.String()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/pygrum/siphon/cmd/generator/generator" | ||
"github.com/pygrum/siphon/internal/logger" | ||
"github.com/pygrum/siphon/internal/version" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func init() { | ||
fmt.Printf("{_/¬ SIPHON GENERATOR %s ¬\\_}\n\n}", version.VersionString()) | ||
} | ||
|
||
var ( | ||
cfgFile string | ||
|
||
rootCmd = &cobra.Command{ | ||
Use: "generator", | ||
Short: "A utility for Siphon agent generation", | ||
Long: ``, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
viper.SetConfigFile(cfgFile) | ||
if err := viper.ReadInConfig(); err != nil { | ||
logger.Fatalf("reading configuration file failed: %v", err) | ||
} | ||
if err := generator.Generate(); err != nil { | ||
logger.Fatal(err) | ||
} | ||
logger.Notifyf("agent has successfully been built. For installation instructions, see the docs: %s", | ||
"https://github.com/pygrum/siphon/blob/main/docs/DOCS.md", | ||
) | ||
}, | ||
} | ||
) | ||
|
||
func init() { | ||
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "generator configuration file - see https://github.com/pygrum/siphon/blob/main/docs/DOCS.md for help") | ||
_ = cobra.MarkFlagRequired(rootCmd.PersistentFlags(), "config") | ||
} | ||
|
||
func main() { | ||
if err := rootCmd.Execute(); err != nil { | ||
logger.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Example configuration file for Siphon | ||
|
||
refreshrate: 5 # Refresh sample list every 5 minutes | ||
cert_file: "/path/to/cert/file.crt" | ||
key_file: "/path/to/key/file.crt" | ||
sources: | ||
- name: "malwarebazaar" | ||
endpoint: | ||
apikey: |
Oops, something went wrong.