-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathscan_functions.cpp
58 lines (43 loc) · 1.19 KB
/
scan_functions.cpp
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
/*
* Copyright 2016 Riccardo Melioli. All Rights Reserved.
*/
#include "scan_functions.h"
void SYN_scan(const char* src, const char* dst, const char* port) {
unsigned char* packet;
packet = (u_char *) malloc(60);
struct ip ip;
ip.ip_hl = 0x5;
ip.ip_v = 0x4;
ip.ip_tos = 0x0;
ip.ip_len = htons(sizeof(ip));
ip.ip_id = htons(12830);
ip.ip_off = 0x0;
ip.ip_ttl = 64;
ip.ip_p = IPPROTO_TCP;
ip.ip_src.s_addr = inet_addr(src);
ip.ip_dst.s_addr = inet_addr(dst);
ip.ip_sum = 0x0;
ip.ip_sum = checksum((u_short *) &ip, sizeof(ip));
// copy the IP header
memcpy(packet, &ip, sizeof(ip));
struct tcphdr tcp;
tcp.source = htons(60000);
tcp.dest = htons(80);
tcp.seq = htonl(rand() % 100000);
tcp.ack_seq = 0;
tcp.doff = sizeof(tcp) / 4;
tcp.fin = 0;
tcp.syn = 1;
tcp.rst = 0;
tcp.psh = 0;
tcp.ack = 0;
tcp.urg = 0;
tcp.res1 = 0; // nonce
tcp.res2 = 0; // ECN
tcp.window = htons(2048);
tcp.check = checksum((unsigned short *) &tcp, sizeof(tcp));
tcp.urg_ptr = 0;
memcpy(packet + sizeof(ip), &tcp, sizeof(tcp));
const char* response = send_packet(packet,dst,port,sizeof(ip),sizeof(tcp));
std::cout << response;
}