SlideShare a Scribd company logo
1 of 15
Download to read offline
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

What's hot

What's hot (20)

Cloud security certifications landscape
Cloud security certifications landscapeCloud security certifications landscape
Cloud security certifications landscape
 
Secure code practices
Secure code practicesSecure code practices
Secure code practices
 
CompTIA Security+.pptx
CompTIA Security+.pptxCompTIA Security+.pptx
CompTIA Security+.pptx
 
Overview of the Cyber Kill Chain [TM]
Overview of the Cyber Kill Chain [TM]Overview of the Cyber Kill Chain [TM]
Overview of the Cyber Kill Chain [TM]
 
Endpoint Security
Endpoint SecurityEndpoint Security
Endpoint Security
 
Windows Security
Windows Security Windows Security
Windows Security
 
Secure coding practices
Secure coding practicesSecure coding practices
Secure coding practices
 
SOC for Cybersecurity Overview
SOC for Cybersecurity OverviewSOC for Cybersecurity Overview
SOC for Cybersecurity Overview
 
Introduction to penetration testing
Introduction to penetration testingIntroduction to penetration testing
Introduction to penetration testing
 
Segmenting your Network for Security - The Good, the Bad and the Ugly
Segmenting your Network for Security - The Good, the Bad and the UglySegmenting your Network for Security - The Good, the Bad and the Ugly
Segmenting your Network for Security - The Good, the Bad and the Ugly
 
API Security Best Practices & Guidelines
API Security Best Practices & GuidelinesAPI Security Best Practices & Guidelines
API Security Best Practices & Guidelines
 
Security Attacks.ppt
Security Attacks.pptSecurity Attacks.ppt
Security Attacks.ppt
 
Presentation cisco iron port email & web security
Presentation   cisco iron port email & web securityPresentation   cisco iron port email & web security
Presentation cisco iron port email & web security
 
Empire Kurulumu ve Kullanımı
Empire Kurulumu ve Kullanımı Empire Kurulumu ve Kullanımı
Empire Kurulumu ve Kullanımı
 
SIEM
SIEMSIEM
SIEM
 
Network Access Control (NAC)
Network Access Control (NAC)Network Access Control (NAC)
Network Access Control (NAC)
 
Information security
Information security Information security
Information security
 
Firewall
FirewallFirewall
Firewall
 
Advanced persistent threats(APT)
Advanced persistent threats(APT)Advanced persistent threats(APT)
Advanced persistent threats(APT)
 
Security Analytics with OpenSearch
Security Analytics with OpenSearchSecurity Analytics with OpenSearch
Security Analytics with OpenSearch
 

Viewers also liked

SANS_Minneapolis_2015_ThreatIntelligence_NeighborhoodWatchForYourNetworks
SANS_Minneapolis_2015_ThreatIntelligence_NeighborhoodWatchForYourNetworksSANS_Minneapolis_2015_ThreatIntelligence_NeighborhoodWatchForYourNetworks
SANS_Minneapolis_2015_ThreatIntelligence_NeighborhoodWatchForYourNetworks
Matthew J. Harmon
 

Viewers also liked (8)

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

Similar to Python + STIX = Awesome

Open erp on ubuntu
Open erp on ubuntuOpen erp on ubuntu
Open erp on ubuntu
Iker Coranti
 

Similar to Python + STIX = Awesome (20)

First python project
First python projectFirst python project
First python project
 
Share your code with the Python world by
 creating pip packages
Share your code with the Python world by
 creating pip packagesShare your code with the Python world by
 creating pip packages
Share your code with the Python world by
 creating pip packages
 
Make an Instant Website with Webhooks
Make an Instant Website with WebhooksMake an Instant Website with Webhooks
Make an Instant Website with Webhooks
 
Open erp on ubuntu
Open erp on ubuntuOpen erp on ubuntu
Open erp on ubuntu
 
2016/11/05: OSWDem16 workshop
2016/11/05: OSWDem16 workshop2016/11/05: OSWDem16 workshop
2016/11/05: OSWDem16 workshop
 
Software Quality Assurance Tooling 2023
Software Quality Assurance Tooling 2023Software Quality Assurance Tooling 2023
Software Quality Assurance Tooling 2023
 
Digital RSE: automated code quality checks - RSE group meeting
Digital RSE: automated code quality checks - RSE group meetingDigital RSE: automated code quality checks - RSE group meeting
Digital RSE: automated code quality checks - RSE group meeting
 
PyCourse - Self driving python course
PyCourse - Self driving python coursePyCourse - Self driving python course
PyCourse - Self driving python course
 
Python Requirements File How to Create Python requirements.txt
Python Requirements File How to Create Python requirements.txtPython Requirements File How to Create Python requirements.txt
Python Requirements File How to Create Python requirements.txt
 
Princeton Wintersession: Software Quality Assurance Tooling
Princeton Wintersession: Software Quality Assurance ToolingPrinceton Wintersession: Software Quality Assurance Tooling
Princeton Wintersession: Software Quality Assurance Tooling
 
SciPy 2022 Scikit-HEP
SciPy 2022 Scikit-HEPSciPy 2022 Scikit-HEP
SciPy 2022 Scikit-HEP
 
Hello Git
Hello GitHello Git
Hello Git
 
4.Building a Data Product using apache Zeppelin - Apache Kylin Meetup @Shanghai
4.Building a Data Product using apache Zeppelin - Apache Kylin Meetup @Shanghai4.Building a Data Product using apache Zeppelin - Apache Kylin Meetup @Shanghai
4.Building a Data Product using apache Zeppelin - Apache Kylin Meetup @Shanghai
 
Steps to install ns3
Steps to install ns3Steps to install ns3
Steps to install ns3
 
Princeton RSE Peer network first meeting
Princeton RSE Peer network first meetingPrinceton RSE Peer network first meeting
Princeton RSE Peer network first meeting
 
Hello, Git!
Hello, Git!Hello, Git!
Hello, Git!
 
Introduction to python 3
Introduction to python 3Introduction to python 3
Introduction to python 3
 
Software Quality Assurance Tooling - Wintersession 2024
Software Quality Assurance Tooling - Wintersession 2024Software Quality Assurance Tooling - Wintersession 2024
Software Quality Assurance Tooling - Wintersession 2024
 
Open source projects with python
Open source projects with pythonOpen source projects with python
Open source projects with python
 
05 python.pdf
05 python.pdf05 python.pdf
05 python.pdf
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

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