@@ -36,8 +36,6 @@ const getPreferredBName = require('../util/util.js').getPreferredBName
36
36
37
37
const bone = require ( "../lib/Bone.js" ) ;
38
38
39
- const fConfig = require ( './config.js' ) . getConfig ( ) ;
40
-
41
39
const MobileDetect = require ( 'mobile-detect' ) ;
42
40
43
41
const flowUtil = require ( '../net2/FlowUtil.js' ) ;
@@ -453,102 +451,100 @@ class Host {
453
451
454
452
const spoofer = new Spoofer ( sysManager . config . monitoringInterface , { } , false ) ;
455
453
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
+ }
462
459
463
- /* This is taken care of by DnsLoopAvoidanceSensor
460
+ /* This is taken care of by DnsLoopAvoidanceSensor
464
461
if (dns && dns.includes(this.o.ipv4Addr)) {
465
462
// do not monitor dns server's traffic
466
463
return;
467
464
}
468
465
*/
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 } ` ;
499
480
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 ) ;
501
482
} ) ;
502
- spoofer . newUnspoof ( this . o . ipv4Addr )
483
+ spoofer . newSpoof ( this . o . ipv4Addr )
503
484
. 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 )
505
486
. catch ( err => log . error ( "Unable to set spoofing in redis" , err ) )
506
487
. 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 ;
509
490
} ) . 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 ) ;
511
492
} )
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
+ }
513
510
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 ;
551
534
}
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;
552
548
}
553
549
}
554
550
}
0 commit comments