Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/js/libs/oracle/oracle.go
2070 views
1
package oracle
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/oracledb"
12
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolstate"
13
)
14
15
type (
16
// IsOracleResponse is the response from the IsOracle function.
17
// this is returned by IsOracle function.
18
// @example
19
// ```javascript
20
// const oracle = require('nuclei/oracle');
21
// const isOracle = oracle.IsOracle('acme.com', 1521);
22
// ```
23
IsOracleResponse struct {
24
IsOracle bool
25
Banner string
26
}
27
)
28
29
// IsOracle checks if a host is running an Oracle server
30
// @example
31
// ```javascript
32
// const oracle = require('nuclei/oracle');
33
// const isOracle = oracle.IsOracle('acme.com', 1521);
34
// log(toJSON(isOracle));
35
// ```
36
func IsOracle(ctx context.Context, host string, port int) (IsOracleResponse, error) {
37
executionId := ctx.Value("executionId").(string)
38
return memoizedisOracle(executionId, host, port)
39
}
40
41
// @memo
42
func isOracle(executionId string, host string, port int) (IsOracleResponse, error) {
43
resp := IsOracleResponse{}
44
45
dialer := protocolstate.GetDialersWithId(executionId)
46
if dialer == nil {
47
return IsOracleResponse{}, fmt.Errorf("dialers not initialized for %s", executionId)
48
}
49
50
timeout := 5 * time.Second
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
oracledbPlugin := oracledb.ORACLEPlugin{}
60
service, err := oracledbPlugin.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.Banner = service.Metadata().(plugins.ServiceOracle).Info
69
resp.IsOracle = true
70
return resp, nil
71
}
72
73