Extend IPED functionality with JavaScript and Python scripts
IPED supports extensible processing through JavaScript and Python scripts, allowing you to create custom tasks that run during evidence processing. Scripts can analyze items, set attributes, create bookmarks, and control which files are processed.
Python scripts use a class-based structure. The class name must match the filename without .py:
PythonScriptTask.py
class PythonScriptTask: def isEnabled(self): """Returns if this task is enabled""" return True def getConfigurables(self): """Returns optional list of configurable objects""" return [] def init(self, configuration): """Initialize - runs once per processing thread""" # Load models, config, etc. return def process(self, item): """Process each item""" # Ignore DLL files if item.getExt() is not None and ".dll" in item.getExt().lower(): item.setToIgnore(True) # Set custom attribute if item.getParsedTextCache() is not None and ".com" in item.getParsedTextCache().lower(): item.setExtraAttribute("containsDotCom", True) def finish(self): """Cleanup - runs after all items processed""" # Create bookmarks, save results query = "type:doc" searcher.setQuery(query) ids = searcher.search().getIds() bookmarkId = ipedCase.getBookmarks().newBookmark("DOC files") ipedCase.getBookmarks().setBookmarkComment(bookmarkId, "Documents of DOC file format") ipedCase.getBookmarks().addBookmark(ids, bookmarkId) ipedCase.getBookmarks().saveState(True)
This script uses Keras and TensorFlow to detect nudity in images:
NSFWNudityDetectTask.py
# ConfigurationuseImageThumbs = TruebatchSize = 50maxThreads = None # Limit GPU memory usageenableProp = 'enableYahooNSFWDetection'targetSize = (224, 224)class NSFWNudityDetectTask: def __init__(self): self.itemList = [] self.imageList = [] def isEnabled(self): return enabled def getConfigurables(self): from iped.engine.config import EnableTaskProperty return [EnableTaskProperty(enableProp)] def init(self, configuration): global enabled, PilImage, np enabled = configuration.getEnableTaskProperty(enableProp) if not enabled: return from PIL import Image as PilImage import numpy as np loadModel() def process(self, item): if not item.isQueueEnd() and not supported(item): return # Check cache if item.getHash() is not None: cache = caseData.getCaseObject('nsfw_score_cache') score = cache.get(item.getHash()) if score is not None: item.setExtraAttribute('nsfw_nudity_score', score) return # Process image or video if isSupportedVideo(item): processVideoFrames(item) else: # Load image and add to batch img = loadImage(item) if img is not None: self.imageList.append(img) self.itemList.append(item) # Process batch when full if len(self.itemList) >= batchSize: processImages(self.imageList, self.itemList) self.itemList.clear() self.imageList.clear()
// Ignore item (exclude from processing and case)item.setToIgnore(true);// Include/exclude from case after processingitem.setAddToCase(false);// Modify categoriesitem.addCategory("Suspicious");item.removeCategory("Documents");item.setCategory("Malware"); // Replaces all// Set media typeitem.setMediaTypeStr("application/x-custom");// Set custom attributes (creates new columns)item.setExtraAttribute("score", 95.5);item.setExtraAttribute("flagged", "true");// Override extracted textitem.setParsedTextCache("Custom text");
You can create bookmarks in the finish() method using the ipedCase and searcher objects:
function finish() { // Define search query var query = "type:pdf"; // Search for items searcher.setQuery(query); var ids = searcher.search().getIds(); // Create bookmark var bookmarkId = ipedCase.getBookmarks().newBookmark("PDF files"); // Set description ipedCase.getBookmarks().setBookmarkComment(bookmarkId, "Documents of PDF file format"); // Add items to bookmark ipedCase.getBookmarks().addBookmark(ids, bookmarkId); // Save changes synchronously ipedCase.getBookmarks().saveState(true);}
def process(self, item): self.batch.append(item) if len(self.batch) >= 50: processBatch(self.batch) self.batch.clear()
2
Cache Results
Use hash-based caching to avoid reprocessing:
cache = caseData.getCaseObject('result_cache')if cache is None: from java.util.concurrent import ConcurrentHashMap cache = ConcurrentHashMap() caseData.putCaseObject('result_cache', cache)result = cache.get(item.getHash())if result is None: result = expensiveOperation(item) cache.put(item.getHash(), result)
3
Avoid Full Text Search
Searching text in all items is very slow:
// SLOW - avoid this!if (item.getParsedTextCache().indexOf("keyword") != -1) { // ...}// BETTER - use regex validation on regex matches// or filter by file type firstif (item.getMediaType().toString().startsWith("text/")) { // Now safe to search text}