Snake Bites: Python for Pentesters

c0c0n 2013

28 September 2013

AI Generated Summary

AI Generated Content Disclaimer

Note: This summary is AI-generated and may contain inaccuracies, errors, or omissions. If you spot any issues, please contact the site owner for corrections. Errors or omissions are unintended.

Python for Web Pen-testers (Snake bites) was presented at c0c0n 2013. The deck introduces working web penetration testers to Python’s practical side: why the language fits security tooling, the modules worth learning first, live builds of small tools for CMS fingerprinting, XSS fuzzing, and SVN extraction, and how to package the results so they run anywhere from laptops to Android phones.

Summary

The talk set the scope up front: the presentation is only focused on Python, with no comparisons to other languages, the idea is to give a regular web penetration tester a head start with the functionalities available in Python, and there is no new tool release in the deck. The why slide made the case: an easy and flexible language, a massive module base allowing use cases to be written in a small timeframe and codebase, inbuilt language support in tools like Burp and IRONWASP, API support from OWASP-ZAP, room for custom application logic, or simply just for the fact that you can do it. A slide of existing tools anchored the claim, running from w3af and sqlmap through Scapy, Canvas, Sulley, and Peach to SpikeProxy, ProxyStrike, wapiti, and MyNav Idapython.

Variations got a warning slide: Cython, Jython, and IronPython exist, and Python 2.X versus 3.X must be treated as two different things. The module tour then covered three workhorses. Requests replaces urllib2 as the HTTP handler, deals with the http or https transition internally, and exposes a simpler interface: requests.get, with r.text or r.content for the body, r.status_code, and r.headers. BeautifulSoup parses text and HTML, demonstrated by finding each div with class attachment to enumerate WordPress attachments from a fetched page. Argparse builds quick command-line programs with options and switches, shown with a required –url argument and a –debug store_true flag.

Three scenario demos followed. Regular expression pattern matching fingerprinted CMS platforms from page content: a regex keyed on wp-content inside stylesheet link tags detected WordPress, and one keyed on sites/default/themes or all in link and style tags detected Drupal. A simple XSS fuzzer read payloads from a file, URL-encoded each row, requested the target URL with the payload appended, and printed any row that came back reflected in the response. The SVN extractor, published at github.com/anantshri/svn-extractor with a write-up on the blog, pulls all web resources from .SVN folders exposed over a network.

The closing material covered distribution and learning. PyInstaller packages every dependency into a single executable for one-click sharing without a Python dependency, and Python for Android puts Python 2.7 on the phone through SL4A, removing the ssh-or-laptop restriction. The learning path listed Learn Python the Hard Way, Dive into Python, SPSE or other online certification courses, Violent Python, and Grey-hat Python, plus daily use and the inbuilt hooks in IRONWASP inline scripting and Burp extensions, with thanks recorded to the null community members who sharpened the material.

Key Themes

Notable Points

  1. Scope slide: Python only with no language comparisons, aimed at giving a regular web penetration tester a head start, and explicitly no new tool release.
  2. Variations named: CPython, Jython, IronPython, with Python 2.X and 3.X called out as different.
  3. Requests sample interface: requests.get for the call, r.text/r.content for content, r.status_code, and r.headers, with the module internally handling the http or https transition.
  4. BeautifulSoup demo: import requests, from BeautifulSoup import BeautifulSoup, fetch http://www.anantshri.info, then soup.find(‘div’,{‘class’:‘attachment’}) to search for each div with class attachment.
  5. Argparse sample: a parser with –url as a required argument (dest target) and –debug as a store_true action flag.
  6. CMS fingerprinting regexes: WordPress matched on ‘<link rel=“stylesheet” [^>]+wp-content’ and Drupal on ‘<(?:link|style)[^>]+sites/(?:default|all)/(?:themes|modules)/’, checked against fetched page content with re.search.
  7. The XSS fuzzer read payloads from xss.txt, encoded each row with urllib.quote, requested the URL with the payload appended, and printed the row when it appeared in the response content.
  8. SVN extractor published at github.com/anantshri/svn-extractor extracts all web resources from .SVN folders exposed over the network, with the write-up at blog.anantshri.info/svn-extractor-for-web-pentesters.
  9. PyInstaller packages every dependency into a single executable package, for code shipped as a one-click executable without a Python dependency.
  10. Python for Android: Python 2.7 installable on Android with android-specific features accessible through SL4A, so ssh or a laptop are no longer restrictions; the learning list added Learn Python the Hard Way, Dive into Python, SPSE or online courses, Violent Python, Grey-hat Python, daily use, IRONWASP inline scripting, and Burp extensions.

Notable Quotes

“Presentation is only focused on python. (No comparisons with other languages please)”

“Idea is to introduce a regular web penetration tester with various functionalities available in Python and give them a head start”

“There is no new tools release”

“JUST FOR THE FACT THAT YOU CAN DO IT”

“PyInstaller packages every dependency into a single executable package”

“Ssh or laptop are not the restrictions now.”