Fix crash #174 by duplicating curl handle

Wrap libcurl to bypass lack of covariance support
This commit is contained in:
Brendan Le Glaunec
2018-03-13 10:24:25 +01:00
committed by Brendan LE GLAUNEC
parent 6392dcd9a0
commit bcc8099f91
4 changed files with 25 additions and 4 deletions
+6 -2
View File
@@ -32,6 +32,8 @@ func routeAttack(c Curler, camera Stream, route string, timeout time.Duration, e
c.Setopt(curl.OPT_WRITEFUNCTION, doNotWrite)
}
// Do not use signals (would break multithreading)
c.Setopt(curl.OPT_NOSIGNAL, 1)
// Do not send a body in the describe request
c.Setopt(curl.OPT_NOBODY, 1)
// Send a request to the URL of the camera we want to attack
@@ -82,6 +84,8 @@ func credAttack(c Curler, camera Stream, username string, password string, timeo
c.Setopt(curl.OPT_WRITEFUNCTION, doNotWrite)
}
// Do not use signals (would break multithreading)
c.Setopt(curl.OPT_NOSIGNAL, 1)
// Do not send a body in the describe request
c.Setopt(curl.OPT_NOBODY, 1)
// Send a request to the URL of the camera we want to attack
@@ -117,7 +121,7 @@ func credAttack(c Curler, camera Stream, username string, password string, timeo
func attackCameraCredentials(c Curler, target Stream, credentials Credentials, resultsChan chan<- Stream, timeout time.Duration, log bool) {
for _, username := range credentials.Usernames {
for _, password := range credentials.Passwords {
ok := credAttack(c, target, username, password, timeout, log)
ok := credAttack(c.Duphandle(), target, username, password, timeout, log)
if ok {
target.CredentialsFound = true
target.Username = username
@@ -133,7 +137,7 @@ func attackCameraCredentials(c Curler, target Stream, credentials Credentials, r
func attackCameraRoute(c Curler, target Stream, routes Routes, resultsChan chan<- Stream, timeout time.Duration, log bool) {
for _, route := range routes {
ok := routeAttack(c, target, route, timeout, log)
ok := routeAttack(c.Duphandle(), target, route, timeout, log)
if ok {
target.RouteFound = true
target.Route = route
+4
View File
@@ -31,6 +31,10 @@ func (m *CurlerMock) Getinfo(info curl.CurlInfo) (interface{}, error) {
return args.Int(0), args.Error(1)
}
func (m *CurlerMock) Duphandle() Curler {
return m
}
func TestAttackCredentials(t *testing.T) {
validStream1 := Stream{
Device: "fakeDevice",
+3 -2
View File
@@ -94,10 +94,11 @@ func main() {
w := startSpinner(options.EnableLogs)
err = curl.GlobalInit(curl.GLOBAL_ALL)
c := curl.EasyInit()
if err != nil || c == nil {
handle := curl.EasyInit()
if err != nil || handle == nil {
printErr(errors.New("libcurl initialization failed"))
}
c := &cmrdr.Curl{CURL: handle}
defer curl.GlobalCleanup()
updateSpinner(w, "Loading dictionaries...", options.EnableLogs)
+12
View File
@@ -10,4 +10,16 @@ type Curler interface {
Setopt(opt int, param interface{}) error
Perform() error
Getinfo(info curl.CurlInfo) (interface{}, error)
Duphandle() Curler
}
// Curl is a libcurl wrapper used to make the Curler interface work even though
// golang currently does not support covariance (see https://github.com/golang/go/issues/7512)
type Curl struct {
*curl.CURL
}
// Duphandle wraps curl.Duphandle
func (c *Curl) Duphandle() Curler {
return &Curl{c.CURL.Duphandle()}
}