फ़ाइल को सुरक्षित करें और विश्लेषण करें
Protect Mode में, content management policies विभिन्न फ़ाइल सामग्री प्रकारों जैसे executable code, interactive form content और कई actions (उदा., external links या JavaScript का execution) पर नियंत्रण की अनुमति देती हैं। ये फ़ाइल तत्व तब सामान्य attack vectors माने जाते हैं जब वे किसी फ़ाइल के भीतर पाए जाते हैं। content management policy यह परिभाषित करेगी कि Glasswall Embedded Engine को इन संरचनाओं को कैसे process करना चाहिए। Analysis Mode में, इन्हें SanitisationItems के रूप में report किया जाता है। content management policy समर्थित फ़ाइल प्रकारों के अनुसार भिन्न होती है।
फ़ाइल के पुनर्जनन के दौरान फ़ाइल specification के अनुरूप स्वचालित सुधार भी किए जाते हैं। इसका उद्देश्य Glasswall Embedded Engine को फ़ाइल संरचना के भीतर छिपे खतरों को हटाने में सक्षम बनाना है, साथ ही फ़ाइल में structural components के दुरुपयोग के माध्यम से exploits के सक्रिय होने की संभावना को रोकना भी है। Analysis Mode में, इन्हें RemedyItems के रूप में report किया जाता है।
फ़ाइलों को protect_file या protect_directory methods का उपयोग करके किसी file path से या memory में अलग-अलग सुरक्षित किया जा सकता है।
उदाहरण
- Protect
- फ़ाइल path से फ़ाइल path तक सुरक्षित करें
- फ़ाइल path से memory तक सुरक्षित करें
- memory से सुरक्षित करें
- किसी directory में फ़ाइलों को सुरक्षित करें
- ऐसी directory में फ़ाइलों को सुरक्षित करें जिसमें unsupported फ़ाइल प्रकार हो सकते हैं
- custom content management policy का उपयोग करके किसी directory में फ़ाइलों को सुरक्षित करें
- फ़ाइल format के आधार पर शर्तानुसार किसी directory में फ़ाइलों को सुरक्षित करें
- Analysis
- फ़ाइल path से फ़ाइल path तक विश्लेषण करें
- फ़ाइल path से memory तक विश्लेषण करें
- memory से विश्लेषण करें
- किसी डायरेक्टरी में फ़ाइलों का विश्लेषण करें
- ऐसी डायरेक्टरी में फ़ाइलों का विश्लेषण करें जिसमें असमर्थित फ़ाइल प्रकार हो सकते हैं
- कस्टम content management policy का उपयोग करके किसी डायरेक्टरी में फ़ाइलों का विश्लेषण करें
- फ़ाइल फ़ॉर्मैट के आधार पर शर्तानुसार किसी डायरेक्टरी में फ़ाइलों का विश्लेषण करें
- Protect और Analyse
Protect
फ़ाइल पथ से फ़ाइल पथ तक Protect
import glasswall
# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")
# Use the default policy to sanitise a file, writing the sanitised file to a new path
editor.protect_file(
input_file=r"C:\gwpw\input\TestFile_11.doc",
output_file=r"C:\gwpw\output\editor\protect_f2f\TestFile_11.doc",
)
फ़ाइल पथ से मेमोरी तक Protect
protect_file सुरक्षित की गई फ़ाइल के bytes लौटाता है। नीचे दिया गया उदाहरण file_bytes वेरिएबल को असाइन करना दर्शाता है। हम देख सकते हैं कि sanitisation के बाद file_bytes के पहले 8 bytes Microsoft Compound File Binary (CFB) फ़ॉर्मैट के file signature, D0 CF 11 E0 A1 B1 1A E1, से मेल खाते हैं।
import glasswall
# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")
# Use the default policy to sanitise a file in memory, returning the file bytes in memory
file_bytes = editor.protect_file(
input_file=r"C:\gwpw\input\TestFile_11.doc"
)
assert file_bytes[:8] == b'\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1'
मेमोरी से Protect करें
import glasswall
# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")
# Read file from disk to memory
with open(r"C:\gwpw\input\TestFile_11.doc", "rb") as f:
input_bytes = f.read()
# Use the default policy to sanitise a file
file_bytes = editor.protect_file(
input_file=input_bytes,
)
assert file_bytes[:8] == b'\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1'
किसी डायरेक्टरी में फ़ाइलों को Protect करें
import glasswall
# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")
# Use the default policy to protect a directory of files, writing the sanitised files to a new directory.
editor.protect_directory(
input_directory=r"C:\gwpw\input",
output_directory=r"C:\gwpw\output\editor\protect_directory"
)
ऐसी डायरेक्टरी में फ़ाइलों को Protect करें जिसमें unsupported फ़ाइल प्रकार हो सकते हैं
Glasswall Python wrapper का डिफ़ॉल्ट व्यवहार यह है कि यदि processing विफल हो जाए, तो वह संबंधित exception raise करता है (देखें: glasswall.libraries.editor.errors)। raise_unsupported=False पास करने से exception raise होने से रोका जाएगा, और यह तब उपयोगी हो सकता है जब आप ऐसी directory के साथ काम कर रहे हों जिसमें supported और unsupported दोनों प्रकार की file types का मिश्रण हो, और जहाँ पहली विफलता पर terminate होने के बजाय जितनी संभव हो उतनी files को process करना वांछनीय हो।
import glasswall
# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")
# Use the default policy to protect a directory of files, writing the sanitised files to a new directory.
editor.protect_directory(
input_directory=r"C:\gwpw\input_with_unsupported_file_types",
output_directory=r"C:\gwpw\output\editor\protect_directory_unsupported",
raise_unsupported=False
)
कस्टम content management policy का उपयोग करके डायरेक्टरी में फ़ाइलों को सुरक्षित करें
glasswall.content_management.policies.Editor का उपयोग करते हुए:
import glasswall
# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")
# Use a custom Editor policy to sanitise all files in the input directory
# and write them to the input_sanitised directory. If macros are present
# in ppt or word files, the file will be marked as non-conforming and blocked.
# If internal or external hyperlinks are present in word files they will not
# be sanitised, and will remain in the regenerated document.
editor.protect_directory(
input_directory=r"C:\gwpw\input",
output_directory=r"C:\gwpw\output\editor\protect_directory_custom",
content_management_policy=glasswall.content_management.policies.Editor(
default="sanitise",
config={
"pptConfig": {
"macros": "disallow",
},
"wordConfig": {
"internal_hyperlinks": "allow",
"external_hyperlinks": "allow",
"macros": "disallow",
}
}
)
)
फ़ाइल फ़ॉर्मेट के आधार पर शर्तानुसार डायरेक्टरी में फ़ाइलों को सुरक्षित करें
नीचे दिया गया उदाहरण कई फ़ाइल फ़ॉर्मेट वाली एक nested डायरेक्टरी से केवल .doc और .docx फ़ाइलों को प्रोसेस करना दर्शाता है।
import os
import glasswall
# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")
input_directory = r"C:\gwpw\input"
output_directory = r"C:\gwpw\output\editor\protect_directory_file_format"
# Iterate relative file paths from input_directory
for relative_file in glasswall.utils.list_file_paths(input_directory, absolute=False):
# Construct absolute paths
input_file = os.path.join(input_directory, relative_file)
output_file = os.path.join(output_directory, relative_file)
# Get the file type of the file
file_type = editor.determine_file_type(
input_file=input_file,
as_string=True,
raise_unsupported=False
)
# Protect only doc and docx files
if file_type in ["doc", "docx"]:
editor.protect_file(input_file, output_file)
विश्लेषण
एक Embedded Engine रिपोर्ट डेटा का विस्तृत, फ़ाइल-प्रकार-अज्ञेय विवरण प्रदान करती है और XML फ़ॉर्मेट में लॉग की जाती है। इस रिपोर्ट की संरचना एक Analysis Report XSD का अनुसरण करती है, जिसे parsing और processing को सरल बनाने के लिए डिज़ाइन किया गया है, जिससे डेटा का integration और analysis आसान हो सके। Engine Reporting देखें।
फ़ाइलों का विश्लेषण अलग-अलग रूप से किसी file path से या memory में analyse_file method का उपयोग करके किया जा सकता है, या किसी directory की सभी फ़ाइलों का विश्लेषण analyse_directory method का उपयोग करके किया जा सकता है।
फ़ाइल पथ से फ़ाइल पथ तक विश्लेषण करें
import glasswall
# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")
# Use the default policy to analyse a file, writing the analysis report to a new path
editor.analyse_file(
input_file=r"C:\gwpw\input\TestFile_11.doc",
output_file=r"C:\gwpw\output\editor\analyse_f2f\TestFile_11.doc.xml",
)
फ़ाइल पथ से memory तक विश्लेषण करें
analyse_file analysis report xml फ़ाइल के bytes लौटाता है। नीचे दिया गया उदाहरण analysis_report variable को assign करना और Editor analysis report की शुरुआत की सामग्री की जाँच करना दर्शाता है।
import glasswall
# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")
# Use the default policy to analyse a file
analysis_report = editor.analyse_file(
input_file=r"C:\gwpw\input\TestFile_11.doc",
)
assert analysis_report[:500] == b'<?xml version="1.0" encoding="utf-8"?>\n<gw:GWallInfo xsi:schemaLocation="http://glasswall.com/namespace/gwallInfo.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gw="http://glasswall.com/namespace">\n\t<gw:DocumentStatistics>\n\t\t<gw:DocumentSummary>\n\t\t\t<gw:TotalSizeInBytes>35840</gw:TotalSizeInBytes>\n\t\t\t<gw:FileType>doc</gw:FileType>\n\t\t\t<gw:Version>Not Applicable</gw:Version>\n\t\t\t<gw:InputSHA256>9FDE85B8800C1019D2865FA298A7F75873E09870B71F9825827E354B865686A6</gw:InputSHA256>\n\t\t\t<gw'
memory से विश्लेषण करें
import glasswall
# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")
# Read file from disk to memory
with open(r"C:\gwpw\input\TestFile_11.doc", "rb") as f:
input_bytes = f.read()
# Use the default policy to analyse a file
analysis_report = editor.analyse_file(
input_file=input_bytes,
)
assert analysis_report[:500] == b'<?xml version="1.0" encoding="utf-8"?>\n<gw:GWallInfo xsi:schemaLocation="http://glasswall.com/namespace/gwallInfo.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gw="http://glasswall.com/namespace">\n\t<gw:DocumentStatistics>\n\t\t<gw:DocumentSummary>\n\t\t\t<gw:TotalSizeInBytes>35840</gw:TotalSizeInBytes>\n\t\t\t<gw:FileType>doc</gw:FileType>\n\t\t\t<gw:Version>Not Applicable</gw:Version>\n\t\t\t<gw:InputSHA256>9FDE85B8800C1019D2865FA298A7F75873E09870B71F9825827E354B865686A6</gw:InputSHA256>\n\t\t\t<gw'
किसी डायरेक्टरी में फ़ाइलों का विश्लेषण करें
import glasswall
# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")
# Use the default policy to analyse a directory of files, writing the analysis reports to a new directory.
editor.analyse_directory(
input_directory=r"C:\gwpw\input",
output_directory=r"C:\gwpw\output\editor\analyse_directory"
)
ऐसी डायरेक्टरी में फ़ाइलों का विश्लेषण करें जिसमें असमर्थित फ़ाइल प्रकार हो सकते हैं
Glasswall Python wrapper का डिफ़ॉल्ट व्यवहार यह है कि यदि processing विफल हो जाए, तो वह संबंधित exception raise करता है (देखें: glasswall.libraries.editor.errors)। raise_unsupported=False पास करने से exception raise होने से रोका जाएगा, और यह तब उपयोगी हो सकता है जब आप ऐसी directory के साथ काम कर रहे हों जिसमें supported और unsupported दोनों प्रकार की file types का मिश्रण हो, और जहाँ पहली विफलता पर terminate होने के बजाय जितनी संभव हो उतनी files को process करना वांछनीय हो।
import glasswall
# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")
# Use the default policy to analyse a directory of files, writing the analysis reports to a new directory.
editor.analyse_directory(
input_directory=r"C:\gwpw\input_with_unsupported_file_types",
output_directory=r"C:\gwpw\output\editor\analyse_directory_unsupported",
raise_unsupported=False
)
कस्टम content management policy का उपयोग करके डायरेक्टरी में फ़ाइलों का विश्लेषण करें
glasswall.content_management.policies.Editor का उपयोग करते हुए:
import glasswall
# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")
# Use a custom Editor policy to analyse all files in the input directory
# and write them to analyse_directory_custom directory. If macros are
# present in ppt or word files, a GeneralFail exception will be raised if the
# raise_unsupported argument is left at its default value of False, but the
# analysis report will still be written to file and will contain IssueItems.
# If internal or external hyperlinks are present in word files they will not
# be sanitised, and will remain in the regenerated document.
editor.analyse_directory(
input_directory=r"C:\gwpw\input",
output_directory=r"C:\gwpw\output\editor\analyse_directory_custom",
content_management_policy=glasswall.content_management.policies.Editor(
default="sanitise",
config={
"pptConfig": {
"macros": "disallow",
},
"wordConfig": {
"internal_hyperlinks": "allow",
"external_hyperlinks": "allow",
"macros": "disallow",
}
}
),
raise_unsupported=False
)
फ़ाइल फ़ॉर्मैट के आधार पर शर्तपूर्वक डायरेक्टरी में फ़ाइलों का विश्लेषण करें
नीचे दिया गया उदाहरण कई फ़ाइल फ़ॉर्मेट वाली एक nested डायरेक्टरी से केवल .doc और .docx फ़ाइलों को प्रोसेस करना दर्शाता है।
import os
import glasswall
# Load the Glasswall Editor library
editor = glasswall.Editor(r"C:\gwpw\libraries\10.0")
input_directory = r"C:\gwpw\input"
output_directory = r"C:\gwpw\output\editor\analyse_directory_file_format"
# Iterate relative file paths from input_directory
for relative_file in glasswall.utils.list_file_paths(input_directory, absolute=False):
# Construct absolute paths
input_file = os.path.join(input_directory, relative_file)
output_file = os.path.join(output_directory, relative_file + ".xml")
# Get the file type of the file
file_type = editor.determine_file_type(
input_file=input_file,
as_string=True,
raise_unsupported=False
)
# Analyse only doc and docx files
if file_type in ["doc", "docx"]:
editor.analyse_file(input_file, output_file)
Protect और Analyse
ये उच्च-स्तरीय फ़ंक्शंस आपको एक ही session के भीतर Analysis methods के साथ Protect चलाने देते हैं। अधिक जानकारी के लिए, नीचे दिए गए documentation links देखें।