public LookupKV<KEY_T, VALUE_T> fromResult(Result result, String columnFamily, KEY_T key, VALUE_T value) throws IOException { if(result == null || result.getRow() == null) { return null; } key.fromBytes(result.getRow()); byte[] cf = Bytes.toBytes(columnFamily); NavigableMap<byte[], byte[]> cols = result.getFamilyMap(cf); value.fromColumns(cols.entrySet()); return new LookupKV<>(key, value); } @Override
@Override public Iterable<LookupKV> extract(String line) throws IOException { if(ignore(line)) { return Collections.emptyList(); } String[] tokens = parser.parseLine(line); LookupKey key = converter.toKey(getType(tokens), tokens[indicatorColumn]); Map<String, Object> values = new HashMap<>(); for(Map.Entry<String, Integer> kv : columnMap.entrySet()) { values.put(kv.getKey(), tokens[kv.getValue()]); } return Arrays.asList(new LookupKV(key, converter.toValue(values))); }
public LookupKV<KEY_T, VALUE_T> fromPut(Put put, String columnFamily, KEY_T key, VALUE_T value) throws IOException { key.fromBytes(put.getRow()); byte[] cf = Bytes.toBytes(columnFamily); value.fromColumns(Iterables.transform(put.getFamilyCellMap().get(cf), CELL_TO_ENTRY)); return new LookupKV<>(key, value); }
for(String token : StixExtractor.split(value)) { final String indicatorType = typeStr + ":" + category; LookupKV results = new LookupKV(new EnrichmentKey(indicatorType, token) , new EnrichmentValue( new HashMap<String, Object>() {{
@Override public Iterable<LookupKV> extract(final Hostname type, Map<String, Object> config) throws IOException { StringObjectPropertyType value = type.getHostnameValue(); String typeStr = getType(); if(config != null) { Object o = config.get(TYPE_CONFIG); if(o != null) { typeStr = o.toString(); } } List<LookupKV> ret = new ArrayList<>(); for(String token : StixExtractor.split(value)) { final String indicatorType = typeStr; LookupKV results = new LookupKV(new EnrichmentKey(indicatorType, token) , new EnrichmentValue(new HashMap<String, Object>() {{ put("source-type", "STIX"); put("indicator-type", indicatorType); put("source", type.toXMLString()); }} ) ); ret.add(results); } return ret; } @Override
@Override public Iterable<LookupKV> extract(final DomainName type, Map<String, Object> config) throws IOException { List<LookupKV> ret = new ArrayList<>(); String typeStr = getType(); if(config != null) { Object o = config.get(TYPE_CONFIG); if(o != null) { typeStr = o.toString(); } } final DomainNameTypeEnum domainType = type.getType(); if(domainType == null || SUPPORTED_TYPES.contains(domainType)) { StringObjectPropertyType value = type.getValue(); for (String token : StixExtractor.split(value)) { final String indicatorType = typeStr + ":" + DomainNameTypeEnum.FQDN; LookupKV results = new LookupKV(new EnrichmentKey(indicatorType, token) , new EnrichmentValue( new HashMap<String, Object>() {{ put("source-type", "STIX"); put("indicator-type", indicatorType); put("source", type.toXMLString()); }} ) ); ret.add(results); } } return ret; } @Override
@Override public Iterable<LookupKV> extract(URIObjectType type, Map<String, Object> config) throws IOException { List<LookupKV> ret = new ArrayList<>(); if(type != null) { AnyURIObjectPropertyType val = type.getValue(); if(val != null) { Object v = val.getValue(); if(v != null) { final String indicatorType = getType(); LookupKV results = new LookupKV(new EnrichmentKey(indicatorType, v.toString()) , new EnrichmentValue( new HashMap<String, Object>() {{ put("source-type", "STIX"); put("uri", v.toString()); put("indicator-type", indicatorType); put("source", type.toXMLString()); }} ) ); ret.add(results); } } } return ret; }
@Before public void setup() throws Exception { final MockHTable trackerTable = (MockHTable) MockHBaseTableProvider.addToCache(atTableName, cf); final MockHTable threatIntelTable = (MockHTable) MockHBaseTableProvider.addToCache(threatIntelTableName, cf); EnrichmentHelper.INSTANCE.load(threatIntelTable, cf, new ArrayList<LookupKV<EnrichmentKey, EnrichmentValue>>() {{ add(new LookupKV<>(new EnrichmentKey("10.0.2.3", "10.0.2.3"), new EnrichmentValue(new HashMap<>()))); }}); BloomAccessTracker bat = new BloomAccessTracker(threatIntelTableName, 100, 0.03); PersistentAccessTracker pat = new PersistentAccessTracker(threatIntelTableName, "0", trackerTable, cf, bat, 0L); lookup = new EnrichmentLookup(threatIntelTable, cf, pat); JSONParser jsonParser = new JSONParser(); expectedMessage = (JSONObject) jsonParser.parse(expectedMessageString); }
@Before public void setup() throws Exception { final MockHTable hbaseTable = (MockHTable) MockHBaseTableProvider.addToCache(hbaseTableName, cf); EnrichmentHelper.INSTANCE.load(hbaseTable, cf, new ArrayList<LookupKV<EnrichmentKey, EnrichmentValue>>() {{ for(int i = 0;i < 5;++i) { add(new LookupKV<>(new EnrichmentKey(ENRICHMENT_TYPE, "indicator" + i) , new EnrichmentValue(ImmutableMap.of("key" + i, "value" + i)) ) ); } }}); context = new Context.Builder() .with( Context.Capabilities.GLOBAL_CONFIG , () -> ImmutableMap.of( SimpleHBaseEnrichmentFunctions.TABLE_PROVIDER_TYPE_CONF , MockHBaseTableProvider.class.getName() ) ) .build(); } public Object run(String rule, Map<String, Object> variables) throws Exception {
@Before public void setup() throws Exception { final MockHTable trackerTable = (MockHTable) MockHBaseTableProvider.addToCache(atTableName, cf); final MockHTable hbaseTable = (MockHTable) MockHBaseTableProvider.addToCache(hbaseTableName, cf); EnrichmentHelper.INSTANCE.load(hbaseTable, cf, new ArrayList<LookupKV<EnrichmentKey, EnrichmentValue>>() {{ add(new LookupKV<>(new EnrichmentKey(PLAYFUL_CLASSIFICATION_TYPE, "10.0.2.3") , new EnrichmentValue(PLAYFUL_ENRICHMENT) ) ); }}); EnrichmentHelper.INSTANCE.load(hbaseTable, cf1, new ArrayList<LookupKV<EnrichmentKey, EnrichmentValue>>() {{ add(new LookupKV<>(new EnrichmentKey(CF1_CLASSIFICATION_TYPE, "10.0.2.4") , new EnrichmentValue(CF1_ENRICHMENT) ) ); }}); BloomAccessTracker bat = new BloomAccessTracker(hbaseTableName, 100, 0.03); PersistentAccessTracker pat = new PersistentAccessTracker(hbaseTableName, "0", trackerTable, cf, bat, 0L); lookup = new EnrichmentLookup(hbaseTable, cf, pat); JSONParser jsonParser = new JSONParser(); expectedMessage = (JSONObject) jsonParser.parse(expectedMessageString); }
final MockHTable threatIntelTable = (MockHTable) MockHBaseTableProvider.addToCache(threatIntelTableName, cf); EnrichmentHelper.INSTANCE.load(threatIntelTable, cf, new ArrayList<LookupKV<EnrichmentKey, EnrichmentValue>>() {{ add(new LookupKV<>(new EnrichmentKey(MALICIOUS_IP_TYPE, "10.0.2.3"), new EnrichmentValue(new HashMap<>()))); }}); final MockHTable enrichmentTable = (MockHTable) MockHBaseTableProvider.addToCache(enrichmentsTableName, cf); EnrichmentHelper.INSTANCE.load(enrichmentTable, cf, new ArrayList<LookupKV<EnrichmentKey, EnrichmentValue>>() {{ add(new LookupKV<>(new EnrichmentKey(PLAYFUL_CLASSIFICATION_TYPE, "10.0.2.3") , new EnrichmentValue(PLAYFUL_ENRICHMENT)