diff options
| author | jvoisin | 2011-06-25 19:06:55 +0200 |
|---|---|---|
| committer | jvoisin | 2011-06-25 19:06:55 +0200 |
| commit | 321b024daee08992495a80e2f998a5913c5b0a49 (patch) | |
| tree | e2a26b8e3c411764b1aadb1878b2ee60103a5e0c /lib | |
| parent | 9ebc62273ec8abfc4520660597fa80fe3de40203 (diff) | |
Add a binding to shred. Rudimentary protection against shell injection.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/mat.py | 9 | ||||
| -rw-r--r-- | lib/parser.py | 7 |
2 files changed, 6 insertions, 10 deletions
| @@ -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 | ||
| 42 | def create_class_file(name, backup): | 39 | def 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 | |||
| 7 | import hachoir_editor | 7 | import hachoir_editor |
| 8 | import sys | 8 | import sys |
| 9 | import os | 9 | import os |
| 10 | import shutil | 10 | import subprocess |
| 11 | 11 | ||
| 12 | POSTFIX = ".cleaned" | 12 | POSTFIX = ".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 | ||
