Skip to content

Commit

Permalink
Color library
Browse files Browse the repository at this point in the history
  • Loading branch information
alex27riva committed Oct 19, 2024
1 parent 6d2f472 commit d37d9ea
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 37 deletions.
12 changes: 0 additions & 12 deletions cmd/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@ package cmd

import "regexp"

// ANSI escape codes for colors
const (
Reset = "\033[0m"
Red = "\033[31m"
Green = "\033[32m"
Yellow = "\033[33m"
Blue = "\033[34m"
Magenta = "\033[35m"
Cyan = "\033[36m"
White = "\033[37m"
)

var (
IPRegex = regexp.MustCompile(`\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b`)
RFC1918Regex = regexp.MustCompile(`^(10\.\d{1,3}\.\d{1,3}\.\d{1,3}|172\.(1[6-9]|2[0-9]|3[0-1])\.\d{1,3}\.\d{1,3}|192\.168\.\d{1,3}\.\d{1,3})$`)
Expand Down
13 changes: 7 additions & 6 deletions cmd/extractIoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package cmd
import (
"encoding/json"
"fmt"
"github.com/fatih/color"
"github.com/spf13/cobra"
"log"
"os"
Expand Down Expand Up @@ -69,38 +70,38 @@ func extractIOCs(filePath string, asJSON bool) {
} else {

if len(uniqueIPs)+len(uniqueURLs)+len(uniqueEmails)+len(uniqueHashes) > 0 {
fmt.Println(Blue + "Extracted IOCs" + Reset)
color.Blue("Extracted IOCs")
} else {
fmt.Println(Blue + "No IOCs found" + Reset)
color.Red("No IOCs found")
}

// Print IPs
if len(uniqueIPs) > 0 {
fmt.Println(Green + "\nIP Addresses:" + Reset)
color.Green("\nIP Addresses:")
for _, ip := range uniqueIPs {
fmt.Println(ip)
}
}

// Print URLs
if len(uniqueURLs) > 0 {
fmt.Println(Green + "\nURLs:" + Reset)
color.Green("\nURLs:")
for _, url := range uniqueURLs {
fmt.Println(url)
}
}

// Print Emails
if len(uniqueEmails) > 0 {
fmt.Println(Green + "\nEmail Addresses:" + Reset)
color.Green("\nEmail Addresses:")
for _, email := range uniqueEmails {
fmt.Println(email)
}
}

// Print SHA256 Hashes
if len(uniqueHashes) > 0 {
fmt.Println(Green + "\nSHA256 Hashes:" + Reset)
color.Green("\nSHA256 Hashes:")
for _, hash := range uniqueHashes {
fmt.Println(hash)
}
Expand Down
9 changes: 5 additions & 4 deletions cmd/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"crypto/sha1"
"crypto/sha256"
"fmt"
"github.com/fatih/color"
"github.com/spf13/cobra"
"io"
"log"
Expand All @@ -20,7 +21,7 @@ import (
func openFile(filePath string) (*os.File, error) {
file, err := os.Open(filePath)
if err != nil {
return nil, fmt.Errorf(Red+"failed to open file: %w"+Reset, err)
return nil, fmt.Errorf("failed to open file: %w", err)
}

return file, nil
Expand Down Expand Up @@ -70,12 +71,12 @@ var hashCmd = &cobra.Command{

defer file.Close()

fmt.Println(Green+"MD5:"+Reset, calculateMd5(file))
fmt.Println(color.GreenString("MD5:"), calculateMd5(file))
// Reset the file pointer to the beginning
file.Seek(0, 0)
fmt.Println(Green+"SHA1:"+Reset, calculateSha1(file))
fmt.Println(color.GreenString("SHA1:"), calculateSha1(file))
file.Seek(0, 0)
fmt.Println(Green+"SHA-256:"+Reset, calculateSha256(file))
fmt.Println(color.GreenString("SHA-256:"), calculateSha256(file))
},
}

Expand Down
16 changes: 8 additions & 8 deletions cmd/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ package cmd

import (
"fmt"
"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"log"
"os"
"soc-cli/internal/apis"

"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func analyzeIP(ip string) {
Expand Down Expand Up @@ -55,26 +55,26 @@ func analyzeIP(ip string) {
abuseIPDBData := apis.GetAbuseIPDBInfo(ip, abuseIPDBApiKey)

// Print the IP information
fmt.Println(Blue + "IP information from IPInfo" + Reset)
color.Blue("IP information from IPInfo")
fmt.Printf("IP: %s\nHostname: %s\nOrg: %s\nCountry: %s\n",
ipInfoData.IP, ipInfoData.Hostname, ipInfoData.Org, ipInfoData.Country)

if greyNoiseData != nil {
fmt.Println(Blue + "\nGreyNoise Threat Intelligence" + Reset)
color.Blue("\nGreyNoise Threat Intelligence")

classification := greyNoiseData.Classification
if classification == "malicious" {
classification = fmt.Sprintf("%s%s%s", Red, classification, Reset)
classification = color.RedString(classification)
} else if classification == "benign" {
classification = fmt.Sprintf("%s%s%s", Green, classification, Reset)
classification = color.GreenString(classification)
}

fmt.Printf("Noise: %v\nRiot: %v\nClassification: %s\nName: %s\nLink: %s\n",
greyNoiseData.Noise, greyNoiseData.Riot, classification, greyNoiseData.Name, greyNoiseData.Link)
}

if abuseIPDBData != nil {
fmt.Println(Blue + "\nAbuseIPDB report" + Reset)
color.Blue("\nAbuseIPDB report")

// Print AbuseIPDB info
fmt.Printf("Abuse Confidence Score: %d\n", abuseIPDBData.Data.AbuseConfidenceScore)
Expand Down
5 changes: 3 additions & 2 deletions cmd/urlscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"log"
Expand Down Expand Up @@ -116,9 +117,9 @@ func displayResults(scanResult urlScanResult) {
fmt.Printf("Country: %s\n", scanResult.Page.Country)
fmt.Printf("IP: %s\n", scanResult.Page.IP)
if scanResult.Verdict.Malicious {
fmt.Println("Verdict: " + Red + "MALICIOUS")
fmt.Println("Verdict: " + color.RedString("MALICIOUS"))
} else {
fmt.Println("Verdict: " + Green + "SAFE")
fmt.Println("Verdict: " + color.RedString("SAFE"))
}

}
Expand Down
7 changes: 4 additions & 3 deletions cmd/whois.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ package cmd

import (
"fmt"
"github.com/fatih/color"
"github.com/spf13/cobra"
"soc-cli/internal/apis"
)

func displayData(domainInfo apis.DomainInfo) {

fmt.Println("Domain Information:")
color.Blue("Domain Information")
fmt.Printf("Domain Name: %s\n", domainInfo.Domain.Domain)
fmt.Printf("Domain ID: %s\n", domainInfo.Domain.ID)
fmt.Printf("Extension: %s\n", domainInfo.Domain.Extension)
Expand All @@ -24,12 +25,12 @@ func displayData(domainInfo apis.DomainInfo) {
fmt.Printf("Updated Date: %s\n", domainInfo.Domain.UpdatedDate)
fmt.Printf("Expiration Date: %s\n", domainInfo.Domain.ExpirationDate)

fmt.Println("\nRegistrar Information:")
color.Blue("\nRegistrar Information:")
fmt.Printf("Registrar Name: %s\n", domainInfo.Registrar.Name)
fmt.Printf("Registrar Phone: %s\n", domainInfo.Registrar.Phone)
fmt.Printf("Registrar Email: %s\n", domainInfo.Registrar.Email)

fmt.Println("\nRegistrant Information:")
color.Blue("\nRegistrant Information:")
fmt.Printf("Registrant Name: %s\n", domainInfo.Registrant.Name)
fmt.Printf("Registrant Organization: %s\n", domainInfo.Registrant.Organization)
fmt.Printf("Registrant Country: %s\n", domainInfo.Registrant.Country)
Expand Down
9 changes: 7 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ module soc-cli

go 1.22.7

require github.com/spf13/cobra v1.8.1
require (
github.com/fatih/color v1.17.0
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
)

require (
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
Expand All @@ -17,7 +23,6 @@ require (
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.19.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
Expand Down
26 changes: 26 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
Expand All @@ -39,6 +60,7 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
Expand All @@ -48,11 +70,15 @@ go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down

0 comments on commit d37d9ea

Please sign in to comment.