Skip to content

Instantly share code, notes, and snippets.

@benbrown
Created March 23, 2025 20:43
Show Gist options
  • Save benbrown/6f36b4f6834be0a5ae486c1c2b72f94b to your computer and use it in GitHub Desktop.
Save benbrown/6f36b4f6834be0a5ae486c1c2b72f94b to your computer and use it in GitHub Desktop.
download pcap and qmdl files from rayhunter with a bash scipt
#!/bin/bash
# Configuration
LOCAL_PORT="8080"
REMOTE_PORT="8080"
OUTPUT_DIR="downloads"
# Function to check if a port is in use
is_port_in_use() {
lsof -i :$1 >/dev/null 2>&1
}
# Function to download a file
download_file() {
local url=$1
local output=$2
echo "Downloading $output..."
curl -s "$url" -o "$output"
if [ $? -eq 0 ]; then
echo "✓ Downloaded $output"
else
echo "✗ Failed to download $output"
fi
}
# Set up ADB port forwarding
echo "Setting up ADB port forwarding..."
if is_port_in_use $LOCAL_PORT; then
echo "Port $LOCAL_PORT is already in use. Attempting to remove existing forwarding..."
adb forward --remove tcp:$LOCAL_PORT
fi
adb forward tcp:$LOCAL_PORT tcp:$REMOTE_PORT
if [ $? -ne 0 ]; then
echo "Failed to set up ADB port forwarding"
exit 1
fi
# Create output directory if it doesn't exist
mkdir -p "$OUTPUT_DIR"
# Get the manifest
echo "Fetching manifest..."
MANIFEST=$(curl -s "http://localhost:$LOCAL_PORT/api/qmdl-manifest")
if [ $? -ne 0 ]; then
echo "Failed to fetch manifest"
adb forward --remove tcp:$LOCAL_PORT
exit 1
fi
# Process current entry if it exists
CURRENT_ENTRY=$(echo "$MANIFEST" | jq -r '.current_entry')
if [ "$CURRENT_ENTRY" != "null" ]; then
NAME=$(echo "$CURRENT_ENTRY" | jq -r '.name')
echo "Processing current entry: $NAME"
# Download PCAP
download_file "http://localhost:$LOCAL_PORT/api/pcap/$NAME" "$OUTPUT_DIR/${NAME}.pcap"
# Download QMDL
download_file "http://localhost:$LOCAL_PORT/api/qmdl/${NAME}.qmdl" "$OUTPUT_DIR/${NAME}.qmdl"
fi
# Process all entries
echo "$MANIFEST" | jq -r '.entries[] | .name' | while read -r name; do
echo "Processing entry: $name"
# Download PCAP
download_file "http://localhost:$LOCAL_PORT/api/pcap/$name" "$OUTPUT_DIR/${name}.pcap"
# Download QMDL
download_file "http://localhost:$LOCAL_PORT/api/qmdl/${name}.qmdl" "$OUTPUT_DIR/${name}.qmdl"
done
# Clean up port forwarding
echo "Cleaning up ADB port forwarding..."
adb forward --remove tcp:$LOCAL_PORT
echo "Download complete! Files are in the '$OUTPUT_DIR' directory"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment