When One Door Closes
by Gregory Porter
Pop culture portrays hacking as super intense programmers cracking into the FBI database or reverse engineering a virus (or writing one if the hacker is a villain). It's all very glamorous. But that, reader of 2600, as I'm sure you know, isn't really what hacking is about. It's about problem-solving with creativity and ingenuity. Today, I'm writing about one such experience.
I recently saw a tweet advertising a free virtual conference. I registered and looked at the schedule. Alas, a doctor's appointment overlapped with the presentation I wanted to see.
Nevertheless, I logged in that morning, found a page for that presentation, and bookmarked it. Maybe I'd be able to come back that afternoon and watch it, I thought.
I got sidetracked and forgot about my bookmark and the presentation for a couple of days. When I saw a "thank you for attending" email, I thought, oh yeah, let's give watching it a try. Unfortunately, the conference website didn't allow me to re-login. It had closed the door, so to speak, because the show was over. I went about my day, checking the conference's YouTube channel, regretting not scheduling my appointment for another time. I logged into my computer and, lo-and-behold, I see my forgotten bookmark. I click it. Huzzah, it works!
They may have closed the door but they didn't seem to be kicking me out now that I was already there. That said, I felt as if I was on borrowed time. If the cookie expires or I refresh the page, surely they would kick me out. So as the presentation is playing, I am looking through the site to see if there is a "Download" button. Unfortunately, and not surprisingly, no such button; they'd want you to stay on their platform for the conference.
All right, now if they are going to potentially cut me off, let's find another way to download it. I open up the browser's "Developer Tools" and switch to the "Network" tab. Naturally, there are network calls going out, but there was a series that piqued my interest. Every couple of seconds, a request was made to the following URLs in what seemed to be a pattern (note that this has been changed slightly for brevity and privacy):
https://conference.net/896aaae5d1e4ac3f_960x540p-1.2Mbps-1200000_00010.ts https://conference.net/896aaae5d1e4ac3f_960x540p-1.2Mbps-1200000_00011.ts https://conference.net/896aaae5d1e4ac3f_960x540p-1.2Mbps-1200000_00012.tsLet's start out by seeing if I can get something if I Curl-ed one of those URLs:
$ curl https://conference.net/896aaae5d1e4ac3f_960x540p-1.2Mbps-1200000_00010.ts > test.tsMPEG TS is a video file geared towards streaming and opening test.ts with VLC revealed a five-second video! Now, we're cookin' with gas.
The next step was to make a Bash script to cycle from zero to the ending video number and Curl the URLs.
#!/bin/bash for i in {0..600} do curl 'https://conference.net/896aaae5d1e4ac3f_960x540p-1.2Mbps-1200000_0000${i}.ts' > $i.ts done exit 0I then hit a snag. It seems the last five characters in the URL were a fixed length. Meaning, for the first file, the URL is 00001.ts while the six-hundredth would be 00600.ts.
Now, this felt very much like a problem out of my computer science education. But I don't have a clue about how to do that in Bash. I let out a sigh. Would this be where my quest would end? No! There must be another way.
So let's take a step back and think about the data that we are going to be using. We know the string is going to have four zeroes when i is less than ten, three zeros when i is between ten and 100, and two zeros when i is between 100 and 1000.
Let's adapt our script to account for just those scenarios:
#!/bin/bash for i in {0..600} do if [ $i -lt 10 ]; then curl 'https://conference.net/896a-aae5d1e4ac3f_960x540p-1.2Mbps-1200000_0000${i}' > $i.ts elif [ $i -lt 100 ]; then curl 'https://conference.net/896a-aae5d1e4ac3f_960x540p-1.2Mbps-1200000_000${i}' > $i.ts elif [ $i -lt 1000 ]; then curl 'https://conference.net/896a-aae5d1e4ac3f_960x540p-1.2Mbps-1200000_00${i}' > $i.ts else echo "Something is a miss" fi done exit 0 # Concatenate the files with: ls -v | xargs cat > video.tsIs it the fanciest approach? No, but it does work. Upon running the script, I had about 550 short video files. The last step is to concatenate them with:
$ ls -v | xargs cat > video.tsNote, ls -v is needed because a simple:
$ cat *.ts > video.tswill result in an ordering of:
1.ts 10.ts 100.ts 101.ts 102.ts 103.ts ...And so, my quest to download the conference presentation was successful! The moral of the story, don't let a closed-door be the be-all and end-all (unless you'd be infringing on someone's privacy, then it's probably best to let them be).
As a reader of 2600, I'm sure you've seen all sorts of really complicated technical solutions to problems; don't feel intimidated! After all, a very simple solution to a problem is still a solution.
Thanks for reading, happy hacking, and stay safe.
Code: WhenOneDoor.sh
#!/bin/bash # # From 2600 Magazine - Volume 39, No. 1 # Letter from David Mooter # PLAYLIST_FILE=`mktemp` TEMP_FILE=`mktemp` curl -s -L --compressed --retry 3 "${1}" -o "${PLAYLIST_FILE}" BASE_PATH=`echo "$1" | sed 's|\(.*\)/.*|\1|'`/ while IFS= read -r INPUT_LINE do if [ "${INPUT_LIN:0:1}" != "#" ] then curl -s -L --compressed --retry 3 "${BASE_PATH}${INPUT_LINE}" -o "${TEMP_FILE}" cat "{TEMP_FILE}" >> "{$2}" rm "${TEMP_FILE}" fi done < "${PLAYLIST_FILE}" rm "${PLAYLIST_FILE}"Alternate: M3U.sh