Powershell based Plex “Local Player”

So, imagine a scenario where you’re trying to give a presentation on a customer’s PC, what you are trying to show is a video on a remote Plex server, but the customer’s PC is so locked down (whitelisted apps only) that whilst vlc will work, a web browser won’t! Seriously!!!

However, powershell did work and that gave me a way in.

So, what I thought wouldtake just a few simple lines to download the file from the plex server and play it through vlc, actually became a bit of an epic.

Therefore, in case anybody ever gets stuck in the same hole or wants some sample code demonstrating to do take “streamed” content and convert it back into something a media player will play locally. The code is now on github at https://github.com/glennpegden/PlexLocalPlayer

To use it just pass in the URL of the video details page in Plex, your plex username andpassword and the foldername to dump the video into (also optionally the paths to ffmpeg and vlc, or you can redefine these at the top of the script)

e.g.
.\PlexLocalPlay.ps1 “http://app.plex.tv/web/app#!/server/01380a5c2c9b4290-9c1136b6882a65c1/details/%2Flibrary%2Fmetadata%2F12345” “user@email.com” “yourplexpasswrd” “G:\Users\Glenn\Downloads”

Disclaimer: I’ve no idea if interacting with Plex is this way is against their terms and conditions. I’m also not sure any of how I’m doing it is “the right way” because it was reverse engineered by examining how the Plex Web Player works on a laptop rather than from any official documentation. I’m also not responsible for how you use it. My use case was to download marketing material that I was allowed to distribute, I imagine doing this with your family’s blu ray connection may be illegal in many places.

For anyone writing your own version of this, a few things about the design.

The convoluted background download. This is to address two problema.

  1. The Plex server seems to time out connections, even if they are happily delivering content. Their own web player gets around this by hitting a “ping” end point as a keep alive, we have to emulate that.
  2. Invoke-Webrequest is nice and simple, but it loads the entire downloaded content into memory and saves it upon completion. Fine for tiny webpages, a disaster waiting to happen for huge files. BITS would normally be my go to alternative (BITS support in powershell is great), but it needs a Content-Length header from the server, which we’re not going to get from a stream.

    So, we have to use .net functions to stream the content into a file, in a background task, so the foreground task can hand the keep alive.

    Potions of the stream downloading code are based on this blog post – https://blogs.msdn.microsoft.com/jasonn/2008/06/13/downloading-files-from-the-internet-in-powershell-with-progress/

I also added some hokey support for roughly passing back the progress, but as we only know the size of the file on the remote OS and who knows what the transfer/transcode is going to do with it, it’s far from accurate. It also only updates once every 15 seconds (which is how often the keep alive is sent). Really, only consider this as an indicator something is still happening, not a real estimate of progress.

Obviously simply saving the stream to a file doesn’t generate valid video file, however ffmpeg does a brilliant job or repairing it (or has done in all my tests at least, your mileage may vary).

Enjoy!

Online Anonymity, Privacy and Risk Evaluation

I got into a conversation the other day about why I, as a massive supporter of the right to online privacy, still tended to use my real name online, in places where a more anonymous handle would be more than acceptable.

You’d have thought as somebody quite proficient at OSINT (Open Source, Intelligence,  the art of finding information, particularly relating to people, from public information sources), I’d have taken every opportunity to grab a little anonymity, especially as my real name is almost certainly unique in the world.

It comes down to risk vs reward. Understanding and mitigating the risk is crucial.

If you know my real name (which is pretty obvious from the domain name of this blog) then there is already loads of freely available information out there on me. I bought domain names in the 90s, back when a real postal address was mandatory (they even sent you a physical certificate of ownership) and I used to run a business out of my house, so it was a legal requirement to have my business address on any formal paperwork, so finding my home address is trivial.  I couldn’t find anywhere leaking my date of birth online but I’d bet there is some site I’ve entered it into (back before I thought to lie about it) which now leaks it publicly. Similarly, I get so many requests for genealogy info that I’m sure somewhere discloses my mothers maiden name. There are also documents I wrote at University on what is now called Cyber Security with my name on that I now wish didn’t exist, that highlight my security “white hat” has been bleached over the years.

That information is all out there. The genie is out of the bottle, it’s never going back in. So, you’d think that was ever MORE reason to hide my real name online? Not really and it’s all down to understanding and managing that risk.

If I operate under a pseudonym, I have a new risk. The risk of some detail linking the anonymous me to the real me. I’m going to be in the same physical location as my anonymous self, probably using the same computer, browser and internet connection, I’m going to have similar views, knowledge, understanding, frailties and experiences, the same grammar mistakes, the same typing patterns the same mouse movement patterns.

As mass tracking and analysis of both data and metadata becomes easier and more prevalent, the chances of me accidentally revealing a link between my real self and my anonymous self increases and once somebody makes that link, there is no point being anonymous at all.

What’s more, the ability to operate under a pseudonym means I’m more likely to reveal additional information than I normally would under my real identity (even if only subconsciously), increasing the risk even further. The instant all the content you wished to keep anonymous is linked back to your real identity you’re essentially stood there with a big sign saying “this is the stuff I didn’t want you to know was by me”.

To further evaluate the risk, you also have to understand that data can last forever and who can access this data over time changes. It’s not about who can see your private content now, it’s about who can see it in the future and then associate it back to you.

Back in 2006, I was in Amsterdam mainly to watch Feyenoord vs Blackburn Rovers, but I also visited the Amsterdam Museum (despite the cliche, not all English football fans in Amsterdam just hang out in De Wallen drinking beer and smoking weed) and read a fascinating but terrifying account of the Nazi occupation of Holland in World War 2. The dutch, quite sensibly, had collected everyone’s religion as part of the census, to ensure that in the case of their funeral being organised by the state, an appropriate ceremony was performed. However, after Nazi occupation, this same list has a whole different purpose.

The details you put online are no different. Just because you trust a website to responsibly keep your private data private, what if they are sold, hackedpressured by a nation state or have a rogue or sloppy employee?

I therefore operate under the assumption that EVERYTHING I put online can potentially end up in the wrong hands one day.

That doesn’t mean that I instantly post everything public, just because one day people might see it anyway, but it’s always a thought in the back of my mind when I post.

So, I’ve given up on online privacy? Hell No! It’s important to realise anonymity and privacy are not the same thing and the right to privacy is an important right to have, even if I choose to waive it.

Just because I feel one day, a hack, leak or change of government could see my emails/PMs/Skype calls etc being put in the wrong hands, doesn’t mean that I want to share them with everyone right now.  It’s precisely because anonymity is mere obfuscation that gives people a false sense of security that I think privacy is so very very important.

For example, my twitter account is public, this is my choice and I know anything I post on there can be seen by the entire world in perpetuity, so it tends to be limited mostly to conversations about tech, football or politics. Facebook however, I have configured to be more private,  that doesn’t mean I’ll post anything incriminating or particularly personal, but it will give you more of an insight into my daily comings and going, my social life and particularly upcoming and current events I’m attending. This includes data that may be of some value ahead of time (i.e. to allow you to break into my house, or scam my friends/bank etc into believing I’m stranded abroad without money) but virtually zero value after the fact. Therefore as long as I can trust Facebook to keep that data private for a short period, the risk is much smaller.

But privacy in the modern world is tricky. It’s 16 years since of the launch of PGP and almost 3 years since google announced End to End, but there is still no practical way for me to send an email to any non-technical friends with the belief that nobody other than them will ever be able to read it. End to End (E2E) encrypted messengers like Signal, Telegram, WhatsApp and even Facebook Messenger are great, but do I really trust my phone and computer operating systems enough to  be sure the message wasn’t snooped on when it’s decrypted and even if I did, is it reasonable to expect my mum to install a new messenger app, when it’s unlikely I would ever say anything I’d couldn’t be overheard saying to her in the street?

