daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Mar 18th, 2019 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2. import sys
  3. sys.path.insert(0, 'ModSecurity.cpython-35m-x86_64-linux-gnu.so')
  4. from ModSecurity import Rules
  5. from ModSecurity import ModSecurity
  6. from ModSecurity import Transaction
  7. from ModSecurity import ModSecurityIntervention
  8.  
  9. from os import listdir
  10. from os.path import isfile, join
  11. rule_files = [f for f in listdir('rules/') if isfile(join('rules/', f))]
  12.  
  13. modsec = ModSecurity()
  14. rules = Rules()
  15.  
  16.  
  17. request = {
  18.     "method": "GET",
  19.     "source_ip": "42.114.255.46",
  20.     "url": "/docs/index.html?a=%3Cscript%3Ealert%281%29%3C%2Fscript%3E&q=test",
  21.     "http_version": "HTTP/1.1",
  22.     "headers": {
  23.         "accept-encoding": "gzip, deflate",
  24.         "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36",
  25.         "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
  26.         "cookie": "cart=18",
  27.         "host": "35.201.157.47",
  28.         "upgrade-insecure-requests": "1",
  29.         "connection": "keep-alive",
  30.         "purpose": "prefetch",
  31.         "accept-language": "en-US,en;q=0.9"
  32.     },
  33.     "source_port": "24671",
  34.     "protocol": "tcp",
  35.     "params": {
  36.         "id": "<script>alert(1)</script>"
  37.     },
  38.     "body": ""
  39. }
  40.  
  41. for f in rule_files:
  42.     filename, file_extension = os.path.splitext('rules/' + f)
  43.     if file_extension == '.conf':
  44.         count = rules.loadFromUri('rules/' + f)
  45.  
  46.  
  47. def filter_request(request):
  48.     transaction = Transaction(modsec, rules, None)
  49.     transaction.processURI(
  50.         request['url'], request['method'], request['http_version'])
  51.     for key, value in request['headers'].items():
  52.         transaction.addRequestHeader(key, value)
  53.     transaction.processRequestHeaders()
  54.     run_intervention(transaction)
  55.  
  56.  
  57. def run_intervention(transaction):
  58.     intervention = ModSecurityIntervention()
  59.     if transaction.intervention(intervention):
  60.         print('Bad request')
  61.     print('Good request')
  62.  
  63.  
  64. filter_request(request)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top