Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 82d063ca8b | |||
| 561c19581c | |||
| d7366c970b | |||
| beb59543dc | |||
| e4ec21e135 | |||
| f715379a44 | |||
| 8d216370d3 | |||
| f3eb09812b | |||
| 75e9b8dc50 | |||
| d70d774be6 | |||
| 62ab02acf0 | |||
| d3a51c18c0 | |||
| 4535a38ad8 | |||
| 9195485b99 | |||
| 4cc5808883 | |||
| 2d96b9ed8d | |||
| 58e81a7c02 | |||
| a3ab13cbf5 | |||
| 2bb748e78f | |||
| 5c30baa11e | |||
| 5912ed5283 | |||
| 6871ee1c09 | |||
| 4953b16a08 | |||
| 2865295911 | |||
| 5bb2684d9e | |||
| 2c548c6b68 | |||
| f89af3bfd0 | |||
| f66c0f6d94 | |||
| c2c9a6e546 | |||
| 6d52cf0259 |
@@ -308,7 +308,7 @@ See [Troubleshooting & FAQ](https://github.com/Ullaakut/cameradar/wiki/Troublesh
|
|||||||
|
|
||||||
`docker run --rm -t --net=host -v /tmp:/tmp ullaakut/cameradar --targets /tmp/test.txt --ports 8554`
|
`docker run --rm -t --net=host -v /tmp:/tmp ullaakut/cameradar --targets /tmp/test.txt --ports 8554`
|
||||||
|
|
||||||
> Running cameradar on a subnetwork with custom dictionaries, on ports 554, 5554 and 8554
|
> Running cameradar on a subnetwork with custom dictionaries, on ports 554, 5554, 8554, 322, and 8322
|
||||||
|
|
||||||
`docker run --rm -t --net=host -v /tmp:/tmp ullaakut/cameradar --targets 192.168.0.0/24 --custom-credentials "/tmp/dictionaries/credentials.json" --custom-routes "/tmp/dictionaries/routes" --ports 554,5554,8554`
|
`docker run --rm -t --net=host -v /tmp:/tmp ullaakut/cameradar --targets 192.168.0.0/24 --custom-credentials "/tmp/dictionaries/credentials.json" --custom-routes "/tmp/dictionaries/routes" --ports 554,5554,8554`
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ var flags = cmd.Flags{
|
|||||||
Usage: "The ports on which to search for RTSP streams",
|
Usage: "The ports on which to search for RTSP streams",
|
||||||
Aliases: []string{"p"},
|
Aliases: []string{"p"},
|
||||||
Sources: cli.EnvVars(strcase.ToSNAKE(flagPorts)),
|
Sources: cli.EnvVars(strcase.ToSNAKE(flagPorts)),
|
||||||
Value: []string{"554", "5554", "8554", "http"},
|
Value: []string{"554", "5554", "8554", "http", "322", "8322"},
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: flagCustomRoutes,
|
Name: flagCustomRoutes,
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ func (a Attacker) attackCredentialsForStream(ctx context.Context, target camerad
|
|||||||
msg := fmt.Sprintf("credential attempt failed for %s:%d (%s:%s): %v", target.Address.String(), target.Port, username, password, err)
|
msg := fmt.Sprintf("credential attempt failed for %s:%d (%s:%s): %v", target.Address.String(), target.Port, username, password, err)
|
||||||
a.reporter.Debug(cameradar.StepAttackCredentials, msg)
|
a.reporter.Debug(cameradar.StepAttackCredentials, msg)
|
||||||
|
|
||||||
return target, nil
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if ok {
|
if ok {
|
||||||
@@ -253,7 +253,7 @@ func (a Attacker) attackRoutesForStream(ctx context.Context, target cameradar.St
|
|||||||
if emitProgress {
|
if emitProgress {
|
||||||
a.reporter.Progress(cameradar.StepAttackRoutes, cameradar.ProgressTickMessage())
|
a.reporter.Progress(cameradar.StepAttackRoutes, cameradar.ProgressTickMessage())
|
||||||
}
|
}
|
||||||
ok, err := a.routeAttack(target, dummyRoute)
|
ok, err := a.routeAttack(ctx, &target, dummyRoute)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.reporter.Debug(cameradar.StepAttackRoutes, fmt.Sprintf("route probe failed for %s:%d: %v", target.Address.String(), target.Port, err))
|
a.reporter.Debug(cameradar.StepAttackRoutes, fmt.Sprintf("route probe failed for %s:%d: %v", target.Address.String(), target.Port, err))
|
||||||
return target, nil
|
return target, nil
|
||||||
@@ -275,7 +275,7 @@ func (a Attacker) attackRoutesForStream(ctx context.Context, target cameradar.St
|
|||||||
if emitProgress {
|
if emitProgress {
|
||||||
a.reporter.Progress(cameradar.StepAttackRoutes, cameradar.ProgressTickMessage())
|
a.reporter.Progress(cameradar.StepAttackRoutes, cameradar.ProgressTickMessage())
|
||||||
}
|
}
|
||||||
ok, err := a.routeAttack(target, route)
|
ok, err := a.routeAttack(ctx, &target, route)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.reporter.Debug(cameradar.StepAttackRoutes, fmt.Sprintf("route attempt failed for %s:%d (%s): %v", target.Address.String(), target.Port, route, err))
|
a.reporter.Debug(cameradar.StepAttackRoutes, fmt.Sprintf("route attempt failed for %s:%d (%s): %v", target.Address.String(), target.Port, route, err))
|
||||||
return target, nil
|
return target, nil
|
||||||
@@ -290,18 +290,30 @@ func (a Attacker) attackRoutesForStream(ctx context.Context, target cameradar.St
|
|||||||
return target, nil
|
return target, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a Attacker) routeAttack(stream cameradar.Stream, route string) (bool, error) {
|
func (a Attacker) routeAttack(ctx context.Context, stream *cameradar.Stream, route string) (bool, error) {
|
||||||
u, urlStr, err := buildRTSPURL(stream, route, stream.Username, stream.Password)
|
u, urlStr, err := buildRTSPURL(*stream, route, stream.Username, stream.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf("building rtsp url: %w", err)
|
return false, fmt.Errorf("building rtsp url: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
code, err := a.describeStatus(u)
|
code, headers, err := a.probeDescribeHeaders(ctx, u, urlStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf("performing describe request at %q: %w", urlStr, err)
|
return false, fmt.Errorf("performing describe request at %q: %w", urlStr, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a.reporter.Debug(cameradar.StepAttackRoutes, fmt.Sprintf("DESCRIBE %s RTSP/1.0 > %d", urlStr, code))
|
a.reporter.Debug(cameradar.StepAttackRoutes, fmt.Sprintf("DESCRIBE %s RTSP/1.0 > %d", urlStr, code))
|
||||||
|
|
||||||
|
if code == base.StatusMovedPermanently {
|
||||||
|
a.handleRedirect(stream, headers)
|
||||||
|
u, urlStr, err = buildRTSPURL(*stream, route, stream.Username, stream.Password)
|
||||||
|
if err == nil {
|
||||||
|
code, _, err = a.probeDescribeHeaders(ctx, u, urlStr)
|
||||||
|
if err == nil {
|
||||||
|
a.reporter.Debug(cameradar.StepAttackRoutes, fmt.Sprintf("DESCRIBE %s RTSP/1.0 (redirect followed) > %d", urlStr, code))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
access := code == base.StatusOK || code == base.StatusUnauthorized || code == base.StatusForbidden
|
access := code == base.StatusOK || code == base.StatusUnauthorized || code == base.StatusForbidden
|
||||||
return access, nil
|
return access, nil
|
||||||
}
|
}
|
||||||
@@ -314,10 +326,12 @@ func (a Attacker) credAttack(stream cameradar.Stream, username, password string)
|
|||||||
|
|
||||||
code, err := a.describeStatus(u)
|
code, err := a.describeStatus(u)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
a.reporter.Debug(cameradar.StepAttackCredentials, fmt.Sprintf("Error testing %s:%s -> %v", username, password, err))
|
||||||
return false, fmt.Errorf("performing describe request at %q: %w", urlStr, err)
|
return false, fmt.Errorf("performing describe request at %q: %w", urlStr, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a.reporter.Debug(cameradar.StepAttackCredentials, fmt.Sprintf("DESCRIBE %s RTSP/1.0 > %d", urlStr, code))
|
a.reporter.Debug(cameradar.StepAttackCredentials, fmt.Sprintf("DESCRIBE %s RTSP/1.0 > %d", urlStr, code))
|
||||||
|
|
||||||
return code == base.StatusOK || code == base.StatusNotFound, nil
|
return code == base.StatusOK || code == base.StatusNotFound, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+58
-2
@@ -3,9 +3,11 @@ package attack
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/tls"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"net/netip"
|
||||||
"net/textproto"
|
"net/textproto"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -19,10 +21,16 @@ import (
|
|||||||
"github.com/bluenviron/gortsplib/v5/pkg/liberrors"
|
"github.com/bluenviron/gortsplib/v5/pkg/liberrors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
rtsp = "rtsp"
|
||||||
|
rtsps = "rtsps"
|
||||||
|
)
|
||||||
|
|
||||||
func (a Attacker) newRTSPClient(u *base.URL) (*gortsplib.Client, error) {
|
func (a Attacker) newRTSPClient(u *base.URL) (*gortsplib.Client, error) {
|
||||||
client := &gortsplib.Client{
|
client := &gortsplib.Client{
|
||||||
ReadTimeout: a.timeout,
|
ReadTimeout: a.timeout,
|
||||||
WriteTimeout: a.timeout,
|
WriteTimeout: a.timeout,
|
||||||
|
TLSConfig: &tls.Config{InsecureSkipVerify: true},
|
||||||
}
|
}
|
||||||
client.Scheme = u.Scheme
|
client.Scheme = u.Scheme
|
||||||
client.Host = u.Host
|
client.Host = u.Host
|
||||||
@@ -63,7 +71,16 @@ func (a Attacker) describeStatus(u *base.URL) (base.StatusCode, error) {
|
|||||||
// which is exactly what we need in order to detect authentication methods.
|
// which is exactly what we need in order to detect authentication methods.
|
||||||
func (a Attacker) probeDescribeHeaders(ctx context.Context, u *base.URL, urlStr string) (base.StatusCode, base.Header, error) {
|
func (a Attacker) probeDescribeHeaders(ctx context.Context, u *base.URL, urlStr string) (base.StatusCode, base.Header, error) {
|
||||||
dialer := &net.Dialer{Timeout: a.timeout}
|
dialer := &net.Dialer{Timeout: a.timeout}
|
||||||
conn, err := dialer.DialContext(ctx, "tcp", u.Host)
|
var conn net.Conn
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if u.Scheme == rtsps {
|
||||||
|
tlsDialer := &tls.Dialer{NetDialer: dialer, Config: &tls.Config{InsecureSkipVerify: true}}
|
||||||
|
conn, err = tlsDialer.DialContext(ctx, "tcp", u.Host)
|
||||||
|
} else {
|
||||||
|
conn, err = dialer.DialContext(ctx, "tcp", u.Host)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
}
|
}
|
||||||
@@ -117,6 +134,40 @@ func (a Attacker) probeDescribeHeaders(ctx context.Context, u *base.URL, urlStr
|
|||||||
return base.StatusCode(code), headers, nil
|
return base.StatusCode(code), headers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a Attacker) handleRedirect(stream *cameradar.Stream, resHeaders base.Header) {
|
||||||
|
locations := headerValues(resHeaders, "Location")
|
||||||
|
if len(locations) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
location, err := url.Parse(locations[0])
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch location.Scheme {
|
||||||
|
case rtsps:
|
||||||
|
stream.Secure = true
|
||||||
|
case rtsp:
|
||||||
|
stream.Secure = false
|
||||||
|
}
|
||||||
|
|
||||||
|
if location.Hostname() != "" {
|
||||||
|
addr, err := netip.ParseAddr(location.Hostname())
|
||||||
|
if err == nil {
|
||||||
|
stream.Address = addr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if location.Port() != "" {
|
||||||
|
port, err := strconv.Atoi(location.Port())
|
||||||
|
if err == nil {
|
||||||
|
if port >= 0 && port <= 65535 {
|
||||||
|
stream.Port = uint16(port)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func authTypeFromHeaders(values base.HeaderValue) cameradar.AuthType {
|
func authTypeFromHeaders(values base.HeaderValue) cameradar.AuthType {
|
||||||
if len(values) == 0 {
|
if len(values) == 0 {
|
||||||
return cameradar.AuthUnknown
|
return cameradar.AuthUnknown
|
||||||
@@ -168,8 +219,13 @@ func buildRTSPURL(stream cameradar.Stream, route, username, password string) (*b
|
|||||||
host := net.JoinHostPort(stream.Address.String(), strconv.Itoa(int(stream.Port)))
|
host := net.JoinHostPort(stream.Address.String(), strconv.Itoa(int(stream.Port)))
|
||||||
path := "/" + strings.TrimLeft(strings.TrimSpace(route), "/") // Ensure path starts with a single "/"
|
path := "/" + strings.TrimLeft(strings.TrimSpace(route), "/") // Ensure path starts with a single "/"
|
||||||
|
|
||||||
|
scheme := rtsp
|
||||||
|
if stream.Secure {
|
||||||
|
scheme = rtsps
|
||||||
|
}
|
||||||
|
|
||||||
u := &url.URL{
|
u := &url.URL{
|
||||||
Scheme: "rtsp",
|
Scheme: scheme,
|
||||||
Host: host,
|
Host: host,
|
||||||
Path: path,
|
Path: path,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ func TestBuildRTSPURL(t *testing.T) {
|
|||||||
route string
|
route string
|
||||||
username string
|
username string
|
||||||
password string
|
password string
|
||||||
|
secure bool
|
||||||
wantURL string
|
wantURL string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
@@ -74,11 +75,27 @@ func TestBuildRTSPURL(t *testing.T) {
|
|||||||
username: "user",
|
username: "user",
|
||||||
wantURL: "rtsp://user:@192.168.0.10:554/stream",
|
wantURL: "rtsp://user:@192.168.0.10:554/stream",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "secure rtsps scheme without credentials",
|
||||||
|
route: "stream",
|
||||||
|
secure: true,
|
||||||
|
wantURL: "rtsps://192.168.0.10:554/stream",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "secure rtsps scheme with credentials",
|
||||||
|
route: "stream",
|
||||||
|
username: "admin",
|
||||||
|
password: "password",
|
||||||
|
secure: true,
|
||||||
|
wantURL: "rtsps://admin:password@192.168.0.10:554/stream",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
_, gotURL, err := buildRTSPURL(stream, test.route, test.username, test.password)
|
s := stream
|
||||||
|
s.Secure = test.secure
|
||||||
|
_, gotURL, err := buildRTSPURL(s, test.route, test.username, test.password)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, test.wantURL, gotURL)
|
require.Equal(t, test.wantURL, gotURL)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -119,5 +119,10 @@ func formatRTSPURL(stream cameradar.Stream) string {
|
|||||||
credentials = stream.Username + ":" + stream.Password + "@"
|
credentials = stream.Username + ":" + stream.Password + "@"
|
||||||
}
|
}
|
||||||
|
|
||||||
return "rtsp://" + credentials + stream.Address.String() + ":" + strconv.FormatUint(uint64(stream.Port), 10) + path
|
scheme := "rtsp"
|
||||||
|
if stream.Secure {
|
||||||
|
scheme = "rtsps"
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%s://%s%s:%s%s", scheme, credentials, stream.Address.String(), strconv.FormatUint(uint64(stream.Port), 10), path)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,9 +83,12 @@ func runScan(ctx context.Context, runner Runner, reporter Reporter) ([]cameradar
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isSecure := port.Number == 322 || port.Number == 8322
|
||||||
|
|
||||||
streams = append(streams, cameradar.Stream{
|
streams = append(streams, cameradar.Stream{
|
||||||
Address: addr,
|
Address: addr,
|
||||||
Port: uint16(port.Number),
|
Port: uint16(port.Number),
|
||||||
|
Secure: isSecure,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,15 +53,16 @@ func TestRunScan(t *testing.T) {
|
|||||||
name: "collects streams from multiple hosts",
|
name: "collects streams from multiple hosts",
|
||||||
result: &masscanlib.Run{
|
result: &masscanlib.Run{
|
||||||
Hosts: []masscanlib.Host{
|
Hosts: []masscanlib.Host{
|
||||||
{Address: "192.0.2.10", Ports: []masscanlib.Port{{Number: 8554, Status: "open"}}},
|
{Address: "192.0.2.10", Ports: []masscanlib.Port{{Number: 8554, Status: "open"}, {Number: 8322, Status: "open"}}},
|
||||||
{Address: "198.51.100.9", Ports: []masscanlib.Port{{Number: 554, Status: "open"}}},
|
{Address: "198.51.100.9", Ports: []masscanlib.Port{{Number: 554, Status: "open"}}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
wantStreams: []cameradar.Stream{
|
wantStreams: []cameradar.Stream{
|
||||||
{Address: netip.MustParseAddr("192.0.2.10"), Port: 8554},
|
{Address: netip.MustParseAddr("192.0.2.10"), Port: 8554, Secure: false},
|
||||||
{Address: netip.MustParseAddr("198.51.100.9"), Port: 554},
|
{Address: netip.MustParseAddr("192.0.2.10"), Port: 8322, Secure: true},
|
||||||
|
{Address: netip.MustParseAddr("198.51.100.9"), Port: 554, Secure: false},
|
||||||
},
|
},
|
||||||
wantProgress: []string{"Found 2 RTSP streams"},
|
wantProgress: []string{"Found 3 RTSP streams"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "returns error when scan fails",
|
name: "returns error when scan fails",
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ func runScan(ctx context.Context, nmap Runner, reporter Reporter) ([]cameradar.S
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isSecure := strings.Contains(port.Service.Name, "rtsps") || strings.Contains(port.Service.Name, "ssl") || port.ID == 322 || port.ID == 8322
|
||||||
|
|
||||||
for _, address := range host.Addresses {
|
for _, address := range host.Addresses {
|
||||||
addr, err := netip.ParseAddr(address.Addr)
|
addr, err := netip.ParseAddr(address.Addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -82,6 +84,7 @@ func runScan(ctx context.Context, nmap Runner, reporter Reporter) ([]cameradar.S
|
|||||||
Device: port.Service.Product,
|
Device: port.Service.Product,
|
||||||
Address: addr,
|
Address: addr,
|
||||||
Port: port.ID,
|
Port: port.ID,
|
||||||
|
Secure: isSecure,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ func TestScanner_Scan(t *testing.T) {
|
|||||||
Addresses: []nmaplib.Address{{Addr: "192.0.2.10"}, {Addr: "192.0.2.11"}},
|
Addresses: []nmaplib.Address{{Addr: "192.0.2.10"}, {Addr: "192.0.2.11"}},
|
||||||
Ports: []nmaplib.Port{
|
Ports: []nmaplib.Port{
|
||||||
openPort(8554, "rtsp-alt", "Model A"),
|
openPort(8554, "rtsp-alt", "Model A"),
|
||||||
|
openPort(322, "rtsps", "Model C"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
nmaplib.Host{
|
nmaplib.Host{
|
||||||
@@ -68,19 +69,34 @@ func TestScanner_Scan(t *testing.T) {
|
|||||||
Device: "Model A",
|
Device: "Model A",
|
||||||
Address: netip.MustParseAddr("192.0.2.10"),
|
Address: netip.MustParseAddr("192.0.2.10"),
|
||||||
Port: 8554,
|
Port: 8554,
|
||||||
|
Secure: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Device: "Model A",
|
Device: "Model A",
|
||||||
Address: netip.MustParseAddr("192.0.2.11"),
|
Address: netip.MustParseAddr("192.0.2.11"),
|
||||||
Port: 8554,
|
Port: 8554,
|
||||||
|
Secure: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Device: "Model C",
|
||||||
|
Address: netip.MustParseAddr("192.0.2.10"),
|
||||||
|
Port: 322,
|
||||||
|
Secure: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Device: "Model C",
|
||||||
|
Address: netip.MustParseAddr("192.0.2.11"),
|
||||||
|
Port: 322,
|
||||||
|
Secure: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Device: "Model B",
|
Device: "Model B",
|
||||||
Address: netip.MustParseAddr("198.51.100.9"),
|
Address: netip.MustParseAddr("198.51.100.9"),
|
||||||
Port: 554,
|
Port: 554,
|
||||||
|
Secure: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
wantProgress: "Found 3 RTSP streams",
|
wantProgress: "Found 5 RTSP streams",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "returns error when scan fails",
|
name: "returns error when scan fails",
|
||||||
|
|||||||
@@ -51,9 +51,11 @@ func buildStreamsFromTargets(ctx context.Context, targets, ports []string) ([]ca
|
|||||||
streams := make([]cameradar.Stream, 0, len(resolvedTargets)*len(resolvedPorts))
|
streams := make([]cameradar.Stream, 0, len(resolvedTargets)*len(resolvedPorts))
|
||||||
for _, addr := range resolvedTargets {
|
for _, addr := range resolvedTargets {
|
||||||
for _, port := range resolvedPorts {
|
for _, port := range resolvedPorts {
|
||||||
|
isSecure := port == 322 || port == 8322
|
||||||
streams = append(streams, cameradar.Stream{
|
streams = append(streams, cameradar.Stream{
|
||||||
Address: addr,
|
Address: addr,
|
||||||
Port: port,
|
Port: port,
|
||||||
|
Secure: isSecure,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ func TestNew_ExpandsTargetsAndPorts(t *testing.T) {
|
|||||||
"192.0.2.15",
|
"192.0.2.15",
|
||||||
"192.0.2.10-11",
|
"192.0.2.10-11",
|
||||||
}
|
}
|
||||||
ports := []string{"554", "8554-8555"}
|
ports := []string{"554", "322", "8554-8555"}
|
||||||
|
|
||||||
scanner := skip.New(targets, ports)
|
scanner := skip.New(targets, ports)
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ func TestNew_ExpandsTargetsAndPorts(t *testing.T) {
|
|||||||
netip.MustParseAddr("192.0.2.11"),
|
netip.MustParseAddr("192.0.2.11"),
|
||||||
netip.MustParseAddr("192.0.2.15"),
|
netip.MustParseAddr("192.0.2.15"),
|
||||||
}
|
}
|
||||||
portsExpected := []uint16{554, 8554, 8555}
|
portsExpected := []uint16{554, 322, 8554, 8555}
|
||||||
|
|
||||||
var want []string
|
var want []string
|
||||||
for _, addr := range addrs {
|
for _, addr := range addrs {
|
||||||
@@ -44,6 +44,13 @@ func TestNew_ExpandsTargetsAndPorts(t *testing.T) {
|
|||||||
var got []string
|
var got []string
|
||||||
for _, stream := range streams {
|
for _, stream := range streams {
|
||||||
got = append(got, stream.Address.String()+":"+strconv.Itoa(int(stream.Port)))
|
got = append(got, stream.Address.String()+":"+strconv.Itoa(int(stream.Port)))
|
||||||
|
|
||||||
|
if stream.Port == 322 || stream.Port == 8322 {
|
||||||
|
assert.True(t, stream.Secure)
|
||||||
|
} else {
|
||||||
|
assert.False(t, stream.Secure)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.ElementsMatch(t, want, got)
|
assert.ElementsMatch(t, want, got)
|
||||||
|
|||||||
@@ -126,7 +126,12 @@ func formatRTSPURL(stream cameradar.Stream) string {
|
|||||||
credentials = stream.Username + ":" + stream.Password + "@"
|
credentials = stream.Username + ":" + stream.Password + "@"
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("rtsp://%s%s:%d%s", credentials, stream.Address.String(), stream.Port, path)
|
scheme := "rtsp"
|
||||||
|
if stream.Secure {
|
||||||
|
scheme = "rtsps"
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%s://%s%s:%d%s", scheme, credentials, stream.Address.String(), stream.Port, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatAdminPanelURL(stream cameradar.Stream) string {
|
func formatAdminPanelURL(stream cameradar.Stream) string {
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ func TestFormatSummary(t *testing.T) {
|
|||||||
Device: "Model A",
|
Device: "Model A",
|
||||||
Address: netip.MustParseAddr("10.0.0.1"),
|
Address: netip.MustParseAddr("10.0.0.1"),
|
||||||
Port: 8554,
|
Port: 8554,
|
||||||
|
Secure: true,
|
||||||
Available: true,
|
Available: true,
|
||||||
Routes: []string{"stream1", "stream2"},
|
Routes: []string{"stream1", "stream2"},
|
||||||
RouteFound: true,
|
RouteFound: true,
|
||||||
@@ -73,7 +74,7 @@ func TestFormatSummary(t *testing.T) {
|
|||||||
"Authentication: digest",
|
"Authentication: digest",
|
||||||
"Routes: stream1, stream2",
|
"Routes: stream1, stream2",
|
||||||
"Credentials: user:pass",
|
"Credentials: user:pass",
|
||||||
"RTSP URL: rtsp://user:pass@10.0.0.1:8554/stream1",
|
"RTSP URL: rtsps://user:pass@10.0.0.1:8554/stream1",
|
||||||
"Admin panel: http://10.0.0.1/",
|
"Admin panel: http://10.0.0.1/",
|
||||||
"Admin panel: http://10.0.0.2/",
|
"Admin panel: http://10.0.0.2/",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ type Stream struct {
|
|||||||
Address netip.Addr `json:"address" validate:"required"`
|
Address netip.Addr `json:"address" validate:"required"`
|
||||||
Port uint16 `json:"port" validate:"required"`
|
Port uint16 `json:"port" validate:"required"`
|
||||||
|
|
||||||
|
Secure bool `json:"secure"`
|
||||||
|
|
||||||
CredentialsFound bool `json:"credentials_found"`
|
CredentialsFound bool `json:"credentials_found"`
|
||||||
RouteFound bool `json:"route_found"`
|
RouteFound bool `json:"route_found"`
|
||||||
Available bool `json:"available"`
|
Available bool `json:"available"`
|
||||||
|
|||||||
Reference in New Issue
Block a user