I've done this successfully, but you need to jump thru quite a few hoops. These instructions are for Kindle only. I think dedrm can cope with Nook encryption but I don't know how to do it. It was a while ago now, but to the best of my recollection:
Get yourself an older model Kindle. I used a Kindle 3 that I found at Goodwill for $20. You may have to rejig your home WiFi if your model doesn't support the right version of WPA.
Register it to your Amazon account somehow. IIRC, you have to try and fail to do it from the device, then Amazon will email you instructions.
Install Calibre and setup the dedrm plugin. It's pretty well documented.
Download what you want onto the Kindle. Pretty sure you have to use the Amazon website for this because of SSL issues on the older models.
Setup your Kindle with Calibre. This is also pretty easy and and well documented.
Grab the DRMed books off the Kindle into Calibre.
Run the conversion process in Calibre to remove DRM and convert to (for example) epub.
Optional: Jailbreak your Kindle and install KOReader to get a bit more value out of the obsolete brick you had to purchase to do this. This is a whole other set of hoops.
I'm not totally sure all this still works. You're honestly probably better off getting a Boox device and downloading stuff from Anna's Archive or similar.
Oh it's an absolute slog for sure. And I can't even guarantee it still works. I wouldn't have even tried if I didn't happen to chance upon a suitable device. Definitely wouldn't recommend paying eBay prices for one just to do this.
I managed to do it somehow without a kindle but it was an absolute pain in the ass. For my first few books I had to download then using a specific old version of the kindle desktop app so that calibre was able to remove the encryption. Apparently the encryption used by the newer kindle desktop app is different.
For my next books that suddenly wasn't enough and I had to use an old android app version in an emulator and get the books out of the hidden app storage using adb.
I'm never buying an ebook of amazon again if I can avoid it
I believe it sometimes works based on when the book was published for some reason and that newer books may have a better DRM protection against this method