Python Web Security

General Web Libraries

  • urillib

  • uribil2

  • urllib3

  • httplib

  • httplib2

  • Requests (Best)

    • Supports Authentication (Basic,Digest,Kerberos,NTLM,AWS,OAuth1)

    • Handles SSL

    • Export specific header

      • r.headers['server'], r.headers['user-agent']

General Security Libraries

  • scapy (interacting with packets)

  • nmap (network scanner)

  • bs4 (scrape information from web pages)

  • yara (finds patterns within data by strings or regex patterns) (Made by VirusTotal)

Examples

GET request and print response (Request lib)

GET request and Basic Authentication (Request lib)

Py2 - GET request and Basic Authentication (urrlib2 lib)

POST request

HTTPS GET request with invalid cert

Timing username harvesting attack

Use case: Testing timing username harvesting attack against Login page, knowing login (1 letter first name, last name) pattern, we go through alphabet + list of last names we got from OSINT against login page. Script will print request roundtrip time + username so we can see if site is vulnerable to attack.

Forced Directory script

Use case: Script runs through aaa through zzz (17,576 requests) and tries to directory brute force. Will return code and url if a 200 or else is found.

Drupalgeddon python exploit made by Vitalii Rudnykh https://github.com/a2u/CVE-2018-7600

Basic Authentication Brute Force

References

ByteScout's Python Web Sec: https://bytescout.com/blog/python-tutorial-web-app-security.html

Last updated

Was this helpful?