Difference between revisions of "Python"
| (20 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| − | Truxton supports [https://www.python.org/ Python] 3. | + | Truxton supports [https://www.python.org/ Python] 3.12 via a [https://docs.python.org/3/faq/windows.html#is-a-pyd-file-the-same-as-a-dll pyd] library named <code>Truxton.pyd</code>. |
This exposes the functionality of Truxton to Python. | This exposes the functionality of Truxton to Python. | ||
| − | |||
=Overview= | =Overview= | ||
| − | You must use the "import" directive to load the Truxton Python provider in <code>truxton.pyd</code>. | + | You must use the "import" directive to load the Truxton Python provider in a file named <code>truxton.pyd</code>. |
This directive will search a variety of folders for the <code>[https://docs.python.org/3/faq/windows.html#is-a-pyd-file-the-same-as-a-dll pyd]</code> file for Truxton (<code>truxton.pyd</code>). | This directive will search a variety of folders for the <code>[https://docs.python.org/3/faq/windows.html#is-a-pyd-file-the-same-as-a-dll pyd]</code> file for Truxton (<code>truxton.pyd</code>). | ||
Normally, this file is installed in the SDK folder (<code>C:\Program Files\Truxton\SDK</code>) along with all of the dependent files. Be sure to include the full path (e.g. <code>c:\program files\truxton\sdk</code>) | Normally, this file is installed in the SDK folder (<code>C:\Program Files\Truxton\SDK</code>) along with all of the dependent files. Be sure to include the full path (e.g. <code>c:\program files\truxton\sdk</code>) | ||
| Line 10: | Line 9: | ||
You can modify the <code>[https://docs.python.org/3/using/cmdline.html?highlight=pythonpath#envvar-PYTHONPATH PYTHONPATH]</code> environment variable to include the SDK folder and Python will automatically search this folder. | You can modify the <code>[https://docs.python.org/3/using/cmdline.html?highlight=pythonpath#envvar-PYTHONPATH PYTHONPATH]</code> environment variable to include the SDK folder and Python will automatically search this folder. | ||
| − | Doing so will allow you to | + | Doing so will allow you to specify the Truxton library at the top of your scripts: |
<source lang="Python"> | <source lang="Python"> | ||
| Line 49: | Line 48: | ||
import truxton | import truxton | ||
| − | def main(): | + | def main() -> None: |
t = truxton.create() | t = truxton.create() | ||
print(t.version) | print(t.version) | ||
| Line 55: | Line 54: | ||
if __name__ == "__main__": | if __name__ == "__main__": | ||
| − | main() | + | sys.exit(main()) |
</source> | </source> | ||
| Line 86: | Line 85: | ||
* [[TruxtonJurisdiction]] - For creating new jurisdictions in Truxton. This will make an entry in the <code>[Jurisdiction]</code> table. | * [[TruxtonJurisdiction]] - For creating new jurisdictions in Truxton. This will make an entry in the <code>[Jurisdiction]</code> table. | ||
* [[TruxtonLocation]] - For adding geographic coordinates to the <code><nowiki>[</nowiki>[[Location Table|Location]]<nowiki>]</nowiki></code> table. | * [[TruxtonLocation]] - For adding geographic coordinates to the <code><nowiki>[</nowiki>[[Location Table|Location]]<nowiki>]</nowiki></code> table. | ||
| − | * [[TruxtonMedia]] - For adding media to Truxton. This will make an entry in the <code>[Media]</code> table. | + | * [[TruxtonMedia]] - For adding media to Truxton. This will make an entry in the <code><nowiki>[</nowiki>[[Media Table|Media]]<nowiki>]</nowiki></code> table. |
* [[TruxtonMessage]] - The way Truxton [https://en.wikipedia.org/wiki/Extract,_transform,_load ETL] processes communicate. | * [[TruxtonMessage]] - The way Truxton [https://en.wikipedia.org/wiki/Extract,_transform,_load ETL] processes communicate. | ||
| + | * [[TruxtonMessageAddress]] - | ||
| + | * [[TruxtonMessageParticipant]] - | ||
| + | * [[TruxtonNote]] - This will add notes to an investigation. This will make an entry in the <code>[InvestigatorNote]</code> table. | ||
* [[TruxtonObject]] - The object responsible for a connection to Truxton. | * [[TruxtonObject]] - The object responsible for a connection to Truxton. | ||
* [[TruxtonOptions]] - The object responsible for retrieving configuration variables from Truxton's [[Configuration System]]. | * [[TruxtonOptions]] - The object responsible for retrieving configuration variables from Truxton's [[Configuration System]]. | ||
* [[TruxtonRelation]] - For adding records to the <code><nowiki>[</nowiki>[[Relation Table|Relation]]<nowiki>]</nowiki></code> table for relating two items in Truxton. | * [[TruxtonRelation]] - For adding records to the <code><nowiki>[</nowiki>[[Relation Table|Relation]]<nowiki>]</nowiki></code> table for relating two items in Truxton. | ||
| − | * [[TruxtonSensitiveSiteList]] - For handling Sensitive Site Lists | + | * [[TruxtonSensitiveSiteList]] - For handling Sensitive Site Lists. A sensitive site is an area that you want to be aware if any geographic coordinate in the siezed media was near. |
* [[TruxtonSubject]] - For adding subjects of investigations, aka persons of interest, aka suspects. This will make an entry in the <code>[Suspect]</code> table. | * [[TruxtonSubject]] - For adding subjects of investigations, aka persons of interest, aka suspects. This will make an entry in the <code>[Suspect]</code> table. | ||
* [[TruxtonUrl]] - For adding records to the <code><nowiki>[</nowiki>[[WebsiteVisit Table|WebsiteVisit]]<nowiki>]</nowiki></code> table. | * [[TruxtonUrl]] - For adding records to the <code><nowiki>[</nowiki>[[WebsiteVisit Table|WebsiteVisit]]<nowiki>]</nowiki></code> table. | ||
| Line 102: | Line 104: | ||
=Samples= | =Samples= | ||
| + | * [[TruxtonFileIO#Sample|Open a file in Truxton]] - How to access the contents of a file in Truxton | ||
* [[Python Sample Register a New File Type|Register a New File Type]] - Create your own type of file | * [[Python Sample Register a New File Type|Register a New File Type]] - Create your own type of file | ||
| − | * [[Python Sample Identification ETL|ETL for File Identification]] - | + | * [[Python Sample Identification ETL|ETL for File Identification]] - Plug into Truxton's ETL pipeline to identify new types of files |
| − | * [[Python Sample Exploitation ETL|ETL for File Exploitation]] - | + | * [[Python Sample Exploitation ETL|ETL for File Exploitation]] - Extend Truxton's ETL pipeling to exploit new file types |
* [[Python Sample Export Videos|Export Videos]] - Export only unique videos from Truxton | * [[Python Sample Export Videos|Export Videos]] - Export only unique videos from Truxton | ||
* [[Helpful scripts#E01 of E01s|Export E01s]] - Exporting [https://en.wikipedia.org/wiki/EnCase#Expert_Witness_File_Format E01s] from Truxton | * [[Helpful scripts#E01 of E01s|Export E01s]] - Exporting [https://en.wikipedia.org/wiki/EnCase#Expert_Witness_File_Format E01s] from Truxton | ||
* [[Creating a Rack#Display Machine Configuration|Rack Configuration]] - Displaying information about the configuration of a server in a rack | * [[Creating a Rack#Display Machine Configuration|Rack Configuration]] - Displaying information about the configuration of a server in a rack | ||
* [[Query Truxton|Query the Truxton Database]] - Using Python to pull information out of the Truxton database | * [[Query Truxton|Query the Truxton Database]] - Using Python to pull information out of the Truxton database | ||
| − | * [[Python Sample Tag Notification ETL|Tag Notification]] - Your ETL gets notified when a user tags something | + | * [[Python Sample Tag Notification ETL|Tag Notification]] - Your ETL process gets notified when a user tags something in the GUI |
| − | * [[Helpful scripts#Carve a File in Truxton|Carve a File's Contents]] - You can carve a file already in Truxton | + | * [[Helpful scripts#Carve a File in Truxton|Carve a File's Contents]] - You can carve a file that already exists in Truxton |
| − | * [[Useful_SQL_Queries#Python_Script_to_Change_Depot_Path|Change Depot Paths]] - Change the path to the depot files in the database | + | * [[Useful_SQL_Queries#Python_Script_to_Change_Depot_Path|Change Depot Paths]] - Change the path to the [[Depot|depot]] files in the database |
| − | * [[Python Sample Identify File Type|Identify Type of File]] - How to determine the type of a file | + | * [[Python Sample Identify File Type|Identify Type of File]] - How to determine the type of a file on your local drive |
| + | * [[Python Sample List File Types|List Supported File Types]] - How to list the types of files that Truxton knows about | ||
| + | * [[Python Sample Triage File|Add a file to be triaged]] - How to add a new file to be included in a [[Triage]] load | ||
| + | * [[Python Sample SQLite|Using SQLite]] - How to access [https://sqlite.org/ SQLite] databases in Truxton | ||
| + | * [[TruxtonEnumeration#Sample|Enumerating all investigations]] and the media in each investigation | ||
| + | * [[TruxtonEnumeration#Media_Sample|Enumerating events]] in one particular piece of media | ||
Latest revision as of 07:42, 30 September 2025
Truxton supports Python 3.12 via a pyd library named Truxton.pyd.
This exposes the functionality of Truxton to Python.
Contents
Overview
You must use the "import" directive to load the Truxton Python provider in a file named truxton.pyd.
This directive will search a variety of folders for the pyd file for Truxton (truxton.pyd).
Normally, this file is installed in the SDK folder (C:\Program Files\Truxton\SDK) along with all of the dependent files. Be sure to include the full path (e.g. c:\program files\truxton\sdk)
in your PATH environment variable so that Windows can locate all the needed dependencies.
You can modify the PYTHONPATH environment variable to include the SDK folder and Python will automatically search this folder.
Doing so will allow you to specify the Truxton library at the top of your scripts:
import truxton
If you don't have permission to modify environment variables, or you want to test your code with different versions of Truxton, you can manually modify Python's module search path.
Instead of using PYTHONPATH environment variable, you can tell Python which folder contains truxton.pyd by adding the following to the top of your scripts:
import sys
sys.path.append('C:/Program Files/Truxton/SDK')
import truxton
You can, within code, change which version of Truxton will be used with your script. This ensures your script will always work should a breaking change be introduced in a subsequent release of Truxton.
When you import truxton you will get all of the predefined constants for file type, data type, origins, locations,
messages, entities, relations, events, media, objects, url methods, and urls.
You can see them all by issuing a dir command.
>>> dir(truxton)
This will allow your Python code to use the same constant names as C, C++ and C# code.
>>> print(truxton.Type_JPEG)
203
Once you have this working, you can start playing with Truxton.
import sys
sys.path.append('C:/Program Files/Truxton/SDK')
import truxton
def main() -> None:
t = truxton.create()
print(t.version)
return None
if __name__ == "__main__":
sys.exit(main())
Style
In general, when using a Truxton Python object, you will follow this pattern:
- Create the object
- Set the data members of the object
- Call
save()to store the object in the Truxton database.
Until you call save(), nothing will appear in Truxton.
Classes
Truxton exposes several classes to Python.
- Truxton - The top level object.
- TruxtonArtifact - For adding records to the
[Entity]table. - TruxtonArtifactType - For adding custom artifact types to Truxton. This will make an entry in the
[EntityType]table. - TruxtonBolo - For adding BOLO criteria to generate alerts.
- TruxtonChildFileIO - For writing a file to Truxton.
- TruxtonCommunication - For adding email, sms, mms, etc. communications to Truxton.
- TruxtonEnumeration - For enumerating everything in Truxton.
- TruxtonETL - For becoming a Truxton ETL process.
- TruxtonEvent - For adding records to the
[Event]table. - TruxtonEventType - For adding custom event types to Truxton. This will make an entry in the
[EventType]table. - TruxtonExport - For exporting files out of Truxton.
- TruxtonEXIF - For adding records to the
[EXIF]table. - TruxtonFileIO - For working with a read-only file stored in Truxton.
- TruxtonFileType - For adding new file types to Truxton. This will make an entry in the
[FileType]table. - TruxtonInvestigation - For creating new investigations in Truxton. This will make an entry in the
[Investigation]table. - TruxtonInvestigationEvent - For creating new investigation events in Truxton. This will make an entry in the
[InvestigationEvent]table. - TruxtonJurisdiction - For creating new jurisdictions in Truxton. This will make an entry in the
[Jurisdiction]table. - TruxtonLocation - For adding geographic coordinates to the
[Location]table. - TruxtonMedia - For adding media to Truxton. This will make an entry in the
[Media]table. - TruxtonMessage - The way Truxton ETL processes communicate.
- TruxtonMessageAddress -
- TruxtonMessageParticipant -
- TruxtonNote - This will add notes to an investigation. This will make an entry in the
[InvestigatorNote]table. - TruxtonObject - The object responsible for a connection to Truxton.
- TruxtonOptions - The object responsible for retrieving configuration variables from Truxton's Configuration System.
- TruxtonRelation - For adding records to the
[Relation]table for relating two items in Truxton. - TruxtonSensitiveSiteList - For handling Sensitive Site Lists. A sensitive site is an area that you want to be aware if any geographic coordinate in the siezed media was near.
- TruxtonSubject - For adding subjects of investigations, aka persons of interest, aka suspects. This will make an entry in the
[Suspect]table. - TruxtonUrl - For adding records to the
[WebsiteVisit]table. - TruxtonUSB - For adding records to the
[USBDevice]table.
Remarks
The Python API is designed primarily for programs to contribute to Truxton.
Truxton.pyd was developed using the C API with a thin adapter layer of code to translate from Python provider semantics to Truxton calls.
Samples
- Open a file in Truxton - How to access the contents of a file in Truxton
- Register a New File Type - Create your own type of file
- ETL for File Identification - Plug into Truxton's ETL pipeline to identify new types of files
- ETL for File Exploitation - Extend Truxton's ETL pipeling to exploit new file types
- Export Videos - Export only unique videos from Truxton
- Export E01s - Exporting E01s from Truxton
- Rack Configuration - Displaying information about the configuration of a server in a rack
- Query the Truxton Database - Using Python to pull information out of the Truxton database
- Tag Notification - Your ETL process gets notified when a user tags something in the GUI
- Carve a File's Contents - You can carve a file that already exists in Truxton
- Change Depot Paths - Change the path to the depot files in the database
- Identify Type of File - How to determine the type of a file on your local drive
- List Supported File Types - How to list the types of files that Truxton knows about
- Add a file to be triaged - How to add a new file to be included in a Triage load
- Using SQLite - How to access SQLite databases in Truxton
- Enumerating all investigations and the media in each investigation
- Enumerating events in one particular piece of media