From 68455a248bccacf5eebcbf8df4c990b622ea5457 Mon Sep 17 00:00:00 2001 From: basebandit Date: Fri, 8 Jan 2021 19:24:39 +0300 Subject: [PATCH 01/16] else is redundant the return statement in the if clause already guards against executing the code outside the clause --- core/certdb.go | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/core/certdb.go b/core/certdb.go index 52a6426..3b89d64 100644 --- a/core/certdb.go +++ b/core/certdb.go @@ -445,34 +445,34 @@ func (d *CertDb) SignCertificateForHost(host string, phish_host string, port int srvCert := d.getServerCertificate(host, port) if srvCert == nil { return nil, fmt.Errorf("failed to get TLS certificate for: %s", host) - } else { - serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128) - serialNumber, err := rand.Int(rand.Reader, serialNumberLimit) - if err != nil { - return nil, err - } + } + serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128) + serialNumber, err := rand.Int(rand.Reader, serialNumberLimit) + if err != nil { + return nil, err + } - template = x509.Certificate{ - SerialNumber: serialNumber, - Issuer: x509ca.Subject, - Subject: srvCert.Subject, - NotBefore: srvCert.NotBefore, - NotAfter: srvCert.NotAfter, - KeyUsage: srvCert.KeyUsage, - ExtKeyUsage: srvCert.ExtKeyUsage, - IPAddresses: srvCert.IPAddresses, - DNSNames: []string{phish_host}, - BasicConstraintsValid: true, - } - template.Subject.CommonName = phish_host + template = x509.Certificate{ + SerialNumber: serialNumber, + Issuer: x509ca.Subject, + Subject: srvCert.Subject, + NotBefore: srvCert.NotBefore, + NotAfter: srvCert.NotAfter, + KeyUsage: srvCert.KeyUsage, + ExtKeyUsage: srvCert.ExtKeyUsage, + IPAddresses: srvCert.IPAddresses, + DNSNames: []string{phish_host}, + BasicConstraintsValid: true, } + template.Subject.CommonName = phish_host + } var pkey *rsa.PrivateKey if pkey, err = rsa.GenerateKey(rand.Reader, 1024); err != nil { return nil, err } - + var derBytes []byte if derBytes, err = x509.CreateCertificate(rand.Reader, &template, x509ca, &pkey.PublicKey, d.CACert.PrivateKey); err != nil { return nil, err @@ -486,4 +486,3 @@ func (d *CertDb) SignCertificateForHost(host string, phish_host string, port int d.tls_cache[host] = cert return cert, nil } - From 4ae2434485d937e91cb190d7e8782df4fee39533 Mon Sep 17 00:00:00 2001 From: basebandit Date: Sun, 17 Jan 2021 15:53:55 +0300 Subject: [PATCH 02/16] read blacklisted ips from disk --- core/blacklist.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/core/blacklist.go b/core/blacklist.go index f2970dd..0fe3529 100644 --- a/core/blacklist.go +++ b/core/blacklist.go @@ -118,3 +118,27 @@ func (bl *Blacklist) IsBlacklisted(ip string) bool { } return false } + +func (bl *Blacklist) IPs() (ips []string, err error) { + f, err := os.Open(bl.configPath) + if err != nil { + return nil, err + } + + defer func() { + if err != nil { + f.Close() + } + }() + + s := bufio.NewScanner(f) + for s.Scan() { + ips = append(ips, s.Text()) + } + + if err := s.Err(); err != nil { + return nil, fmt.Errorf("IPs: error reading blacklist: %w", err) + } + + return +} From 5817ee75d373d396b0fe43ede593d3fafe14b872 Mon Sep 17 00:00:00 2001 From: basebandit Date: Sun, 17 Jan 2021 15:56:43 +0300 Subject: [PATCH 03/16] create single column ascii table string --- core/table.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/core/table.go b/core/table.go index 374ab41..33f4623 100644 --- a/core/table.go +++ b/core/table.go @@ -144,6 +144,50 @@ func AsTable(columns []string, rows [][]string) string { return table } +//AsSingleColTable creates a single column ascii table. +// col is the header of the table and cells are the individual rows under the header col +func AsSingleColTable(col string, cells []string) string { + dg := color.New(color.FgHiBlack) + + rMaxLens := make([]int, 0) + + for _, cell := range cells { + rlen := viewLen(fmt.Sprintf(" %s ", cell)) + 4 + if rlen < minColLen { + rlen = minColLen + } + rMaxLens = append(rMaxLens, rlen) + } + + //lets find the longest column and set that to be the maxwidthlen + var MaxLen int + for _, len := range rMaxLens { + if len > MaxLen { + MaxLen = len + } + } + + var lineSep string + column := []string{col} + column = append(column, cells...) + + lineSep += fmt.Sprintf("+%s", strings.Repeat("-", MaxLen+1)) + lineSep += "+" + + var table string + table += dg.Sprintf("%s\n", lineSep) + table += dg.Sprintf("|") + padded(col, MaxLen, AlignCenter) + table += dg.Sprintf("|\n") + table += dg.Sprintf("%s\n", lineSep) + for _, cell := range cells { + table += dg.Sprintf("|") + padded(cell, MaxLen, AlignCenter) + table += dg.Sprintf("|\n") + } + + table += dg.Sprintf(lineSep) + "\n" + return table +} + func AsRows(keys []string, vals []string) string { clr := color.New(color.FgHiBlack) mLen := maxLen(keys) From 31cb1e3ed653059a1f6ced5552a979cf036ea336 Mon Sep 17 00:00:00 2001 From: basebandit Date: Sun, 17 Jan 2021 16:21:41 +0300 Subject: [PATCH 04/16] move common variable decl to the top this will avoid redundancy in code that need to redeclare the same variables --- core/terminal.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/core/terminal.go b/core/terminal.go index 83e3f5c..ddcf92d 100644 --- a/core/terminal.go +++ b/core/terminal.go @@ -31,6 +31,15 @@ const ( LAYER_TOP = 1 ) +var ( + lblue = color.New(color.FgHiBlue) + dgray = color.New(color.FgHiBlack) + lgreen = color.New(color.FgHiGreen) + yellow = color.New(color.FgYellow) + lred = color.New(color.FgHiRed) + cyan = color.New(color.FgCyan) +) + type Terminal struct { rl *readline.Instance completer *readline.PrefixCompleter @@ -329,12 +338,6 @@ func (t *Terminal) handleProxy(args []string) error { } func (t *Terminal) handleSessions(args []string) error { - lblue := color.New(color.FgHiBlue) - dgray := color.New(color.FgHiBlack) - lgreen := color.New(color.FgHiGreen) - yellow := color.New(color.FgYellow) - lred := color.New(color.FgHiRed) - cyan := color.New(color.FgCyan) pn := len(args) if pn == 0 { From 0d3ca442873a2e2f22f98c58791c1430cede98da Mon Sep 17 00:00:00 2001 From: basebandit Date: Sun, 17 Jan 2021 16:29:08 +0300 Subject: [PATCH 05/16] add blacklist show subcommand help menu --- core/terminal.go | 141 ++++++++++++++++++++++++++--------------------- 1 file changed, 77 insertions(+), 64 deletions(-) diff --git a/core/terminal.go b/core/terminal.go index ddcf92d..5c1e5c1 100644 --- a/core/terminal.go +++ b/core/terminal.go @@ -133,59 +133,59 @@ func (t *Terminal) ProcessCommand(line string) bool { cmd_ok := false switch args[0] { - case "clear": - cmd_ok = true - readline.ClearScreen(color.Output) - case "config": - cmd_ok = true - err := t.handleConfig(args[1:]) - if err != nil { - log.Error("config: %v", err) - } - case "proxy": - cmd_ok = true - err := t.handleProxy(args[1:]) - if err != nil { - log.Error("proxy: %v", err) - } - case "sessions": - cmd_ok = true - err := t.handleSessions(args[1:]) - if err != nil { - log.Error("sessions: %v", err) - } - case "phishlets": - cmd_ok = true - err := t.handlePhishlets(args[1:]) - if err != nil { - log.Error("phishlets: %v", err) - } - case "lures": - cmd_ok = true - err := t.handleLures(args[1:]) - if err != nil { - log.Error("lures: %v", err) - } - case "blacklist": - cmd_ok = true - err := t.handleBlacklist(args[1:]) - if err != nil { - log.Error("blacklist: %v", err) - } - case "help": - cmd_ok = true - if len(args) == 2 { - if err := t.hlp.PrintBrief(args[1]); err != nil { - log.Error("help: %v", err) - } - } else { - t.hlp.Print(0) + case "clear": + cmd_ok = true + readline.ClearScreen(color.Output) + case "config": + cmd_ok = true + err := t.handleConfig(args[1:]) + if err != nil { + log.Error("config: %v", err) + } + case "proxy": + cmd_ok = true + err := t.handleProxy(args[1:]) + if err != nil { + log.Error("proxy: %v", err) + } + case "sessions": + cmd_ok = true + err := t.handleSessions(args[1:]) + if err != nil { + log.Error("sessions: %v", err) + } + case "phishlets": + cmd_ok = true + err := t.handlePhishlets(args[1:]) + if err != nil { + log.Error("phishlets: %v", err) + } + case "lures": + cmd_ok = true + err := t.handleLures(args[1:]) + if err != nil { + log.Error("lures: %v", err) + } + case "blacklist": + cmd_ok = true + err := t.handleBlacklist(args[1:]) + if err != nil { + log.Error("blacklist: %v", err) + } + case "help": + cmd_ok = true + if len(args) == 2 { + if err := t.hlp.PrintBrief(args[1]); err != nil { + log.Error("help: %v", err) } - case "q", "quit", "exit": - return true - default: - log.Error("unknown command: %s", args[0]) - cmd_ok = true + } else { + t.hlp.Print(0) + } + case "q", "quit", "exit": + return true + default: + log.Error("unknown command: %s", args[0]) + cmd_ok = true } if !cmd_ok { log.Error("invalid syntax: %s", line) @@ -253,6 +253,18 @@ func (t *Terminal) handleBlacklist(args []string) error { case "off": t.cfg.SetBlacklistMode(args[0]) return nil + case "show": + ips, err := t.p.bl.IPs() + if err != nil { + log.Error("%v", err) + break + } + if len(ips) > 0 { + log.Printf("\n%s\n", AsSingleColTable("ip", ips)) + } else { + log.Printf("%s", dgray.Sprintf("none")) + } + return nil } } return fmt.Errorf("invalid syntax: %s", args) @@ -511,13 +523,13 @@ func (t *Terminal) handleSessions(args []string) error { log.Info("exported sessions to csv: %s", outFile.Name()) case "json": type ExportedSession struct { - Id string `json:"id"` - Phishlet string `json:"phishlet"` - Username string `json:"username"` - Password string `json:"password"` - Tokens string `json:"tokens_base64_encoded"` + Id string `json:"id"` + Phishlet string `json:"phishlet"` + Username string `json:"username"` + Password string `json:"password"` + Tokens string `json:"tokens_base64_encoded"` RemoteAddr string `json:"remote_ip"` - Time string `json:"time"` + Time string `json:"time"` } var exported []*ExportedSession for _, s := range sessions { @@ -527,13 +539,13 @@ func (t *Terminal) handleSessions(args []string) error { break } es := &ExportedSession{ - Id: strconv.Itoa(s.Id), - Phishlet: s.Phishlet, - Username: s.Username, - Password: s.Password, - Tokens: base64.StdEncoding.EncodeToString([]byte(t.tokensToJSON(pl, s.Tokens))), + Id: strconv.Itoa(s.Id), + Phishlet: s.Phishlet, + Username: s.Username, + Password: s.Password, + Tokens: base64.StdEncoding.EncodeToString([]byte(t.tokensToJSON(pl, s.Tokens))), RemoteAddr: s.RemoteAddr, - Time: time.Unix(s.UpdateTime, 0).Format("2006-01-02 15:04"), + Time: time.Unix(s.UpdateTime, 0).Format("2006-01-02 15:04"), } exported = append(exported, es) } @@ -1119,6 +1131,7 @@ func (t *Terminal) createHelp() { h.AddSubCommand("blacklist", []string{"all"}, "all", "block and blacklist ip addresses for every single request (even authorized ones!)") h.AddSubCommand("blacklist", []string{"unauth"}, "unauth", "block and blacklist ip addresses only for unauthorized requests") h.AddSubCommand("blacklist", []string{"off"}, "off", "never add any ip addresses to blacklist") + h.AddSubCommand("blacklist", []string{"show"}, "show", "list all blacklisted ip addresses") h.AddCommand("clear", "general", "clears the screen", "Clears the screen.", LAYER_TOP, readline.PcItem("clear")) From 222de20d2092da9b1f76a4f96d061c7224dafda1 Mon Sep 17 00:00:00 2001 From: basebandit Date: Sun, 17 Jan 2021 18:25:18 +0300 Subject: [PATCH 06/16] refactor: change to variadic ip param this allows the caller to add one or more ips to the blacklist --- core/blacklist.go | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/core/blacklist.go b/core/blacklist.go index 0fe3529..4344b30 100644 --- a/core/blacklist.go +++ b/core/blacklist.go @@ -75,30 +75,32 @@ func NewBlacklist(path string) (*Blacklist, error) { return bl, nil } -func (bl *Blacklist) AddIP(ip string) error { - if bl.IsBlacklisted(ip) { - return nil - } +func (bl *Blacklist) AddIP(ips ...string) error { + for _, ip := range ips { + if bl.IsBlacklisted(ip) { + return nil + } - ipv4 := net.ParseIP(ip) - if ipv4 != nil { - bl.ips[ipv4.String()] = &BlockIP{ipv4: ipv4, mask: nil} - } else { - return fmt.Errorf("blacklist: invalid ip address: %s", ip) - } + ipv4 := net.ParseIP(ip) + if ipv4 != nil { + bl.ips[ipv4.String()] = &BlockIP{ipv4: ipv4, mask: nil} + } else { + return fmt.Errorf("blacklist: invalid ip address: %s", ip) + } - // write to file - f, err := os.OpenFile(bl.configPath, os.O_APPEND|os.O_WRONLY, 0644) - if err != nil { - return err - } - defer f.Close() + // write to file + f, err := os.OpenFile(bl.configPath, os.O_APPEND|os.O_WRONLY, 0644) + if err != nil { + return err + } + defer f.Close() - _, err = f.WriteString(ipv4.String() + "\n") - if err != nil { - return err + _, err = f.WriteString(ipv4.String() + "\n") + if err != nil { + return err + } + log.Success("successfully blacklisted '%s'", ip) } - return nil } From d3178be2f02d78b5034cef00c3b1e8c25bcfc97b Mon Sep 17 00:00:00 2001 From: basebandit Date: Sun, 17 Jan 2021 18:26:16 +0300 Subject: [PATCH 07/16] add one or more ips to blacklist --- core/terminal.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/terminal.go b/core/terminal.go index 5c1e5c1..1280e68 100644 --- a/core/terminal.go +++ b/core/terminal.go @@ -266,6 +266,16 @@ func (t *Terminal) handleBlacklist(args []string) error { } return nil } + } else if pn > 2 { + switch args[0] { + case "add": + err := t.p.bl.AddIP(args[1:]...) + if err != nil { + log.Error("%v", err) + return nil + } + return nil + } } return fmt.Errorf("invalid syntax: %s", args) } @@ -1132,6 +1142,7 @@ func (t *Terminal) createHelp() { h.AddSubCommand("blacklist", []string{"unauth"}, "unauth", "block and blacklist ip addresses only for unauthorized requests") h.AddSubCommand("blacklist", []string{"off"}, "off", "never add any ip addresses to blacklist") h.AddSubCommand("blacklist", []string{"show"}, "show", "list all blacklisted ip addresses") + h.AddSubCommand("blacklist", []string{"add"}, "add", "add one or more ips to blacklist") h.AddCommand("clear", "general", "clears the screen", "Clears the screen.", LAYER_TOP, readline.PcItem("clear")) From f1d68c2b2c53b0592efa62715f9ef1921f6d98da Mon Sep 17 00:00:00 2001 From: basebandit Date: Sun, 17 Jan 2021 18:29:06 +0300 Subject: [PATCH 08/16] add help menu for blacklist's add subcommand --- core/terminal.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/terminal.go b/core/terminal.go index 1280e68..2ac36d4 100644 --- a/core/terminal.go +++ b/core/terminal.go @@ -1142,7 +1142,7 @@ func (t *Terminal) createHelp() { h.AddSubCommand("blacklist", []string{"unauth"}, "unauth", "block and blacklist ip addresses only for unauthorized requests") h.AddSubCommand("blacklist", []string{"off"}, "off", "never add any ip addresses to blacklist") h.AddSubCommand("blacklist", []string{"show"}, "show", "list all blacklisted ip addresses") - h.AddSubCommand("blacklist", []string{"add"}, "add", "add one or more ips to blacklist") + h.AddSubCommand("blacklist", []string{"add"}, "add ...", "add one or more ips to blacklist") h.AddCommand("clear", "general", "clears the screen", "Clears the screen.", LAYER_TOP, readline.PcItem("clear")) From 0419d8da46d71fb8ff2f2b7061d1d69cd5d6d351 Mon Sep 17 00:00:00 2001 From: basebandit Date: Sun, 17 Jan 2021 18:42:35 +0300 Subject: [PATCH 09/16] add blacklist exist subcommand exist subcommand checks if the given ip exists in the blacklist returns true if it exists otherwise false --- core/terminal.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/terminal.go b/core/terminal.go index 2ac36d4..3a507dd 100644 --- a/core/terminal.go +++ b/core/terminal.go @@ -275,6 +275,10 @@ func (t *Terminal) handleBlacklist(args []string) error { return nil } return nil + case "exists": + exists := t.p.bl.IsBlacklisted(args[0]) + log.Success("%v", exists) + return nil } } return fmt.Errorf("invalid syntax: %s", args) From cd456b0ac0e5c397fcd53f8ed1623a883bec4461 Mon Sep 17 00:00:00 2001 From: basebandit Date: Sun, 17 Jan 2021 18:46:43 +0300 Subject: [PATCH 10/16] BUG FIX: update the check for the cli parameters passed in checks whether the cli params passed in are also equal to 2 to cater for the blacklist 'exists' subcommand whose cli params length is exactly 2 --- core/terminal.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/terminal.go b/core/terminal.go index 3a507dd..5e5cbcb 100644 --- a/core/terminal.go +++ b/core/terminal.go @@ -266,7 +266,7 @@ func (t *Terminal) handleBlacklist(args []string) error { } return nil } - } else if pn > 2 { + } else if pn >= 2 { switch args[0] { case "add": err := t.p.bl.AddIP(args[1:]...) From 0707334f3ca8716d624398a9b757ab3d70a157f4 Mon Sep 17 00:00:00 2001 From: basebandit Date: Sun, 17 Jan 2021 18:56:36 +0300 Subject: [PATCH 11/16] add blacklist 'exists' subcommand help menu --- core/terminal.go | 1 + 1 file changed, 1 insertion(+) diff --git a/core/terminal.go b/core/terminal.go index 5e5cbcb..a412d04 100644 --- a/core/terminal.go +++ b/core/terminal.go @@ -1147,6 +1147,7 @@ func (t *Terminal) createHelp() { h.AddSubCommand("blacklist", []string{"off"}, "off", "never add any ip addresses to blacklist") h.AddSubCommand("blacklist", []string{"show"}, "show", "list all blacklisted ip addresses") h.AddSubCommand("blacklist", []string{"add"}, "add ...", "add one or more ips to blacklist") + h.AddSubCommand("blacklist", []string{"exists"}, "exists ", "verifies if the given ip is already blacklisted") h.AddCommand("clear", "general", "clears the screen", "Clears the screen.", LAYER_TOP, readline.PcItem("clear")) From daa0006bdbe920234bdf468c5d709df814e0b9bc Mon Sep 17 00:00:00 2001 From: basebandit Date: Sun, 17 Jan 2021 21:12:01 +0300 Subject: [PATCH 12/16] print error message for invalid ip values --- core/blacklist.go | 1 + 1 file changed, 1 insertion(+) diff --git a/core/blacklist.go b/core/blacklist.go index 4344b30..fa2abd4 100644 --- a/core/blacklist.go +++ b/core/blacklist.go @@ -107,6 +107,7 @@ func (bl *Blacklist) AddIP(ips ...string) error { func (bl *Blacklist) IsBlacklisted(ip string) bool { ipv4 := net.ParseIP(ip) if ipv4 == nil { + log.Error("not a valid ip '%s'", ip) return false } From 221738f070f70a030a7b4e5f0ed71115c4a2b123 Mon Sep 17 00:00:00 2001 From: basebandit Date: Sun, 17 Jan 2021 21:13:14 +0300 Subject: [PATCH 13/16] BUG FIX: pass the ip value initially passed in the subcommand value instead of the ip value whose index is 1 --- core/terminal.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/terminal.go b/core/terminal.go index a412d04..de8254b 100644 --- a/core/terminal.go +++ b/core/terminal.go @@ -276,7 +276,7 @@ func (t *Terminal) handleBlacklist(args []string) error { } return nil case "exists": - exists := t.p.bl.IsBlacklisted(args[0]) + exists := t.p.bl.IsBlacklisted(args[1]) log.Success("%v", exists) return nil } From 8ea18231386b10a977f4e68e0d711155ef0b6f60 Mon Sep 17 00:00:00 2001 From: basebandit Date: Sun, 17 Jan 2021 21:55:58 +0300 Subject: [PATCH 14/16] lint fix: inefectual assignment removed unused column slice --- core/table.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/table.go b/core/table.go index 33f4623..499668a 100644 --- a/core/table.go +++ b/core/table.go @@ -168,8 +168,6 @@ func AsSingleColTable(col string, cells []string) string { } var lineSep string - column := []string{col} - column = append(column, cells...) lineSep += fmt.Sprintf("+%s", strings.Repeat("-", MaxLen+1)) lineSep += "+" From 2dc9624ab60303afb6a2f317869fe22bd5a2a87c Mon Sep 17 00:00:00 2001 From: JamesCullum Date: Mon, 11 Jan 2021 13:00:58 +0100 Subject: [PATCH 15/16] Skip all tests at end for PRs, as they all rely on the successful login beforehand --- main_test.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/main_test.go b/main_test.go index 1722442..32ba31f 100644 --- a/main_test.go +++ b/main_test.go @@ -125,12 +125,13 @@ func TestStart(t *testing.T) { redditPassword := os.Getenv("REDDITPASSWORD") if redditPassword == "" { - log.Println("[SKIP]", "Valid login is accepted") - } else { - _, _, body, _ = test.HttpPost("https://www.localhost/login", baseData+redditPassword) - test.assertContains(body, "https://www.localhost", "Valid login is accepted") - test.assertLogContains("all authorization tokens intercepted", "Valid login is detected as correct") - } + log.Println("[SKIP]", "Valid login tests skipped due to missing environment variable") + return + } + + _, _, body, _ = test.HttpPost("https://www.localhost/login", baseData+redditPassword) + test.assertContains(body, "https://www.localhost", "Valid login is accepted") + test.assertLogContains("all authorization tokens intercepted", "Valid login is detected as correct") test.Clear() _, url, _, _ = test.HttpGet("https://www.localhost") From bc808fcdbd246257304586a7e63aa5d9d6cb7fb8 Mon Sep 17 00:00:00 2001 From: basebandit Date: Sun, 17 Jan 2021 23:32:34 +0300 Subject: [PATCH 16/16] add tests for blacklist command --- main_test.go | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/main_test.go b/main_test.go index 32ba31f..92d7c39 100644 --- a/main_test.go +++ b/main_test.go @@ -101,6 +101,20 @@ func TestStart(t *testing.T) { log.Println("Finished configuration, setting up HTTP") time.Sleep(1 * time.Second) + //Test Blacklist mode + log.Println("Testing blacklist mode") + terminal.ProcessCommand("blacklist") + test.assertLogContains("blacklist mode set to: off", "Default blacklist mode") //default mode + terminal.ProcessCommand("blacklist show") + test.assertLogContains("", "Can list blacklisted ips") //we expect none at first since blacklist mode is off + terminal.ProcessCommand("blacklist add 127.0.0.2") + terminal.ProcessCommand("blacklist show") + test.assertLogContains("127.0.0.2", "Can add ip to blacklist") + terminal.ProcessCommand("blacklist exists 127.0.0.2") + test.assertLogContains("true", "Can verify ip exists in blacklist") + terminal.ProcessCommand("blacklist exists 127.0.0.1") + test.assertLogContains("false", "Can verify ip does not exist in blacklist") + // Test HTTP requests log.Println("Testing interaction") _, url, _, _ := test.HttpGet("https://www.localhost") @@ -127,8 +141,8 @@ func TestStart(t *testing.T) { if redditPassword == "" { log.Println("[SKIP]", "Valid login tests skipped due to missing environment variable") return - } - + } + _, _, body, _ = test.HttpPost("https://www.localhost/login", baseData+redditPassword) test.assertContains(body, "https://www.localhost", "Valid login is accepted") test.assertLogContains("all authorization tokens intercepted", "Valid login is detected as correct") @@ -143,10 +157,10 @@ func TestStart(t *testing.T) { test.assertLogContains("captured", "Session token captured") test.assertLogContains(`","name":"reddit_session","httpOnly":true`, "Session cookie displayed") test.Clear() - - exportPath := path+"/export.json" + + exportPath := path + "/export.json" os.RemoveAll(exportPath) - terminal.ProcessCommand("sessions export json "+strings.ReplaceAll(exportPath, `\`, `\\`)) + terminal.ProcessCommand("sessions export json " + strings.ReplaceAll(exportPath, `\`, `\\`)) test.assertLogContains("exported sessions to json", "Can export sessions to file") time.Sleep(1 * time.Second) readDump, err := ioutil.ReadFile(exportPath)