Skip to content

Instantly share code, notes, and snippets.

@grigorescu
Forked from sethhall/http-more-files-names.bro
Last active September 10, 2020 21:36
Show Gist options
  • Save grigorescu/40700b2afb1f4a13493acc48f8b288d1 to your computer and use it in GitHub Desktop.
Save grigorescu/40700b2afb1f4a13493acc48f8b288d1 to your computer and use it in GitHub Desktop.
Get some extra file names from http
@load base/protocols/http/entities
module HTTP;
redef record HTTP::Info += {
potential_fname: string &optional;
};
event http_request(c: connection, method: string, original_URI: string,
unescaped_URI: string, version: string) &priority=5
{
if ( !c$http?$uri )
return;
# Get rid of uri arguments
local path = split_string(c$http$uri, /\?/)[0];
local out = split_string(path, /\//);
# Take the last component in the uri path
c$http$potential_fname = out[|out|-1];
}
event http_header(c: connection, is_orig: bool, name: string, value: string) &priority=3
{
if ( is_orig )
return;
if ( !c$http?$current_entity )
c$http$current_entity = Entity();
if ( name == "ETAG" && /\"/ in value )
{
if ( c$http?$potential_fname && c$http$potential_fname != "" )
c$http$current_entity$filename = c$http$potential_fname;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment