[Oisf-users] How do I match a URL with a Suricata rule?

Alan Wanderley dos Santos alan.santos at rnp.br
Thu Dec 10 17:11:20 UTC 2015

Hi all, 

Very interesting work... 

We have this issue here, so, i wrote a script (using shell) that read http.log and match it with a bad urls list. If match, the script send me a email with the fullpath URL in mail body and http.log line attached. Works fine for us. For example: 

Domain: terr a .com.br 
URL: http://terra.com.br 
LOGs attached 
If you want, i can share the script. 


Alan Santos 
Analista de Seguran├ža 
Centro de Atendimento a Incidentes de Seguran├ža (CAIS) 
Rede Nacional de Ensino e Pesquisa (RNP) 
(19) 3787-3314 | alan.santos at rnp.br 

De: "Marius" <wishinet at gmail.com> 
Para: "oisf-users" <oisf-users at openinfosecfoundation.org> 
Enviadas: Quinta-feira, 10 de dezembro de 2015 14:56:08 
Assunto: [Oisf-users] How do I match a URL with a Suricata rule? 


I am working on a way for URL matching using Suri (2.0.8, but I can upgrade) 

I think the easiest way is using LuaJIT in a rule. The use case is matching "bad URLs" - which are from dynamic Malware analysis. 

Here is what I tried so far: 

I create a file and put the bad URLs in there - like this: 


I want to match these URLs with Suri. To do this I write a quick rule: 

$$ more /etc/suricata/rules/custom.rules 
alert http any any -> any any (msg:"LUAJIT test"; luajit:file.lua; sid:900000; flow:established; rev:1) 

I have compiled suricata 2.0.8 on a Gentoo system: 

./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 

libnss support: no 
libnspr support: no 
libjansson support: yes 
Prelude support: no 
PCRE jit: yes 
LUA support: yes 
libluajit: yes 

That looks fine to me. Now I test it: 
sudo suricata --af-packet=eno1 -S /etc/suricata/rules/custom.rules -v 

I see the following error: 
<Info> - Loading rule file: /etc/suricata/rules/custom.rules 
<Error> - [ERRCODE: SC_ERR_LUAJIT_ERROR(212)] - unsupported data type protocol 
<Error> - [ERRCODE: SC_ERR_INVALID_SIGNATURE(39)] - error par 
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 
<Error> - [ERRCODE: SC_ERR_NO_RULES(42)] - No rules loaded from /etc/suricata/rules/custom.rules 

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. 

Below is my current lua code for reference. I tested some simpler lua scripts with the same error in the log. 


local open = io.open 

function init (args) 
local needs = {} 
needs["protocol"] = "http" 
-- needs["http.uri"] = tostring(true) 
return needs 

function setup (args) 
filename = SCLogPath() .. "/" .. name 
file = assert(io.open(filename, "a")) 
SCLogInfo("HTTP Log Filename " .. filename) 
http = 0 

function match(args) 
--for line in io.lines("bad_urls.txt") do 
-- print(line) 
-- end 
http_host = HttpGetRequestHost() 
if http_host == nil then 
return 0 

http_uri = HttpGetRequestUriNormalized() 
if http_uri == nil then 
return 0 

local file = io.open("bad_urls.txt", "r"); 
local arr = {} 
for line in file:lines() do 
table.insert (arr, line); 

ts = SCPacketTimeString() 
ipver, srcip, dstip, proto, sp, dp = SCFlowTuple() 

file:write(ts .. " " .. http_host .. " [**] " .. http_uri .. " [**] " .. 
http_ua .. " [**] " .. srcip .. ":" .. sp .. " -> " .. 
dstip .. ":" .. dp .. "\n") 

a = tostring(args["http.uri"]) 
a = http_host + "/" + a 

for url in arr do 
net_url = "http://" .. http_host .. http_uri 
if url == net_url then 
-- file:write(net_url .. " matches bad url - potential Malware\n") 
return 1 

return 0 

function deinit (args) 
SCLogInfo ("Bad URLs transactions logged"); 

Suricata IDS Users mailing list: oisf-users at openinfosecfoundation.org 
Site: http://suricata-ids.org | Support: http://suricata-ids.org/support/ 
List: https://lists.openinfosecfoundation.org/mailman/listinfo/oisf-users 
Suricata User Conference November 4 & 5 in Barcelona: http://oisfevents.net 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openinfosecfoundation.org/pipermail/oisf-users/attachments/20151210/7d8f3425/attachment-0002.html>

More information about the Oisf-users mailing list