-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan_engine.h
executable file
·126 lines (108 loc) · 2.37 KB
/
scan_engine.h
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
#define SCAN_ENGINE_H
#include <stdio.h>
#include <stdlib.h>
#include <string>
#ifdef WIN32
#include <windows.h>
#endif
#if (defined WINSOCK1 && defined WIN32)
#include <winsock.h>
#else
#include <winsock2.h>
#include <ws2tcpip.h>
#endif
#ifndef WIN32
#include <unistd.h>
#include <netinet/in.h>
#include <netdb.h>
#define __FAVOR_BSD
#include <arpa/inet.h>
#include <netinet/ip_icmp.h>
#include <netinet/udp.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#endif
enum{
SYN,
FIN,
XMAS,
NULL_S,
UDP,
};
#ifdef WIN32
USHORT in_cksum(USHORT *buffer, int size);
#else
unsigned short in_cksum(unsigned short *addr,int len);
#endif
inline int tcp_scan(int port);
inline int udp_scan(int port);
inline int raw_scan(int port, int scan_type);
struct hostent *host;
struct timeval timeout;
#ifdef WIN32
char *local_ip;
#else
char local_ip[100];
#endif
int STOP_SNIFFER;
int STARTED_SNIFFER;
void closed_raw_port(int port);
void opened_raw_port(int port);
void get_ip();
void set_sniffer(int scan_type);
#define MAX_ADDR_LEN 16
#define MAX_HOSTNAME_LAN 255
#if (!defined WINSOCK1 && defined WIN32)
#define SIO_RCVALL _WSAIOW(IOC_VENDOR,1)
#define IPDEFTTL 255
#define TH_CWR 0x80 // 10000000
#define TH_ECE 0x40 // 01000000
#define TH_URG 0x20 // 00100000
#define TH_ACK 0x10 // 00010000
#define TH_PUSH 0x08 // 00001000
#define TH_RST 0x04 // 00000100
#define TH_SYN 0x02 // 00000010
#define TH_FIN 0x01
#endif
/*headers*/
struct pseudohdr {
unsigned long saddr;
unsigned long daddr;
char zer0;
unsigned char protocol;
unsigned short length;
};
#ifdef WIN32
struct tcphdr {
unsigned short int th_sport;
unsigned short int th_dport;
unsigned int th_seq;
unsigned int th_ack;
unsigned char th_x2:4, th_off:4;
unsigned char th_flags;
unsigned short int th_win;
unsigned short int th_sum;
unsigned short int th_urp;
};
struct iphdr {
unsigned char ihl:4, version:4;
unsigned char tos;
unsigned short int tot_len;
unsigned short int ip_id;
unsigned short int frag_off;
unsigned char ttl;
unsigned char protocol;
unsigned short int check;
unsigned int saddr;
unsigned int daddr;
};
struct udp_hdr
{
unsigned short sport;
unsigned short dport;
unsigned short Length;
unsigned short Checksum;
};
#endif