From 91abb6b143753fe4ad58caacced64b5cef8471ae Mon Sep 17 00:00:00 2001 From: shubhamj99 Date: Fri, 8 Oct 2021 01:58:53 +0530 Subject: [PATCH] Scanning malicious files before upload --- .DS_Store | Bin 0 -> 6148 bytes requirements.txt | 1 + src/__pycache__/info.cpython-39.pyc | Bin 0 -> 1333 bytes src/__pycache__/mailer.cpython-39.pyc | Bin 0 -> 3094 bytes src/mailer.py | 45 ++++++++++++++++++++------ 5 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 .DS_Store create mode 100644 src/__pycache__/info.cpython-39.pyc create mode 100644 src/__pycache__/mailer.cpython-39.pyc diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..d1539cf37af70403aeba90f0580419fd8d3c8570 GIT binary patch literal 6148 zcmeHK%Z}496uoW>lN2E;ghV$;*{~~BJA)8iAZ0r3q7ooP5G(-AG)ZAtJi`hw;uD<4a+TD)rXB=>-K8lAoWKT`O>Q=q?TDfckWw z9O@UcKNPY}dWg(@%ySRe#Jao!<9mTo!|CSJD<~0&XpCA!8B}Vbd_!5DUpg-E%g9V< zl+P0CeO^;fWx2C-qBQ>MPQoC~TCH!aRIZ#mzhf9xqk6IW+&PJ7PBzS@X?K`B<+TUH z?8H^^qc{$K#Y6XT;Li?gR}SJR8wQb|2y)>0NO|@oh`e~#ji-^9ig6s-VHl=i9@gsf z`R?sb!`f?i77c6O*=;qfn|rqw3)8rIy?tkJG(LShf46x55etSfTn54}DO|xP1ZsJ& zog@n5h)cA}US(Kp~z0zzUj$A?CjX zoMS1p6)q*B2gW27D5*?6F_@&I-BNkB!lgt>C#D`BOwG*H3x$ce3w{LW#`BgE1qFq=jzz$) d;yPRy`Yav*ZG}sTXo2Y;0U?7fv;tdI;3sv(w7&oV literal 0 HcmV?d00001 diff --git a/requirements.txt b/requirements.txt index d55b14e..5fe820d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -82,3 +82,4 @@ watchdog==2.1.5 wcwidth==0.2.5 webencodings==0.5.1 widgetsnbextension==3.5.1 +cloudmersive-virus-api-client \ No newline at end of file diff --git a/src/__pycache__/info.cpython-39.pyc b/src/__pycache__/info.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c9d16a4f3a337136056c87dcaa8bb2b35f5f2432 GIT binary patch literal 1333 zcmeHHO>WdM6i%j{nex+i3p-0JU<6Lu=`fu^2vJo)Sx_pqLIQ*$Pwbgk^~90wG@7dH zI0fPYoPiz3$d)6pgALDiO1nUa1K`9?oP6(nexKhnSzWyvK>PSAAzzn+;G3OXZY`KR zhOV!}Km!_n2;Ky=br|%P(hxqKH;d~)--WJkz(7OVqDyp{wrS^6`+ay8o&`4puI1=uW{3zOEA(tmxVWv++oOytiVlb}Xs0OjyE~aN#e+Dmsw$dEITI{Oz6y*^_G3eTD(_M1JR^coC7s}(la&(4an e$KQT0bk7T4{_P6G2h#aT4ql>YMXu`T7cfmJA=h&(X8?FrNL6P1bjVO z<_ps+CnQ?o%Y5Z%l?4w8NUlO#<0~ihghtmsC#=DmF9>Tsx1!gWy-T{Se}V_3OLcoF zvO>lEQIV>wEI{H7xRl8O-vQp={>AoZd;FOKzJ>huC|B7q5hyT|pCpn4-~9P7`|MfD zhjS(F(C8h%b$|c<#{Ikdx7Ydm>D~2v8+Sff|M1R-ch^6-^FG^P_mbQDcQ+yzc0c0B zDcW@LvtjTtH2Dq?P9n+(#FH}X1&M6tGl$h)P>8h4Jdo6kXLapvCt1!#>cFPc4|&wK z2~EBZq@opxNo4^AZfaHb2}*26AUbrX>u7fXYBHw%VIt+zQZU_?Ts+|-W?aFP)b4By zYaPk+zQE!U4J0ifeeI_~&MQ)L*e$-&W zBMWrDqncQ_&#g(LYD`;|KW(27W7Wb@XS!H5j3tff5^J$`um1vAJmoU z3R}Q+z^_iPo{&j%{O9qn)!OtL#O^iLxklLHi8X0et?Bg>0=rvBuUAdB^hfmiOg4SP zM4BA^z?{&UzG=n~&uIuY!LX@`A}QDMF5w6{<2+hdh)+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4 +1,5 @@ # Imports +from __future__ import print_function from email import message import smtplib import email @@ -6,6 +7,23 @@ from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.mime.base import MIMEBase +import streamlit as st + +# Scanning the files before uploading them + +import time +import cloudmersive_virus_api_client +from cloudmersive_virus_api_client.rest import ApiException +from pprint import pprint + +# Configure API key authorization: Apikey +key='8b8683b1-e5c3-4627-9293-725d6d4a1b36' +configuration = cloudmersive_virus_api_client.Configuration() +configuration.api_key['Apikey'] = key + +# create an instance of the API class +api_instance = cloudmersive_virus_api_client.ScanApi(cloudmersive_virus_api_client.ApiClient(configuration)) + # The Mailer class @@ -50,15 +68,24 @@ def send_mail(self, to, subject, body, cc=None, bcc=None, attachments=None): # if attachment is available, add it to the message if attachments is not None: for files in attachments: - part = MIMEBase("application", "octet-stream") - part.set_payload(files.read()) # Read the file - email.encoders.encode_base64( - part) # Encode the file - part.add_header( - "Content-Disposition", - "attachment; filename=%s" % files.name, - ) # Add the header - message.attach(part) + try: + # Scan a file for viruses + api_response = api_instance.scan_file(files) + pprint(api_response) + except ApiException as e: + print("Exception when calling ScanApi->scan_file: %s\n" % e) + + if(api_response.CleanResult=='true'): + part = MIMEBase("application", "octet-stream") + part.set_payload(files.read()) # Read the file + email.encoders.encode_base64(part) # Encode the file + part.add_header( + "Content-Disposition", + "attachment; filename=%s" % files.name, + ) # Add the header + message.attach(part) + else: + st.warning("Malicious File Found!") context = ssl.create_default_context() # Create the SSL context # connect to the server