Created
March 21, 2025 18:36
-
-
Save dscp46/29ae04d9f226a38ca1929e3c5bf522a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Input & output files | |
| INPUT_PCAP="input.pcapng" | |
| RAW_HEX="raw_hex.txt" | |
| CLEAN_HEX="clean_hex.txt" | |
| FORMATTED_HEX="formatted_hex.txt" | |
| OUTPUT_PCAP="ax25_output.pcapng" | |
| echo "[+] Extracting KISS payload from TCP:8001..." | |
| tshark -r "$INPUT_PCAP" -Y "tcp.port == 8001" -T fields -e tcp.payload > "$RAW_HEX" | |
| echo "[+] Stripping leading/trailing 0xC0 from each frame..." | |
| rm -f "$CLEAN_HEX" | |
| touch "$CLEAN_HEX" | |
| while read -r line; do | |
| # Remove spaces/newlines | |
| hex=$(echo "$line" | tr -d '[:space:]') | |
| # Remove leading and trailing C0 (hex) if present | |
| hex=$(echo "$hex" | sed -E 's/^(c0)+//; s/(c0)+$//') | |
| # Skip empty lines | |
| if [ -n "$hex" ]; then | |
| echo "$hex" >> "$CLEAN_HEX" | |
| fi | |
| done < "$RAW_HEX" | |
| echo "[+] Formatting hex dump for text2pcap..." | |
| rm -f "$FORMATTED_HEX" | |
| touch "$FORMATTED_HEX" | |
| while read -r line; do | |
| # Reset offset for each new packet | |
| offset=0 | |
| # Insert spaces between hex bytes | |
| spaced_hex=$(echo "$line" | sed 's/\(..\)/\1 /g') | |
| # Calculate actual byte count | |
| byte_count=$(( $(echo "$spaced_hex" | wc -w) )) | |
| # Print correctly formatted output (each new frame starts at 0000) | |
| printf "%04x %s\n" "$offset" "$spaced_hex" >> "$FORMATTED_HEX" | |
| # Insert a blank line to separate packets | |
| echo "" >> "$FORMATTED_HEX" | |
| done < "$CLEAN_HEX" | |
| echo "[+] Converting to PCAP with DLT 202 (AX.25 KISS)..." | |
| text2pcap -l 202 "$FORMATTED_HEX" "$OUTPUT_PCAP" | |
| echo "[+] Done! Output saved as: $OUTPUT_PCAP" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment