Skip to content

pcbje/pymtgx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pymtgx

Python API for generating Maltego mtgx files.

Installation

$ python setup.py install

Usage

import pymtgx
mtgx = pymtgx.Pymtgx()
mtgx.register_entities("custom_entities.mtz")
id1 = mtgx.add_node("maltego.EmailAddress", "[email protected]")
id2 = mtgx.add_node("maltego.EmailAddress", "[email protected]")
id3 = mtgx.add_node("maltego.EmailAddress", "[email protected]")
mtgx.add_edge(id1, id2)
mtgx.add_edge(id1, id3, "I am edge label")
mtgx.create("example")

The importer

The API comes with a built-in importer, capable of generating mtgx archives from CSV files based on some format specification file. The format specification file can either be based on column name or column index.

Basic usage:

$ python pymtgx/importer.py -h
usage: importer.py [-h] -i INPUT_FILE -f FORMAT_FILE -o OUTPUT_FILE -e
                   ENTITY_FILES [-d DELIMITER] [-q QUOTECHAR] [-s SKIP_LINES]
                   [-m MAP_HEADER]

optional arguments:
  -h, --help            show this help message and exit
  -i INPUT_FILE, --input-file INPUT_FILE
                        Path to file to parse
  -f FORMAT_FILE, --format-file FORMAT_FILE
                        Path to format specification file.
  -o OUTPUT_FILE, --output-file OUTPUT_FILE
                        Path to output file. Extension is added if missing.
  -e ENTITY_FILES, --entity-files ENTITY_FILES
                        Comma separated list of .mtz files to use.
  -d DELIMITER, --delimiter DELIMITER
                        How values are delimited. Default: ,
  -q QUOTECHAR, --quotechar QUOTECHAR
                        How values are quoted, remember escape character.
                        Default: None
  -s SKIP_LINES, --skip-lines SKIP_LINES
                        Number of lines to skip. Default: 0
  -m MAP_HEADER, --map-header MAP_HEADER
                        Use column names in format specification. If not, the
                        columns in the specifications are 0-indexed.

The general syntax for entity and edge specifications is:

[FORM_COLUMN]:[FROM_ENTITY_TYPE] > [TO_COLUMN]:[TO_ENTITY_TYPE] | [EDGE LABEL]

The entity types field must match one of the entity types registered using the '-e' option, without the 'maltego.' prefix.

Example for specification file using column index:
0:Person > 2:EmailAddress | Edge label 1
0:Person > 1:Person | Edge label 2
2:EmailAddress > 1:Person | Edge label 3
Example for specification file using column names:
Col1:Person > Col3:EmailAddress | Edge label 1
Col1:Person > Col2:Person | Edge label 2
Col3:EmailAddress > Col2:Person | Edge label 3

Both of these are capable of parsing the input CSV file:

"Col1","Col2","Col3"
"P1","P3","P4"
"P2","P3","P4"

Example runs:

Based on column index:
$ python -m pymtgx.importer -i test/importer/data.csv -f test/importer/indexed.format -o index_test.mtgx -e test/test_entities.mtz -q \"
Parsed 3 lines. Created index_test.mtgx
Based on column name:
$ python -m pymtgx.importer -i test/importer/data.csv -f test/importer/mapped.format -o mapped_test.mtgx -e test/test_entities.mtz -m True -q \"
Parsed 3 lines. Created mapped_test.mtgx

About

Python API for generating Maltego mtgx files.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages