Officedissector는 MIT의 Lincoln Laboratory의 Cyber System Assessments Group을 위해 Grier Forensics에 의해 생성 된 OOXML (Office Open XML) 문서의 정적 보안 분석을위한 파서 라이브러리입니다.
Offeedissector는 OOXML 문서의 보안 분석을 위해 특별히 설계된 최초의 파서입니다. 문서 속성, 부품, 콘텐츠 유형, 관계, 임베디드 매크로 및 멀티미디어 등을 포함한 모든 내부를 노출시킵니다. 전체 JSON 내보내기 및 Mastiff 기반 플러그인 아키텍처를 제공합니다. 또한 거의 600MB 테스트 코퍼스, 거의 100% 적용 범위를 가진 단위 테스트, 전체 코퍼스에 대한 연기 테스트, 간단하고 잘 알려진 완전히 댓글이 달린 코드가 포함됩니다.
Officedissector에는 Python 2.7 및 LXML 패키지가 필요합니다.
Officedissector를 설치하는 가장 쉬운 방법은 PIP를 사용하여 자동으로 다운로드하여 설치하는 것입니다.
$ sudo pip install lxml # If you haven't installed lxml already
$ sudo pip install officedissector
또는 Github 또는 Zip에서 Officedissector를 다운로드하고 PIP (권장) 또는 Python 설정을 사용하여 로컬 사본을 설치할 수 있습니다.
$ sudo pip install /path/to/thisfolder # Recommended, as pip supports uninstall
$ sudo python setup.py install # Alternative
마지막으로 설치하지 않고 OfficedIssector를 사용하려면 다운로드하여 PYTHONPATH officedissector 디렉토리로 설정하십시오.
$ export PYTHONPATH=/path/to/thisfolder
Officedissector 문서를 보려면 브라우저에서 열 수 있습니다.
$ doc/html/index.html
테스트하려면 먼저 위에서 설명한대로 PythonPath 또는 설치 officedissector 설정하십시오. 그 다음에:
# Unit tests
$ cd test/unit_test
$ python test_officedissector.py
# Smoke tests
$ cd test
$ python smoke_tests.py
연기 테스트는 더 많은 정보가 포함 된 로그 파일을 만듭니다.
Mastiff 아키텍처 및 샘플 플러그인에 대한 자세한 내용은 mastiff-plugins/README.txt 참조하십시오.
아래는 Officedissector의 사용을 보여주는 Ipython 세션입니다.
$ ipython
In [1]: import officedissector
In [2]: doc = officedissector.doc.Document('test/fraunhoferlibrary/Artikel.docx')
In [4]: doc.is_macro_enabled
Out[4]: False
In [5]: doc.is_template
Out[5]: False
In [6]: mp = doc.main_part()
In [7]: mp.content_type()
Out[7]: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml'
In [9]: mp.name
Out[9]: '/word/document.xml'
In [10]: mp.content_type()
Out[10]: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml'
# We can read the part's stream of data:
In [17]: mp.stream().read(200)
Out[17]: '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>rn<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mc="http://schemas.openxmlformats.org/markup-c'
# Or use XPath to parse it:
In [33]: t = mp.xpath('//w:t', {'w': "http://schemas.openxmlformats.org/wordprocessingml/2006/main"})
In [37]: t[2].text
Out[37]: u'Das vorliegende Dokument ist ein Beispiel fxfcr einen zur Publikation in einer Zeitschrift vorgesehenen Artikel. Es verwendet fxfcr Autor und Titel in den Dokumenteigenschaften festgelegte Eintrxe4ge.'
# All Relationships in and out are exposed:
In [38]: mp.relationships_in()
Out[38]: [Relationship [rId1] (source Part [RootPart])]
In [39]: mp.relationships_out()
Out[39]:
[Relationship [rId8] (source Part [/word/document.xml]),
Relationship [rId13] (source Part [/word/document.xml]),
Relationship [rId3] (source Part [/word/document.xml]),
...
Relationship [rId14] (source Part [/word/document.xml])]
In [40]: rel = mp.relationships_out()[0]
In [43]: rel.type
Out[43]: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes'
In [46]: endnotes = rel.target_part
In [48]: endnotes.content_type()
Out[48]: 'application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml'
# Any Part (or the entire Document) can be exported to JSON:
In [50]: print endnotes.to_json()
{
"content-type": "application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml",
"uri": "/word/endnotes.xml",
"relationships_out": [],
"relationships_in": [
"Relationship [rId8] (source Part [/word/document.xml])"
]
}
# Features are automatically exposed:
In [55]: doc.features.[TAB]
...
doc.features.comments
doc.features.custom_properties
doc.features.custom_xml
doc.features.digital_signatures
doc.features.doc
doc.features.embedded_controls
doc.features.embedded_objects
doc.features.embedded_packages
doc.features.fonts
doc.features.get_parts
doc.features.get_union
doc.features.images
doc.features.macros
doc.features.sounds
doc.features.videos
In [55]: doc.features.images
Out[55]: [Part [/word/media/image1.jpeg]]
In [56]: image = doc.features.images[0]
In [58]: image.content_type()
Out[58]: 'image/jpeg'
# We can export the binary data to JSON as well, by setting include_stream = True:
In [61]: print image.to_json(include_stream = True)
{
"stream_b64": "/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAFAAUDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD3uGGO3iWKJdqL0Gc0UUUAf//Z",
"content-type": "image/jpeg",
"uri": "/word/media/image1.jpeg",
"relationships_out": [],
"relationships_in": [
"Relationship [rId1] (source Part [/word/theme/theme1.xml])"
]
}
# Check for macros:
In [62]: doc.features.macros
Out[62]: []
# Or comments:
In [63]: doc.features.comments
Out[63]: []
# Core properties are exposed:
In [64]: doc.core_properties.[TAB]
...
doc.core_properties.content_status
doc.core_properties.core_prop_part
doc.core_properties.created
doc.core_properties.creator
doc.core_properties.description
doc.core_properties.identifier
doc.core_properties.keywords
doc.core_properties.language
doc.core_properties.last_modified_by
doc.core_properties.last_printed
doc.core_properties.modified
doc.core_properties.name
doc.core_properties.parse_all
doc.core_properties.parse_prop
doc.core_properties.revision
doc.core_properties.subject
doc.core_properties.title
doc.core_properties.version
doc.core_properties.category
In [68]: doc.core_properties.modified
Out[68]: '2009-12-04T14:47:00Z'
OOXML 문서를 분석하기 위해 OXCML 문서를 분석하는 방법에 대한 빠른 시작 안내서는 doc/txt/ANALYZING_OOXML.txt 참조하십시오.
Officedissector에 대한 자세한 내용은 API- doc/html/rst/api.html 문서를 참조하십시오.
프로젝트에 대한 자세한 내용은 http://www.officedissector.com을 참조하십시오.