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