Fix crash #174 by duplicating curl handle
Wrap libcurl to bypass lack of covariance support
This commit is contained in:
committed by
Brendan LE GLAUNEC
parent
6392dcd9a0
commit
bcc8099f91
@@ -32,6 +32,8 @@ func routeAttack(c Curler, camera Stream, route string, timeout time.Duration, e
|
|||||||
c.Setopt(curl.OPT_WRITEFUNCTION, doNotWrite)
|
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
|
// Do not send a body in the describe request
|
||||||
c.Setopt(curl.OPT_NOBODY, 1)
|
c.Setopt(curl.OPT_NOBODY, 1)
|
||||||
// Send a request to the URL of the camera we want to attack
|
// 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)
|
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
|
// Do not send a body in the describe request
|
||||||
c.Setopt(curl.OPT_NOBODY, 1)
|
c.Setopt(curl.OPT_NOBODY, 1)
|
||||||
// Send a request to the URL of the camera we want to attack
|
// 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) {
|
func attackCameraCredentials(c Curler, target Stream, credentials Credentials, resultsChan chan<- Stream, timeout time.Duration, log bool) {
|
||||||
for _, username := range credentials.Usernames {
|
for _, username := range credentials.Usernames {
|
||||||
for _, password := range credentials.Passwords {
|
for _, password := range credentials.Passwords {
|
||||||
ok := credAttack(c, target, username, password, timeout, log)
|
ok := credAttack(c.Duphandle(), target, username, password, timeout, log)
|
||||||
if ok {
|
if ok {
|
||||||
target.CredentialsFound = true
|
target.CredentialsFound = true
|
||||||
target.Username = username
|
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) {
|
func attackCameraRoute(c Curler, target Stream, routes Routes, resultsChan chan<- Stream, timeout time.Duration, log bool) {
|
||||||
for _, route := range routes {
|
for _, route := range routes {
|
||||||
ok := routeAttack(c, target, route, timeout, log)
|
ok := routeAttack(c.Duphandle(), target, route, timeout, log)
|
||||||
if ok {
|
if ok {
|
||||||
target.RouteFound = true
|
target.RouteFound = true
|
||||||
target.Route = route
|
target.Route = route
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ func (m *CurlerMock) Getinfo(info curl.CurlInfo) (interface{}, error) {
|
|||||||
return args.Int(0), args.Error(1)
|
return args.Int(0), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *CurlerMock) Duphandle() Curler {
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
func TestAttackCredentials(t *testing.T) {
|
func TestAttackCredentials(t *testing.T) {
|
||||||
validStream1 := Stream{
|
validStream1 := Stream{
|
||||||
Device: "fakeDevice",
|
Device: "fakeDevice",
|
||||||
|
|||||||
@@ -94,10 +94,11 @@ func main() {
|
|||||||
w := startSpinner(options.EnableLogs)
|
w := startSpinner(options.EnableLogs)
|
||||||
|
|
||||||
err = curl.GlobalInit(curl.GLOBAL_ALL)
|
err = curl.GlobalInit(curl.GLOBAL_ALL)
|
||||||
c := curl.EasyInit()
|
handle := curl.EasyInit()
|
||||||
if err != nil || c == nil {
|
if err != nil || handle == nil {
|
||||||
printErr(errors.New("libcurl initialization failed"))
|
printErr(errors.New("libcurl initialization failed"))
|
||||||
}
|
}
|
||||||
|
c := &cmrdr.Curl{CURL: handle}
|
||||||
defer curl.GlobalCleanup()
|
defer curl.GlobalCleanup()
|
||||||
|
|
||||||
updateSpinner(w, "Loading dictionaries...", options.EnableLogs)
|
updateSpinner(w, "Loading dictionaries...", options.EnableLogs)
|
||||||
|
|||||||
@@ -10,4 +10,16 @@ type Curler interface {
|
|||||||
Setopt(opt int, param interface{}) error
|
Setopt(opt int, param interface{}) error
|
||||||
Perform() error
|
Perform() error
|
||||||
Getinfo(info curl.CurlInfo) (interface{}, 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()}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user