mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-22 07:46:16 -04:00
Made variables non-private, and followed convention for the references to the IP lib.
This commit is contained in:
parent
ea36687205
commit
3ba12ae9ac
7 changed files with 70 additions and 70 deletions
|
@ -6,7 +6,7 @@
|
|||
|
||||
import Operation from "../Operation";
|
||||
import Utils from "../Utils";
|
||||
import {fromHex} from "../lib/Hex";
|
||||
import {fromHex} from "../lib/Hex.mjs";
|
||||
|
||||
/**
|
||||
* Change IP format operation
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
import Operation from "../Operation";
|
||||
import Utils from "../Utils";
|
||||
import {_ipv6ToStr, _genIpv6Mask, IPV4_REGEX, _strToIpv6, _ipv4ToStr, IPV6_REGEX, _strToIpv4} from "../lib/Ip";
|
||||
import {ipv6ToStr, genIpv6Mask, IPV4_REGEX, strToIpv6, ipv4ToStr, IPV6_REGEX, strToIpv4} from "../lib/Ip.mjs";
|
||||
|
||||
/**
|
||||
* Group IP addresses operation
|
||||
|
@ -53,7 +53,7 @@ class GroupIPAddresses extends Operation {
|
|||
cidr = args[1],
|
||||
onlySubnets = args[2],
|
||||
ipv4Mask = cidr < 32 ? ~(0xFFFFFFFF >>> cidr) : 0xFFFFFFFF,
|
||||
ipv6Mask = _genIpv6Mask(cidr),
|
||||
ipv6Mask = genIpv6Mask(cidr),
|
||||
ips = input.split(delim),
|
||||
ipv4Networks = {},
|
||||
ipv6Networks = {};
|
||||
|
@ -71,7 +71,7 @@ class GroupIPAddresses extends Operation {
|
|||
// Parse all IPs and add to network dictionary
|
||||
for (i = 0; i < ips.length; i++) {
|
||||
if ((match = IPV4_REGEX.exec(ips[i]))) {
|
||||
ip = _strToIpv4(match[1]) >>> 0;
|
||||
ip = strToIpv4(match[1]) >>> 0;
|
||||
network = ip & ipv4Mask;
|
||||
|
||||
if (ipv4Networks.hasOwnProperty(network)) {
|
||||
|
@ -80,7 +80,7 @@ class GroupIPAddresses extends Operation {
|
|||
ipv4Networks[network] = [ip];
|
||||
}
|
||||
} else if ((match = IPV6_REGEX.exec(ips[i]))) {
|
||||
ip = _strToIpv6(match[1]);
|
||||
ip = strToIpv6(match[1]);
|
||||
network = [];
|
||||
networkStr = "";
|
||||
|
||||
|
@ -88,7 +88,7 @@ class GroupIPAddresses extends Operation {
|
|||
network.push(ip[j] & ipv6Mask[j]);
|
||||
}
|
||||
|
||||
networkStr = _ipv6ToStr(network, true);
|
||||
networkStr = ipv6ToStr(network, true);
|
||||
|
||||
if (ipv6Networks.hasOwnProperty(networkStr)) {
|
||||
ipv6Networks[networkStr].push(ip);
|
||||
|
@ -102,11 +102,11 @@ class GroupIPAddresses extends Operation {
|
|||
for (network in ipv4Networks) {
|
||||
ipv4Networks[network] = ipv4Networks[network].sort();
|
||||
|
||||
output += _ipv4ToStr(network) + "/" + cidr + "\n";
|
||||
output += ipv4ToStr(network) + "/" + cidr + "\n";
|
||||
|
||||
if (!onlySubnets) {
|
||||
for (i = 0; i < ipv4Networks[network].length; i++) {
|
||||
output += " " + _ipv4ToStr(ipv4Networks[network][i]) + "\n";
|
||||
output += " " + ipv4ToStr(ipv4Networks[network][i]) + "\n";
|
||||
}
|
||||
output += "\n";
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ class GroupIPAddresses extends Operation {
|
|||
|
||||
if (!onlySubnets) {
|
||||
for (i = 0; i < ipv6Networks[networkStr].length; i++) {
|
||||
output += " " + _ipv6ToStr(ipv6Networks[networkStr][i], true) + "\n";
|
||||
output += " " + ipv6ToStr(ipv6Networks[networkStr][i], true) + "\n";
|
||||
}
|
||||
output += "\n";
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
import {_ipv4CidrRange, _ipv4HyphenatedRange, _ipv6CidrRange, _ipv6HyphenatedRange} from "../lib/Ip";
|
||||
import {ipv4CidrRange, ipv4HyphenatedRange, ipv6CidrRange, ipv6HyphenatedRange} from "../lib/Ip";
|
||||
|
||||
/**
|
||||
* Parse IP range operation
|
||||
|
@ -60,13 +60,13 @@ class ParseIPRange extends Operation {
|
|||
let match;
|
||||
|
||||
if ((match = ipv4CidrRegex.exec(input))) {
|
||||
return _ipv4CidrRange(match, includeNetworkInfo, enumerateAddresses, allowLargeList);
|
||||
return ipv4CidrRange(match, includeNetworkInfo, enumerateAddresses, allowLargeList);
|
||||
} else if ((match = ipv4RangeRegex.exec(input))) {
|
||||
return _ipv4HyphenatedRange(match, includeNetworkInfo, enumerateAddresses, allowLargeList);
|
||||
return ipv4HyphenatedRange(match, includeNetworkInfo, enumerateAddresses, allowLargeList);
|
||||
} else if ((match = ipv6CidrRegex.exec(input))) {
|
||||
return _ipv6CidrRange(match, includeNetworkInfo);
|
||||
return ipv6CidrRange(match, includeNetworkInfo);
|
||||
} else if ((match = ipv6RangeRegex.exec(input))) {
|
||||
return _ipv6HyphenatedRange(match, includeNetworkInfo);
|
||||
return ipv6HyphenatedRange(match, includeNetworkInfo);
|
||||
} else {
|
||||
return "Invalid input.\n\nEnter either a CIDR range (e.g. 10.0.0.0/24) or a hyphenated range (e.g. 10.0.0.0 - 10.0.1.0). IPv6 also supported.";
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
import Operation from "../Operation";
|
||||
import Utils from "../Utils";
|
||||
import {fromHex, toHex} from "../lib/Hex";
|
||||
import {_ipv4ToStr, _protocolLookup, calculateTCPIPChecksum} from "../lib/Ip";
|
||||
import {fromHex, toHex} from "../lib/Hex.mjs";
|
||||
import {ipv4ToStr, protocolLookup, calculateTCPIPChecksum} from "../lib/Ip.mjs";
|
||||
|
||||
/**
|
||||
* Parse IPv4 header operation
|
||||
|
@ -83,7 +83,7 @@ class ParseIPv4Header extends Operation {
|
|||
}
|
||||
|
||||
// Protocol
|
||||
const protocolInfo = _protocolLookup[protocol] || {keyword: "", protocol: ""};
|
||||
const protocolInfo = protocolLookup[protocol] || {keyword: "", protocol: ""};
|
||||
|
||||
// Checksum
|
||||
const correctChecksum = calculateTCPIPChecksum(checksumHeader),
|
||||
|
@ -112,8 +112,8 @@ class ParseIPv4Header extends Operation {
|
|||
"<tr><td>Time-To-Live</td><td>" + ttl + "</td></tr>" +
|
||||
"<tr><td>Protocol</td><td>" + protocol + ", " + protocolInfo.protocol + " (" + protocolInfo.keyword + ")</td></tr>" +
|
||||
"<tr><td>Header checksum</td><td>" + checksumResult + "</td></tr>" +
|
||||
"<tr><td>Source IP address</td><td>" + _ipv4ToStr(srcIP) + "</td></tr>" +
|
||||
"<tr><td>Destination IP address</td><td>" + _ipv4ToStr(dstIP) + "</td></tr>";
|
||||
"<tr><td>Source IP address</td><td>" + ipv4ToStr(srcIP) + "</td></tr>" +
|
||||
"<tr><td>Destination IP address</td><td>" + ipv4ToStr(dstIP) + "</td></tr>";
|
||||
|
||||
if (ihl > 5) {
|
||||
output += "<tr><td>Options</td><td>" + toHex(options) + "</td></tr>";
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
import Operation from "../Operation";
|
||||
import Utils from "../Utils";
|
||||
import {_strToIpv6, _ipv6ToStr, _ipv4ToStr, IPV6_REGEX} from "../lib/Ip";
|
||||
import {strToIpv6, ipv6ToStr, ipv4ToStr, IPV6_REGEX} from "../lib/Ip.mjs";
|
||||
import BigInteger from "jsbn";
|
||||
|
||||
/**
|
||||
|
@ -38,9 +38,9 @@ class ParseIPv6Address extends Operation {
|
|||
output = "";
|
||||
|
||||
if ((match = IPV6_REGEX.exec(input))) {
|
||||
const ipv6 = _strToIpv6(match[1]),
|
||||
longhand = _ipv6ToStr(ipv6),
|
||||
shorthand = _ipv6ToStr(ipv6, true);
|
||||
const ipv6 = strToIpv6(match[1]),
|
||||
longhand = ipv6ToStr(ipv6),
|
||||
shorthand = ipv6ToStr(ipv6, true);
|
||||
|
||||
output += "Longhand: " + longhand + "\nShorthand: " + shorthand + "\n";
|
||||
|
||||
|
@ -57,13 +57,13 @@ class ParseIPv6Address extends Operation {
|
|||
ipv6[3] === 0 && ipv6[4] === 0 && ipv6[5] === 0xffff) {
|
||||
// IPv4-mapped IPv6 address
|
||||
output += "\nIPv4-mapped IPv6 address detected. IPv6 clients will be handled natively by default, and IPv4 clients appear as IPv6 clients at their IPv4-mapped IPv6 address.";
|
||||
output += "\nMapped IPv4 address: " + _ipv4ToStr((ipv6[6] << 16) + ipv6[7]);
|
||||
output += "\nMapped IPv4 address: " + ipv4ToStr((ipv6[6] << 16) + ipv6[7]);
|
||||
output += "\nIPv4-mapped IPv6 addresses range: ::ffff:0:0/96";
|
||||
} else if (ipv6[0] === 0 && ipv6[1] === 0 && ipv6[2] === 0 &&
|
||||
ipv6[3] === 0 && ipv6[4] === 0xffff && ipv6[5] === 0) {
|
||||
// IPv4-translated address
|
||||
output += "\nIPv4-translated address detected. Used by Stateless IP/ICMP Translation (SIIT). See RFCs 6145 and 6052 for more details.";
|
||||
output += "\nTranslated IPv4 address: " + _ipv4ToStr((ipv6[6] << 16) + ipv6[7]);
|
||||
output += "\nTranslated IPv4 address: " + ipv4ToStr((ipv6[6] << 16) + ipv6[7]);
|
||||
output += "\nIPv4-translated addresses range: ::ffff:0:0:0/96";
|
||||
} else if (ipv6[0] === 0x100) {
|
||||
// Discard prefix per RFC 6666
|
||||
|
@ -73,7 +73,7 @@ class ParseIPv6Address extends Operation {
|
|||
ipv6[3] === 0 && ipv6[4] === 0 && ipv6[5] === 0) {
|
||||
// IPv4/IPv6 translation per RFC 6052
|
||||
output += "\n'Well-Known' prefix for IPv4/IPv6 translation detected. See RFC 6052 for more details.";
|
||||
output += "\nTranslated IPv4 address: " + _ipv4ToStr((ipv6[6] << 16) + ipv6[7]);
|
||||
output += "\nTranslated IPv4 address: " + ipv4ToStr((ipv6[6] << 16) + ipv6[7]);
|
||||
output += "\n'Well-Known' prefix range: 64:ff9b::/96";
|
||||
} else if (ipv6[0] === 0x2001 && ipv6[1] === 0) {
|
||||
// Teredo tunneling
|
||||
|
@ -87,8 +87,8 @@ class ParseIPv6Address extends Operation {
|
|||
flagUg = (ipv6[4] >>> 8) & 3,
|
||||
flagRandom2 = ipv6[4] & 255;
|
||||
|
||||
output += "\nServer IPv4 address: " + _ipv4ToStr(serverIpv4) +
|
||||
"\nClient IPv4 address: " + _ipv4ToStr(clientIpv4) +
|
||||
output += "\nServer IPv4 address: " + ipv4ToStr(serverIpv4) +
|
||||
"\nClient IPv4 address: " + ipv4ToStr(clientIpv4) +
|
||||
"\nClient UDP port: " + udpPort +
|
||||
"\nFlags:" +
|
||||
"\n\tCone: " + flagCone;
|
||||
|
@ -142,7 +142,7 @@ class ParseIPv6Address extends Operation {
|
|||
output += "\n6to4 transition IPv6 address detected. See RFC 3056 for more details." +
|
||||
"\n6to4 prefix range: 2002::/16";
|
||||
|
||||
const v4Addr = _ipv4ToStr((ipv6[1] << 16) + ipv6[2]),
|
||||
const v4Addr = ipv4ToStr((ipv6[1] << 16) + ipv6[2]),
|
||||
slaId = ipv6[3],
|
||||
interfaceIdStr = ipv6[4].toString(16) + ipv6[5].toString(16) + ipv6[6].toString(16) + ipv6[7].toString(16),
|
||||
interfaceId = new BigInteger(interfaceIdStr, 16);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
import {calculateTCPIPChecksum} from "../lib/Ip";
|
||||
import {calculateTCPIPChecksum} from "../lib/Ip.mjs";
|
||||
|
||||
/**
|
||||
* TCP/IP Checksum operation
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue