summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjvoisin2011-06-25 19:06:55 +0200
committerjvoisin2011-06-25 19:06:55 +0200
commit321b024daee08992495a80e2f998a5913c5b0a49 (patch)
treee2a26b8e3c411764b1aadb1878b2ee60103a5e0c
parent9ebc62273ec8abfc4520660597fa80fe3de40203 (diff)
Add a binding to shred. Rudimentary protection against shell injection.
-rw-r--r--lib/mat.py9
-rw-r--r--lib/parser.py7
2 files changed, 6 insertions, 10 deletions
diff --git a/lib/mat.py b/lib/mat.py
index 156c683..732dc25 100644
--- a/lib/mat.py
+++ b/lib/mat.py
@@ -31,20 +31,17 @@ def is_secure(filename):
31 ''' 31 '''
32 Prevent shell injection 32 Prevent shell injection
33 ''' 33 '''
34 if not(os.path.isfile(name)): #check if the file exist 34
35 if not(os.path.isfile(filename)): #check if the file exist
35 print("Error: %s is not a valid file" % name) 36 print("Error: %s is not a valid file" % name)
36 sys.exit(1) 37 sys.exit(1)
37 filename.strip('\s') #separations
38 filename.strip('`') #injection `rm / -Rf`
39 filename.strip('\$(.*)')#injection $(rm / -Rf)
40 filename.strip(';')#injection $filename;rm / -Rf
41 38
42def create_class_file(name, backup): 39def create_class_file(name, backup):
43 ''' 40 '''
44 return a $FILETYPEStripper() class, 41 return a $FILETYPEStripper() class,
45 corresponding to the filetype of the given file 42 corresponding to the filetype of the given file
46 ''' 43 '''
47 #is_secure(name) 44 is_secure(name)
48 45
49 filename = "" 46 filename = ""
50 realname = name 47 realname = name
diff --git a/lib/parser.py b/lib/parser.py
index 12ef15a..c7e189e 100644
--- a/lib/parser.py
+++ b/lib/parser.py
@@ -7,7 +7,7 @@ import hachoir_parser
7import hachoir_editor 7import hachoir_editor
8import sys 8import sys
9import os 9import os
10import shutil 10import subprocess
11 11
12POSTFIX = ".cleaned" 12POSTFIX = ".cleaned"
13 13
@@ -23,10 +23,9 @@ class Generic_parser():
23 ''' 23 '''
24 securely remove the file 24 securely remove the file
25 ''' 25 '''
26 #FIXME : not secure at all ! 26 #FIXME : Vulnerable to shell injection ?
27 try: 27 try:
28 shutil.rmtree(self.filename) 28 subprocess.call('shred --remove %s' % self.filename, shell=True)
29 #shutil.subprocess('shutil' , '--remove', 'self.filename')
30 except: 29 except:
31 print('Unable to remove %s' % self.filename) 30 print('Unable to remove %s' % self.filename)
32 31