The scripted field I am trying to create, DomainFronting, is as follows:
//Returns True if the HostHeader is different to C2_Host
if (doc['HostHeader.keyword'].value == "") {
return "False";
}
else if (doc['HostHeader.keyword'].value == "Not Found") {
return "False";
}
else {
String CleanHostHeader = doc['HostHeader.keyword'].value.splitOnToken('Host: ')[1];
String CleanHostHeader2 = CleanHostHeader.splitOnToken('\\')[0];
if (doc['C2_Host.keyword'].value == CleanHostHeader2) {
return "False";
}
else {
return "True";
}
}
Which should, in theory:
Return False is HostHeader.keyword is empty;
Return False if HostHeader.keyword has a value of "Not Found";
Return False if HostHeader.keyword is the same as C2_Host;
Return True if HostHeader.keyword is different to C2_Host;
Unfortunately, for the above example, the outcome is True, despite both values being the same. When I change the return value to instead return CleanHostHeader2, I can see that the string is correct, and an exact match to C2_Host. Can someone steer me in the right direction, as to where I am going wrong please? I feel like I am very nearly there.
Yes @snkhan Question before digging in do you really mean this fields is an Array?
the [] signifies and array ... if so that may be why your script is not working...
2nd you should really be using a runtime field not a scripted field that is the new approach.
Indeed it is, but I would have thought doc['C2_Host.keyword'].value would just pick out its value? I am very new to ELK, and running 7.17, so thought Scripted Fields were the way to go. I see the note about it in the interface, but the link simply takes me to the help page, and it seems that RunTime fields cannot be configured in the GUI
Thanks Stephen. I am running 7.17. Appreciate the comment if there are multiple C2_Host values, ideally I would have it as if CleanHostHeader2 in C2_Host (pseudocode), but for the time being happy for it to just pick the first value, as that is what I am seeing in 99% of cases.
What I also do not understand is, if I return the value of CleanHostHeader2 instead, the string is exactly the same as C2_Host if there is 1 domain, so in that case I would absolutely expect the condition to return False, and yet it still returns True.
Yeah it's pretty much like Java I find in the UI just put the type and then the dot and then it'll show you all the functions. But the editor is not super helpful.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.