From 3c7fe723a3083cb7f6e7f79fecb7150a35cd3150 Mon Sep 17 00:00:00 2001 From: Michael De Roover Date: Tue, 1 Apr 2025 22:35:01 +0200 Subject: [PATCH] Finish this evening project --- readme.md | 9 +++++++ urldeconstruct | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 readme.md create mode 100755 urldeconstruct diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..2fc448c --- /dev/null +++ b/readme.md @@ -0,0 +1,9 @@ +#### urldeconstruct + +A program that deconstructs URLs! I'm sure that's news to you... + +It was an evening project at 2025-04-01, and served as a means to discover why a Greenpeace link of all things would cause my Linux system to generate a fork bomb. + +[url](https://act.greenpeace.org/page/168809/action/1?locale=nl-BE&utm_medium=email&utm_source=email&utm_campaign=Send%20a%20letter%20Ship%20Tour%202025%20-%20NL%20&utm_content=Send+a+letter+Ship+Tour+2025+-+NL+&ea.url.id=7993625&forwarded=true) + +So I guess that's another evening wasted. Gotta admire that training though, AI won't give you any of that :) diff --git a/urldeconstruct b/urldeconstruct new file mode 100755 index 0000000..b413811 --- /dev/null +++ b/urldeconstruct @@ -0,0 +1,66 @@ +#!/bin/bash + +# May cause fork bomb, do not use this! +#url="$1" +# Set a user limit just to be safe. +# Current process count seems to be between 512 and 600. +# Quite unsettling... +ulimit -u 600 +# And query interactively from user instead. +read -sp "URL: " url + +#printf "%s\n\n" "$url" +printf "\n" + +# Prepare URL +url=$(sed 's/\?/\n/g' <<< $url) +url=$(sed 's/\&/\n/g' <<< $url) + +# Turn it into an array +url_array=$(sed 's/\n/ /g' <<< $url) +url_array=($url_array) + +#printf "%s\n" "${url_array[*]}" + +#printf "%s %s\n" "Base URL:" "${url_array[0]}" + +# https://stackoverflow.com/questions/6723426 +for url_argument in "${!url_array[@]}" +do + # Zero is base URL, everything else is arguments + if [ "$url_argument" = "0" ] + then + export url_property="Base URL:" + elif [ "$url_argument" != "0" ] + then + export url_property="Argument:" + fi + + # Separate key=value pairs into an array + url_parameter=($(sed 's/\=/ /g' <<< ${url_array[$url_argument]})) + + # Differentiate trackers from other arguments + if grep -q utm <<< ${url_parameter[0]} + then + url_property="Tracker:" + fi + + # Turn %20 / + urlencoding into human-readable spaces + url_despace=${url_parameter[1]} + [ $(grep '%20' <<< "$url_despace") ] && \ + url_despaced="$(sed 's/\%20/ /g' <<< $url_despace)" + [ $(grep '+' <<< "$url_despace") ] && \ + url_despaced="$(sed 's/\+/ /g' <<< $url_despace)" + + # For publication purposes only + [ ${url_parameter[0]} = "ea.url.id" ] && \ + url_parameter[1]="redacted" + + # Print out the resulting text + printf "%-10s%-15s%-15s\n" "$url_property" "${url_parameter[0]}" "${url_parameter[1]}" #"${url_array[$url_argument]}" + [ ! -z "$url_despaced" ] && + printf "%-25s%15s\n" "" "$url_despaced" + + # Clear variables for next loop + unset url_despaced +done