Skip to content
This repository was archived by the owner on Feb 19, 2020. It is now read-only.

Commit e4b6c24

Browse files
committed
remove config.newSpoof
1 parent 1f61170 commit e4b6c24

File tree

4 files changed

+126
-175
lines changed

4 files changed

+126
-175
lines changed

flow/CategoryFlowTool.js

+8-12
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,17 @@ class CategoryFlowTool {
8585

8686
async getCategories(mac) {
8787
mac = mac || '*' // match all mac addresses if mac is not defined
88-
let keyPattern = this.getCategoryFlowKey(mac, '*')
89-
let keys = await rclient.keysAsync(keyPattern)
90-
let categories = keys.map((key) => {
91-
let result = key.match(/[^:]*$/)
88+
const keyPattern = this.getCategoryFlowKey(mac, '*')
89+
const keys = await rclient.keysAsync(keyPattern)
90+
const categories = new Set();
91+
keys && keys.forEach((key) => {
92+
const result = key.split(':').pop();
9293
if (result && result !== 'intel') {
93-
return result[0]
94-
} else {
95-
return null
94+
categories.add(result)
9695
}
97-
}).filter((x) => x != null)
98-
99-
// removes duplicate
100-
return categories.filter((elem, pos) => {
101-
return categories.indexOf(elem) == pos;
10296
})
97+
98+
return [ ... categories ];
10399
}
104100

105101
async getCategoryMacAddresses(category) {

net2/Host.js

+79-83
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ const getPreferredBName = require('../util/util.js').getPreferredBName
3636

3737
const bone = require("../lib/Bone.js");
3838

39-
const fConfig = require('./config.js').getConfig();
40-
4139
const MobileDetect = require('mobile-detect');
4240

4341
const flowUtil = require('../net2/FlowUtil.js');
@@ -453,102 +451,100 @@ class Host {
453451

454452
const spoofer = new Spoofer(sysManager.config.monitoringInterface, {}, false);
455453

456-
if(fConfig.newSpoof) {
457-
// new spoof supports spoofing on same device for mutliple times,
458-
// so no need to check if it is already spoofing or not
459-
if (this.o.ipv4Addr === gateway || this.o.mac == null || this.o.ipv4Addr === sysManager.myIp()) {
460-
return;
461-
}
454+
// new spoof supports spoofing on same device for mutliple times,
455+
// so no need to check if it is already spoofing or not
456+
if (this.o.ipv4Addr === gateway || this.o.mac == null || this.o.ipv4Addr === sysManager.myIp()) {
457+
return;
458+
}
462459

463-
/* This is taken care of by DnsLoopAvoidanceSensor
460+
/* This is taken care of by DnsLoopAvoidanceSensor
464461
if (dns && dns.includes(this.o.ipv4Addr)) {
465462
// do not monitor dns server's traffic
466463
return;
467464
}
468465
*/
469-
if (this.o.mac == "00:00:00:00:00:00" || this.o.mac.indexOf("00:00:00:00:00:00")>-1) {
470-
return;
471-
}
472-
if (this.o.mac == "FF:FF:FF:FF:FF:FF" || this.o.mac.indexOf("FF:FF:FF:FF:FF:FF")>-1) {
473-
return;
474-
}
475-
if(state === true) {
476-
hostTool.getMacByIP(gateway).then((gatewayMac) => {
477-
if (gatewayMac && gatewayMac === this.o.mac) {
478-
// ignore devices that has same mac address as gateway
479-
log.info(this.o.ipv4Addr + " has same mac address as gateway. Skip spoofing...");
480-
return;
481-
}
482-
const cmd = `sudo ipset del -! not_monitored_mac_set ${this.o.mac}`;
483-
exec(cmd).catch((err) => {
484-
log.error("Failed to delete from not_monitored_mac_set " + this.o.mac, err);
485-
});
486-
spoofer.newSpoof(this.o.ipv4Addr)
487-
.then(() => {
488-
rclient.hmsetAsync("host:mac:" + this.o.mac, 'spoofing', true, 'spoofingTime', new Date() / 1000)
489-
.catch(err => log.error("Unable to set spoofing in redis", err))
490-
.then(() => this.dnsmasq.onSpoofChanged());
491-
log.debug("Started spoofing", this.o.ipv4Addr, this.o.mac, this.o.name);
492-
this.spoofing = true;
493-
}).catch((err) => {
494-
log.error("Failed to spoof", this.o.ipv4Addr, this.o.mac, this.o.name, err);
495-
})
496-
})
497-
} else {
498-
const cmd = `sudo ipset add -! not_monitored_mac_set ${this.o.mac}`;
466+
if (this.o.mac == "00:00:00:00:00:00" || this.o.mac.indexOf("00:00:00:00:00:00")>-1) {
467+
return;
468+
}
469+
if (this.o.mac == "FF:FF:FF:FF:FF:FF" || this.o.mac.indexOf("FF:FF:FF:FF:FF:FF")>-1) {
470+
return;
471+
}
472+
if(state === true) {
473+
hostTool.getMacByIP(gateway).then((gatewayMac) => {
474+
if (gatewayMac && gatewayMac === this.o.mac) {
475+
// ignore devices that has same mac address as gateway
476+
log.info(this.o.ipv4Addr + " has same mac address as gateway. Skip spoofing...");
477+
return;
478+
}
479+
const cmd = `sudo ipset del -! not_monitored_mac_set ${this.o.mac}`;
499480
exec(cmd).catch((err) => {
500-
log.error("Failed to add to not_monitored_mac_set " + this.o.mac, err);
481+
log.error("Failed to delete from not_monitored_mac_set " + this.o.mac, err);
501482
});
502-
spoofer.newUnspoof(this.o.ipv4Addr)
483+
spoofer.newSpoof(this.o.ipv4Addr)
503484
.then(() => {
504-
rclient.hmsetAsync("host:mac:" + this.o.mac, 'spoofing', false, 'unspoofingTime', new Date() / 1000)
485+
rclient.hmsetAsync("host:mac:" + this.o.mac, 'spoofing', true, 'spoofingTime', new Date() / 1000)
505486
.catch(err => log.error("Unable to set spoofing in redis", err))
506487
.then(() => this.dnsmasq.onSpoofChanged());
507-
log.debug("Stopped spoofing", this.o.ipv4Addr, this.o.mac, this.o.name);
508-
this.spoofing = false;
488+
log.debug("Started spoofing", this.o.ipv4Addr, this.o.mac, this.o.name);
489+
this.spoofing = true;
509490
}).catch((err) => {
510-
log.error("Failed to unspoof", this.o.ipv4Addr, this.o.mac, this.o.name, err);
491+
log.error("Failed to spoof", this.o.ipv4Addr, this.o.mac, this.o.name, err);
511492
})
512-
}
493+
})
494+
} else {
495+
const cmd = `sudo ipset add -! not_monitored_mac_set ${this.o.mac}`;
496+
exec(cmd).catch((err) => {
497+
log.error("Failed to add to not_monitored_mac_set " + this.o.mac, err);
498+
});
499+
spoofer.newUnspoof(this.o.ipv4Addr)
500+
.then(() => {
501+
rclient.hmsetAsync("host:mac:" + this.o.mac, 'spoofing', false, 'unspoofingTime', new Date() / 1000)
502+
.catch(err => log.error("Unable to set spoofing in redis", err))
503+
.then(() => this.dnsmasq.onSpoofChanged());
504+
log.debug("Stopped spoofing", this.o.ipv4Addr, this.o.mac, this.o.name);
505+
this.spoofing = false;
506+
}).catch((err) => {
507+
log.error("Failed to unspoof", this.o.ipv4Addr, this.o.mac, this.o.name, err);
508+
})
509+
}
513510

514-
/* put a safety on the spoof */
515-
log.debug("Spoof For IPv6",this.o.mac, JSON.stringify(this.ipv6Addr),JSON.stringify(this.o.ipv6Addr));
516-
let myIp6 = sysManager.myIp6();
517-
if (this.ipv6Addr && this.ipv6Addr.length>0) {
518-
for (let i in this.ipv6Addr) {
519-
if (this.ipv6Addr[i] == gateway6) {
520-
continue;
521-
}
522-
if (myIp6 && myIp6.indexOf(this.ipv6Addr[i])>-1) {
523-
continue;
524-
}
525-
if (dns && dns.indexOf(this.ipv6Addr[i]) > -1) {
526-
continue;
527-
}
528-
if (state == true) {
529-
spoofer.newSpoof6(this.ipv6Addr[i]).then(()=>{
530-
log.debug("Starting v6 spoofing", this.ipv6Addr[i]);
531-
}).catch((err)=>{
532-
log.error("Failed to spoof", this.ipv6Addr, err);
533-
})
534-
if (i>20) {
535-
log.error("Failed to Spoof, over ",i, " of ", this.ipv6Addr);
536-
break;
537-
}
538-
// prototype
539-
// log.debug("Host:Spoof:True", this.o.ipv4Addr, gateway,this.ipv6Addr,gateway6);
540-
// spoofer.spoof(null, null, this.o.mac, this.ipv6Addr,gateway6);
541-
// this.spoofing = true;
542-
} else {
543-
spoofer.newUnspoof6(this.ipv6Addr[i]).then(()=>{
544-
log.debug("Starting v6 unspoofing", this.ipv6Addr[i]);
545-
}).catch((err)=>{
546-
log.error("Failed to [v6] unspoof", this.ipv6Addr);
547-
})
548-
// log.debug("Host:Spoof:False", this.o.ipv4Addr, gateway, this.ipv6Addr,gateway6);
549-
// spoofer.unspoof(null, null, this.o.mac,this.ipv6Addr, gateway6);
550-
// this.spoofing = false;
511+
/* put a safety on the spoof */
512+
log.debug("Spoof For IPv6",this.o.mac, JSON.stringify(this.ipv6Addr),JSON.stringify(this.o.ipv6Addr));
513+
let myIp6 = sysManager.myIp6();
514+
if (this.ipv6Addr && this.ipv6Addr.length>0) {
515+
for (let i in this.ipv6Addr) {
516+
if (this.ipv6Addr[i] == gateway6) {
517+
continue;
518+
}
519+
if (myIp6 && myIp6.indexOf(this.ipv6Addr[i])>-1) {
520+
continue;
521+
}
522+
if (dns && dns.indexOf(this.ipv6Addr[i]) > -1) {
523+
continue;
524+
}
525+
if (state == true) {
526+
spoofer.newSpoof6(this.ipv6Addr[i]).then(()=>{
527+
log.debug("Starting v6 spoofing", this.ipv6Addr[i]);
528+
}).catch((err)=>{
529+
log.error("Failed to spoof", this.ipv6Addr, err);
530+
})
531+
if (i>20) {
532+
log.error("Failed to Spoof, over ",i, " of ", this.ipv6Addr);
533+
break;
551534
}
535+
// prototype
536+
// log.debug("Host:Spoof:True", this.o.ipv4Addr, gateway,this.ipv6Addr,gateway6);
537+
// spoofer.spoof(null, null, this.o.mac, this.ipv6Addr,gateway6);
538+
// this.spoofing = true;
539+
} else {
540+
spoofer.newUnspoof6(this.ipv6Addr[i]).then(()=>{
541+
log.debug("Starting v6 unspoofing", this.ipv6Addr[i]);
542+
}).catch((err)=>{
543+
log.error("Failed to [v6] unspoof", this.ipv6Addr, err);
544+
})
545+
// log.debug("Host:Spoof:False", this.o.ipv4Addr, gateway, this.ipv6Addr,gateway6);
546+
// spoofer.unspoof(null, null, this.o.mac,this.ipv6Addr, gateway6);
547+
// this.spoofing = false;
552548
}
553549
}
554550
}

0 commit comments

Comments
 (0)