Skip to content

Commit

Permalink
* exclude invalid samples.
Browse files Browse the repository at this point in the history
	* keep filename of sample to show when sending it fails.
	* better parsing of email samples.
  • Loading branch information
Filipe Gonçalves committed Apr 10, 2014
1 parent 3bd24ef commit 91fa20c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
29 changes: 15 additions & 14 deletions bomber.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,22 @@ func main() {
s, err := sample.Unmarshal(SAMPLES_DIRECTORY+"/"+val.Name())
if err != nil {
if VERBOSE {
fmt.Printf("Failed to load %s sample\n",val.Name())
fmt.Printf("Failed to load %s sample: %v\n",val.Name(), err)
}
}
if VERBOSE {
fmt.Printf("Loaded %s sample\n",val.Name())
}
if LIST_ONLY {
for _, s_category := range s.Type {
asdfg := strings.ToLower(s_category)
categories[asdfg] = true
} else {
if VERBOSE {
fmt.Printf("Loaded %s sample\n",val.Name())
}
if LIST_ONLY {
for _, s_category := range s.Type {
asdfg := strings.ToLower(s_category)
categories[asdfg] = true
}
}
if CATEGORY == "all" || hasCategory(s,CATEGORY) {
sample_list[idx] = s
idx++
}
}
if CATEGORY == "all" || hasCategory(s,CATEGORY) {
sample_list[idx] = s
idx++
}
}
}
Expand Down Expand Up @@ -182,7 +183,7 @@ func main() {
}
err := send_sample(HOST, sample_list[samples_idx])
if err != nil {
fmt.Printf("Failed to send message #%v: %v\n", j+1, err)
fmt.Printf("Failed to send message #%v (%v): %v\n", j+1, sample_list[samples_idx].SampleFileName, err)
}
if THROTTLING > 0 {
// TODO throttling should consider the running time of send_sample
Expand Down
13 changes: 8 additions & 5 deletions encoding/mail/sample/sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"fmt"
"errors"
"regexp"
)

/*
Expand All @@ -26,6 +27,7 @@ import (
*/

type MailSample struct {
SampleFileName string
Type []string
Port int
To string
Expand Down Expand Up @@ -55,12 +57,12 @@ func (s *MailSample) buildEmail(file_path string) error {
if err != nil {
return err
}
data_split := strings.SplitN(string(f), "\n\n", 2)
data_split := regexp.MustCompile("\r?\n\r?\n").Split(string(f), 2)
if len(data_split) != 2 {
return errors.New(fmt.Sprintf("Invalid email file: %v", file_path))
return errors.New(fmt.Sprintf("Invalid email file: %v", path.Dir(file_path)+"/"+s.EmailFile))
}
// parse headers
headers_aux := strings.Split(data_split[0], "\n")
headers_aux := regexp.MustCompile("\r?\n").Split(data_split[0], -1)
headers := make([]string, len(headers_aux))
idx := -1
for _, val := range headers_aux {
Expand All @@ -69,7 +71,7 @@ func (s *MailSample) buildEmail(file_path string) error {
} else {
headers[idx] += "\r\n"
}
headers[idx] += strings.TrimRight(val,"\r")
headers[idx] += val
}
headers = headers[0:idx+1]
s.Headers = headers
Expand All @@ -87,7 +89,7 @@ func (s *MailSample) buildHeaders(file_path string) error {
if err != nil {
return err
}
headers_aux := strings.Split(string(f), "\n")
headers_aux := regexp.MustCompile("\r?\n").Split(string(f), -1)
headers := make([]string, len(headers_aux))
idx := -1
for _, val := range headers_aux {
Expand Down Expand Up @@ -135,5 +137,6 @@ func Unmarshal(file_path string) (MailSample, error){
if err := s.buildBody(file_path) ; err != nil {
return s, err
}
s.SampleFileName = path.Base(file_path)
return s, nil
}

0 comments on commit 91fa20c

Please sign in to comment.