<div dir="ltr"><div><div>Hi,<br><br></div>I am working on a way for URL matching using Suri (2.0.8, but I can upgrade) <br><br>I think the easiest way is using LuaJIT in a rule. The use case is matching "bad URLs" - which are from dynamic Malware analysis. <br><br></div><div>Here is what I tried so far:<br><br></div><div>I create a file and put the bad URLs in there - like this:<br></div><div><br><a href="http://badstuff.com/bad/malware.exe">http://badstuff.com/bad/malware.exe</a><br></div><div><a href="http://reallybadstuff.com/worse/evilware.msi">http://reallybadstuff.com/worse/evilware.msi</a><br></div><div> <br></div><div>I want to match these URLs with Suri. To do this I write a quick rule:<br></div><div><br>$$ more /etc/suricata/rules/custom.rules <br>alert http any any -> any any (msg:"LUAJIT test"; luajit:file.lua; sid:900000; flow:established; rev:1)<br><br></div><div>I have compiled suricata 2.0.8 on a Gentoo system:<br><br>./configure --enable-luajit --with-libpcap_ng-libraries=/usr/local/lib --with-libpcap_ng-includes=/usr/local/include/ --prefix=/usr/ --sysconfdir=/etc/ --localstatedir=/var/ --disable-gccmarch-native --enable-gccprotect --with-libluajit-includes=/usr/include/luajit-2.0<br></div><div><br>...<br>  libnss support:                          no<br>  libnspr support:                         no<br>  libjansson support:                      yes<br>  Prelude support:                         no<br>  PCRE jit:                                yes<br>  LUA support:                             yes<br>  libluajit:                               yes<br>....<br><br></div><div>That looks fine to me. Now I test it:<br>sudo suricata --af-packet=eno1 -S /etc/suricata/rules/custom.rules  -v<br><br></div><div>I see the following error:<br> <Info> - Loading rule file: /etc/suricata/rules/custom.rules<br><Error> - [ERRCODE: SC_ERR_LUAJIT_ERROR(212)] - unsupported data type protocol<br> <Error> - [ERRCODE: SC_ERR_INVALID_SIGNATURE(39)] - error par<br>sing signature "alert http any any -> any any (msg:"LUAJIT test"; luajit:file.lua; sid:900000; flow:established; rev:1)" from file /etc/suricata/rules/custom.rules at line 1<br><Error> - [ERRCODE: SC_ERR_NO_RULES(42)] - No rules loaded from /etc/suricata/rules/custom.rules<br><br></div><div>Does someone know why the rule parser steps out? From what I see the feature is compiled into the engine. I don't see what the error message indicates. <br></div><div><br></div>Below is my current lua code for reference. I tested some simpler lua scripts with the same error in the log.<br><div><br></div><div>Best,<br></div><div>Marius<br></div><div><br></div><div><br>local open = io.open<br><br>function init (args)<br>    local needs = {}<br>    needs["protocol"] = "http" <br>     -- needs["http.uri"] = tostring(true)<br>    return needs<br>end<br><br><br>function setup (args)<br>    filename = SCLogPath() .. "/" .. name<br>    file = assert(io.open(filename, "a"))<br>    SCLogInfo("HTTP Log Filename " .. filename)<br>    http = 0<br>end<br><br><br>function match(args)<br>    --for line in io.lines("bad_urls.txt") do<br>    --   print(line)<br>    -- end<br>    http_host = HttpGetRequestHost()<br>    if http_host == nil then<br>        return 0 <br>    end<br><br>    http_uri = HttpGetRequestUriNormalized()<br>    if http_uri == nil then<br>        return 0<br>    end<br><br>    local file = io.open("bad_urls.txt", "r");<br>    local arr = {}<br>    for line in file:lines() do<br>       table.insert (arr, line);<br>    end<br><br>    ts = SCPacketTimeString()<br>    ipver, srcip, dstip, proto, sp, dp = SCFlowTuple()<br><br>    file:write(ts .. " " .. http_host .. " [**] " .. http_uri .. " [**] " ..<br>           http_ua .. " [**] " .. srcip .. ":" .. sp .. " -> " ..<br>           dstip .. ":" .. dp .. "\n")<br>    file:flush()<br><br><br>    a = tostring(args["http.uri"])<br>    a = http_host + "/" + a <br><br>    for url in arr do<br>       net_url = "http://" .. http_host .. http_uri<br>       if url == net_url then<br>           -- file:write(net_url .. " matches bad url - potential Malware\n")<br>       return 1<br>       end<br>    end<br><br>    return 0<br>end<br><br>function deinit (args)<br>    SCLogInfo ("Bad URLs transactions logged");<br>    file:close(file)<br>end<br></div></div>