And what of systems that don’t purport to offer E2E encryption? I love slack, but even if their data is encrypted both in transit and at rest as they claim, they can still be decrypted and subpoenaed. The tech simply isn’t there yet to make privacy EASY and that’s the way both corporations (who sell you data) and government agencies (who use is for surveillance purposes) like it.

Which brings us back to risk vs reward. In much the same way to only truly secure a computer is unplug it and encase in in concrete, the only way to stay truly private online is to never be online, However, if you want the rewards being online brings, the have to accept the risks. But, when you understand the risks, you can start to mitigate them somewhat.

There is always a risk and E2E encrypted chat could still be made public, but it’s certainly less risk than some public forum with an unknown operator who may be doing anything with your data to fund their project, even if you are operating under some veil of anonymity. There is a chance the government’s mass surveillance data could be compromised, but it’s much more likely that dodgy service that provides you with free PPV films and sports will have their subscribers details made public. There is chance your slack logs may be subpoenaed, but there is a greater chance you’ll leave your PC or phone unattended and logged into slack.

Risk vs Reward, but make sure you understand ALL the risks. Not just the immediate ones.

My advice – Choose your tools and sites wisely, choose what you say online and who you say it to wisely and work with people like the Open Rights Group and EFF to ensure your right to privacy is a legally protected right.

InfoSec Posts

A change of circumstances means I am able to blog about InfoSec related topics again (having previously removed all the old posts) !

I’ll probably start with a few write-up of the InfoSec Pentest Challenges and CTFs I’ve done recently and them something on how to set up and ELK stack as a super-low-cost SIEM system.

I can also announce that I’m getting on the the Pentest Challenge Bandwagon by building my own VPN of hosts with simulated vulnerabilities, but in this case the novelty is that we’ll be focusing on long dead OSs such as VMS, OS/2, SCO Sys V, PR1MEOS etc. More news as it happens

Disneyland Paris 1/2 Marathon (Part 3 – Race Day)

So, race day. Firstly, having to wake up at 5am for a race is no fun, waking up in a Cars themed hotel room and having somebody interrupt your race-day prep to take pictures even less so, especially when you know the photographer is going back to sleep for another few hours, hence the grumpy/asleep face

img_20160925_055620594

This picture illustrates where mine and Dom’s attitude to the race had differed, he’d raised a load of money for charity, and was going to have a great time. I was now a club runner who was going to set a good time (or at least hoped to), so shorts and vest at 5am it was.

I say Dom was going to have a good time, he looked about as happy as I did about being awake at 5am, only he’d realised he was now going to spend the morning in a Tigger Onesie

14435000_10100307919091702_2871977039754512637_o

About half five I left the hotel room, and started scoffing down bananas, cakes and whatever else why lying around the hotel room (the hotels were all full of runners, but Disney didn’t think doing a pre-race breakfast shift in the restaurant would have been a good idea) as I walked the mile or so to the start I was joined by more and more runners

img_6099

and more

img_6100

and more

img_6101

It was only when I got to the back of my starting pen I began to realise just how many people were running

img_6105

Even though the planned start was over an hour and a half away, I could barely see the start line, so I slowly and gently worked my way forward.

I wasn’t much closer when the first runners went off, what’s worse an hour after the first runners had set off, I’d still only made it to here, but at least now I could see the start.

img_6107

As you can see, it was light by then!

The start(s) were also a little bizarre, they were breaking people off into groups or 20 or 30 and doing little countdowns to have a race-start with each group. I’m sure there was a practical reason for it, but just added to my annoyance as I was beginning to realise there was a real chance people would finish before I set off.

csztghfwgaav1ui

