@@ -8,17 +8,23 @@ import (
88 "math/rand"
99 "net"
1010 "net/smtp"
11- "os"
12- "strings"
1311 "time"
1412)
1513
14+ // generateRandomContent creates random email content for variety.
15+ func generateRandomContent () (subject string , body string ) {
16+ // #nosec G404 -- non-crypto random for email content
17+ subject = fmt .Sprintf ("%016x" , rand .Uint64 ())
18+ // #nosec G404 -- non-crypto random for email content
19+ body = fmt .Sprintf ("%016x%016x%016x%016x" , rand .Uint64 (), rand .Uint64 (), rand .Uint64 (), rand .Uint64 ())
20+ return
21+ }
22+
1623type Smtp struct {
1724 Service
1825 Encrypted bool
1926 Domain string
2027 RequireAuth bool
21- Fortunes []string
2228}
2329
2430type unencryptedAuth struct {
@@ -34,38 +40,12 @@ func (a unencryptedAuth) Start(server *smtp.ServerInfo) (string, []byte, error)
3440
3541func (c Smtp ) Run (teamID uint , teamIdentifier string , roundID uint , resultsChan chan Result ) {
3642 definition := func (teamID uint , teamIdentifier string , checkResult Result , response chan Result ) {
37- fortunes , err := os .ReadFile ("/usr/share/fortune/fortunes" )
38- if err != nil {
39- checkResult .Error = "failed to load fortune file (/usr/share/fortune/fortunes)"
40- checkResult .Debug = err .Error ()
41- response <- checkResult
42- return
43- }
44- c .Fortunes = strings .Split (string (fortunes ), "\n %\n " )
45- if len (c .Fortunes ) == 0 {
46- checkResult .Error = "failed to load fortune file (/usr/share/fortune/fortunes)"
47- checkResult .Debug = "no fortunes found"
48- response <- checkResult
49- return
50- }
51-
5243 // Create a dialer
5344 dialer := net.Dialer {
5445 Timeout : time .Duration (c .Timeout ) * time .Second ,
5546 }
5647
57- fortune := c .Fortunes [rand .Intn (len (c .Fortunes ))] // #nosec G404 -- non-crypto selection of fortune text
58- words := strings .Fields (fortune )
59- subject := ""
60- if len (words ) <= 3 {
61- subject = fortune
62- } else {
63- selected := make ([]string , 3 )
64- for i := range 3 {
65- selected [i ] = words [rand .Intn (len (words ))] // #nosec G404 -- non-crypto selection of words for subject
66- }
67- subject = strings .Join (selected , " " )
68- }
48+ subject , body := generateRandomContent ()
6949
7050 // ***********************************************
7151 // Set up custom auth for bypassing net/smtp protections
@@ -176,20 +156,20 @@ func (c Smtp) Run(teamID uint, teamIdentifier string, roundID uint, resultsChan
176156 }
177157 }()
178158
179- body := fmt .Sprintf ("Subject: %s\n \n %s\n \n " , subject , fortune )
159+ message := fmt .Sprintf ("Subject: %s\n \n %s\n \n " , subject , body )
180160
181- // Write the body using Fprint to avoid treating the contents as a
161+ // Write the message using Fprint to avoid treating the contents as a
182162 // format string.
183- _ , err = fmt .Fprint (wc , body )
163+ _ , err = fmt .Fprint (wc , message )
184164 if err != nil {
185- checkResult .Error = "writing body failed"
165+ checkResult .Error = "writing message failed"
186166 checkResult .Debug = err .Error ()
187167 response <- checkResult
188168 return
189169 }
190170
191171 checkResult .Status = true
192- checkResult .Debug = "successfully wrote '" + body + "' to " + toUser + " from " + username
172+ checkResult .Debug = "successfully wrote '" + message + "' to " + toUser + " from " + username
193173 response <- checkResult
194174 }
195175
0 commit comments