SlideShare a Scribd company logo
python-stix primer
Ben Schmoker
github.com/bschmoker
What is python-stix?
• Developer friendly
– Python objects > raw XML
• Re-usable
– Open-source libraries
• Plug-in ready
– Integrate with existing tools
github.com/STIXProject/python-stix
Let's get started!
• Install Python 2.7 and dependencies
apt-get install python-dev python-pip
apt-get install libxml2-dev libxslt-dev
apt-get install zlib1g-dev
pip install stix
github.com/STIXProject/python-stix
Create a STIX document
github.com/STIXProject/python-stix
$ cat > write.py
from stix.core import STIXPackage, STIXHeader
header = STIXHeader ()
header.title = "My first document!"
pkg = STIXPackage()
pkg.stix_header = header
print pkg.to_xml() // output XML
Generate a STIX Indicator
• The following slides will reference
this example code
github.com/STIXProject/python-stix
Create IP Address Indicator
github.com/STIXProject/python-stix
$ cat >> write.py
ind = Indicator()
ind.title="malicious IP"
ind.add_indicator_type("IP Watchlist")
// set value
addr = Address()
addr.address_value="10.0.0.0"
addr.category = 'ipv4-addr'
addr.condition = "Equals"
// add to package
ind.add_observable(addr)
stix_package.add_indicator(ind)
Add optional fields
github.com/STIXProject/python-stix
$ cat >> write.py
// add a type of malicious activity
activity = TTP(title="C2 Behavior")
stix_package.add_ttp(activity)
//link indicator to activity
ind.add_indicated_ttp(TTP(idref = activity.id_) )
Parsing STIX
• The following slides will reference
this example code
github.com/STIXProject/python-stix
Load a STIX document
$ curl http://tiny.cc/samplestix > in.xml
$ python
from stix.core import STIXPackage, STIXHeader
myfile = open('in.xml')
pkg = STIXPackage.from_xml(myfile)
github.com/STIXProject/python-stix
Access Data Elements
$cat in.xml
<stix:STIX_Package
<stix:Package_Intent>Incident
<stix:Description>Sample breach report
</>
$ cat >> read.py
print pkg.stix_header.description
github.com/STIXProject/python-stix
Iterate Lists
$cat in.xml
<stix:Incident>
<incident:Title>Breach of Cyber Tech Dynamics
</>
$ cat >> read.py
for inc in pkg.incidents:
print inc.title
github.com/STIXProject/python-stix
Parsing STIX (Advanced)
• The following slides will reference
this example code
github.com/STIXProject/python-stix
$curl http://tiny.cc/samplestixobs > in.xml
<stix:Indicator>
<indicator:Observable>
<cybox:Object>
<cybox:Properties>
<FileObj:Hashes>
<cyboxCommon:Hash>d3adb33f
</>
$ cat > read.py
for ind in pkg.indicators:
for obs in ind.observables:
for digest in obs.object_.properties.hashes:
print digest
Examine Observables
github.com/STIXProject/python-stix
Dereference Links
github.com/STIXProject/python-stix
$cat in.xml
<stix:TTPs>
<stix:TTP id="id_value">
[...]
</>
<stix:Indicator>
<indicator:Indicated_TTP>
<stixCommon:TTP idref="id_value">
</>
$ cat >> read.py
relationship_dict = {}
for ttp in package.ttps.ttps:
relationship_dict [ttp.id_] = ttp # assign object to dictionary value, with I
as key
for rel_ttp in indicator.indicated_ttps:
if rel_ttp.item.idref in ttps: # look up object by ID
print relationship_dict[rel_ttp.item.idref].title
Further Reading
• Sample code and use cases
– stixproject.github.io/documentation/idioms
• Python documentation
– stix.readthedocs.org
github.com/STIXProject/python-stix

More Related Content

PPTX
Using Wildcards with rsyslog's File Monitor imfile
PDF
Best Practices for Middleware and Integration Architecture Modernization with...
PDF
El core de Alfresco 4.2
PDF
SGX Trusted Execution Environment
PDF
Kamailio :: A Quick Introduction
PDF
Kafka slideshare
PDF
Cilium - API-aware Networking and Security for Containers based on BPF
PDF
Active MQ
Using Wildcards with rsyslog's File Monitor imfile
Best Practices for Middleware and Integration Architecture Modernization with...
El core de Alfresco 4.2
SGX Trusted Execution Environment
Kamailio :: A Quick Introduction
Kafka slideshare
Cilium - API-aware Networking and Security for Containers based on BPF
Active MQ

