├── MaltegoTransform.py ├── README.md ├── fb-get-page-with-name-maltego.py ├── fbmaltego-details.py ├── fbmaltego.py ├── install-pictures ├── 1.png ├── 2.png ├── 3.png ├── 4.png ├── 5.png ├── 6.png ├── 7.png ├── 8.png └── 9.png └── totem-maltego.mtz /MaltegoTransform.py: -------------------------------------------------------------------------------- 1 | # 2 | # Updated Maltego Python library 3 | # 2013/03/30 4 | # See TRX documentation 5 | # 6 | # RT 7 | 8 | import sys 9 | from xml.dom import minidom 10 | 11 | BOOKMARK_COLOR_NONE="-1" 12 | BOOKMARK_COLOR_BLUE="0" 13 | BOOKMARK_COLOR_GREEN="1" 14 | BOOKMARK_COLOR_YELLOW="2" 15 | BOOKMARK_COLOR_ORANGE="3" 16 | BOOKMARK_COLOR_RED="4" 17 | LINK_STYLE_NORMAL="0" 18 | LINK_STYLE_DASHED="1" 19 | LINK_STYLE_DOTTED="2" 20 | LINK_STYLE_DASHDOT="3" 21 | UIM_FATAL='FatalError' 22 | UIM_PARTIAL='PartialError' 23 | UIM_INFORM='Inform' 24 | UIM_DEBUG='Debug' 25 | 26 | 27 | class MaltegoEntity(object): 28 | value = "" 29 | weight = 100 30 | displayInformation = [] 31 | additionalFields = [] 32 | iconURL = "" 33 | entityType = "Phrase" 34 | 35 | def __init__(self,eT=None,v=None): 36 | if (eT is not None): 37 | self.entityType = eT 38 | if (v is not None): 39 | self.value = v 40 | self.additionalFields = None 41 | self.additionalFields = [] 42 | self.weight = 100 43 | self.displayInformation = [] 44 | self.iconURL = "" 45 | 46 | def setType(self,eT=None): 47 | if (eT is not None): 48 | self.entityType = eT 49 | 50 | def setValue(self,eV=None): 51 | if (eV is not None): 52 | self.value = eV 53 | 54 | def setWeight(self,w=None): 55 | if (w is not None): 56 | self.weight = w 57 | 58 | def addDisplayInformation(self,di=None,dl='Info'): 59 | if (di is not None): 60 | self.displayInformation.append([dl,di]) 61 | 62 | def addProperty(self,fieldName=None,displayName=None,matchingRule=False,value=None): 63 | self.additionalFields.append([fieldName,displayName,matchingRule,value]) 64 | 65 | def setIconURL(self,iU=None): 66 | if (iU is not None): 67 | self.iconURL = iU 68 | 69 | def setLinkColor(self,color): 70 | self.addProperty('link#maltego.link.color','LinkColor','',color) 71 | 72 | def setLinkStyle(self,style): 73 | self.addProperty('link#maltego.link.style','LinkStyle','',style) 74 | 75 | def setLinkThickness(self,thick): 76 | self.addProperty('link#maltego.link.thickness','Thickness','',str(thick)) 77 | 78 | def setLinkLabel(self,label): 79 | self.addProperty('link#maltego.link.label','Label','',label) 80 | 81 | def setBookmark(self,bookmark): 82 | self.addProperty('bookmark#','Bookmark','',bookmark) 83 | 84 | def setNote(self,note): 85 | self.addProperty('notes#','Notes','',note) 86 | 87 | def returnEntity(self): 88 | r='' 89 | r+= "" 90 | r+= "" + str(self.value) + "" 91 | r+= "" + str(self.weight) + "" 92 | if (len(self.displayInformation) > 0): 93 | r+= "" 94 | for i in range(len(self.displayInformation)): 95 | r+='' 96 | r+='' 97 | if (len(self.additionalFields) > 0): 98 | r+= "" 99 | for i in range(len(self.additionalFields)): 100 | if (str(self.additionalFields[i][2]) != "strict"): 101 | r+= "" + str(self.additionalFields[i][3]) + "" 102 | else: 103 | r+= "" + str(self.additionalFields[i][3]) + "" 104 | r+= "" 105 | if (len(self.iconURL) > 0): 106 | r+= "" + self.iconURL + "" 107 | r+= "" 108 | return r 109 | 110 | 111 | class MaltegoTransform(object): 112 | # We were lazy to use a proper XML library to generate 113 | # our XML. Thus - encode data before you insert! 114 | # ..Sorry - RT 115 | entities = [] 116 | exceptions = [] 117 | UIMessages = [] 118 | 119 | def __init__(self): 120 | self.entities=[] 121 | self.exceptions = [] 122 | self.UIMessages = [] 123 | self=None 124 | 125 | def addEntity(self,enType=None,enValue=None): 126 | me = MaltegoEntity(enType,enValue) 127 | self.entities.append(me) 128 | return me 129 | 130 | def addUIMessage(self,message,messageType="Inform"): 131 | self.UIMessages.append([messageType,message]) 132 | 133 | def addException(self,exceptionString): 134 | self.exceptions.append(exceptionString) 135 | 136 | def throwExceptions(self): 137 | r='' 138 | r+= "" 139 | r+= "" 140 | r+= "" 141 | 142 | for i in range(len(self.exceptions)): 143 | r+= "" + self.exceptions[i] + "" 144 | r+= "" 145 | r+= "" 146 | r+= "" 147 | return r 148 | 149 | def returnOutput(self): 150 | r='' 151 | r+= "" 152 | r+= "" 153 | r+= "" 154 | for i in range(len(self.entities)): 155 | r+=self.entities[i].returnEntity() 156 | r+= "" 157 | r+= "" 158 | for i in range(len(self.UIMessages)): 159 | r+= "" + self.UIMessages[i][1] + "" 160 | r+= "" 161 | r+= "" 162 | r+= "" 163 | return r 164 | 165 | 166 | class MaltegoMsg: 167 | def __init__(self,MaltegoXML=""): 168 | xmldoc = minidom.parseString(MaltegoXML) 169 | #read the easy stuff like value, limits etc 170 | self.Value = self.i_getNodeValue(xmldoc,"Value") 171 | self.Weight = self.i_getNodeValue(xmldoc,"Weight") 172 | self.Slider = int(self.i_getNodeAttributeValue(xmldoc,"Limits","SoftLimit")) 173 | self.Type = self.i_getNodeAttributeValue(xmldoc,"Entity","Type") 174 | 175 | 176 | #read additional fields 177 | Properties = {} 178 | try: 179 | AFNodes= xmldoc.getElementsByTagName("AdditionalFields")[0] 180 | Settings = AFNodes.getElementsByTagName("Field") 181 | for node in Settings: 182 | AFName = node.attributes["Name"].value 183 | AFValue = self.i_getText(node.childNodes) 184 | Properties[AFName] = AFValue 185 | except: 186 | #sure this is not the right way...;) 187 | dontcare=1 188 | 189 | 190 | #parse transform settings 191 | TransformSettings = {} 192 | try: 193 | TSNodes= xmldoc.getElementsByTagName("TransformFields")[0] 194 | Settings = TSNodes.getElementsByTagName("Field") 195 | for node in Settings: 196 | TSName = node.attributes["Name"].value 197 | TSValue = self.i_getText(node.childNodes) 198 | TransformSettings[TSName] = TSValue 199 | except: 200 | dontcare=1 201 | 202 | #load back into object 203 | self.Properties = Properties 204 | self.TransformSettings = TransformSettings 205 | 206 | def i_getText(self,nodelist): 207 | rc = [] 208 | for node in nodelist: 209 | if node.nodeType == node.TEXT_NODE: 210 | rc.append(node.data) 211 | return ''.join(rc) 212 | 213 | def i_getNodeValue(self,node,Tag): 214 | return self.i_getText(node.getElementsByTagName(Tag)[0].childNodes) 215 | 216 | def i_getNodeAttributeValue(self,node,Tag,Attribute): 217 | return node.getElementsByTagName(Tag)[0].attributes[Attribute].value 218 | 219 | def getProperty(self,skey): 220 | if skey in self.Properties.keys(): 221 | return self.Properties[skey] 222 | else: 223 | return None 224 | 225 | def getTransformSetting(self,skey): 226 | if skey in self.TransformSettings.keys(): 227 | return self.TransformSettings[skey] 228 | else: 229 | return None 230 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # totem-maltego 2 | Buy Me A Coffee 3 | ### Educational purposes only 4 | [Totem](https://github.com/megadose/facebook_totem) allows you to retrieve information about ads of a facebook page , we can retrieve the number of people targeted, how much the ad cost and a lot of other information. 5 | [![forthebadge made-with-python](http://ForTheBadge.com/images/badges/made-with-python.svg)](https://www.python.org/) 6 | 7 | ## 🛠️ For the Installation check the [wiki](https://github.com/megadose/totem-maltego/wiki/Installation) 8 | ## Démo 9 | ![HD Demo](https://github.com/megadose/gif-demo/raw/master/opti.mp4) 10 | 11 | ## 📝 License 12 | [GNU General Public License v3.0](https://www.gnu.org/licenses/gpl-3.0.fr.html) 13 | -------------------------------------------------------------------------------- /fb-get-page-with-name-maltego.py: -------------------------------------------------------------------------------- 1 | from MaltegoTransform import * 2 | from facebook_totem import * 3 | id=sys.argv[1] 4 | 5 | trx = MaltegoTransform() 6 | 7 | for page in getFacebookPageFromName(id): 8 | PageFb = trx.addEntity("megadose.facebookpage", page["name"].replace("&","&")) 9 | PageFb.addProperty(fieldName="id",value=str(page["id"])) 10 | PageFb.addProperty(fieldName="category",value=str(page["category"].replace("&","&"))) 11 | PageFb.addProperty(fieldName="likes",value=str(page["likes"])) 12 | PageFb.addProperty(fieldName="verification",value=str(page["verification"])) 13 | PageFb.addProperty(fieldName="igUsername",value=str(page["igUsername"])) 14 | PageFb.addProperty(fieldName="igFollowers",value=str(page["igFollowers"])) 15 | PageFb.addProperty(fieldName="igVerification",value=str(page["igVerification"])) 16 | PageFb.addProperty(fieldName="pageIsDeleted",value=str(page["pageIsDeleted"])) 17 | PageFb.setIconURL(page["imageURI"].replace("&","&")) 18 | 19 | print(trx.returnOutput()) 20 | -------------------------------------------------------------------------------- /fbmaltego-details.py: -------------------------------------------------------------------------------- 1 | from MaltegoTransform import * 2 | import json,requests,base64,random,string 3 | id=sys.argv[2].split("jsonInfo=")[1] 4 | global trx 5 | trx = MaltegoTransform() 6 | import requests,json 7 | data=json.loads(base64.b64decode(id).decode("utf-8")) 8 | 9 | def addIfNotNone(entity,value,toadd): 10 | if str(value) !="None": 11 | if str(value)!="": 12 | trx.addEntity(entity,toadd+str(value).replace("<","<")) 13 | 14 | addIfNotNone("megadose.versionsAdNumber",str(data["collationCount"]),"") 15 | addIfNotNone("megadose.Impressions",str(data["impressionsWithIndex"]["impressionsText"]),"") 16 | addIfNotNone("megadose.Estimatereach",str(data["reachEstimate"]),"") 17 | addIfNotNone("megadose.Countreport",str(data["reportCount"]),"") 18 | 19 | addIfNotNone("megadose.Price",str(data["spend"]),"") 20 | for platform in data["publisherPlatform"]: 21 | addIfNotNone("megadose.Platformpublisher",str(platform),"") 22 | 23 | info = data["snapshot"] 24 | 25 | addIfNotNone("megadose.Buyby",str(info["byline"]),"") 26 | addIfNotNone("megadose.captionFb",str(info["caption"]),"") 27 | addIfNotNone("megadose.display_format",str(info["display_format"]),"") 28 | if info["title"]!=None: 29 | if "{{product.name}}" not in info["title"]: 30 | addIfNotNone("megadose.title",str(info["title"]),"") 31 | addIfNotNone("megadose.link_url",str(info["link_url"]),"") 32 | for video in info["videos"]: 33 | trx.addEntity("megadose.Attachment", video["video_sd_url"].replace("&","&")).setIconURL(video["video_preview_image_url"].replace("&","&")) 34 | 35 | for images in info["images"]: 36 | trx.addEntity("megadose.Attachment", images["original_image_url"].replace("&","&")).setIconURL(images["original_image_url"].replace("&","&")) 37 | 38 | 39 | additional_info=info["additional_info"] 40 | if additional_info!=None: 41 | addIfNotNone("maltego.Person",additional_info["treasurer_name"],"treasurer_name : ") 42 | addIfNotNone("maltego.Person",str(additional_info["director_name"]), "director_name : ") 43 | addIfNotNone("maltego.Phrase",str(additional_info["point_of_contact"]),"point_of_contact : ") 44 | addIfNotNone("maltego.Phrase",str(additional_info["committee_id"]),"committee_id : ") 45 | 46 | addIfNotNone("maltego.PhoneNumber", str(additional_info["phone_number"]),"") 47 | addIfNotNone("maltego.EmailAddress", str(additional_info["email"]),"") 48 | addIfNotNone("maltego.Website", str(additional_info["website"]),"") 49 | addIfNotNone("maltego.Location", str(str(additional_info["street_address_1"])+" , "+str(additional_info["city"])+" , "+str(additional_info["zipcode"])).replace("/>",""),"") 50 | 51 | print(trx.returnOutput()) 52 | -------------------------------------------------------------------------------- /fbmaltego.py: -------------------------------------------------------------------------------- 1 | from MaltegoTransform import * 2 | import json,requests,base64 3 | from facebook_totem import * 4 | 5 | id=str(sys.argv).split("id=")[1].split("#category")[0] 6 | 7 | trx = MaltegoTransform() 8 | for ad in getAdsFromId(id): 9 | poost = trx.addEntity("megadose.FacebookAdsPosts", ad["adArchiveID"]) 10 | jsoovalue=str(json.dumps(ad)) 11 | b64value=str(base64.b64encode(jsoovalue.encode('ascii')).decode("utf-8")) 12 | poost.addProperty(fieldName="jsonInfo",value=b64value) 13 | 14 | print(trx.returnOutput()) 15 | -------------------------------------------------------------------------------- /install-pictures/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/megadose/totem-maltego/1be4d4fa5fa02ccd27dffb5ec907583cf7e2c1e2/install-pictures/1.png -------------------------------------------------------------------------------- /install-pictures/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/megadose/totem-maltego/1be4d4fa5fa02ccd27dffb5ec907583cf7e2c1e2/install-pictures/2.png -------------------------------------------------------------------------------- /install-pictures/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/megadose/totem-maltego/1be4d4fa5fa02ccd27dffb5ec907583cf7e2c1e2/install-pictures/3.png -------------------------------------------------------------------------------- /install-pictures/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/megadose/totem-maltego/1be4d4fa5fa02ccd27dffb5ec907583cf7e2c1e2/install-pictures/4.png -------------------------------------------------------------------------------- /install-pictures/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/megadose/totem-maltego/1be4d4fa5fa02ccd27dffb5ec907583cf7e2c1e2/install-pictures/5.png -------------------------------------------------------------------------------- /install-pictures/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/megadose/totem-maltego/1be4d4fa5fa02ccd27dffb5ec907583cf7e2c1e2/install-pictures/6.png -------------------------------------------------------------------------------- /install-pictures/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/megadose/totem-maltego/1be4d4fa5fa02ccd27dffb5ec907583cf7e2c1e2/install-pictures/7.png -------------------------------------------------------------------------------- /install-pictures/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/megadose/totem-maltego/1be4d4fa5fa02ccd27dffb5ec907583cf7e2c1e2/install-pictures/8.png -------------------------------------------------------------------------------- /install-pictures/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/megadose/totem-maltego/1be4d4fa5fa02ccd27dffb5ec907583cf7e2c1e2/install-pictures/9.png -------------------------------------------------------------------------------- /totem-maltego.mtz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/megadose/totem-maltego/1be4d4fa5fa02ccd27dffb5ec907583cf7e2c1e2/totem-maltego.mtz --------------------------------------------------------------------------------