Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed handling of Weka data files

The burp CLI script can now be run from any location.
The Weka model and training set are now located in the burp package.
burp.py now uses a temporary file to store the test-set ARFF data.
  • Loading branch information...
commit bccc84e8f5c02813031b5d185ea7b3cdaa1c37da 1 parent 366546f
@eromba eromba authored
View
7 burp/__init__.py
@@ -1,2 +1,9 @@
__all__ = ['url', 'html']
+import os
+import burp
+
+def getWekaFile(filename):
+ packageDir = burp.__path__[0]
+ return os.path.join(packageDir, 'weka', filename)
+
View
0  weka/J48.model → burp/weka/J48.model
File renamed without changes
View
0  weka/training_set.arff → burp/weka/training_set.arff
File renamed without changes
View
31 scripts/burp
@@ -5,15 +5,22 @@
# Usage: burp [URL]
##
-import sys, os, re, requests, arff
+# System packages
+import sys, os, tempfile, re
from subprocess import Popen, PIPE, STDOUT
+
+# Contributed packages
+import requests
+import arff
+
+# BURP packages
+import burp
from burp.html import HTMLAnalyzer
from burp.url import getTokens
from burp.url import getIpAddr, getWhoIs
-WEKA_MODEL = 'weka/J48.model'
-WEKA_TRAINING_SET = 'weka/training_set.arff'
-WEKA_TEST_SET = 'weka/test_set.arff'
+WEKA_MODEL = burp.getWekaFile('J48.model')
+WEKA_TRAINING_SET = burp.getWekaFile('training_set.arff')
if not len(sys.argv) == 2:
print("Usage: burp [URL]")
@@ -84,7 +91,7 @@ if whois is not None:
analysis[key] = str(value)
##
-# Export Feature Analysis to ARFF File
+# Export feature analysis to temporary ARFF file
##
arffData = dict(
@@ -120,9 +127,10 @@ arffData = dict(
analysis['domain_length']
]]
)
-testSetFile = open(WEKA_TEST_SET, 'w')
-arff.dump(testSetFile, arffData)
-testSetFile.close()
+wekaTestSet = tempfile.NamedTemporaryFile(suffix='.arff')
+arff.dump(wekaTestSet, arffData)
+# Return the file pointer to the beginning of the file for reading
+wekaTestSet.seek(0)
##
# Invoke Weka to classify the URL
@@ -133,7 +141,7 @@ p = Popen(['java',
'weka.classifiers.misc.InputMappedClassifier',
'-L', WEKA_MODEL,
'-t', WEKA_TRAINING_SET,
- '-T', WEKA_TEST_SET,
+ '-T', wekaTestSet.name,
'-M', # Suppress the output of the mapping report
'-classifications', 'weka.classifiers.evaluation.output.prediction.CSV'],
stdout=PIPE,
@@ -158,5 +166,6 @@ else:
classification = 'BENIGN'
print(url + ' is ' + classification)
-# Delete the generated ARFF file
-os.remove(WEKA_TEST_SET)
+# Delete the temporary ARFF file
+wekaTestSet.close()
+
View
3  setup.py
@@ -8,6 +8,9 @@
version = '0.1',
packages = find_packages(),
scripts = ['scripts/burp'],
+ package_data = {
+ '': ['weka/*']
+ },
test_suite = 'burp.html.tests',
install_requires = [
'requests>=0.14.2',
Please sign in to comment.
Something went wrong with that request. Please try again.