Tag Archives: Coding

Violent Python: A cookbook for hackers

Python is pretty readable

A lot of security folks have little to no development experience, complicating their jobs when they want to do something that’s slightly different from what existing tools can do. Python provides a particularly useful tool for them because of its innate readability, support for multiple programming paradigms, and tremendous library of existing modules that we can adapt and connect to do new and interesting things. And for those of us with more extensive programming backgrounds in addition to our security skill sets, Python provides an excellent workbench for nearly any relevant task.

This book

Violent Python does not pretend in any way to teach readers how to program. In fact, when kicking off the brief section introducing the language itself, it flat-out refers to the reader “as an experienced programmer” (p. 6). However, a motivated hacker with limited exposure to Python can still follow along and pick things up relatively quickly, as VP doesn’t really use any particularly esoteric language features.

That said, it also does not necessarily require the reader to cover it linearly from page 1 to the end. The subtitle of the book, after all, calls it a “cookbook for hackers”, and it handles its end of the bargain. VP does not go into great detail for these projects but illustrates how to accomplish them relatively simply, primarily as inspiration for the reader who can then use the ideas and code as building blocks for self-driven projects.

I rarely like getting technology books in electronic format, and so I have the paperback copy. Given the complete lack of diagrams in this book, however, it wouldn’t matter as much in this case. The paper and printing quality seems relatively high; the papers have a smooth, creamy texture, and the book has wide margins that lend themselves very well to note taking and similar marginalia. While I’m not particularly a fan of the particular typeface used for code in the book, I didn’t find it so distracting as to make it impossible to work. As has become sadly common these days, the book contains a number of typographical errors and I really wish the publisher had put it through one more review iteration to catch them. Perhaps the companion site will eventually contain appropriate errata.

Contents

Chapter 2, “Penetration Testing with Python”, provides examples of how to perform a port scan (first using the socket API and then with nmap integration), brute forcing, using weaknesses in SSH key generation, injecting malicious IFRAMEs, interacting with Metasploit, and sending custom buffer overflow code over the network.

Chapter 3, “Forensic Investigations with Python”, discusses analyzing the history of wireless access points in the Windows registry (including geolocation), investigation of the Recycle Bin, examining metadata in various document types, and using application artifacts like SQLite databases in Firefox and Skype or iTunes Mobile.

Chapter 4, “Network Traffic Analysis with Python”, gets into better geolocation, packet parsing using dpkt and Scapy, KML generation, and analyzing various types of traffic like the LOIC DDOS tool, varying TTLs from spoofed port scans, and DNS fast-flux, and TCP sequence prediction. It also briefly covers generating packets to match IDS signatures.

Chapter 5, “Wireless Mayhem with Python”, reviews mining WiFi traffic for personal information like payment cards and authentication credentials, analyzing 802.11 probes and beacons, intercepting and hijacking UAV command traffic, detecting Firesheep use, and manipulate Bluetooth networks.

Chapter 6, “Web Recon with Python”, explains the Mechanize and BeautifulSoup libraries as well as using the Google and Twitter APIs, plus a small section on spear phishing.

Chapter 7, “Antivirus Evasion with Python”, covers how to use Pyinstaller to obfuscate a Metasploit payload from antivirus as well as how to check your code automatically against AV scanners.

Everyone codes. No one quits.

Chewbacca fighting Nazis on a giant squirrel.So FreeCause has an initiative to make all its employees learn how to code. Not that everyone will join in developing production code, but they have to learn the fundamentals. In their case, they use Codecademy which teaches JavaScript. Despite some of the bellyaching on Hacker News, this makes sense to me for a number of reasons.

  • This can help people understand the tools that could assist them with their normal day jobs as hey gain the confidence to look into writing scripts and macros. IT staff in particular frequently lack any coding (scripting) skills unless they are developers or Unix sysadmins.
  • They will have a better understanding of the web technologies they run across in their daily lives. This applies especially well to Codecademy users who learn JavaScript.
  • Learning to code teaches you to break a problem into parts and think analytically. We can probably all agree that our society could use more people with good critical thinking skills.
  • Everyone in an enterprise should have a core understanding of the elements of major functions. Yes, this means programmers should understand the very basics of finance and human resources and probably other areas that don’t occur to me at the moment.

There are two kinds of elitism: One is the belief that only the most informed and qualified individuals should make the decisions for a group. The other is the belief that those who do not belong to the “elite” have no business even dabbling in affairs beyond their supposed comprehension. The latter isn’t healthy to any organization, much less broader society, but walking a mile in your neighbor’s (or co-worker’s) shoes can have lots of positive effects.