Skip to content

Instantly share code, notes, and snippets.

@aiwilliams
Created October 22, 2013 14:50
Show Gist options
  • Save aiwilliams/7102105 to your computer and use it in GitHub Desktop.
Save aiwilliams/7102105 to your computer and use it in GitHub Desktop.
Generating suggested whitelists for Naxsi Web Application Firewall from multiple error logs. This assumes you want a distinct set for each log.
#!/usr/bin/env ruby
require 'fileutils'
nx_dir = 'naxsi-rules.d'
rules_dir = 'etc/nginx/naxsi'
FileUtils.mkdir_p nx_dir
Dir['var/log/nginx/*.error.log'].each do |log_path|
log_name = File.basename(log_path, '.error.log')
db_path = File.join nx_dir, "#{log_name}.naxsi.sqlite"
rules_path = File.join rules_dir, "#{log_name}-generated.rules"
`nx_util.py -l #{log_path}* -d #{db_path}`
`nx_util.py -o -d #{db_path} -c nx_util.conf > #{rules_path}`
end
[nx_util]
data_dir=/usr/local/nx_datas
database_dir=
naxsi_core_rules=etc/nginx/naxsi_core.rules
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment