How to Convert Threat Intelligence PDF into Text James Bower, September 2, 2009April 21, 2023 Here’s your guide to effortlessly convert threat intelligence from cumbersome PDFs (blah to work with), into easily accessible text, streamlining your cybersecurity analysis and response like never before! I’m sure like me you’ve been struggling to convert threat intelligence PDFs into text? Well I hear you friend. As you know my Python isn’t the greatest so this has taken me awhile to figure out. But all those lonely nights have paid off. Continue reading for how I did it.The PDF that I’m using is a threat assessment from the Senate Select Committee on Intelligence. Why? Because it sounds cool of course! And if I’m going to work on a project I at least want to feel like JaThe PDF that I’m using is a threat assessment from the Senate Select Committee on Intelligence. Why? Because it sounds cool of course! And if I’m going to work on a project I at least want to feel like James Bond doing it! I put it up on Dropbox so you can grab it yourself. I put it up on Dropbox so you can grab it yourself.https://bit.ly/41pNT2CLet’s look at a paragraph from the second page as our example for comparison. It’s pretty straight forward as far as text goes. It gets a lot more difficult when dealing with tables and images. But we’ll discuss that in another blog post.Here is the code I used and I pinned the version of pdfminer to help prevent any issues. I also did this in Python 2.5easy_install pippip install 'pdfminer==20080407'import sys import urllib from pdfminer.pdfparser import PDFParser from pdfminer.pdfdocument import PDFDocument from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter from pdfminer.converter import TextConverter from pdfminer.layout import LAParams from pdfminer.pdfpage import PDFPage from cStringIO import StringIO def download_pdf(url, file_name): urllib.urlretrieve(url, file_name) def convert_pdf_to_txt(file_path): rsrcmgr = PDFResourceManager() retstr = StringIO() codec = 'utf-8' laparams = LAParams() device = TextConverter(rsrcmgr, retstr, codec=codec, laparams=laparams) fp = open(file_path, 'rb') parser = PDFParser(fp) doc = PDFDocument(parser) interpreter = PDFPageInterpreter(rsrcmgr, device) for page in PDFPage.create_pages(doc): interpreter.process_page(page) fp.close() device.close() text = retstr.getvalue() retstr.close() return text pdf_url = "https://www.dropbox.com/s/e7ho2tentz3fns4/2009_threat_assessment_intelligence_subcommittee.pdf?dl=0" input_pdf = "input.pdf" output_txt = "output.txt" download_pdf(pdf_url, input_pdf) with open(output_txt, "w") as output_file: output_file.write(convert_pdf_to_txt(input_pdf))Here’s what it should look like now. You can we have some new line and spacing issues. Also some slight formatting issues. But overall I would say it looks pretty darn good and is definitely something we can work with moving forward.And there you have it! And here is the link to our new “text” file.https://www.dropbox.com/s/gsk1gieyihg3od0/threat_assessment.txt?dl=0I hope you have found this useful. This is something I’ve been wanting to figure out for some time now. Also make sure to keep coming back to my blog as I’m going to be putting out more threat intelligence posts here:https://www.jamesbower.com/category/threat-intelligence/And as always, thank you for taking the time to read this. If you have any comments, questions, or critiques, please reach out to me on our FREE ML Security Discord Server – HERE Text Analytics Threat Intelligence NLTKpdfminer
Threat Intelligence Threat Profile: Killer Swag June 13, 2017April 21, 2023Introduction I’ve been monitoring an interesting threat for the past several days, a group I’m referring to as “Killer Swag”. Mainly because the initial dropper is called “Swag.sh” and “Killer Swag” just sounds cool. In another life I think I would have been a marketing genius, but I digress. This… Read More
Security Tools DNS Enumeration Uncut: The Best Guide for Hackers April 17, 2016April 21, 2023DNS enumeration and DNS reconnaissance is a critical threat intelligence skill to learn. In literally every aspect of threat intel you will end up running into malicious domains. For me this most often occurs when working with threat intel from my honeynet. An example would be when I come across a… Read More
Entity Recognition Unlock the Potential of Text Analytics with Python NLTK March 1, 2016April 21, 2023Introduction Let’s start at the beginning. As businesses and organizations collect more data than ever, it’s essential to make sense of it so we can drive informed decision-making. Text Analytics is a subfield of Natural Language Processing (NLP) that analyzes unstructured or semi-structured text data. What is Text Analytics? Text… Read More