Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Finding Vulnerabilities with Bandit

Kevin London
September 24, 2015

Finding Vulnerabilities with Bandit

Security is tough. It’s so easy to forget something or get a couple of things wrong. The stakes have also never been higher - announcements about a company getting hacked come out weekly. So what can we do?

One part of the solution is tooling. OpenStack’s security team created Bandit to help them solve the problem of doing security reviews on 18+ projects. It’s an open source tool that we can use to scan our code and find out if we’re calling insecure or deprecated functions.

In these slides, I cover some of my findings from running Bandit on 16 popular open-source Python projects as well as some of the potential security flaws that Bandit can identify.

I originally gave this talk at a SoCal Python meetup.

Kevin London

September 24, 2015
Tweet

More Decks by Kevin London

Other Decks in Programming

Transcript

  1. Two kinds of big companies: 1. Those that have been

    hacked 2. Those who don’t know they have been hacked
  2. >> Issue: Use of assert detected. The enclosed code will

    be removed when compiling to optimised byte code. 70 @percent.setter 71 def percent(self, value): 72 assert value >= 0 73 assert value <= 100 Assertions
  3. >> Issue: Audit url open for permitted schemes. Allowing use

    of file:/ or custom schemes is often unexpected. 165 try: 166 conn = urllib2.urlopen(request) Opening URLs
  4. >> Issue: Requests call with verify=False disabling SSL certificate checks,

    security issue. 206 resp = requests.get(uri, verify=False) Requests
  5. 87 # Create ECC privatekey 88 proc = subprocess.Popen( 89

    “openssl -genkey -out %s" % key_path, 90 shell=True, 91 ) Shell Commands
  6. >> Issue: subprocess call with shell=True identified, security issue. 87

    # Create ECC privatekey 88 proc = subprocess.Popen( 89 “openssl -genkey -out %s" % key_path, 90 shell=True, 91 ) Shell Commands
  7. >> Issue: Use of insecure and deprecated function (mktemp). 291

    listpath = tempfile.mktemp(“.tmp") Temporary Files
  8. >> Issue: Using ElementTree.fromstring to parse untrusted XML data is

    known to be vulnerable to XML attacks. Replace with its defusedxml equivalent function. 47 root = ElementTree.fromstring(content) Loading XML
  9. <?xml version="1.0"?> <!DOCTYPE lolz [ <!ENTITY lol "lol"> <!ELEMENT lolz

    (#PCDATA)> <!ENTITY lol1 "&lol;&lol;&lol;&lol;&lol;&lol;"> <!ENTITY lol2 "&lol1;&lol1;&lol1;&lol1;&lol1;"> <!ENTITY lol3 "&lol2;&lol2;&lol2;&lol2;&lol2;"> <!ENTITY lol4 "&lol3;&lol3;&lol3;&lol3;&lol3;"> <lolz>&lol4;</lolz> Loading XML Billion Laughs Attack
  10. >> Issue: Use of unsafe yaml load. Allows instantiation of

    arbitrary objects. Consider yaml.safe_load(). 446 yamlFile = open(yamlPath) 447 regexes = yaml.load(yamlFile) Deserializing
  11. Deserializing >> Issue: Pickle library appears to be in use,

    possible security issue. 42 def loads(self, value): 43 return pickle.loads(value)
  12. Deserializing >> Issue: Deserialization with the marshal module is possibly

    dangerous. 89 def unpack_db_value(self, val): 92 return marshal.loads(val)