September 30, 2014, 04:38:05 pm
Maltego Forum

Username
Password

Pages: [1]
Print
Author Topic: Ruby Lib  (Read 81017 times)
RobertMcArdle
Newbie
*
Posts: 7


« on: January 14, 2011, 12:11:46 pm »

I've coded up a Library for Local Transform in Ruby, based on the existing Python and PHP ones. It designed to be almost identical to those existing libraries - to make it easy to port code to Ruby.

The main differences for the PHP and Python classes are:
  • The "Return" methods (ReturnEntity, ReturnTransform) to do not directly print out the XML - they return a string. To print the XML call printEntity or printTransform
  • There are no "get" and "set" functions - you can simple access the class variable directly
Note: The library files are attached to the post

Basic Example: (will create a Person Entity with a value of "Robert McArdle"

require "maltego_transform.rb"
me = MaltegoTransform();
me.debug("Starting Transform"); #Debug Info
me.addEntity("Person","Robert McArdle"); #New Person Entity
me.printOutput();


More Advanced Example:
require "maltego_transform.rb"
me = MaltegoTransform();
me.debug("Starting Transform"); #Debug Info
NewEnt = me.addEntity("Person","Robert McArdle"); #New Person Entity
NewEnt.weight = 300; #Set the Weight of the entity
NewEnt.addAdditionalFields("Age","Age Of Person","strict","28");
me.printOutput();


Available Functions:

Maltego Transform:
==============
parseArguments()
Parse the parameters passed to the transform and places them in the @entityFields hash. This will include the value and any additional fields of the calling Entity

addEntity(entityType, value):
entityType: Entity Type
value: Entity Value

addEntityToMessage(newEntity):
newEntity: MaltegoEntity Object to be added to the outputted "message"

addUIMessage(message,messageType="Inform"):
message: The Message to be displayed
messageType: FatalError/PartialError/Inform/Debug - note this defaults to "Inform" see documentation for additional information

addException(exceptionString):
exceptionString: Exception message to be thrown (eg "Error! Could not connect to 10.4.0.1")

throwException():
Simply return exception XML to the application

returnOutput():
Function to return all the added entities as well as the UI Messages

writeSTDERR(msg):
Function to write msg to STDErr

heartbeat():
Function to produce a "heartbeat"

progress(percent):
Function to output progress, eg MaltegoTransform.progress(20); #20% done

debug(msg)
msg: Debug message to be sent out

returnOutput()
Returns the XML of the Transform "message" as a String

printOutput()
Prints the Transform "message" to STD OUT


Maltego Entity
===========

initialize(entityType=nil, value=nil)
entityType: Entity Type (eg. Person,IPAddress)
value: Value for this entity

addAdditionalFields(fieldName=None,displayName=None,matchingRule=False,value=None)
Set additional fields for the entity
fieldName: Name used on the code side, eg displayName may be "Age of Person", but the app and your transform will see it as the fieldName variable
displayName: display name of the field shown within the entity properties
matchingRule: either "strict" for strict matching on this specific field or false
value: The additional fields value

returnEntity()
Returns the entity with the correct XML formatting as a String

printEntity()
Prints the XML of the entity to STD OUT


* MaltegoRubyLibv0.2.zip (3.55 KB - downloaded 14803 times.)
Logged
RobertMcArdle
Newbie
*
Posts: 7


« Reply #1 on: January 14, 2011, 12:13:31 pm »

Any comments or suggestions, just let me know and I'll update it
Logged
AndrewMacPherson
Administrator
Full Member
*****
Posts: 132


« Reply #2 on: January 17, 2011, 04:53:28 am »

Hi Robert,

Fantastic looking library, i'm not a ruby scripter so unfortunately i cannot test it, but i really do appreciate the effort you have taken to share it with the community.

-AM
Logged
Pages: [1]
Print
Jump to: