Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/js/libs/rsync/rsync.go
2070 views
1
package rsync
2
3
import (
4
"context"
5
"fmt"
6
"net"
7
"strconv"
8
"time"
9
10
"github.com/praetorian-inc/fingerprintx/pkg/plugins"
11
"github.com/praetorian-inc/fingerprintx/pkg/plugins/services/rsync"
12
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolstate"
13
)
14
15
type (
16
// IsRsyncResponse is the response from the IsRsync function.
17
// this is returned by IsRsync function.
18
// @example
19
// ```javascript
20
// const rsync = require('nuclei/rsync');
21
// const isRsync = rsync.IsRsync('acme.com', 873);
22
// log(toJSON(isRsync));
23
// ```
24
IsRsyncResponse struct {
25
IsRsync bool
26
Banner string
27
}
28
)
29
30
// IsRsync checks if a host is running a Rsync server.
31
// @example
32
// ```javascript
33
// const rsync = require('nuclei/rsync');
34
// const isRsync = rsync.IsRsync('acme.com', 873);
35
// log(toJSON(isRsync));
36
// ```
37
func IsRsync(ctx context.Context, host string, port int) (IsRsyncResponse, error) {
38
executionId := ctx.Value("executionId").(string)
39
return memoizedisRsync(executionId, host, port)
40
}
41
42
// @memo
43
func isRsync(executionId string, host string, port int) (IsRsyncResponse, error) {
44
resp := IsRsyncResponse{}
45
46
timeout := 5 * time.Second
47
dialer := protocolstate.GetDialersWithId(executionId)
48
if dialer == nil {
49
return IsRsyncResponse{}, fmt.Errorf("dialers not initialized for %s", executionId)
50
}
51
conn, err := dialer.Fastdialer.Dial(context.TODO(), "tcp", net.JoinHostPort(host, strconv.Itoa(port)))
52
if err != nil {
53
return resp, err
54
}
55
defer func() {
56
_ = conn.Close()
57
}()
58
59
rsyncPlugin := rsync.RSYNCPlugin{}
60
service, err := rsyncPlugin.Run(conn, timeout, plugins.Target{Host: host})
61
if err != nil {
62
return resp, err
63
}
64
if service == nil {
65
return resp, nil
66
}
67
resp.Banner = service.Version
68
resp.IsRsync = true
69
return resp, nil
70
}
71
72