Commit 58ac4e12 authored by Philipp's avatar Philipp

fixed system calls for archivers to not bail out when receiving multiple arguments

parent 5c12a07f
......@@ -22,6 +22,7 @@ Simple BBS upload checker written in python
* 7z
* arj
* tar
* clamd
## Installation
Download to your desired destination path. In this example, this will be
......
#!/usr/bin/python
#
# CHKR v0.2
#
# (C)opyright 2017-2019 by Philipp Giebel <stimpy@kuehlbox.wtf>
# Licensed under GPL v3
#
# CHKR is a simple BBS upload checker written in python
# It does:
# - Scan for viruses
# - Inject files (eg your bbs ads)
# - Removes unwanted files (eg other bbs ads)
#
# More info: https://www.kuehlbox.wtf/chkr
#
from __future__ import print_function
from subprocess import call
from time import sleep
......@@ -28,26 +43,27 @@ ARJ = '/usr/bin/arj'
TAR = '/usr/bin/tar'
# Archiver Options
DELZIPARGS = '-qqd'
DELRARARGS = 'd -ep -idq'
DEL7ZARGS = 'd'
DELARFARGS = 'd q9'
DELGZARGS = '-dzf'
DELBZ2ARGS = '-djf'
DELXZARGS = '-dJf'
ADDZIPARGS = '-uqqj'
ADDRARARGS = 'u -ds -ep -idq'
ADD7ZARGS = 'u -bd'
ADDARJARGS = 'u -e q9'
ADDGZARGS = '-uzf'
ADDBZ2ARGS = '-ujf'
ADDXZARGS = '-uJf'
DELZIPARGS = ['-qqd']
DELRARARGS = ['d', '-ep', '-idq']
DEL7ZARGS = ['d']
DELARJARGS = ['d', 'q9']
DELGZARGS = ['-dzf']
DELBZ2ARGS = ['-djf']
DELXZARGS = ['-dJf']
ADDZIPARGS = ['-uqqj']
ADDRARARGS = ['u', '-ds', '-ep', '-idq']
ADD7ZARGS = ['u', '-bd']
ADDARJARGS = ['u', '-e', 'q9']
ADDGZARGS = ['-uzf']
ADDBZ2ARGS = ['-ujf']
ADDXZARGS = ['-uJf']
# ANSI sequences
ACLR = '\033[2J'
ASAVE = '\033[s'
ARESTORE = '\033[u'
WHITE = '\033[37m'
ansi_home = base64.b64decode( 'G1swOzQwOzM3bRtbNkMbWzFt29vb29/b2yDb2yDb29vbINvb29sg29sg29vf29vb2w0KIBtbMzBt'+
'3Nvf3yAbWzM3bdvb29sgICAg29sg29vb2yDb29vbINvbINvbINvb29sgG1szMG3f39/f39/f39/f'+
......@@ -169,39 +185,41 @@ def deleteUnwanted( filename ):
FNULL = open(os.devnull, 'w')
if ( ext.lower() == 'zip' ):
try:
ret = call( [ ZIP, DELZIPARGS, filename ]+REMOVE, stdout=FNULL, stderr=FNULL, shell=False )
ret = call( [ ZIP ]+DELZIPARGS+[ filename ]+REMOVE, stdout=FNULL, stderr=FNULL, shell=False )
if ( ret == 12 ):
ret = 0
except:
ret = 254
elif ( ext.lower() == 'rar' ):
try:
ret = call( [ RAR, DELRARARGS, filename ]+REMOVE, stdout=FNULL, stderr=FNULL, shell=False )
ret = call( [ RAR ]+DELRARARGS+[ filename ]+REMOVE, stdout=FNULL, stderr=FNULL, shell=False )
if ( ret == 1 ) or ( ret == 10 ):
ret = 0
except:
ret = 254
elif ( ext.lower() == '.7z' ):
try:
ret = call( [ Z7, DEL7ZARGS, filename ]+REMOVE, stdout=FNULL, stderr=FNULL, shell=False )
ret = call( [ Z7 ]+DEL7ZARGS+[ filename ]+REMOVE, stdout=FNULL, stderr=FNULL, shell=False )
except:
ret = 254
elif ( ext.lower() == 'arj' ):
try:
ret = call( [ ARJ, DELARJARGS, filename ]+REMOVE, stdout=FNULL, stderr=FNULL, shell=False )
ret = call( [ ARJ ]+DELARJARGS+[ filename ]+REMOVE, stdout=FNULL, stderr=FNULL, shell=False )
except:
ret = 254
elif ( ext.lower() == '.gz' ):
try:
ret = call( [ TAR, DELGZARGS, filename ]+REMOVE, stdout=FNULL, stderr=FNULL, shell=False )
ret = call( [ TAR ]+DELGZARGS+[ filename ]+REMOVE, stdout=FNULL, stderr=FNULL, shell=False )
except:
ret = 254
elif ( ext.lower() == 'bz2' ):
try:
ret = call( [ TAR, DELBZ2ARGS, filename ]+REMOVE, stdout=FNULL, stderr=FNULL, shell=False )
ret = call( [ TAR ]+DELBZ2ARGS+[ filename ]+REMOVE, stdout=FNULL, stderr=FNULL, shell=False )
except:
ret = 254
elif ( ext.lower() == '.xz' ):
try:
ret = call( [ TAR, DELXZARGS, filename ]+REMOVE, stdout=FNULL, stderr=FNULL, shell=False )
ret = call( [ TAR ]+DELXZARGS+[ filename ]+REMOVE, stdout=FNULL, stderr=FNULL, shell=False )
except:
ret = 254
......@@ -215,24 +233,26 @@ def addAds( filename ):
FNULL = open(os.devnull, 'w')
if ( ext.lower() == 'zip' ):
try:
ret = call( [ ZIP, ADDZIPARGS, filename ]+ADDFILES, stdout=FNULL, stderr=FNULL, shell=False )
ret = call( [ ZIP ]+ ADDZIPARGS +[ filename ]+ADDFILES, stdout=FNULL, stderr=FNULL, shell=False )
if ( ret == 12 ):
ret = 0
except:
ret = 254
elif ( ext.lower() == 'rar' ):
try:
ret = call( [ RAR, ADDRARARGS, filename ]+ADDFILES, stdout=FNULL, stderr=FNULL, shell=False )
ret = call( [ RAR ]+ADDRARARGS+[ filename ]+ADDFILES, stdout=FNULL, stderr=FNULL, shell=False )
if ( ret == 1 ) or ( ret == 10 ):
ret = 0
except:
ret = 254
elif ( ext.lower() == '.7z' ):
try:
ret = call( [ Z7, ADD7ZARGS, filename ]+ADDFILES, stdout=FNULL, stderr=FNULL, shell=False )
ret = call( [ Z7 ]+ADD7ZARGS+[ filename ]+ADDFILES, stdout=FNULL, stderr=FNULL, shell=False )
except:
ret = 254
elif ( ext.lower() == 'arj' ):
try:
ret = call( [ ARJ, ADDARJARGS, filename ]+ADDFILES, stdout=FNULL, stderr=FNULL, shell=False )
ret = call( [ ARJ ]+ADDARJARGS+[ filename ]+ADDFILES, stdout=FNULL, stderr=FNULL, shell=False )
except:
ret = 254
FNULL.close()
......@@ -285,17 +305,17 @@ for filename in args.filenames:
ansiHL( 'error! ', 62, 8, 1 )
error += 4
if ( '{0:04b}'.format(error)[1:2] == '1' ):
errors.append( filename +': '+errordescription[2] )
errors.append( filename +': '+errordescription[2] + ' ('+str(ret)+')' )
else:
warnings.append( filename +': '+errordescription[2] )
warnings.append( filename +': '+errordescription[2] + ' ('+str(ret)+')' )
else:
ansiHL( 'found! ', 62, 8, 1 )
os.rename( filename, QUARANTINE+'VIRUS_'+filename )
error += 8
if ( '{0:04b}'.format(error)[0:1] == '1' ):
errors.append( filename +': '+errordescription[3] )
errors.append( filename +': '+errordescription[3] + ' ('+str(ret)+')' )
else:
warninngs.append( filename +': '+errordescription[3] )
warninngs.append( filename +': '+errordescription[3] + ' ('+str(ret)+')' )
else:
ansiHL( 'skipped ', 62, 8 )
......@@ -304,15 +324,15 @@ for filename in args.filenames:
ansiHL( 'working ', 62, 10 )
ret = deleteUnwanted( filename )
if ( ret == 0 ):
if ( ret == 0 ):
ansiHL( 'success ', 62, 10, 2 )
else:
ansiHL( 'error! ', 62, 10, 1 )
error += 1
if ( '{0:04b}'.format(error)[3:4] == '1' ):
errors.append( filename +': '+errordescription[0] )
errors.append( filename +': '+errordescription[0] + ' ('+str(ret)+')' )
else:
warnings.append( filename +': '+errordescription[0] )
warnings.append( filename +': '+errordescription[0] + ' ('+str(ret)+')' )
else:
ansiHL( 'skipped ', 62, 10 )
......@@ -327,9 +347,9 @@ for filename in args.filenames:
ansiHL( 'error! ', 62, 12, 1 )
error += 2
if ( '{0:04b}'.format(error)[2:3] == '1' ):
errors.append( filename +': '+errordescription[1] )
errors.append( filename +': '+errordescription[1] + ' ('+str(ret)+')' )
else:
warnings.append( filename +': '+errordescription[1] )
warnings.append( filename +': '+errordescription[1] + ' ('+str(ret)+')' )
else:
ansiHL( 'skipped ', 62, 12 )
......@@ -345,15 +365,17 @@ for filename in args.filenames:
ansiRESTORE()
if ( len(errors) >= 1 ):
sys.stderr.write( 'There were errors processing your file(s):' )
sys.stderr.write( WHITE+"There were errors processing your file(s):\n" )
for e in errors:
sys.stderr.write( '- '+e+"\n" )
sys.stderr.write( "\n" );
sys.exit(2)
if ( len(warnings) >= 1 ):
sys.stderr.write( 'There were warnings processing your file(s):' )
sys.stderr.write( WHITE+"There were warnings processing your file(s):\n" )
for w in warnings:
sys.stderr.write( '- '+w+"\n" )
sys.stderr.write( "\n" );
sys.exit(1)
sys.exit(0)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment