<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Cary Roys on Medium]]></title>
        <description><![CDATA[Stories by Cary Roys on Medium]]></description>
        <link>https://medium.com/@caryroys?source=rss-202615c96c2d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Cary Roys on Medium</title>
            <link>https://medium.com/@caryroys?source=rss-202615c96c2d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 04:22:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@caryroys/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Awesome HomeLab monitoring with Powershell]]></title>
            <link>https://medium.com/@caryroys/awesome-homelab-monitoring-with-powershell-fe814a0b65dc?source=rss-202615c96c2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe814a0b65dc</guid>
            <category><![CDATA[powershell]]></category>
            <category><![CDATA[prometheus]]></category>
            <category><![CDATA[pode]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[grafana]]></category>
            <dc:creator><![CDATA[Cary Roys]]></dc:creator>
            <pubDate>Sat, 18 Apr 2026 15:40:02 GMT</pubDate>
            <atom:updated>2026-04-18T17:24:47.439Z</atom:updated>
            <content:encoded><![CDATA[<p>As any reader of my Medium blog can probably guess, I have a homelab setup I work on some evenings and weekends.</p><p>The time had finally come where it was all working relatively well, and I should focus on monitoring. Since one of the goals of my homelab is to learn fundamentals without having a lot of things done for you in the cloud, I chose Prometheus + Grafana as my self-hosted components.</p><p>Prometheus is mainly a pull-based monitoring operation, where it gets its data from web services. So I needed to build some web services. You might guess where I’m going from here…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/0*YDcFPrYbrWHqpNr2.jpg" /></figure><p>My “lever” of choice is Powershell.</p><p>How does one write web services in Powershell? At work, I’d invoked some .Net socket classes to create a really simple web server for certain repro cases, but that was going to be a lot work to expand on that. Plus, I’m sure some weird nerd already had done that work already.</p><p>I quickly found the <a href="https://www.powershellgallery.com/packages/Pode/2.12.0">Pode </a>package. Pode is a Powershell based web server, which lets you define web services. Perfect fit!</p><p>The basic pattern is to bind to an address and port and protocol:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*iT2-1IrtcjKRxE96lpKpkw.png" /></figure><p>And then add a script which maps to a URI path:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*7Vp8_yNrNQX_ZNeG6AYctw.png" /></figure><p>Now — there’s some extra things you have to do… Pode is smart in that they didn’t just take the output stream of the script block and write it to the client browser, they have a dedicated cmdlet for it <strong>Write-PodeTextResponse.</strong></p><p>In our case, we have the special metrics format that Prometheus expects. I added a couple of helper functions which get inherited by my scripts which I map to URI paths:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/494/1*r0g0mgqMd3N5QHKPTH5cqQ.png" /></figure><p>As part of my scripts which execute when the URI is called, I just have a simple Metrics array which holds my PSCustomObjects with defined fields for the Prometheus metrics and associated labels:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*EqGvNCZcCB2UpPS0o2CScQ.png" /></figure><p>The real challenge I ran into was calling Window’s Get-Counter cmdlet for every value I wanted. The reason being — this grabs every counter on every call, and filters the results back to you. This took so long for every metric, Prometheus would time out on requests.</p><p>The solution was a single call to populate a collection of values, and then read out the values when needed via helper function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*R7Mbqs115o4JXUkjO-ywmg.png" /></figure><p>Now we’re cooking. No more timeouts.</p><p>At this point, I had functioning web services I could point Prometheus at, and all the metrics and labels needed to start dashboarding with Grafana.</p><p>I’ve got all kinds of stuff now, including pulling information out of my gateway router via SSH, doing traceroutes for network health monitoring and status of running services, CPU/Memory/NUMA usage/Disk IO and network ingress/egress bytes for router and various servers.</p><p>…But there’s a problem:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BZlx3LmAhSdWIRPEkzjo_g.png" /></figure><p>We keep ending up in this state where we are missing data points.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AQqcph1Fv3Uqf8zpTYl2mQ.png" /></figure><p>We can see our pode script ends up chewing up 4gb+ of memory, and requests start timing out, hence the missing data points:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*gw4piwuhjb3-GcidMG7P6w.png" /></figure><p>It’s not due to lack of memory — I have over 200gb free on this machine. A restart seems to resolve the issue, but it may be back within a few days I’ve found.</p><p>It’s not every service call which bogs down, which is the weird thing. I went back to look at my code, trying to see if I missed something. It took me a while to spot it, since I had some working assumptions about how Powershell worked under the hood with scriptblocks.</p><p>It’s this bit, which is all over my scripts:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*EqGvNCZcCB2UpPS0o2CScQ.png" /></figure><p>The += operator has the same problem in Powershell that it does in regular .Net: it creates a copy of the array to be garbage collected later, instead resizing the current array. So you’re at the mercy of garbage collection behavior, which may or may not work in your favor — either way, it’s a memory leak. This is the kind of stuff most powershell scripters never have to worry about — since your script runs and exits and you’re not running powershell.exe for months or years at a time.</p><p>In retrospect, I should have known better, since my scripts were inheriting my helper functions — a clue that we had a session and associated memory that wouldn’t just magically go away when the script was done executing.</p><p>So anyways, I switch to a generic list:</p><blockquote>[System.Collections.Generic.List[pscustomobject]]::new()</blockquote><p>…and use the Add() method.</p><p>And things look a ton better — after letting it run overnight, memory has only climbed to 400mb. It goes up, it goes down, but it’s not the huge persistent growth we were seeing before.</p><p>I think there’s other optimizations I can do, like explicit cleanup at the end of the script:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/163/1*DkPQmyej3PMleNDt53khkg.png" /></figure><p>This might be “good enough for government work”, but for production ready uses, you’ll want to definitely audit your scripts for ways to free up memory at the end of your Pode scripts.</p><p>Lastly — how are we going to run this Pode stuff as a service? The same way most people <a href="https://guides.hakedev.com/wiki/windows/prometheus-service/">run Prometheus as a service</a> on Windows — using the <a href="https://github.com/dkxce/NSSM">Non-Sucking Service Manager</a>.</p><p>It’s a beautiful thing once this setup works:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*s4W6XRZgDL35uUSgY9ptvg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe814a0b65dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A working example of JellyFin Automation — AI Redux]]></title>
            <link>https://medium.com/@caryroys/a-working-example-of-jellyfin-automation-ai-redux-2458b360837a?source=rss-202615c96c2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2458b360837a</guid>
            <category><![CDATA[powershell]]></category>
            <category><![CDATA[jellyfin]]></category>
            <category><![CDATA[claude-code]]></category>
            <category><![CDATA[automation]]></category>
            <dc:creator><![CDATA[Cary Roys]]></dc:creator>
            <pubDate>Sun, 01 Mar 2026 17:18:27 GMT</pubDate>
            <atom:updated>2026-03-03T23:05:57.510Z</atom:updated>
            <content:encoded><![CDATA[<p>About 2 years ago now, I <a href="https://medium.com/@caryroys/a-working-example-of-jellyfin-automation-196d72bf4542">wrote an article</a> out of frustration about how poor the API docs were on JellyFin, and how there was no working examples.</p><p>A lot of people read that article! I was quite surprised. In the interim I started putting all the helper functions I wrote into a Powershell module to share — but never got all that far with it and never got around to publishing it. I just got a bunch of my automation scripts working, added the functions to my own private module and called it a day.</p><p>A lot of things in Tech have happened since I wrote that last article. More than just me rebuilding my JellyFin server twice…</p><p>So — some things of note:</p><p>It is totally possible to figure things out yourself, using the API Spec located here: <a href="https://api.jellyfin.org/">https://api.jellyfin.org/</a></p><p>It <em>does</em> mention an authorization header for the API key — funny enough not the one that the UI uses which I mentioned in my previous article, it’s <strong>X-Emby-Authorization</strong> which you stick the API key in instead of <strong>X-MediaBrowser-Token </strong>like the UI uses. And this API Spec doc <em>has</em> been around since 2021, but it’s a long read, and there’s no code samples which implement it. That’s my excuse anyways. Certainly not that I hadn’t found it! Perish the thought…</p><p>More importantly, generative AI has come a <em>long</em> way. I decided I was going to finally try out Claude Code Pro, which I’d been reading near-supernatural things about for some time.</p><p>So — I signed up, installed the VSCode plugin, and fed it in the latest API spec and told it to “Write me a powershell module of this API spec” — off to the races we went!</p><p>As I expected, there was some “Missing Manual” types of things — functions which were written to spec, but didn’t work because there was extra things you had to do. There also was a lot of little things I had to try again or manually fix, like renaming functions to match between the core module and the unit tests, and also fixing a bunch of missing things in the unit tests. It also got query parameters wrong which require comma delimited items. Lastly — I had to have it read through api.jellyfin.org and take another pass at the documentation, and add validatesets for parameters and make sure the inline docs were filled out.</p><p>The biggest “missing manual” item was trying to get an auth token using a username/password instead of using an API key. This straight up just didn’t work if you followed the spec.</p><p>The key was of course that it requires an extra Authorization header which has a big blob of characters:</p><blockquote>Authorization: MediaBrowser Client=”Jellyfin Web”, Device=”Chrome”, DeviceId=”TW96aWxsYS81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzEzNS4wLjAuMCBTYWZhcmkvNTM3LjM2fDE3NDY4NDgxMzE1Nzc1&quot;, Version=”10.11.3&quot;</blockquote><p>So, of course, we have to figure out what it is, and then reproduce it. This was easy enough — after a while, you learn to eyeball what Base64 looks like and just decode it. We can see clearly it’s just the user-agent string, and some unique identifier pipe delimited:</p><blockquote>Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36|17468481315775</blockquote><p>Apparently, the large number is <em>not</em> epoch time, but some Device Identifier that JellyFin uses to track the client? I just couldn’t figure out how to get JellyFin to spit out my client’s identifier, so I just generated one using UTC time in Microseconds — helpfully suggested by Claude, in keeping with the rest of this exercise:</p><blockquote># Generate a Jellyfin-like numeric suffix (13–17 digit monotonic ID)</blockquote><blockquote># Using current time in microseconds for Jellyfin-style uniqueness — a random ID is as good as anything</blockquote><blockquote>$MicroSeconds = [int64]([DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds() * 1000 + (Get-Random -Minimum 0 -Maximum 1000))</blockquote><blockquote># Combine to produce a Jellyfin-style DeviceId string</blockquote><blockquote>$DeviceIdString = “$UserAgent|$MicroSeconds”</blockquote><p>Works just fine!</p><p>The hardest part of this whole exercise was getting all of the unit tests to actually run successfully.</p><p>Now — without further ado — I have put the fruits of my labor out on <a href="https://github.com/CaryRoys/PSJellyFin/blob/main/README.md">GitHub </a>and <a href="https://www.powershellgallery.com/packages/PSJellyFin/0.1.0">Powershell Gallery</a>.</p><p>Did I actually test all these functions to make sure they worked? Nah. Just the ones I had already implemented in my own private module, and the ones I obviously knew I needed a closer look at.</p><p>Actually <em>testing</em> all the code AI spits out is not the Vibe Coder’s way. ;)</p><figure><img alt="Honoring the memory of Mr. Kirk with the kind of hot take he was known for — stupid and bad." src="https://cdn-images-1.medium.com/max/693/1*A7FfIEDNdsuezr8TgxeN_w.png" /><figcaption>We’re going to come back to building tests for this module later…</figcaption></figure><p>Now — there’s a reason I’ve put the repo out on <a href="https://github.com/CaryRoys/PSJellyFin">GitHub</a>. So if there are issues (and there will be), we can fix them.</p><p>Let’s take a look at what my previous automation sample looks like with the new module now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*N3xDA09WUXDgxE_88YIuhA.png" /></figure><p>Pretty similar, actually. But now — username and password login works, and it no longer requires passing around the authentication PSCustomObject, as it stores the session info.</p><p>All things considered, really nice! I have a lot of work to do now reworking my various automation scripts to make sure that Claude got the implementation right. I hope anyone using this module will make sure to create an issue or pull request so we can improve this and make it more usable.</p><p>For now… I’ve published it for all to use out on <a href="https://github.com/CaryRoys/PSJellyFin">GitHub </a><a href="https://www.powershellgallery.com/packages/PSJellyFin/0.1.0">as well as PowerShell Gallery</a> so you can just <em>install-module</em> it from the ether.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9W79KJqkhoFyYQOwUYkl4w.png" /><figcaption>Behold: PSJellyFin Module</figcaption></figure><p>Enjoy!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2458b360837a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The moment I knew widescreen TV’s were the future and not a fad]]></title>
            <link>https://medium.com/@caryroys/the-moment-i-knew-widescreen-tvs-were-the-future-and-not-a-fad-b7f866e3f51b?source=rss-202615c96c2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7f866e3f51b</guid>
            <category><![CDATA[widescreen]]></category>
            <category><![CDATA[crt]]></category>
            <category><![CDATA[x-men]]></category>
            <dc:creator><![CDATA[Cary Roys]]></dc:creator>
            <pubDate>Fri, 16 May 2025 04:20:41 GMT</pubDate>
            <atom:updated>2025-05-30T14:53:28.609Z</atom:updated>
            <content:encoded><![CDATA[<p>I sometimes notice small details. Stuff sticks out to me sometimes. I’m good at finding Waldo.</p><p>I was recently mulling over the march of technology, how some developments prove to be passing fads, and some have real staying power. Is Virtual Reality mainstream yet? Discuss.</p><p>I was reminded of my college years. Widescreen TV’s were something people were buying, as well as the HD TV versions. Flat plasma displays, that sort of thing. Fancy TV’s for fancy people.</p><p>…But was widescreen TV a fad, or the way of the future? It sounds like a weird thing to consider now — of course it’s the future. Movies are filmed in widescreen and historically had to be mangled severely to fit on a standard 4:3 display.</p><p>I didn’t have a strong opinion on it. I liked the basic idea of widescreen — because you could watch movies closer to as they were intended to be viewed (1.85:1 or 2.39:1 usually — which can be shown nicely on a 16:9 display).</p><p>But there was a moment when I knew it would become the standard. It was the first X-Men movie, released in 2000. There is a scene where Senator Kelly washes ashore after being transformed into a mutant. You can watch the whole clip:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F4QTEsu51ZeI%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D4QTEsu51ZeI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F4QTEsu51ZeI%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e12d5776e96538aad5ad5add23964191/href">https://medium.com/media/e12d5776e96538aad5ad5add23964191/href</a></iframe><p>…Or instead, you can just check out this freeze-frame:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vRjv0RYQCD6u3fZexrBRRw.png" /></figure><p>Boom: A CRT 16:9 TV on the vendor’s cart. Nevermind I’ve never seen a vendor on beach with a TV (or even A vendor on a beach with a cart), what’s important is that 20th Century Fox <em>chose</em> to depict this small detail — a TV on a food cart — as a widescreen TV and not the TV’s which were in almost all of our living rooms at the time which had an aspect ratio of 4:3.</p><p>I showed this to my wife, and her take was, “That is the kind of detail you <em>would</em> notice”.</p><p>But think about it — the intent behind this decision in the film. Did the filmmakers care about what kind of TV was shown? Probably not. They have no skin in the game, really. This almost certainly had to be the decision of a film executive, in much the same vein as product placement happens. (And it does! Ever noticed how the laptops shown in TV shows and films are almost always bearing the logo of one of the 2 most valuable companies in the world — Microsoft and Apple?)</p><p>Yes — this was a statement. This is the future, get used to it. We’re cluing you into it.</p><p>It’s true — it was the future! You saw it here first — in 2000.</p><p>It gets a little more strange before we’re done. So I decided I should see if I could find the model of TV on display here — but was unable to. There’s just no widescreen CRT on the market I could find from the era which looks like it! Let’s get a closer look at it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/1*bfoPtBY_5G5hAFL-gFQ-RQ.png" /></figure><p>Pretty fuzzy. I sought out a Blu-ray copy of the film which yielded a slightly better picture (full disclosure: after some level adjustment to tease out detail):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/1*rqvuxVjN3zv8oJUElebyEA.png" /></figure><p>So first up — it looks like the video is just composited onto the set. I guess fair enough.</p><p>But also — it much more clearly looks like a 4:3 TV with some stuff attached to it to make it look like a widescreen TV. Like, on the inside of the bezel, it looks like they’ve added some sort of dummy shim. They went to a lot of effort for this shot!</p><p>Try as I might, I couldn’t actually find any model of TV which looks like this. Either it’s just lost to antiquity, or they fabricated a fake TV just to make it look widescreen. Wild!</p><p>Maybe someone else will have better luck than I.</p><p>The take-away is clear though: the film studio went to *a lot* of effort to depict a widescreen TV.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7f866e3f51b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IP Cam password recovery]]></title>
            <link>https://medium.com/@caryroys/ip-cam-password-recovery-f76def9f07ab?source=rss-202615c96c2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/f76def9f07ab</guid>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[passwords]]></category>
            <category><![CDATA[ip-camera]]></category>
            <dc:creator><![CDATA[Cary Roys]]></dc:creator>
            <pubDate>Sat, 04 Jan 2025 16:51:14 GMT</pubDate>
            <atom:updated>2025-01-04T17:04:42.394Z</atom:updated>
            <content:encoded><![CDATA[<p>I had a recent project where I wanted to (basically) put a Power-over-Ethernet camera into an upside-down fishbowl, and sink it underwater to livestream the goings-on of the fishes in the river out back of my house.</p><p>So — I didn’t want to spend a whole lot of money on this project, if I was just going to end up zapping the camera if I made a mistake in fabricating the setup. Good underwater cameras are hundreds (or thousands) of dollars — so that was out too. A cheap camera it was going to be!</p><p>For about ~30 USD, I picked up an old PoE IP Cam off eBay, a <a href="https://www.trendnet.com/products/surveillance-camera/indoor-2mp-1080p-hd-wdr-mini-pan-tilt-poe-ir-network-camera-TVIP410PI">Trendnet TV-IP410PI</a>.</p><p>Unfortunately… It was used, and had a non-default password on it. The seller wasn’t sure what to do about it.</p><p>The manufacturer has a password reset request function built in, where you can send them a file pulled off the device, and they will send you a new file to reset the password using the Camera utility, but since this particular camera has been out of support for so long, I wasn’t sure my chances of that.</p><p>Besides, this could be a fun project!</p><p>I noticed that the UI of the tool was showing me plenty of details about the camera, and even the old IP assigned to it. So I was able to connect to it, even with a wrong IP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oJLXIgczuSl50X0_68Np6Q.png" /></figure><p>So of course, to understand what’s going on, I had to have a look with Wireshark.</p><p>As you can see, attempting to update the config with the management app sends 2 UDP broadcast packets to the magic broadcast IP: 239.255.255.250, and then gets a response:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*ah3QDYl6SYHvufQSzfEGhg.png" /></figure><p>So what is it sending? Wellp, the whole UDP payload is an XML blob in cleartext:</p><blockquote>&lt;?xml version=”1.0&quot; encoding=”utf-8&quot;?&gt;<br>&lt;Probe&gt;<br> &lt;Uuid&gt;5B70168C-77CA-40CA-AD3B-25794E04D85D&lt;/Uuid&gt;<br> &lt;Types&gt;update&lt;/Types&gt;<br> &lt;MAC&gt;3c-8c-f8-a1–92–91&lt;/MAC&gt;<br> &lt;Password&gt;ISMvKXpXpadDiUoOSoAfww==&lt;/Password&gt;<br> &lt;IPv4Address&gt;10.40.47.205&lt;/IPv4Address&gt;<br> &lt;CommandPort&gt;8000&lt;/CommandPort&gt;<br> &lt;HttpPort&gt;80&lt;/HttpPort&gt;<br> &lt;IPv4SubnetMask&gt;255.255.255.0&lt;/IPv4SubnetMask&gt;<br> &lt;IPv4Gateway&gt;10.40.47.1&lt;/IPv4Gateway&gt;<br> &lt;IPv6Address&gt;::&lt;/IPv6Address&gt;<br> &lt;IPv6Gateway&gt;::&lt;/IPv6Gateway&gt;<br> &lt;IPv6MaskLen&gt;0&lt;/IPv6MaskLen&gt;<br> &lt;DHCP&gt;false&lt;/DHCP&gt;<br>&lt;/Probe&gt;</blockquote><p>This is awesome! That password is clearly Base64 encoded, and seeing Base64 usually means they didn’t invest a whole lot of effort in making the thing secure.</p><p>Now, the length of the hash gives me a sneaking suspicion of what this is likely to be, but I also for good measure did the lazy thing and ran it through the <a href="https://hashes.com/en/tools/hash_identifier">Hash Identifier tool</a> which just told me my gut was probably right. It’s most likely just MD5 base64 encoded.</p><p>So I break out the old Powershell ISE and tinker a little bit. The above XML file was from trying out a password of “admin”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*08lWs8RHu8hFm5sUow0JTA.png" /></figure><p>And there we go! Easy enough. MD5?? What year is it? Lazy security folks in 2008 were at least using SHA1 (itself long considered not secure in our modern age), but MD5 has had known vulnerabilities since around the time Season 3 of <em>Friends </em>aired.</p><p>Anyways… We now understand (roughly) how to test if our password is correct or not. We send an XML blob with the appropriate details, and then listen for the response — all tunneled through the magic broadcast address. Helpfully the camera sends us back another XML message to tell us the password is wrong:</p><blockquote>&lt;?xml version=”1.0&quot; encoding=”UTF-8&quot;?&gt;<br>&lt;ProbeMatch&gt;&lt;Uuid&gt;F5EC31D4–124C-4E0C-9040-E01B549E2644&lt;/Uuid&gt;<br>&lt;Types&gt;update&lt;/Types&gt;<br>&lt;Result&gt;failed&lt;/Result&gt;<br>&lt;/ProbeMatch&gt;</blockquote><p>I should mention at this point that one thing which had me suspecting this might not be as easy as just sending some UDP packets from PowerShell and brute forcing the camera password was the fact that the camera software which configures the camera required you to install <a href="https://en.wikipedia.org/wiki/Pcap#WinPcap">WinPCap</a>. That’s a sign that they have to do something lower level that Windows wouldn’t normally allow them to do.</p><p>Well, I quickly found out what that was.</p><p>I tried out a <a href="https://stackoverflow.com/questions/12148666/send-and-receive-data-via-udp-in-powershell">few </a><a href="https://gist.github.com/PeteGoo/21a5ab7636786670e47c">code </a>samples to try and send an XML UDP message, and then listen for the response from the camera. No dice — Wireshark didn’t even show any packets going out. I found some guy suggesting that Windows 7 changed how the network stack worked, and certain broadcast addresses didn’t seem to work anymore (indeed, many people reported other broadcast addresses worked, but not the one I was trying to use, which is commonly used for <a href="https://en.wikipedia.org/wiki/Simple_Service_Discovery_Protocol">SSDP</a>).</p><p>I don’t know the full story, but that’s enough story for me — and the explanation for why Trendnet is shipping WinPCap with their Camera admin tools. This also makes sense of why they include a UUID in the XML messages — because the app listens in Promiscuous mode and you have to know how to map a request to a response since you get *all* packets.</p><p>So it looks like we also have to use WinPCap to do the same, and send traffic Windows doesn’t want to let us send to the magic broadcast address. It seems like there’s a <a href="https://github.com/PcapDotNet/Pcap.Net">Nuget package</a> of a nice .Net wrapper, and plenty of <a href="https://github.com/PcapDotNet/Pcap.Net/wiki/Pcap.Net-Tutorial-Opening-an-adapter-and-capturing-the-packets">code </a><a href="https://github.com/PcapDotNet/Pcap.Net/wiki/Pcap.Net-Tutorial-Sending-Packets">samples </a>to get you started.</p><p>I’m on a relatively new laptop which I’ve mostly used for gaming so far, so I download <a href="https://visualstudio.microsoft.com/vs/community/">Visual Studio Community edition</a>, and ~45gb of downloads later… I start putting together a simple tool to send these messages to the camera, and read the response.</p><p>Let’s fast forward through to where we have a working forms app, which lets us test it all out:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*ovuo43rGkm2y8sG9wkQiEA.png" /><figcaption>(I do love a good quick-and-dirty forms app!)</figcaption></figure><p>The sample code was pretty good, and it was no more than a few hour’s effort to get working. Now comes the actual password recovery.</p><p>Password cracking basically comes down to picking the most sensible way of generating and testing passwords given what you know about the target. The more you know about the target, the more shortcuts you can take and shorten the amount of time you spend trying out passwords. There’s really not that many parameters… So given the <a href="https://www.trendnet.com/download_manager/default.asp?iFile=31794">User Manual</a>, let’s review what we know:</p><p><strong>Previous owner</strong>: Unknown — no wordlist focus is obvious</p><p><strong>Retry limit</strong>: None seemingly</p><p><strong>End-To-End password test time</strong>: ~70ms</p><p><strong>Password Length</strong>: 8–16 characters</p><p><strong>Password charset</strong>: a-z,A-Z,0–9,!@#$</p><p>Some quick math (charset ^ length) suggests given these constraints that the min/max possible passwords are:</p><p><strong>Min</strong>: 66 ^ 8 = 360,040,606,269,696</p><p><strong>Max</strong>: 66^ 16 = 129,629,238,163,050,258,624,287,932,416</p><p>Given the end-to-end time it takes to validate a password, we can at maximum test ~1,234,300 passwords per day. There is a lengthy and boring discussion about how we can remove some network latency, but it’s just not worth having… It’s got marginal returns for anything reasonably easy and cheap to do.</p><p>So it looks like we’ll be using a wordlist, and hoping the previous owner picked a simplistic password. Given our relatively slow rate of password attempts, this will be smallish wordlists we’re trying out. <a href="https://github.com/kkrypt0nn/wordlists/tree/main/wordlists/passwords">This guy out on GitHub</a> seems like he has some very reasonable sized wordlists, so I’ll be trying a few of these first.</p><p>So I now sit here, waiting… To see if Trendnet support gets back to me first, or if I will find the password all on my own.</p><p>Hopefully this is useful to someone else as well! Check it out on my GitHub:</p><p><a href="https://github.com/CaryRoys/CameraStreamingTools/tree/main/CrackTrendnet">CameraStreamingTools/CrackTrendnet at main · CaryRoys/CameraStreamingTools</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f76def9f07ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting complex objects out of Powershell host in C#]]></title>
            <link>https://medium.com/@caryroys/getting-complex-objects-out-of-powershell-host-in-c-bf8fcec4ad99?source=rss-202615c96c2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf8fcec4ad99</guid>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[powershell]]></category>
            <dc:creator><![CDATA[Cary Roys]]></dc:creator>
            <pubDate>Thu, 26 Dec 2024 17:22:59 GMT</pubDate>
            <atom:updated>2025-01-13T13:13:43.525Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*QdX1IF1vv_-HXOf6sywebA.png" /></figure><p>Every now and then I run into a problem which seemingly is unsolved.</p><p>I am sure plenty of people have solved it, just nobody wrote down the solution anywhere I can find it. So here we are — I’m writing down my use case, and how I worked around it.</p><p>First up: What am I trying to do?</p><p>I am writing a little C# forms app which is a nice wrapper around using a user’s credentials via SSO to authenticate to some various webpages, and then use the auth tokens to call the REST API’s which populate the site content. Essentially — extracting data from a website which doesn’t let you export that information. From there, I’m putting the data into a database and visualizing it with PowerBI.</p><p>Now — since I am writing this for people who may not possess the same appetite or aptitude for writing C# code, I wanted to delegate the calling and scraping of web content to Powershell, which is far more fast and forgiving, and also has the benefit of browser dev mode having a “copy as Powershell” option which does a fair bit of work for you.</p><p>For this to work, I need a way of getting data out of a Powershell script and into memory in my C# app to work with it.</p><p>Simple stuff is old hat — you can add parameter values for the script like this:</p><blockquote>PowerShell ps = PowerShell.Create();</blockquote><blockquote>ps.AddScript(scriptBody);</blockquote><blockquote>ps.AddParameter(“samplevalue”, “myvalue”);</blockquote><p>Returning values is easy as well — the Powershell.Invoke() method just returns a collection of PSObjects which you can walk. This article provides a pretty good overview:</p><p><a href="https://stackoverflow.com/questions/10106217/how-would-i-return-an-object-or-multiple-values-from-powershell-to-executing-c-s">https://stackoverflow.com/questions/10106217/how-would-i-return-an-object-or-multiple-values-from-powershell-to-executing-c-s</a></p><p>There’s some issues, of course…I should note I’m using .Net 8.0 and the System.Management.Automation 7.4.6 nuget package here. My first observation is that I got a lot of other stuff returned in the object collection (such as each DataRow I created, and any other parameters in scope), so I had to find a way of being selective.</p><p>The above article recommended using a HashTable, which lets me be selective based on type name (the object.TypeNames[0] gives you the type you can use). But — a funny thing happened, in every time I tried to access the appropriate value for my DataTable, it looked like it was calling ToString() on every DataRow, and I was just getting a big long string like:</p><blockquote>System.Data.DataRow System.Data.DataRow System.Data.DataRow System.Data.DataRow</blockquote><p>Well, that is obnoxious. It turns out this is <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_return?view=powershell-7.4">related to the behavior of “Return” and functions</a>, but I went ahead anyways with the following solution.</p><p>Here’s my solution — using a Ref type to pass by reference. It took some trial and error to figure it out, but now I am successfully passing a DataTable by reference and having my Powershell populate it with columns and records.</p><p>C#:</p><blockquote>DataTable resultsTable = new DataTable();</blockquote><blockquote>PSReference refDT = new PSReference(resultsTable);</blockquote><blockquote>ps.AddParameter(“resultstable”, refDT);</blockquote><blockquote>ps.Invoke(); //DataTable has records at this point</blockquote><p>Powershell:</p><blockquote>param($samplevalue,[ref]$resultstable)</blockquote><blockquote>$resultstable.Value.Columns.Add(“Id”)</blockquote><blockquote>$resultstable.Value.Columns.Add(“Value1”)</blockquote><blockquote>$resultstable.Value.Columns.Add(“Value2”)</blockquote><blockquote>$resultstable.Value.Columns.Add(“Value3”)</blockquote><blockquote>1..10 | % {</blockquote><blockquote>$row = $_</blockquote><blockquote>$row.Value1 = “$_ Four score and seven years ago”</blockquote><blockquote>$row.Value2 = “$_ our fathers brought forth on this continent”</blockquote><blockquote>$row.Value3 = “$_ a new nation, conceived in Liberty”</blockquote><blockquote>$resultstable.Value.Rows.Add($row)</blockquote><blockquote>}</blockquote><p>If you’ve never used Powershell ref types, start <a href="https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_ref?view=powershell-7.4#writing-functions-to-accept-reference-parameters">here</a>.</p><p>This is a ton easier than untangling whatever the heck is going on with the values I’m trying to pass back via a return statement.</p><p>Hope this is useful to someone!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf8fcec4ad99" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A working example of JellyFin automation]]></title>
            <link>https://medium.com/@caryroys/a-working-example-of-jellyfin-automation-196d72bf4542?source=rss-202615c96c2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/196d72bf4542</guid>
            <category><![CDATA[jellyfin]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[powershell]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Cary Roys]]></dc:creator>
            <pubDate>Sat, 30 Dec 2023 03:33:21 GMT</pubDate>
            <atom:updated>2023-12-31T18:58:46.362Z</atom:updated>
            <content:encoded><![CDATA[<p>A while back, I discovered the open-source fork of <a href="https://emby.media/">Emby</a>, “<a href="https://jellyfin.org/">JellyFin</a>” and decided to check it out. I had been using a DLNA server for many years, because most device manufacturer’s with streaming capabilities did not build into the device the ability to just load a file off a SMB Share. DLNA, of course, <a href="https://gxben.wordpress.com/2008/08/24/why-do-i-hate-dlna-protocol-so-much/">sucks</a>. This had just started to change, with a build of VLC being available for Android and XBox, but it crashed a lot and was a little clunky (although it did happily play media off SMB and NFS shares!).</p><p>For those which are unaware, <a href="https://emby.media/">Emby</a> basically lets you run your own Netflix-like service from a box sitting in your living room. With a little more work, you can stream it on the go across the internet just like Netflix. That seemed really up my alley!</p><p>So I set about setting up <a href="https://jellyfin.org/">JellyFin</a>. It was not too hard to install and configure, but there was a lot of things which I had to figure out to get it just how I wanted it.</p><p>One of the biggest things for me was being able to create collections of my various media, based on a folder structure. <a href="https://jellyfin.org/">JellyFin</a> doesn’t really like to do this… But then I learned it had a REST API.</p><p>Unfortunately, the official docs were out of date, or just plain wrong — to the extent that the docs existed on the REST API at all.</p><p>I found a lot of Reddit threads (generally outdated), and even some amazingly useless medium articles <a href="https://medium.com/@divitia/an-introduction-to-jellyfin-api-10bf386e1be7">like this one</a>.</p><p>So here we go — I’m just going to provide a dump of what I figured out based on the many threads out there, as well as just using Browser Dev Mode to sniff out how the JellyFin UI does things. Browser Dev Mode is probably how everyone manages to figure it out anyways…</p><h3>Powershell to the rescue</h3><p>Powershell is my weapon of choice when writing automation. It’s really flexible and forgiving and lets you gloss over a lot of stuff and focus on solving the actual problem, instead of the quirks of the language itself. There’s built-in functionality for <em>a ton of stuff</em>, so you don’t even usually find yourself struggling with dodgy third party libraries.</p><h3>Authentication</h3><p>You’ll see this in my comments — authentication via API key is largely undocumented. The secret sauce is really simple: Stick it into the <strong>X-MediaBrowser-Token </strong>header value.</p><p>In my helper functions I use a PSCustomObject so I don’t have to pass around so many parameters:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*x3w_5wjgbeJLmtFogCbkMA.png" /></figure><p>You’ll note I’m using the UserID as part of the URI — this is the same thing the JellyFin UI does as you’re interacting with things. To obtain your UserId, just go to user in the dashboard of JellyFin — the ID will be in the URI when you’re viewing the profile:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/1*6g5Lkz-9PX1veUWAUwdEAg.png" /></figure><h3>Hierarchical Basics</h3><p>Before we dive into the API, let’s get some basics down.</p><p>JellyFin Views are what you see when at the top when you log in:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j_SUkcjoLXhgeVAsqbfFpg.png" /></figure><p>A collection is just a container underneath the “Collections” view, which can contain media of any type. You can really go nuts with this, mixing and matching movies, music, folders of media, etc.</p><p>Everything in JellyFin has a unique identifier associated with it, which the various REST API’s need to do something with those things.</p><h3>Helper Function: Get the ID of a given view</h3><p>One of my patterns I like to use in Powershell is breaking out of a foreach loop when I find the thing I’m looking for. I could use where-object to select the exact right one, but this foreach pattern leaves the object in memory after the loop is done so I can inspect it.</p><p>I also am of the opinion that when you’re writing a script which n00bs may want to pick up and use, that it’s better to try to keep to the basic coding structures instead of language-specific “sugar”. It makes it a lot easier for newbies to understand how you’re doing things. Anyways, here goes… It takes the AuthInfo PSCustomObject for authentication and the name of a view, and passes back the unique ID of the matching view (if none matches it throws an exception so you know what went wrong):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*eZRwr5zWQPcxnaaExdTOWQ.png" /></figure><h3>Helper Function: Get the ID of a given Collection</h3><p>This is just about the same as the former helper function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NwCKZ9dCK_Vob7LI5bpfyQ.png" /></figure><h3>Helper Function: Get the items in a collection</h3><p>Don’t ask me why I used <em>Invoke-WebRequest</em> here and then deserialized the JSON via C<em>onvertFrom-Json</em>, instead of calling <em>Invoke-RestMethod</em>. I don’t remember. I’m sure I had a good reason, but it was 2am.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a_usmuvU014dmHyj3p9sOg.png" /></figure><h3>Helper Function: Get all items of a certain type</h3><p>Notice how I have “ParentId” commented out? This lets you scope to a specific item (like a view, or a collection, or the top-level item for a TV show or media folder). This wasn’t what I wanted to do, though, so I found the ‘Recursive’ parameter, because I wanted *everything* inside the view regardless of its parent item.</p><p>I discovered if I didn’t recurse, I wouldn’t get any items which lived in a subfolder on the disk. What’s strange is the views seem to conceal the subfolders as discrete objects, but they show up when walking the views and collections via the API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DWP-nPurqAGa4tR1XRWuRw.png" /></figure><h3>Helper Function: Add an Item to a Collection</h3><p>With all the other helper functions, I have everything I need: Media ID, Collection ID, View ID, etc. for calling into my “Add to Collection” function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RybG5kGPMRwputH951eQOQ.png" /></figure><p>Note that if an item already belongs to a collection, this performs a “no-op” and returns an HTTP 204 return code. 204 is also returned when the item does not already belong to the collection — so there’s little sense in checking first to see if it is in the collection or not, just blindly add it.</p><h3>Putting it all together</h3><p>My end goal in this automation script was to take the folders on disk, and use them as the criteria for populating various collections. I could have created collections using the API, but I didn’t have that many I wanted to create — and using the API for collection creation means things could get a little hairy if I messed up while coding or debugging and have to clean up a bunch of collections I didn’t want…</p><p>This little bit of script does a lot of stuff for us! In this case, if the media path contains ‘Discworld’ in it, it adds to the media item to a collection of the same name:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*pm2_4N-Kn-PpRv9aSU_zIw.png" /></figure><p>So there we have it! AN ACTUAL WORKING EXAMPLE OF THE JELLYFIN API.</p><p>That wasn’t so hard, was it guys?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=196d72bf4542" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>