⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hi_client.c

📁 Linux snort-2.4.4源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
**  @retval HI_SUCCESS*/static INLINE int CheckLongDir(HI_SESSION *Session, URI_PTR *uri_ptr,                                u_char *ptr){    int iDirLen;    /*    **  Check for oversize directory    */    if(Session->server_conf->long_dir && uri_ptr->last_dir &&       !uri_ptr->param)    {        iDirLen = ptr - uri_ptr->last_dir;        if(iDirLen > Session->server_conf->long_dir &&           hi_eo_generate_event(Session, HI_EO_CLIENT_OVERSIZE_DIR))        {            hi_eo_client_event_log(Session, HI_EO_CLIENT_OVERSIZE_DIR,                                   NULL, NULL);        }    }    return HI_SUCCESS;}/***  NAME**    SetSlashNorm::*//****  Check for any directory traversal or multi-slash normalization.**  **  @param ServerConf pointer to the server configuration**  @param start      pointer to the start of payload**  @param end        pointer to the end of the payload**  @param ptr        pointer to the pointer of the current index**  @param uri_ptr    pointer to the URI_PTR construct  **  **  @return integer**  **  @retval HI_SUCCESS       function successful**  @retval HI_OUT_OF_BOUNDS reached the end of the buffer*/static int SetSlashNorm(HI_SESSION *Session, u_char *start,        u_char *end, u_char **ptr, URI_PTR *uri_ptr){    HTTPINSPECT_CONF *ServerConf = Session->server_conf;    CheckLongDir(Session, uri_ptr, *ptr);    uri_ptr->last_dir = *ptr;    if(!uri_ptr->norm && !uri_ptr->ident)    {        uri_ptr->norm = *ptr;        (*ptr)++;        if(!hi_util_in_bounds(start,end, *ptr))        {            /*            **  This is the case where there is a slash as the last char            **  and we don't want to normalize that since there really            **  is nothing to normalize.            */            uri_ptr->norm = NULL;            return HI_OUT_OF_BOUNDS;        }        /*        **  Check for directory traversals        */        if(ServerConf->directory.on)        {            if(**ptr == '.')            {                (*ptr)++;                if(!hi_util_in_bounds(start, end, *ptr))                {                    uri_ptr->norm = NULL;                    return HI_OUT_OF_BOUNDS;                }                if(**ptr == '.' || ** ptr == '/')                {                    return HI_SUCCESS;                }            }        }        /*        **  Check for multiple slash normalization        */        if(ServerConf->multiple_slash.on)        {            if(**ptr == '/')            {                return HI_SUCCESS;            }        }        uri_ptr->norm = NULL;        return HI_SUCCESS;    }    (*ptr)++;    return HI_SUCCESS;}/***  NAME**    SetBackSlashNorm::*//****  Check for backslashes and if we need to normalize.**  **  This really just checks the configuration option, and sets the norm**  variable if applicable.**  **  @param ServerConf pointer to the server configuration**  @param start      pointer to the start of payload**  @param end        pointer to the end of the payload**  @param ptr        pointer to the pointer of the current index**  @param uri_ptr    pointer to the URI_PTR construct  **  **  @return integer**  **  @retval HI_SUCCESS       function successful*/static int SetBackSlashNorm(HI_SESSION *Session, u_char *start,        u_char *end, u_char **ptr, URI_PTR *uri_ptr){    HTTPINSPECT_CONF *ServerConf = Session->server_conf;    if(!uri_ptr->norm && !uri_ptr->ident)    {        if(ServerConf->iis_backslash.on)        {            uri_ptr->norm = *ptr;        }    }    (*ptr)++;    return HI_SUCCESS;}/***  NAME**    SetBinaryNorm::*//****  Look for non-ASCII chars in the URI.**  **  We look for these chars in the URI and set the normalization variable**  if it's not already set.  I think we really only need this for IIS**  servers, but we may want to know if it's in the URI too.**  **  @param ServerConf pointer to the server configuration**  @param start      pointer to the start of payload**  @param end        pointer to the end of the payload**  @param ptr        pointer to the pointer of the current index**  @param uri_ptr    pointer to the URI_PTR construct  **  **  @return integer**  **  @retval HI_SUCCESS       function successful*/static int SetBinaryNorm(HI_SESSION *Session, u_char *start,        u_char *end, u_char **ptr, URI_PTR *uri_ptr){    if(!uri_ptr->norm && !uri_ptr->ident)    {        uri_ptr->norm = *ptr;    }    (*ptr)++;    return HI_SUCCESS;}/***  NAME**    SetParamField::*//****  This function sets the parameter field as the first '?'.  The big thing**  is that we set the param value, so we don't false positive long dir**  events when it's really just a long parameter field.**  **  @param ServerConf pointer to the server configuration**  @param start      pointer to the start of payload**  @param end        pointer to the end of the payload**  @param ptr        pointer to the pointer of the current index**  @param uri_ptr    pointer to the URI_PTR construct  **  **  @return integer**  **  @retval HI_SUCCESS       function successful*/static int SetParamField(HI_SESSION *Session, u_char *start,        u_char *end, u_char **ptr, URI_PTR *uri_ptr){    if(!uri_ptr->ident)    {        uri_ptr->param = *ptr;    }    (*ptr)++;    return HI_SUCCESS;}/***  NAME**    SetProxy::*//****  This function checks for an absolute URI in the URI.**  **  @param ServerConf pointer to the server configuration**  @param start      pointer to the start of payload**  @param end        pointer to the end of the payload**  @param ptr        pointer to the pointer of the current index**  @param uri_ptr    pointer to the URI_PTR construct  **  **  @return integer**  **  @retval HI_SUCCESS       function successful*/static int SetProxy(HI_SESSION *Session, u_char *start,        u_char *end, u_char **ptr, URI_PTR *uri_ptr){    HTTPINSPECT_CONF *ServerConf = Session->server_conf;    if(!uri_ptr->ident && !uri_ptr->last_dir)    {        if(Session->global_conf->proxy_alert && !ServerConf->allow_proxy)        {            if(hi_util_in_bounds(start, end, ((*ptr)+2)))            {                if(*((*ptr)+1) == '/' && *((*ptr)+1) == '/')                {                    uri_ptr->proxy = *ptr;                }            }        }    }    (*ptr)++;    return HI_SUCCESS;}/***  NAME**    SetClientVars::*//****  This is where we set the HI_CLIENT values that we found during URI**  discovery.  This also covers checking these values for errors.**  **  @param Client   pointer to HI_CLIENT structure**  @param uri_ptr  pointer to the uri data**  **  @return integer**  **  @retval HI_NONFATAL_ERR problem with the uri values.**  @retval HI_SUCCESS      values set successfully*/static int SetClientVars(HI_CLIENT *Client, URI_PTR *uri_ptr, u_int dsize){    /*    **  We got here either because we found the delimiter or we are    **  out of bounds.    */    /*    if(uri_ptr->first_sp_start)        printf("** first_start  = %c\n", *uri_ptr->first_sp_start);    if(uri_ptr->first_sp_end)        printf("** first_end    = %c\n", *uri_ptr->first_sp_end);    if(uri_ptr->second_sp_start)        printf("** second_start = %c\n", *uri_ptr->second_sp_start);    if(uri_ptr->second_sp_end)        printf("** second_end   = %c\n", *uri_ptr->second_sp_end);    if(uri_ptr->delimiter)        printf("** delimiter    = %c\n", *uri_ptr->delimiter);        if(uri_ptr->uri)        printf("** uri          = %c\n", *uri_ptr->uri);    if(uri_ptr->norm)        printf("** norm         = %.2x\n", *uri_ptr->norm);    */    /*    **  This means that there was only spaces or delimiters within the     **  complete URI.  In this case, there is no valid URI so we just    **  return such.    */    if(uri_ptr->uri == NULL)    {        return HI_NONFATAL_ERR;    }    /*    **  This is where we set the Session variables before moving into more    **  HttpInspect processing.  If we don't get to this point, then we don't    **  need to set these variables since we would have aborted with a    **  NONFATAL_ERR.    */    Client->request.uri      = uri_ptr->uri;    Client->request.uri_size = uri_ptr->uri_end - uri_ptr->uri;    Client->request.uri_norm = uri_ptr->norm;    /*    **  LAST RESORT:    **    **  This is one of the last checks we do to make sure that we didn't    **  mess up or anything.    */    if(Client->request.uri_size < 1 || Client->request.uri_size > dsize)    {        /*        **  Bad stuff, let's just bail.        */        return HI_NONFATAL_ERR;    }    /*    printf("** Norm = %s\n", Client->request.uri_norm ? "YES" : "NO");    printf("** URI: |%.*s| size = %u\n", Client->request.uri_size,           Client->request.uri, Client->request.uri_size);    */    return HI_SUCCESS;}/***  NAME**    StatelessInspection::*//****  Find the URI and determine whether the URI needs to be normalized.**  **  This is a big step in stateless inspection, because we need to reliably**  find the URI and when possible filter out non-URIs.  We do this using a**  simple state machine that is based on characters found in the data**  buffer.**  **  Another important aspect of the stateless inspection is the ability to**  track and inspect pipelined requests.  It is VERY IMPORTANT to reset the**  pipeline_req pointer, since we don't memset the whole structure.  This**  pointer is reset in the hi_si_session_inspection() function.  Check there**  for more details.**  **  Normalization is detected when we are looking at the packet for the URI.**  We look for the following issues:**      - ////**      - /../**      - /./**      - non-ascii charss**      - %**      - \**  When these things are seen we point to the first occurence in the URI, or**  where we have to start normalizing.  If the URI is updated to a new**  pointer, then the normalization pointer is reset and we start over.**  Using this method should cut down the memcpy()s per URI, since most**  URIs are not normalized.**  **  If this function returns HI_NONFATAL_ERR, we return out of mode_inspection**  with an error and abort HttpInspect processing, and continue on with**  any other processing we do.  The Session parameters that we use here are**  reset in the next time that we do session_inspection, so we don't do**  any initialization here.**  **  @param Session pointer to the HTTP session**  @param data    pointer to the start of the packet payload**  @param dsize   size of the payload**  **  @return integer**  **  @retval HI_INVALID_ARG  invalid argument**  @retval HI_NONFATAL_ERR no URI detected**  @retval HI_SUCCESS      URI detected and Session pointers updated*/static int StatelessInspection(HI_SESSION *Session, unsigned char *data,        int dsize){    HTTPINSPECT_CONF *ServerConf;    HTTPINSPECT_CONF *ClientConf;    HI_CLIENT *Client;    URI_PTR uri_ptr;    u_char *start;    u_char *end;    u_char *ptr;    int iRet;    if(!Session || !data || dsize < 1)    {        return HI_INVALID_ARG;    }    ServerConf = Session->server_conf;    if(!ServerConf)    {        return HI_INVALID_ARG;    }    ClientConf = Session->client_conf;    if(!ClientConf)    {        return HI_INVALID_ARG;    }    Client = &Session->client;    memset(&uri_ptr, 0x00, sizeof(URI_PTR));    /*

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -