What are opportunities for academic math outside of academia itself? I finished my PhD program in pure math a few years ago and have been in industry since then. I would love to continue my academic career, but (long story short) I was treated badly by my program and left with the doctorate but without a postdoc or much in the way of a publication record or connections (thus making the doctorate close to pointless) I haven't had much trouble finding jobs in software engineering or government labs, but I haven't found the work there to be interesting or satisfying.

Like pretty much everyone who goes into math, I love math for its own sake, and I love research. Is there anything available outside of academia where I could undertake something close to pure math research? Ideally, I'd like to beef up my publication record and make some connections, but a tech company doesn't seem to be the right place to do that. Although the jobs are certainly there, coding and engineering really aren't my things, and I'd like something more strongly related to math and more academic and research-oriented in nature.
If you are a US citizen living in the USA, you can work for NSA (which, if I recall correctly, is known to be the largest employer of mathematicians in the country) provided you pass their background check and satisfy their other requirements. However, your research will likely be classified, so you will not be able to publish it in the regular math journals. 

Should you happen to be in the UK, their counterpart of NSA is GCHQ. Many other countries also have similar organizations.