~ubuntu-branches/ubuntu/precise/suricata/precise-proposed

« back to all changes in this revision

Viewing changes to src/detect-engine-uri.c

  • Committer: Bazaar Package Importer
  • Author(s): Pierre Chifflier
  • Date: 2010-06-19 17:39:14 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20100619173914-5vkjfgz24mbia29z
Tags: 0.9.2-1
ImportedĀ UpstreamĀ versionĀ 0.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
 *  \param det_ctx Detection engine thread context
63
63
 *  \param s Signature to inspect
64
64
 *  \param sm SigMatch to inspect
65
 
 *  \param p Packet
66
65
 *  \param payload ptr to the uricontent payload to inspect
67
66
 *  \param payload_len length of the uricontent payload
68
67
 *
71
70
 */
72
71
static int DoInspectPacketUri(DetectEngineCtx *de_ctx,
73
72
        DetectEngineThreadCtx *det_ctx, Signature *s, SigMatch *sm,
74
 
        Packet *p, uint8_t *payload, uint32_t payload_len)
 
73
        uint8_t *payload, uint32_t payload_len)
75
74
{
76
75
    SCEnter();
77
76
 
210
209
                /* see if the next payload keywords match. If not, we will
211
210
                 * search for another occurence of this uricontent and see
212
211
                 * if the others match then until we run out of matches */
213
 
                int r = DoInspectPacketUri(de_ctx,det_ctx,s,sm->next, p, payload, payload_len);
 
212
                int r = DoInspectPacketUri(de_ctx,det_ctx,s,sm->next, payload, payload_len);
214
213
                if (r == 1) {
215
214
                    SCReturnInt(1);
216
215
                }
231
230
    /* this sigmatch matched, inspect the next one. If it was the last,
232
231
     * the payload portion of the signature matched. */
233
232
    if (sm->next != NULL) {
234
 
        int r = DoInspectPacketUri(de_ctx,det_ctx,s,sm->next, p, payload, payload_len);
 
233
        int r = DoInspectPacketUri(de_ctx,det_ctx,s,sm->next, payload, payload_len);
235
234
        SCReturnInt(r);
236
235
    } else {
237
236
        SCReturnInt(1);
247
246
 *  \param f Flow
248
247
 *  \param flags app layer flags
249
248
 *  \param state App layer state
250
 
 *  \param p Packet
251
249
 *
252
250
 *  \retval 0 no match
253
251
 *  \retval 1 match
254
252
 */
255
253
int DetectEngineInspectPacketUris(DetectEngineCtx *de_ctx,
256
254
        DetectEngineThreadCtx *det_ctx, Signature *s, Flow *f, uint8_t flags,
257
 
        void *alstate, Packet *p)
 
255
        void *alstate)
258
256
{
259
257
    SCEnter();
260
258
    SigMatch *sm = NULL;
261
259
    int r = 0;
262
260
    HtpState *htp_state = NULL;
263
261
 
 
262
    if (!(det_ctx->sgh->flags & SIG_GROUP_HAVEURICONTENT)) {
 
263
        SCLogDebug("no uricontent in sgh");
 
264
        SCReturnInt(0);
 
265
    }
 
266
 
264
267
    htp_state = (HtpState *)alstate;
265
268
    if (htp_state == NULL) {
266
269
        SCLogDebug("no HTTP state");
270
273
    /* locking the flow, we will inspect the htp state */
271
274
    SCMutexLock(&f->m);
272
275
 
 
276
    if (htp_state->connp == NULL) {
 
277
        SCLogDebug("HTP state has no connp");
 
278
        goto end;
 
279
    }
 
280
 
 
281
    /* If we have the uricontent multi pattern matcher signatures in
 
282
       signature list, then search the received HTTP uri(s) in the htp
 
283
       state against those patterns */
 
284
    if (s->flags & SIG_FLAG_MPM_URI) {
 
285
        if (det_ctx->de_mpm_scanned_uri == FALSE) {
 
286
            uint32_t cnt = DetectUricontentInspectMpm(det_ctx, f, htp_state);
 
287
 
 
288
            /* only consider uri sigs if we've seen at least one match */
 
289
            /** \warning when we start supporting negated uri content matches
 
290
             * we need to update this check as well */
 
291
            if (cnt > 0) {
 
292
                det_ctx->de_have_httpuri = TRUE;
 
293
            }
 
294
 
 
295
            SCLogDebug("uricontent cnt %"PRIu32"", cnt);
 
296
 
 
297
            /* make sure we don't inspect this mpm again */
 
298
            det_ctx->de_mpm_scanned_uri = TRUE;
 
299
 
 
300
        }
 
301
    }
 
302
 
273
303
    /* if we don't have a uri, don't bother inspecting */
274
304
    if (det_ctx->de_have_httpuri == FALSE) {
275
305
        SCLogDebug("We don't have uri");
276
306
        goto end;
277
307
    }
278
308
 
279
 
    if (htp_state->connp == NULL) {
280
 
        SCLogDebug("HTP state has no connp");
281
 
        goto end;
 
309
    if (det_ctx->de_mpm_scanned_uri == TRUE) {
 
310
        if (det_ctx->pmq.pattern_id_bitarray != NULL) {
 
311
            /* filter out sigs that want pattern matches, but
 
312
             * have no matches */
 
313
            if (!(det_ctx->pmq.pattern_id_bitarray[(s->mpm_uripattern_id / 8)] & (1<<(s->mpm_uripattern_id % 8))) &&
 
314
                    (s->flags & SIG_FLAG_MPM_URI) && !(s->flags & SIG_FLAG_MPM_URI_NEG)) {
 
315
                SCLogDebug("mpm sig without matches (pat id %"PRIu32
 
316
                        " check in uri).", s->mpm_uripattern_id);
 
317
                goto end;
 
318
            }
 
319
        }
282
320
    }
283
321
 
284
322
    sm = s->umatch;
290
328
    SCLogDebug("co->id %"PRIu32, co->id);
291
329
#endif
292
330
 
293
 
    size_t idx = 0;
 
331
    size_t idx = AppLayerTransactionGetInspectId(f);
294
332
    htp_tx_t *tx = NULL;
295
333
 
296
 
    for (idx = 0;//htp_state->new_in_tx_index;
297
 
         idx < list_size(htp_state->connp->conn->transactions); idx++)
 
334
    for ( ; idx < list_size(htp_state->connp->conn->transactions); idx++)
298
335
    {
299
336
        tx = list_get(htp_state->connp->conn->transactions, idx);
300
337
        if (tx == NULL || tx->request_uri_normalized == NULL)
302
339
 
303
340
        /* Inspect all the uricontents fetched on each
304
341
         * transaction at the app layer */
305
 
        r = DoInspectPacketUri(de_ctx, det_ctx, s, s->umatch, p,
 
342
        r = DoInspectPacketUri(de_ctx, det_ctx, s, s->umatch,
306
343
                (uint8_t *) bstr_ptr(tx->request_uri_normalized),
307
344
                bstr_len(tx->request_uri_normalized));
308
345