diff --git a/.gitignore b/.gitignore index d588798..43147b8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ /serve/config.txt -/logs diff --git a/flash.sh b/flash.sh index 4df4e6f..ea600cb 100755 --- a/flash.sh +++ b/flash.sh @@ -1,34 +1,20 @@ #!/usr/bin/env bash -if ! curl -s -f http://127.0.0.1:8080/config.txt > /dev/null; then - echo "!!!!!!!!!!!!! please start server" - exit 1 -fi - -SSH_OPTS="-o StrictHostKeyChecking=no" +SSH_OPTS="-o StrictHostKeychecking=no" ssh $SSH_OPTS root@192.168.42.6 "cli request system zeroize" -echo "sleeping for 80s, then ping until up" +echo "sleeping for 10" -sleep 80 +sleep 10 + +./serve.sh & while true; do - if ping -w 1 -c 1 192.168.42.6 > /dev/null; then + if ping -w 1 -c 1 192.168.42.6 > /dev/null then break fi done -echo "collecting logs" - -dir="./logs/$(date +"%Y%m%d_%H%M%S")-zeroize" - -mkdir -p "$dir" - -touch "$dir/zeroize" - -cp "./serve/config.txt" "$dir/" -cp ./flash.sh "$dir" - echo "finished" diff --git a/powercut.sh b/powercut.sh deleted file mode 100755 index 3650a42..0000000 --- a/powercut.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash - -echo "sleeping for 80s, then ping until up" - -sleep 80 - -while true; -do - if ping -w 1 -c 1 192.168.42.6 > /dev/null; then - break - fi -done - -echo "collecting logs" - -dir="./logs/$(date +"%Y%m%d_%H%M%S")-powercut" - -mkdir -p "$dir" - -touch "$dir/powercut" - -cp ./powercut.sh "$dir" - -echo "finished" diff --git a/reboot.sh b/reboot.sh deleted file mode 100755 index 420c8f4..0000000 --- a/reboot.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash - -SSH_OPTS="-o StrictHostKeyChecking=no" - -ssh $SSH_OPTS root@192.168.42.6 "reboot" - -echo "sleeping for 80s, then ping until up" - -sleep 80 - -while true; -do - if ping -w 1 -c 1 192.168.42.6 > /dev/null; then - break - fi -done - -echo "collecting logs" - -dir="./logs/$(date +"%Y%m%d_%H%M%S")-reboot" - -mkdir -p "$dir" - -touch "$dir/reboot" - -cp ./reboot.sh "$dir" - -echo "finished" diff --git a/script.py b/script.py index eda71e9..682219d 100644 --- a/script.py +++ b/script.py @@ -1,11 +1,11 @@ from time import sleep -from scapy.all import ICMP, IP, Dot1Q, Ether, sendp, AsyncSniffer, wrpcap +from scapy.all import ICMP, IP, Dot1Q, Ether, sendp from tqdm import tqdm a = AsyncSniffer(iface="enp5s0d1", filter="icmp") a.start() -for i in tqdm(range(0, 4095)): +for i in tqdm(range(1, 4095)): sendp( Ether(dst="00:02:c9:27:10:73", src="00:f0:cb:ef:e0:3b") / Dot1Q(vlan=i) @@ -14,76 +14,6 @@ for i in tqdm(range(0, 4095)): iface="enp2s0", verbose=False, ) -print("Wrapping up and waiting for last packets") sleep(1) plist = a.stop() - -seen = [False for i in range(4095)] -icmpid = [False for i in range(4095)] - -def pprint(seen): - last = None - s = "" - for k, v in enumerate(seen): - if v and last is None: - last = k - s += str(k) - if not v and last is not None: - if k-1 == last: - s += "," - else: - s += f"-{k-1}," - last = None - if last is not None and last < k: - s += f"-{k}" - return s + "\n" - - -for p in plist: - if Dot1Q in p: - vlan = int(p[Dot1Q].vlan) - seen[vlan] = True - if ICMP in p and p[ICMP].id == vlan: - icmpid[vlan] = True - -print("Icmp correspondance") -print(pprint(icmpid)) -print("Seen vlans") -print(pprint(seen)) - -print("Collecting :") -import subprocess -from datetime import datetime -from pathlib import Path -import shutil - -timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") + "-test" -log_dir = Path("./logs") / timestamp -log_dir.mkdir(parents=True, exist_ok=True) - -with open(log_dir / "seen_vlans.txt", "w") as f: - f.write(pprint(seen)) - -with open(log_dir / "seen_icmp_ids.txt", "w") as f: - f.write(pprint(icmpid)) - -shutil.copy(Path("./script.py"), log_dir / "script.py") - -print(" - [x] script.py") - -with open(log_dir / "egress.pcap", "wb") as file: - wrpcap(file, plist) - -print(" - [x] pcap") - -cmd_config = ["ssh", "-o", "StrictHostKeyChecking=no", "root@192.168.42.6", "cli show config"] -cmd_rsi = ["ssh", "-o", "StrictHostKeyChecking=no", "root@192.168.42.6", "cli request support information"] - -result = subprocess.run(cmd_config, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) - -with open(log_dir / "config.txt", "w") as f: - f.write(result.stdout) - -print(" - [x] config") - -print("Finished, saved to", log_dir) +print(plist) diff --git a/serve/base_config.txt b/serve/base_config.txt index 8b4b3cd..51504cb 100644 --- a/serve/base_config.txt +++ b/serve/base_config.txt @@ -14,7 +14,6 @@ system { ssh-ed25519 "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFdDnSl3cyWil+S5JiyGqOvBR3wVh+lduw58S5WvraoL maurice@fekda"; ## SECRET-DATA ssh-ed25519 "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIGmU7yEOCGuGNt4PlQbzd0Cms1RePpo8yEA7Ij/+TdA foo@bar"; ## SECRET-DATA ssh-ed25519 "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDz9zePZXeH96RotT+xl4ux2kOh3qIp94txtcMjsf3vx foo@bar"; ## SECRET-DATA - ssh-ed25519 "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIBicEt7xV6tjMURJO/dXbxF0VGE3RtxuFaE7ba+1qSN root@elnath"; ## SECRET-DATA } services { netconf {