Skip to content

Commit

Permalink
Allowing use of eyeSegmentAPI application as module.
Browse files Browse the repository at this point in the history
  • Loading branch information
infosecwatchman committed Jun 1, 2023
1 parent 3429d16 commit ae5419a
Show file tree
Hide file tree
Showing 7 changed files with 1,986 additions and 155 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@

# Test binary, built with `go test -c`
*.test
main/*.test

# Ignore Credential files
*.yml
main/*.yml

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
main/*.out

# Ignore local builds
*.exe
main/*.exe

# Dependency directories (remove the comment below to include it)
# vendor/
Connections*/
main/Connections*/
src/*
buildnotes.txt
testing.go
main/testing*
140 changes: 4 additions & 136 deletions main.go → eyeSegmentAPI/eyeSegmentAPI.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package eyeSegmentAPI

import (
"bufio"
Expand All @@ -9,7 +9,6 @@ import (
"crypto/tls"
"encoding/hex"
"errors"
"flag"
"fmt"
"io"
"io/ioutil"
Expand All @@ -22,7 +21,6 @@ import (
"time"

"github.com/Jeffail/gabs/v2"
"github.com/cheggaaa/pb/v3"
"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/input"
"github.com/go-rod/rod/lib/launcher"
Expand Down Expand Up @@ -145,7 +143,7 @@ func skip(b []byte, n int) ([]byte, bool) {
// This function logs in to the website using the constants defined earlier.
func FSLogin() {
// Start a new headless Chrome browser
l := launcher.New().Leakless(false).Headless(true)
l := launcher.New().Leakless(false).Headless(false)
//l = l.Set(flags.ProxyServer, "127.0.0.1:8080")
controlURL, _ := l.Launch()
ctx := rod.New().ControlURL(controlURL).MustConnect().MustIncognito()
Expand Down Expand Up @@ -179,7 +177,7 @@ func FSLogin() {
time.Sleep(2 * time.Second)
page.MustWaitLoad()

page.MustElement("body > app-root > main-topbar > nav > ul:nth-child(2) > div:nth-child(2) > li > a").MustClick()
page.MustElement("body > app-root > main-topbar > nav > ul:nth-child(2) > div:nth-child(2) > li").MustClick()
page.MustWaitLoad()
time.Sleep(2 * time.Second)
page.MustClose()
Expand Down Expand Up @@ -503,7 +501,7 @@ func ExportData(SRCZone string, DSTZone string) {
}

// Search back the number of days by given int. Default is 3 day lookback
func timeBasedFilter(days int) {
func TimeBasedFilter(days int) {
//fmt.Println("Applying filter based on days specified")
//body := buildPostRequest("/seg/api/v1/user/configuration/timeBasedFilter", http.MethodPut, fmt.Sprintf("{\"lastDaysFilter\":%d}", days), false)
buildPostRequest("/seg/api/v1/user/configuration/timeBasedFilter", http.MethodPut, fmt.Sprintf("{\"lastDaysFilter\":%d}", days), false)
Expand Down Expand Up @@ -593,133 +591,3 @@ func GetCredentialsFromFiles() bool {
FSApplianceFQDN = viper.GetString("helper.url")
return true
}

func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)

GetDSTZonesFlag := flag.Bool("d", false, "Get all destination zones from selected source.")
GetSRCZonesFlag := flag.Bool("s", false, "Get all source zones from selected destination.")
CheckZoneID := flag.Bool("c", false, "Print Zone ID from given name.")
ZoneName := flag.String("n", "", "Specify a Zone name to lookup.")
exportDSTDataFlag := flag.Bool("oS", false, "Export data given source name. (Requires -n)")
exportSRCDataFlag := flag.Bool("oD", false, "Export data given destination name. (Requires -n)")
timeFilter := flag.Int("f", 3, "Set how many days to look back into the data.")
test := flag.Bool("t", false, "flag to test functions")
username := flag.String("u", "", "Specify username to connect to server with. Will use embedded username if configured.")
password := flag.String("p", "", "Specify password to connect to server with. Will use embedded password if configured.")
server := flag.String("fS", FSApplianceFQDN, "Specify server to connect to. Will use embedded FQDN if configured.")
flag.Parse()

GetCredentialsFromFiles()
if FSApplianceFQDN == "" || FSusername == "" || FSpassword == "" {
if *username == "" && FSusername == "" {
if FSusername == "" && *username != "" {
FSusername = *username
} else {
fmt.Println("Username not specified.")
FSusername = StringPrompt("Username:")
}
}
if *password == "" && FSpassword == "" {
if FSpassword == "" && *password != "" {
FSpassword = *password
} else {
fmt.Println("Password not specified.")
FSpassword = StringPrompt("Password:")
}
}
if *server == "" && FSApplianceFQDN == "" {
if FSApplianceFQDN == "" && *server != "" {
FSApplianceFQDN = *server
} else {
fmt.Println("Server not specified.")
FSApplianceFQDN = StringPrompt("Forescout Appliance FQDN:")
}
}
}

if *test {
return
} else if *ZoneName == "" {
fmt.Println("You must specify a zone name.")
flag.PrintDefaults()
return
} else {
fmt.Println("Attempting connection to your local forescout instance via " + FSApplianceFQDN + ". Please wait.....")
FSLogin()
if ConnectTest() {
fmt.Printf("Successfully logged into %s\n", FSApplianceFQDN)
} else {
fmt.Printf("Could not login to %s: \n This could be due to incorrect credentials, or it could not connect to the server.", FSApplianceFQDN)
return
}
check := GetZoneID(*ZoneName)
if check == "No Zone ID Found." {
fmt.Println(check)
return
}
ClearFilter()
timeBasedFilter(*timeFilter)
if *GetSRCZonesFlag {
fmt.Println(GetSRCZones(check))
} else if *GetDSTZonesFlag {
fmt.Println(GetDSTZones(check))
} else if *CheckZoneID {
fmt.Println(check)
} else if *exportDSTDataFlag {
SRCZone := check
var DSTZonesWData []string
var DSTZonesCollection []string
dir := fmt.Sprintf("Connections made from %s", *ZoneName)
os.Mkdir(dir, 0600)
os.Chdir(dir)
DSTZones := GetDSTZones(SRCZone)
for _, DSTZone := range DSTZones {
val, _ := CheckOccurrences(SRCZone, DSTZone)
if val {
DSTZonesWData, _ = DSTzoneToZoneConnections(SRCZone, DSTZone)
for _, DSTZone = range DSTZonesWData {
DSTZonesCollection = append(DSTZonesCollection, DSTZone)
}
}
}
bar := pb.StartNew(len(DSTZonesCollection))
for _, DSTZone := range DSTZonesCollection {
ExportData(SRCZone, DSTZone)
bar.Increment()
}
time.Sleep(1 * time.Second)
fmt.Printf("\nData successfully exported to \"%s\"", dir)

} else if *exportSRCDataFlag {
var SRCZonesWData []string
var SRCZoneCollection []string
DSTZone := check
dir := fmt.Sprintf("Connections made to %s", *ZoneName)
fmt.Println("Creating Directory of Connections")
os.Mkdir(dir, 0600)
os.Chdir(dir)
SRCZones := GetSRCZones(DSTZone)
for _, SRCZone := range SRCZones {
val, _ := CheckOccurrences(SRCZone, DSTZone)
if val {
SRCZonesWData, _ = SRCzoneToZoneConnections(SRCZone, DSTZone)
for _, SRCZone = range SRCZonesWData {
SRCZoneCollection = append(SRCZoneCollection, SRCZone)
}
}
}
bar := pb.StartNew(len(SRCZoneCollection))
for _, SRCZone := range SRCZoneCollection {
ExportData(SRCZone, DSTZone)
bar.Increment()
}
time.Sleep(1 * time.Second)

fmt.Printf("\nData successfully exported to \"%s\"", dir)
} else {
flag.PrintDefaults()
}
}

}
5 changes: 2 additions & 3 deletions go.mod → eyeSegmentAPI/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ module github.com/infosecwatchman/eyeSegmentAPI
go 1.16

require (
github.com/Jeffail/gabs/v2 v2.6.1
github.com/cheggaaa/pb/v3 v3.0.8
github.com/go-rod/rod v0.112.6
github.com/Jeffail/gabs/v2 v2.7.0
github.com/go-rod/rod v0.113.1
github.com/spf13/viper v1.16.0
golang.org/x/term v0.8.0
)
Loading

0 comments on commit ae5419a

Please sign in to comment.