-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient.js
109 lines (83 loc) · 2.36 KB
/
client.js
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
// Default config
global.config = {
myMAC: "11:22:33:44:55:66",
myIP: "10.0.0.99",
};
var sys = require('sys');
var Buffer = require('buffer').Buffer;
var Pcap = require('pcap');
var tools = require('./tools');
var AC = require('./aircrack').AirCrackConnection;
// Connect to AirServ
var air = new AC('localhost', 6666);
air.open();
// Find my MAC address
air.getMac(function(mac) {
global.config.myMAC = mac;
console.log("Mac address is: " + mac);
});
// Ond end of connection
air.on('end', function () {
sys.print("End of connection\n");
});
// Unknown Aircrack command
air.on('unknown-aircrack-command', function(cmd, buf) {
console.log("Unknown aircrack command", cmd, sys.inspect(buf));
});
// Add wrapper for sending packets
air.sendPacket = function(pkt, cb) {
// Encode packet and all lower layers
var buf = pkt.encodeAll();
// Send to aircrack
console.log('Injecting packet:', sys.inspect(buf));
air.send(buf, cb || function() { console.log('Packet injected...'); } );
};
// Received an raw packet
air.on('raw-packet', function(buf) {
console.log("Received packet:", sys.inspect(buf));
// Decode as ethernet packet
var eth = tools.EthernetPacket.decode(buf, 0);
// Emit packet.ethernet event
air.emit('packet.ethernet', eth);
});
// Ethernet packet
air.on('packet.ethernet', function(eth) {
var ptype = eth.getPayloadType();
switch(ptype) {
case 'ip':
air.emit('packet.ip', eth.payload);
break;
case 'arp':
air.emit('packet.arp', eth.payload);
break;
}
});
// On IP packet
air.on('packet.ip', function(ip) {
var ptype = ip.getPayloadType();
console.log("Got IP packet with ", ptype, "payload");
switch(ptype) {
case 'icmp':
air.emit('packet.icmp', ip.payload);
break;
case 'udp':
air.emit('packet.udp', ip.payload);
break;
}
});
// ARP request -> send something
air.on('packet.arp', function(arp) {
if(arp.operation == 'request' && arp.target_pa == '10.0.0.7') {
var reply = arp.reply( { sender_ha: global.config.myMAC } );
air.sendPacket(reply);
console.log(sys.inspect(reply));
}
});
// On ping request, send response
air.on('packet.icmp', function(icmp) {
if(icmp.icmp_type == 8 && icmp.lower.daddr == '10.0.0.7') {
var reply = icmp.reply();
air.sendPacket(reply);
console.log(sys.inspect(reply));
}
});