-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathTcpScanner.h
More file actions
136 lines (116 loc) · 3.04 KB
/
TcpScanner.h
File metadata and controls
136 lines (116 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#pragma once
#include <chrono>
#include "Stdafx.h"
#include "ServiceScanner.h"
/*!
* Represents internal scan data for the TCP scanner.
*/
struct TcpScanData
{
/*!
* Active non-blocking socket.
*/
SOCKET socket;
/*!
* File descriptor set for writability.
*/
fd_set* fdset;
/*!
* Expiration time of the current operation.
*/
std::chrono::time_point<std::chrono::system_clock> timeout;
/*!
* Number of probes sent to the service.
*/
int probes;
};
/*!
* Implements an active TCP port scanner.
*
* This will try to initiate the three-way handshake with all the requested services.
* It is not a stealthy method, and does not include any trickery to bypass firewalls.
*/
class TcpScanner : public ServiceScanner
{
public:
/*!
* Gets the currently set value for the option key.
*
* \param option Option index, see `OPT_*` macros.
* \param value Pointer to the value to set.
*
* \return true if it succeeds, false if it fails.
*/
bool GetOption(int option, void* value) override;
/*!
* Sets a specified value for the option key.
*
* \param option Option index, see `OPT_*` macros.
* \param value Pointer to the value to set.
*
* \return true if it succeeds, false if it fails.
*/
bool SetOption(int option, void* value) override;
/*!
* Get a task which scans a service to determine its aliveness.
*
* \param service Service to scan.
*
* \return Task to scan the specified service.
*/
void* GetTask(Service* service) override;
/*!
* Frees up the resources allocated during the lifetime of this instance.
*/
~TcpScanner() override;
private:
/*!
* Number of milliseconds to wait for connections to finish.
*/
unsigned long timeout = 3000;
/*!
* Number of milliseconds to wait between packets sent to the same host.
*/
unsigned long delay = 100;
/*!
* Indicates whether to wait for and grab service banners.
*/
bool grabBanner = true;
/*!
* Initializes the socket and starts the non-blocking connection.
*
* \param service Service.
*
* \return Next task, or `nullptr` if failed to initialize socket.
*/
void* initSocket(Service* service);
/*!
* Collects the result of the socket connection.
*
* \param service Service.
*
* \return Same task if no data received yet, otherwise next task to
* read banner, or `nullptr` if failed to read from socket.
*/
void* pollSocket(Service* service);
/*!
* Reads the banner from the specified service.
* This requires that the service have a connected socket.
*
* \param service Service.
*
* \return Same task if no data received yet, or `nullptr` if succeeded in
* reading the banner or socket disconnected while trying to do so.
*/
void* readBanner(Service* service);
/*!
* Sends a protocol probe to the specified service.
* This requires that the service have a connected socket.
*
* \param service Service.
*
* \return Previous task to re-try reading the service banner, or `nullptr`
* if socket disconnected while trying to send packet.
*/
void* sendProbe(Service* service);
};