Skip to content

Commit 99272d1

Browse files
committed
feat: add cidr support for ip spoof detection indicator on lan table
1 parent 6e126c4 commit 99272d1

File tree

3 files changed

+85
-17
lines changed

3 files changed

+85
-17
lines changed

package-lock.json

Lines changed: 57 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
"compare-versions": "^3.4.0",
3030
"core-js": "^2.5.4",
3131
"highlight.js": "^9.15.6",
32+
"ip-range-check": "^0.2.0",
33+
"ipaddr.js": "^2.2.0",
3234
"jquery": "^3.4.1",
3335
"ng": "0.0.0",
3436
"ngx-highlightjs": "^3.0.3",

src/app/components/lan-table/lan-table.component.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {Component, OnInit, OnDestroy, ViewChild} from '@angular/core';
1+
import ipaddr from 'ipaddr.js';
2+
import isIpInRange from 'ip-range-check';
3+
import {Component, OnInit, OnDestroy} from '@angular/core';
24
import { SortService, ColumnSortedEvent } from '../../services/sort.service';
35
import { ApiService } from '../../services/api.service';
46
import { Host } from '../../models/host';
@@ -59,8 +61,21 @@ export class LanTableComponent implements OnInit, OnDestroy {
5961
this.sortSub.unsubscribe();
6062
}
6163

62-
isSpoofed(host : any) : boolean {
63-
return (host.ipv4 in this.spoofList);
64+
isSpoofed(host: any): boolean {
65+
const whitelistedTargets = this.spoofOpts.whitelist
66+
.split(',')
67+
.map((s) => s.trim())
68+
.filter((s) => s.length);
69+
70+
if (isIpInRange(host.ipv4, whitelistedTargets)) {
71+
return false;
72+
}
73+
74+
if (host.ipv4 in this.spoofList) {
75+
return true;
76+
}
77+
78+
return isIpInRange(host.ipv4, Object.keys(this.spoofList));
6479
}
6580

6681
private updateSpoofOpts() {
@@ -133,8 +148,6 @@ export class LanTableComponent implements OnInit, OnDestroy {
133148
}
134149

135150
private update(session) {
136-
const ipRe = /^(?=.*[^\.]$)((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.?){4}$/;
137-
138151
let spoofing = this.api.session.env.data['arp.spoof.targets']
139152
// split by comma and trim spaces
140153
.split(',')
@@ -153,13 +166,14 @@ export class LanTableComponent implements OnInit, OnDestroy {
153166
this.spoofList = {};
154167
// if there are elements that are not IP addresses, it means the user
155168
// has set the variable manually, which overrides the UI spoof list.
156-
for( let i = 0; i < spoofing.length; i++ ) {
157-
if( ipRe.test(spoofing[i]) ) {
158-
this.spoofList[spoofing[i]] = true;
159-
} else {
160-
this.spoofList = {};
161-
break;
162-
}
169+
for (let i = 0; i < spoofing.length; i++) {
170+
let spoofedTarget = spoofing[i];
171+
if (ipaddr.isValid(spoofedTarget) || ipaddr.isValidCIDR(spoofedTarget)) {
172+
this.spoofList[spoofedTarget] = true;
173+
} else {
174+
this.spoofList = {};
175+
break;
176+
}
163177
}
164178

165179
this.iface = session.interface;

0 commit comments

Comments
 (0)