From cec44a98fd40f855f87742c05de5426a35ae1c28 Mon Sep 17 00:00:00 2001 From: Frikky Date: Wed, 21 Feb 2024 10:43:02 +0100 Subject: [PATCH] Added an action for listing ips in a CIDR range --- shuffle-tools/1.2.0/api.yaml | 13 ++++++++++++ shuffle-tools/1.2.0/src/app.py | 38 ++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/shuffle-tools/1.2.0/api.yaml b/shuffle-tools/1.2.0/api.yaml index cfa1a55b..66704dd8 100644 --- a/shuffle-tools/1.2.0/api.yaml +++ b/shuffle-tools/1.2.0/api.yaml @@ -955,6 +955,19 @@ actions: returns: schema: type: string + - name: list_cidr_ips + description: Lists the IPs for a CIDR + parameters: + - name: cidr + description: IP CIDR to check + multiline: false + example: "1.1.1.0/24" + required: True + schema: + type: string + returns: + schema: + type: string - name: cidr_ip_match description: Check if an IP is contained in a CIDR defined network parameters: diff --git a/shuffle-tools/1.2.0/src/app.py b/shuffle-tools/1.2.0/src/app.py index 03019ed7..2708309c 100644 --- a/shuffle-tools/1.2.0/src/app.py +++ b/shuffle-tools/1.2.0/src/app.py @@ -2654,6 +2654,44 @@ def parse_ioc_new(self, input_string, input_type="all"): return "Failed to parse IOC's: %s" % e return newarray + + def list_cidr_ips(self, cidr): + defaultreturn = { + "success": False, + "reason": "Invalid CIDR address" + } + + if not cidr: + return defaultreturn + + if "/" not in cidr: + defaultreturn["reason"] = "CIDR address must contain / (e.g. /12)" + return defaultreturn + + try: + cidrnumber = int(cidr.split("/")[1]) + except ValueError as e: + defaultreturn["exception"] = str(e) + return defaultreturn + + if cidrnumber < 12: + defaultreturn["reason"] = "CIDR address too large. Please stay above /12" + return defaultreturn + + try: + net = ipaddress.ip_network(cidr) + except ValueError as e: + defaultreturn["exception"] = str(e) + return defaultreturn + + ips = [str(ip) for ip in net] + returnvalue = { + "success": True, + "amount": len(ips), + "ips": ips + } + + return returnvalue if __name__ == "__main__":