From f3087b8a8ede88834285bb5d0655fc96341c174c Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 22 Oct 2019 16:40:27 -0700 Subject: [PATCH] update readme and formatting --- README.md | 319 +++++++++++++++++++++++++++++++++++++++++ changelog.txt | 1 + jc/parsers/iptables.py | 316 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 635 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d4a8a8f2..733e4154 100755 --- a/README.md +++ b/README.md @@ -230,6 +230,325 @@ $ ifconfig | jc --ifconfig -p } ] ``` +### iptables +``` +$ sudo iptables -L -t nat | jc --iptables -p +[ + { + "chain": "PREROUTING", + "rules": [ + { + "target": "PREROUTING_direct", + "prot": "all", + "opt": "--", + "source": "anywhere", + "destination": "anywhere" + }, + { + "target": "PREROUTING_ZONES_SOURCE", + "prot": "all", + "opt": "--", + "source": "anywhere", + "destination": "anywhere" + }, + { + "target": "PREROUTING_ZONES", + "prot": "all", + "opt": "--", + "source": "anywhere", + "destination": "anywhere" + }, + { + "target": "DOCKER", + "prot": "all", + "opt": "--", + "source": "anywhere", + "destination": "anywhere", + "options": "ADDRTYPE match dst-type LOCAL" + } + ] + }, + { + "chain": "INPUT", + "rules": [] + }, + { + "chain": "OUTPUT", + "rules": [ + { + "target": "OUTPUT_direct", + "prot": "all", + "opt": "--", + "source": "anywhere", + "destination": "anywhere" + }, + { + "target": "DOCKER", + "prot": "all", + "opt": "--", + "source": "anywhere", + "destination": "!loopback/8", + "options": "ADDRTYPE match dst-type LOCAL" + } + ] + }, + ... +] +``` +``` +$ sudo iptables -vnL -t filter | jc --iptables -p +[ + { + "chain": "INPUT", + "rules": [ + { + "pkts": "1571", + "bytes": "3394K", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "ctstate RELATED,ESTABLISHED" + }, + { + "pkts": "0", + "bytes": "0", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "lo", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "711", + "bytes": "60126", + "target": "INPUT_direct", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "711", + "bytes": "60126", + "target": "INPUT_ZONES_SOURCE", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "711", + "bytes": "60126", + "target": "INPUT_ZONES", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "DROP", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "ctstate INVALID" + }, + { + "pkts": "710", + "bytes": "60078", + "target": "REJECT", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "reject-with icmp-host-prohibited" + } + ] + }, + { + "chain": "FORWARD", + "rules": [ + { + "pkts": "0", + "bytes": "0", + "target": "DOCKER-ISOLATION", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "DOCKER", + "prot": "all", + "opt": "--", + "in": "*", + "out": "docker0", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "*", + "out": "docker0", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "ctstate RELATED,ESTABLISHED" + }, + { + "pkts": "0", + "bytes": "0", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "docker0", + "out": "!docker0", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "docker0", + "out": "docker0", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "ctstate RELATED,ESTABLISHED" + }, + { + "pkts": "0", + "bytes": "0", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "lo", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "FORWARD_direct", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "FORWARD_IN_ZONES_SOURCE", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "FORWARD_IN_ZONES", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "FORWARD_OUT_ZONES_SOURCE", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "FORWARD_OUT_ZONES", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "DROP", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "ctstate INVALID" + }, + { + "pkts": "0", + "bytes": "0", + "target": "REJECT", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "reject-with icmp-host-prohibited" + } + ] + }, + ... +] +``` ### ls ``` $ ls -l /bin | jc --ls -p diff --git a/changelog.txt b/changelog.txt index 3a0e042f..e01976e1 100644 --- a/changelog.txt +++ b/changelog.txt @@ -7,6 +7,7 @@ jc changelog - Add lsblk parser - Add mount parser - Add uname parser +- Add iptables parser 20191021 v0.6.4 - Flatten netstat parser output diff --git a/jc/parsers/iptables.py b/jc/parsers/iptables.py index 9761861a..2d6756e2 100644 --- a/jc/parsers/iptables.py +++ b/jc/parsers/iptables.py @@ -7,6 +7,321 @@ Usage: Examples: +$ sudo iptables -L -t nat | jc --iptables -p +[ + { + "chain": "PREROUTING", + "rules": [ + { + "target": "PREROUTING_direct", + "prot": "all", + "opt": "--", + "source": "anywhere", + "destination": "anywhere" + }, + { + "target": "PREROUTING_ZONES_SOURCE", + "prot": "all", + "opt": "--", + "source": "anywhere", + "destination": "anywhere" + }, + { + "target": "PREROUTING_ZONES", + "prot": "all", + "opt": "--", + "source": "anywhere", + "destination": "anywhere" + }, + { + "target": "DOCKER", + "prot": "all", + "opt": "--", + "source": "anywhere", + "destination": "anywhere", + "options": "ADDRTYPE match dst-type LOCAL" + } + ] + }, + { + "chain": "INPUT", + "rules": [] + }, + { + "chain": "OUTPUT", + "rules": [ + { + "target": "OUTPUT_direct", + "prot": "all", + "opt": "--", + "source": "anywhere", + "destination": "anywhere" + }, + { + "target": "DOCKER", + "prot": "all", + "opt": "--", + "source": "anywhere", + "destination": "!loopback/8", + "options": "ADDRTYPE match dst-type LOCAL" + } + ] + }, + ... +] + +$ sudo iptables -vnL -t filter | jc --iptables -p +[ + { + "chain": "INPUT", + "rules": [ + { + "pkts": "1571", + "bytes": "3394K", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "ctstate RELATED,ESTABLISHED" + }, + { + "pkts": "0", + "bytes": "0", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "lo", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "711", + "bytes": "60126", + "target": "INPUT_direct", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "711", + "bytes": "60126", + "target": "INPUT_ZONES_SOURCE", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "711", + "bytes": "60126", + "target": "INPUT_ZONES", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "DROP", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "ctstate INVALID" + }, + { + "pkts": "710", + "bytes": "60078", + "target": "REJECT", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "reject-with icmp-host-prohibited" + } + ] + }, + { + "chain": "FORWARD", + "rules": [ + { + "pkts": "0", + "bytes": "0", + "target": "DOCKER-ISOLATION", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "DOCKER", + "prot": "all", + "opt": "--", + "in": "*", + "out": "docker0", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "*", + "out": "docker0", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "ctstate RELATED,ESTABLISHED" + }, + { + "pkts": "0", + "bytes": "0", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "docker0", + "out": "!docker0", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "docker0", + "out": "docker0", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "ctstate RELATED,ESTABLISHED" + }, + { + "pkts": "0", + "bytes": "0", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "lo", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "FORWARD_direct", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "FORWARD_IN_ZONES_SOURCE", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "FORWARD_IN_ZONES", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "FORWARD_OUT_ZONES_SOURCE", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "FORWARD_OUT_ZONES", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "DROP", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "ctstate INVALID" + }, + { + "pkts": "0", + "bytes": "0", + "target": "REJECT", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "reject-with icmp-host-prohibited" + } + ] + }, + ... +] """ @@ -29,7 +344,6 @@ def parse(data): parsed_line = line.split() state.chain['chain'] = parsed_line[1] - # state.chain['references'] = parsed_line[2].lstrip('(').rstrip(')').split()[0] state.chain['rules'] = [] continue