~poptart/sprey

84cde05639ef39e554ddc4f29217f3502f652d80 — poptart 3 years ago 1f48123
Pre-DB restructure 1
3 files changed, 48 insertions(+), 40 deletions(-)

M cmd/sprey.go
M db.go
M sprey.go
M cmd/sprey.go => cmd/sprey.go +18 -17
@@ 36,19 36,19 @@ func main() {
		fmt.Printf("%s\n", err.Error())
		os.Exit(1)
	}
	a, err := sprey.NewTimingCampaign(td, u)
	if err != nil {
		fmt.Printf("0> %s\n", err.Error())
		os.Exit(3)
	}
	a.Campaign, _ = sprey.NewSpray(a)
	a.SetTriggerLow()
	err = sprey.Start(a)
	if err != nil {
		fmt.Printf("0> %s\n", err.Error())
		os.Exit(4)
	}
	//reset
	//a, err := sprey.NewTimingCampaign(td, u)
	//if err != nil {
	//	fmt.Printf("0> %s\n", err.Error())
	//	os.Exit(3)
	//}
	//a.Campaign, _ = sprey.NewSpray(a)
	//a.SetTriggerLow()
	//err = sprey.Start(a, db)
	//if err != nil {
	//	fmt.Printf("0> %s\n", err.Error())
	//	os.Exit(4)
	//}
	////reset
	td = bufio.NewReader(strings.NewReader(test))
	b, err := sprey.NewContentCampaign(td, u, sprey.MatchStatus|sprey.MatchBody)
	if err != nil {


@@ 57,14 57,15 @@ func main() {
	}
	b.Campaign, _ = sprey.NewSpray(b)
	b.SuccessStatusCode(200)
	err = sprey.Start(b)

	c, err := sprey.StartCampaign(db, sprey.PasswordPolicy{}, sprey.Delay{}, []byte(test))
	if err != nil {
		fmt.Printf("1> %s\n", err.Error())
		fmt.Printf("2> %#v %s\n", c, err.Error())
		os.Exit(4)
	}
	c, err := sprey.StartCampaign(db, sprey.PasswordPolicy{}, sprey.Delay{}, []byte(test))
	err = sprey.Start(b, db, c)
	if err != nil {
		fmt.Printf("2> %#v %s\n", c, err.Error())
		fmt.Printf("1> %s\n", err.Error())
		os.Exit(4)
	}
	fmt.Printf("2> %#v\n", c)

M db.go => db.go +24 -22
@@ 2,6 2,7 @@ package sprey

import (
	"database/sql"
	"net/http/httputil"
	"time"

	_ "github.com/mattn/go-sqlite3"


@@ 79,7 80,7 @@ const (
	delay_random INTEGER
);`
	sqlstartcampaign = `INSERT INTO campaign(request_data, policy_duration, policy_threshold, policy_window, delay_global, delay_peruser, delay_perlockout, delay_window, delay_random) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?);`
	sqlrecordattempt = `INSERT INTO sprey(runid, previous, start, stop, username, password, response_data, success, timing_initial, timing_dnsstart, timing_dnsstop, timing_tlsstart, timing_tlsstop, timing_connstart, timing_connstop, timing_firstbyte, timing_lastbyte, meta) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`
	sqlrecordattempt = `INSERT INTO sprey(runid, username, password, response_data, success, timing_initial, timing_dnsstart, timing_dnsstop, timing_tlsstart, timing_tlsstop, timing_connstart, timing_connstop, timing_firstbyte, timing_lastbyte, meta) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`
)

func OpenDB(path string) (*sql.DB, error) {


@@ 141,27 142,28 @@ func StartCampaign(db *sql.DB, policy PasswordPolicy, delay Delay, reqdata []byt
	}, nil
}

func (*DBCampaign) RecordAttempt(db *sql.DB, attempt *Attempt) error {
	//&Entry{
	//	RunID:           1,
	//	Previous:        1,
	//	Start:           1,
	//	Stop:            1,
	//	Username:        "",
	//	Password:        "",
	//	Response:        []byte{},
	//	Success:         false,
	//	TimingInitial:   1,
	//	TimingDNSStart:  1,
	//	TimingDNSStop:   1,
	//	TimingTLSStart:  1,
	//	TimingTLSStop:   1,
	//	TimingConnStart: 1,
	//	TimingConnStop:  1,
	//	TimingFirstByte: 1,
	//	TimingLastByte:  1,
	//	Meta:            []byte{},
	//}, nil
func (d *DBCampaign) RecordAttempt(db *sql.DB, attempt Attempt) error {
	tx, err := db.Begin()
	if err != nil {
		return err
	}
	stmt, err := tx.Prepare(sqlrecordattempt)
	if err != nil {
		return err
	}
	defer stmt.Close()
	a, _ := httputil.DumpResponse(attempt.Exchange.Response, true)

	//TODO runid and previous
	_, err = stmt.Exec(d.RunID,
		attempt.Credential.Username, attempt.Credential.Password,
		a, attempt.Success,
		attempt.Exchange.Timing.InitialStart, attempt.Exchange.Timing.DNSStart,
		attempt.Exchange.Timing.DNSStop,
	)
	if err != nil {
		return err
	}
	tx.Commit()
	return nil
}

M sprey.go => sprey.go +6 -1
@@ 1,6 1,7 @@
package sprey

import (
	"database/sql"
	"fmt"
	"net/http"
	"time"


@@ 80,13 81,17 @@ func NewSpray(s Spray) (*Meta, error) {
	return &Meta{}, nil
}

func Start(s Spray) error {
func Start(s Spray, db *sql.DB, campaign *DBCampaign) error {
	att, err := s.Do()
	if err != nil {
		return err
	}
	fmt.Printf("%#v\n", att)
	fmt.Printf("%#v\n", att.Exchange.Timing)
	fmt.Printf("DNS - %s\n", att.Exchange.Timing.DNSStop.Sub(att.Exchange.Timing.DNSStart).String())
	fmt.Printf("Connect - %s\n", att.Exchange.Timing.ConnectStop.Sub(att.Exchange.Timing.ConnectStart).String())
	fmt.Printf("First Byte - %s\n", att.Exchange.Timing.FirstByte.Sub(att.Exchange.Timing.InitialStart).String())
	fmt.Printf("Real - %s\n", att.Exchange.Timing.Real.String())
	err = campaign.RecordAttempt(db, att)
	return err
}