What's hot (20)

PDF
FIWARE Training: NGSI-LD Advanced Operations
PDF
cilium-public.pdf
PPTX
SSL/TLS 101
PPTX
NGINX Installation and Tuning
PDF
Spring Boot
PDF
TLS/SSL Internet Security Talk
PPTX
Smart Contract Testing
PPTX
Apache Camel K - Copenhagen v2
PDF
Kafka Summit NYC 2017 - Singe Message Transforms are not the Transformations ...
PDF
LetSwift 2017 - 토스 iOS 앱의 개발/배포 환경
PDF
Solidity- Error Handling
PDF
Open Standards in Identity Management
PPTX
Docker-Dasar.pptx
PPTX
Network policy @ k8s day
PDF
Cilium - Bringing the BPF Revolution to Kubernetes Networking and Security
PPTX
Fast Userspace OVS with AF_XDP, OVS CONF 2018
PPTX
Vault - Secret and Key Management
PPTX
Ssh tunnel
PPTX
secure socket layer
FIWARE Training: NGSI-LD Advanced Operations
cilium-public.pdf
SSL/TLS 101
NGINX Installation and Tuning
Spring Boot
TLS/SSL Internet Security Talk
Smart Contract Testing
Apache Camel K - Copenhagen v2
Kafka Summit NYC 2017 - Singe Message Transforms are not the Transformations ...
LetSwift 2017 - 토스 iOS 앱의 개발/배포 환경
Solidity- Error Handling
Open Standards in Identity Management
Docker-Dasar.pptx
Network policy @ k8s day
Cilium - Bringing the BPF Revolution to Kubernetes Networking and Security
Fast Userspace OVS with AF_XDP, OVS CONF 2018
Vault - Secret and Key Management
Ssh tunnel
secure socket layer
Ad

Viewers also liked (8)

PPTX
Introduction to STIX 101
PPTX
Everything about TAXII
PDF
STIX, TAXII, CISA: Impact of the Cybersecurity Information Sharing Act of 2015
PDF
SANS_Minneapolis_2015_ThreatIntelligence_NeighborhoodWatchForYourNetworks
PDF
セキュリティオペレーション自動化に向けた、基盤技術と共通インターフェースの構築 [ISOC-JP workshop, 2016/05/20]
PDF
מצגת החברות המשתתפות בתערוכת מיליפול 2013
PPT
Network security chapter 6 and 7 internet architecture
PDF
Security Strategy and Tactic with Cyber Threat Intelligence (CTI)
Introduction to STIX 101
Everything about TAXII
STIX, TAXII, CISA: Impact of the Cybersecurity Information Sharing Act of 2015
SANS_Minneapolis_2015_ThreatIntelligence_NeighborhoodWatchForYourNetworks
セキュリティオペレーション自動化に向けた、基盤技術と共通インターフェースの構築 [ISOC-JP workshop, 2016/05/20]
מצגת החברות המשתתפות בתערוכת מיליפול 2013
Network security chapter 6 and 7 internet architecture
Security Strategy and Tactic with Cyber Threat Intelligence (CTI)
Ad

Similar to Python + STIX = Awesome (8)

PPTX
STIX Patterning: Viva la revolución!
PDF
Python para equipos de ciberseguridad(pycones)
PDF
Data science for infrastructure dev week 2022
PPT
Sri monthly presentation 2015
PDF
breed_python_tx_redacted
PPTX
USE_OF_PACKET_CAPTURE.pptx
PDF
Russ Savage [Ngrok] | InfluxDB QuickStart | InfluxDays NA 2021
ODP
Zabbix API at FISL12 by Takanori Suzuki
STIX Patterning: Viva la revolución!
Python para equipos de ciberseguridad(pycones)
Data science for infrastructure dev week 2022
Sri monthly presentation 2015
breed_python_tx_redacted
USE_OF_PACKET_CAPTURE.pptx
Russ Savage [Ngrok] | InfluxDB QuickStart | InfluxDays NA 2021
Zabbix API at FISL12 by Takanori Suzuki

Recently uploaded (20)

PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Big Data Technologies - Introduction.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
KodekX | Application Modernization Development
PDF
cuic standard and advanced reporting.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Network Security Unit 5.pdf for BCA BBA.
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPT
Teaching material agriculture food technology
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Big Data Technologies - Introduction.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Unlocking AI with Model Context Protocol (MCP)
MIND Revenue Release Quarter 2 2025 Press Release
Diabetes mellitus diagnosis method based random forest with bat algorithm
Chapter 3 Spatial Domain Image Processing.pdf
KodekX | Application Modernization Development
cuic standard and advanced reporting.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Encapsulation_ Review paper, used for researhc scholars
Network Security Unit 5.pdf for BCA BBA.
“AI and Expert System Decision Support & Business Intelligence Systems”
Programs and apps: productivity, graphics, security and other tools
Review of recent advances in non-invasive hemoglobin estimation
Teaching material agriculture food technology

Python + STIX = Awesome

  • 2. What is python-stix? • Developer friendly – Python objects > raw XML • Re-usable – Open-source libraries • Plug-in ready – Integrate with existing tools github.com/STIXProject/python-stix
  • 3. Let's get started! • Install Python 2.7 and dependencies apt-get install python-dev python-pip apt-get install libxml2-dev libxslt-dev apt-get install zlib1g-dev pip install stix github.com/STIXProject/python-stix
  • 4. Create a STIX document github.com/STIXProject/python-stix $ cat > write.py from stix.core import STIXPackage, STIXHeader header = STIXHeader () header.title = "My first document!" pkg = STIXPackage() pkg.stix_header = header print pkg.to_xml() // output XML
  • 5. Generate a STIX Indicator • The following slides will reference this example code github.com/STIXProject/python-stix
  • 6. Create IP Address Indicator github.com/STIXProject/python-stix $ cat >> write.py ind = Indicator() ind.title="malicious IP" ind.add_indicator_type("IP Watchlist") // set value addr = Address() addr.address_value="10.0.0.0" addr.category = 'ipv4-addr' addr.condition = "Equals" // add to package ind.add_observable(addr) stix_package.add_indicator(ind)
  • 7. Add optional fields github.com/STIXProject/python-stix $ cat >> write.py // add a type of malicious activity activity = TTP(title="C2 Behavior") stix_package.add_ttp(activity) //link indicator to activity ind.add_indicated_ttp(TTP(idref = activity.id_) )
  • 8. Parsing STIX • The following slides will reference this example code github.com/STIXProject/python-stix
  • 9. Load a STIX document $ curl http://tiny.cc/samplestix > in.xml $ python from stix.core import STIXPackage, STIXHeader myfile = open('in.xml') pkg = STIXPackage.from_xml(myfile) github.com/STIXProject/python-stix
  • 10. Access Data Elements $cat in.xml <stix:STIX_Package <stix:Package_Intent>Incident <stix:Description>Sample breach report </> $ cat >> read.py print pkg.stix_header.description github.com/STIXProject/python-stix
  • 11. Iterate Lists $cat in.xml <stix:Incident> <incident:Title>Breach of Cyber Tech Dynamics </> $ cat >> read.py for inc in pkg.incidents: print inc.title github.com/STIXProject/python-stix
  • 12. Parsing STIX (Advanced) • The following slides will reference this example code github.com/STIXProject/python-stix
  • 13. $curl http://tiny.cc/samplestixobs > in.xml <stix:Indicator> <indicator:Observable> <cybox:Object> <cybox:Properties> <FileObj:Hashes> <cyboxCommon:Hash>d3adb33f </> $ cat > read.py for ind in pkg.indicators: for obs in ind.observables: for digest in obs.object_.properties.hashes: print digest Examine Observables github.com/STIXProject/python-stix
  • 14. Dereference Links github.com/STIXProject/python-stix $cat in.xml <stix:TTPs> <stix:TTP id="id_value"> [...] </> <stix:Indicator> <indicator:Indicated_TTP> <stixCommon:TTP idref="id_value"> </> $ cat >> read.py relationship_dict = {} for ttp in package.ttps.ttps: relationship_dict [ttp.id_] = ttp # assign object to dictionary value, with I as key for rel_ttp in indicator.indicated_ttps: if rel_ttp.item.idref in ttps: # look up object by ID print relationship_dict[rel_ttp.item.idref].title
  • 15. Further Reading • Sample code and use cases – stixproject.github.io/documentation/idioms • Python documentation – stix.readthedocs.org github.com/STIXProject/python-stix