Now, like any sane person, my photos stop between start line and finish line. But this is Disney, this is not home of the sane. The first couple of miles wound through the park (before it was open) which was actually very very cool, but at every few hundred meters they had Disney characters you could have your pictures taken with and people where doing … and they were queuing for the privilege! It wasn’t just the characters, every km had a different Disney themed banner and people were queuing to take selfies with them too! I guess it’s a Disney thing, but I just didn’t see the point of adding 5 minutes to your finish time  just to get a pic of me stood next teenager is a giant Donald Duck costume.

It was pretty cool though. Every Disney ride, shop and attraction had it’s staff out front cheering people on and they were making a real effort,  thought I won’t pass comment on the fact that one of the biggest queues for pictures was actually as we were leaving the park through a maintenance exit and Disney’s own fire crew were there to cheer everyone one! What is it about firemen?

It was round about that point that I’d realised they’d screwed the start up more than I expected, as I’d been passing hundreds of runners, many already having to walk, then (not for the last time that day) I hear “alreet Glenn” from a giant West Yorkshire Tigger. Hang on I thought, even at the 3hr ETA I put on my form (that I was now expecting to smash), I should have been a long way ahead of Dom who was genuinely worried about the 16 min mile sweep vehicle (he didn’t  need to be as it happened). Had they really let blocks D and E go ahead of block C, it certainly seemed so!

Still, I was running against my own watch and setting off with a bunch of people running way slower than me (rather than faster, like normal) was probably exactly the start I needed.

As we left the environs of Disney itself, we headed off into some very typical and rather pretty French countryside. A hand full of marshalls and locals were scattered along the route, but I was generally enjoying the scenery (which was nice, even if it was a dual carriageway Disney bypass road). As with many races there were the odd jobbing bands at various points, but special note goes out to the two didgeridoo players accompanied by a human beatboxer, I lost a good couple of miles contemplating that one.

Whilst the main section of the course was a big loop leaving one side of the Disney site and re-entering the other, there were quite sizable sections that looped back on themselves, allowing you to see the runners coming the other way, several miles ahead/behind of you and whilst a staggeringly high number of runners were in fancy dress, I did spot a few traditional UK club running vests, in amongst the myriad of Minnie Mouses and Marvel Characters. I also saw Dom again, who was moving well, albeit a few miles behind me.

The drink stations were plentiful, well stocked, with little bags of surprisingly succulent slices of apple being a pleasant addition to the power bars and isotonic drinks.

About 9.5 miles saw us re-entering Disney environs again, by looping around almost all of the resort hotels, where I was given a bit of a lift by my wife and son taking advantage of the meandering route by popping up to cheer me along a three different points within about a mile and a half.

img_20160925_093853724

Sadly you don’t re-enter the actual main parks on your return (I understand the logistics of this make it impractical), so after a trip down the main Disney shopping Boulevard, it’s a sharp left back into the far less magical Expo Centre Parking Lot to the finish line, which was off limits to non runners. Again I understand the logistics, but after such amazing support on the way around, having virtually none for the last half mile felt odd.

Still, it didn’t matter to me, I’d done it! I’d got around! I wasn’t in an ambulance or a sweep car, I’d got around under my own steam. Then I looked at my watch, 2:12, MUCH quicker than I expected!

3EB46000-6206-408B-B294-B4019231CD69

There were 2 stings in the tail though, the first was in an attempt to make Disney more special that a normal half, they medal they dropped around you neck was more akin to a ships anchor! Trust me, after 12 miles, you felt every ounce.

img_6110r

Now the second sting, the more observant of you may have spotted, I certainly hadn’t at this stage

It was only after the adrenaline had worn off and I was back in my hotel room, about to jump into the bath ….. I’d forgotten the Vaseline and now both me and my new Pudsey Pacers vest were a bit of a bloody mess.

img_6111

So, in summary, it was special to me because mentally after that I consider myself a runner again, rather than a fat lad doing some jogging and the magic of Disney does as a certain something to events, but I can’t see it being one for seasoned runners who aren’t partial to the World of Disney.