#!/usr/bin/env python
# Copyright (c) 2014, The MITRE Corporation. All rights reserved.
# See LICENSE.txt for complete terms.

import sys
from stix.core import STIXPackage


def parse_stix(pkg):
    print("== TTP ==")
    for tactic in pkg.ttps:
        print("---")
        print("Title: " + tactic.title)
        for sample in tactic.behavior.malware_instances:
            print("Malware: " + str(sample.names[0]))
            print("Type: " + str(sample.types[0]))
            if sample.maec:
                print("Contains embedded MAEC content")
    return 0

if __name__ == '__main__':
    try:
        fname = sys.argv[1]
    except:
        exit(1)
    fd = open(fname)
    stix_pkg = STIXPackage.from_xml(fd)

    parse_stix(stix_pkg)
