]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
checkpoint prior to pulling latest with flow in reassemble
authorTom Peters <thopeter@cisco.com>
Tue, 5 Aug 2014 17:38:43 +0000 (13:38 -0400)
committerTom Peters <thopeter@cisco.com>
Tue, 5 Aug 2014 17:38:43 +0000 (13:38 -0400)
21 files changed:
src/service_inspectors/nhttp_inspect/CMakeLists.txt
src/service_inspectors/nhttp_inspect/Makefile.am
src/service_inspectors/nhttp_inspect/nhttp_field.cc
src/service_inspectors/nhttp_inspect/nhttp_field.h
src/service_inspectors/nhttp_inspect/nhttp_flow_data.cc
src/service_inspectors/nhttp_inspect/nhttp_flow_data.h
src/service_inspectors/nhttp_inspect/nhttp_inspect.cc
src/service_inspectors/nhttp_inspect/nhttp_inspect.h
src/service_inspectors/nhttp_inspect/nhttp_msg_chunk_body.cc
src/service_inspectors/nhttp_inspect/nhttp_msg_chunk_body.h
src/service_inspectors/nhttp_inspect/nhttp_msg_header.cc [moved from src/service_inspectors/nhttp_inspect/nhttp_msg_head.cc with 99% similarity]
src/service_inspectors/nhttp_inspect/nhttp_msg_header.h [moved from src/service_inspectors/nhttp_inspect/nhttp_msg_head.h with 96% similarity]
src/service_inspectors/nhttp_inspect/nhttp_msg_request.cc
src/service_inspectors/nhttp_inspect/nhttp_msg_request.h
src/service_inspectors/nhttp_inspect/nhttp_msg_status.cc
src/service_inspectors/nhttp_inspect/nhttp_msg_status.h
src/service_inspectors/nhttp_inspect/nhttp_stream_splitter.cc
src/service_inspectors/nhttp_inspect/nhttp_stream_splitter.h
src/service_inspectors/nhttp_inspect/nhttp_tables.cc
src/service_inspectors/nhttp_inspect/nhttp_uri.cc
src/service_inspectors/nhttp_inspect/nhttp_uri.h

index f86115607b5a2afcc145ded99c618b22eebd739e..6ad38673afcd4376b0545f6119fe7b5d42dacc16 100644 (file)
@@ -12,8 +12,8 @@ set (FILE_LIST
     nhttp_msg_status.h
     nhttp_msg_head_shared.cc
     nhttp_msg_head_shared.h
-    nhttp_msg_head.cc
-    nhttp_msg_head.h
+    nhttp_msg_header.cc
+    nhttp_msg_header.h
     nhttp_msg_body.cc
     nhttp_msg_body.h
     nhttp_msg_chunk_head.cc
index b53e2908f82c9b6fb2c86e00ea28bd83914916b7..b810bfe0d7734a46ed47f49806cad0f7680d0176 100644 (file)
@@ -7,7 +7,7 @@ nhttp_msg_start.cc nhttp_msg_start.h \
 nhttp_msg_request.cc nhttp_msg_request.h \
 nhttp_msg_status.cc nhttp_msg_status.h \
 nhttp_msg_head_shared.cc nhttp_msg_head_shared.h \
-nhttp_msg_head.cc nhttp_msg_head.h \
+nhttp_msg_header.cc nhttp_msg_header.h \
 nhttp_msg_body.cc nhttp_msg_body.h \
 nhttp_msg_chunk_head.cc nhttp_msg_chunk_head.h \
 nhttp_msg_chunk_body.cc nhttp_msg_chunk_body.h \
index b0b5fefac9cfe4731b920d9d4c1991213f3268b5..6c0011c055b971eee82276cc753c7de367a03217 100644 (file)
@@ -35,6 +35,8 @@
 
 using namespace NHttpEnums;
 
+const Field Field::FIELD_NULL { STAT_NOSOURCE };
+
 void Field::print(FILE *output, const char* name, bool intVals) const {
     if ((length == STAT_NOTPRESENT) || (length == STAT_NOTCOMPUTE) || (length == STAT_NOSOURCE)) return;
     int outCount = fprintf(output, "%s, length = %d, ", name, length);
index 3d7b5e2e0d491d96ca1005089bc4f485463b8a6b..8bc7c65a9bd76b3d4e4416ca5c484710efe056e0 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <stdint.h>
 #include <stdio.h>
+#include <assert.h>
 
 // Individual pieces of the message found during parsing
 // Length values <= 0 are StatusCode values and imply that the start pointer is meaningless.
@@ -40,7 +41,10 @@ public:
     int32_t length = NHttpEnums::STAT_NOTCOMPUTE;
     const uint8_t* start = nullptr;
 
+    static const Field FIELD_NULL;
+
     Field(int32_t length_, const uint8_t* start_) : length(length_), start(start_) {};
+    explicit Field(int32_t length_) : length(length_) { assert(length<=0); };
     Field() = default;
     void print(FILE *output, const char* name, bool intVals = false) const;
 };
index 9e5fdfeec397aff35b38370dc17f14c60cb296af..f4669e53c2d3b24e649f42e0b0aa7366fe4bf02a 100644 (file)
@@ -35,7 +35,7 @@
 #include "nhttp_msg_section.h"
 #include "nhttp_msg_request.h"
 #include "nhttp_msg_status.h"
-#include "nhttp_msg_head.h"
+#include "nhttp_msg_header.h"
 
 using namespace NHttpEnums;
 
@@ -44,8 +44,9 @@ unsigned NHttpFlowData::nhttp_flow_id = 0;
 NHttpFlowData::NHttpFlowData() : FlowData(nhttp_flow_id) {}
 
 NHttpFlowData::~NHttpFlowData() {
+    delete requestLine;
+    delete statusLine;
     for(int k=0; k <= 1; k++) {
-        delete startLine[k];
         delete headers[k];
         delete latestOther[k];
     }
index fb0c0463913e7fc2128ba602036dd8cf5fa80800..379c204301d91ffa019e8aa67b27844e350cbde1 100644 (file)
 
 #include "stream/stream_api.h"
 
-class NHttpInspect;
-class NHttpMsgSection;
-class NHttpMsgStart;
-class NHttpMsgRequest;
-class NHttpMsgStatus;
-class NHttpMsgHeader;
-class NHttpMsgBody;
-class NHttpMsgChunkHead;
-class NHttpMsgChunkBody;
-class NHttpMsgTrailer;
-class NHttpTestInput;
-
 class NHttpFlowData : public FlowData
 {
 public:
@@ -92,9 +80,10 @@ private:
     // Stored message sections from this session
     // You must reset to nullptr after deleting a section
     // Never put one section in two places. latestOther is only for things not otherwise listed
-    NHttpMsgStart* startLine[2] = { nullptr, nullptr };
-    NHttpMsgHeader* headers[2] = { nullptr, nullptr };
-    NHttpMsgSection* latestOther[2] = { nullptr, nullptr };
+    class NHttpMsgRequest* requestLine = nullptr;
+    class NHttpMsgStatus* statusLine = nullptr;
+    class NHttpMsgHeader* headers[2] = { nullptr, nullptr };
+    class NHttpMsgSection* latestOther[2] = { nullptr, nullptr };
 };
 
 #endif
index 476d540a93f6353ffb3e0b6c33af4bbac5d1d897..b8b175ccdf094175d804d6bec74184bf6c394af4 100644 (file)
@@ -117,12 +117,10 @@ void NHttpInspect::show(SnortConfig*)
     LogMessage("NHttpInspect\n");
 }
 
-void NHttpInspect::eval(Packet* p)
+void NHttpInspect::eval(Packet*)
 {
-    // Only packets from the StreamSplitter can be processed
-    if (!PacketHasPAFPayload(p)) return;
-
-    process(p->data, p->dsize, p->flow, (p->packet_flags & PKT_FROM_CLIENT) ? SRC_CLIENT : SRC_SERVER);
+    printf("eval()\n"); fflush(nullptr); /* &&& */
+    return;
 }
 
 void NHttpInspect::process(const uint8_t* data, const uint16_t dsize, Flow* const flow, SourceId sourceId)
index 30c3df024e3f0780aea30eab25973cc7b780c21f..53b33a5244f41609f0d3d945e6204e1881323811 100644 (file)
@@ -30,7 +30,7 @@
 #include "framework/inspector.h"
 #include "nhttp_msg_request.h"
 #include "nhttp_msg_status.h"
-#include "nhttp_msg_head.h"
+#include "nhttp_msg_header.h"
 #include "nhttp_msg_body.h"
 #include "nhttp_msg_chunk_head.h"
 #include "nhttp_msg_chunk_body.h"
@@ -54,7 +54,7 @@ public:
     bool enabled();
     void pinit();
     void pterm();
-    NHttpStreamSplitter* get_splitter(bool isClientToServer) { return new NHttpStreamSplitter(isClientToServer); };
+    NHttpStreamSplitter* get_splitter(bool isClientToServer) { return new NHttpStreamSplitter(isClientToServer, this); };
 
 private:
     friend NHttpApi;
index 73b31a47caa9772acc174b1b9c49b7a98f20a36a..551c69ad86bd6045215ade31e995c97f6a9f9825 100644 (file)
@@ -39,7 +39,7 @@
 using namespace NHttpEnums;
 
 NHttpMsgChunkBody::NHttpMsgChunkBody(const uint8_t *buffer, const uint16_t bufSize, NHttpFlowData *sessionData_, SourceId sourceId_) :
-   NHttpMsgBody(buffer, bufSize, sessionData_, sourceId_), numChunks(sessionData->numChunks[sourceId]),
+   NHttpMsgBody(buffer, bufSize, sessionData_, sourceId_), /* numChunks(sessionData->numChunks[sourceId]), &&& */
    chunkSections(sessionData->chunkSections[sourceId]), chunkOctets(sessionData->chunkOctets[sourceId]) {}
 
 void NHttpMsgChunkBody::analyze() {
index 0430affa462a9b859b3ad9ccbb24fc9359392e3f..5a122775b8b1a7f3704b578e8731ee5b1c08e0a4 100644 (file)
@@ -44,7 +44,7 @@ public:
     void updateFlow();
 
 private:
-    int64_t numChunks;
+    // int64_t numChunks;    // will be needed in future commented out to please compiler &&&
     int64_t chunkSections;
     int64_t chunkOctets;
 };
similarity index 99%
rename from src/service_inspectors/nhttp_inspect/nhttp_msg_head.cc
rename to src/service_inspectors/nhttp_inspect/nhttp_msg_header.cc
index 31969d29b16319998b4ef58592ea4193a7e70c38..2bf58e16485ba26fbed0a3d3301f942a312dc063 100644 (file)
@@ -34,7 +34,7 @@
 
 #include "snort.h"
 #include "nhttp_enum.h"
-#include "nhttp_msg_head.h"
+#include "nhttp_msg_header.h"
 
 using namespace NHttpEnums;
 
similarity index 96%
rename from src/service_inspectors/nhttp_inspect/nhttp_msg_head.h
rename to src/service_inspectors/nhttp_inspect/nhttp_msg_header.h
index 2e99349347b3da7c056c353de4f5d2982d019a53..876d91fb8d6e51786deb62ce0ec79fa1553f7502 100644 (file)
@@ -26,8 +26,8 @@
 //  @brief      NHttpMsgHeader class declaration
 //
 
-#ifndef NHTTP_MSG_HEAD_H
-#define NHTTP_MSG_HEAD_H
+#ifndef NHTTP_MSG_HEADER_H
+#define NHTTP_MSG_HEADER_H
 
 #include "nhttp_msg_head_shared.h"
 
index 1ded924be434216313a93271c944a596c193642e..c3d1dda3f7279a9945dff007bfecd25664041af7 100644 (file)
 #include "nhttp_enum.h"
 #include "nhttp_normalizers.h"
 #include "nhttp_msg_request.h"
-#include "nhttp_msg_head.h"
+#include "nhttp_msg_header.h"
 
 using namespace NHttpEnums;
 
 NHttpMsgRequest::NHttpMsgRequest(const uint8_t *buffer, const uint16_t bufSize, NHttpFlowData *sessionData_, SourceId sourceId_) :
        NHttpMsgStart(buffer, bufSize, sessionData_, sourceId_) {
-    delete sessionData->startLine[SRC_CLIENT];
-    sessionData->startLine[SRC_CLIENT] = this;
+    delete sessionData->requestLine;
+    sessionData->requestLine = this;
     delete sessionData->headers[SRC_CLIENT];
     sessionData->headers[SRC_CLIENT] = nullptr;
     delete sessionData->latestOther[SRC_CLIENT];
@@ -87,6 +87,20 @@ void NHttpMsgRequest::deriveMethodId() {
     methodId = (MethodId) strToCode(method.start, method.length, methodList);
 }
 
+const Field& NHttpMsgRequest::getUri() {
+    if (uri != nullptr) {
+        return uri->getUri();
+    }
+    return Field::FIELD_NULL;
+}
+
+const Field& NHttpMsgRequest::getUriNormLegacy() {
+    if (uri != nullptr) {
+        return uri->getNormLegacy();
+    }
+    return Field::FIELD_NULL;
+}
+
 void NHttpMsgRequest::genEvents() {
     if (methodId == METH__OTHER) createEvent(EVENT_UNKNOWN_METHOD);
 
index d4118900a2d141ff12277531126ba536568a8b65..260ba58f9cde04c2b696a1befd4ac3e564302c5d 100644 (file)
@@ -47,6 +47,9 @@ public:
     void genEvents();
     void updateFlow();
     void legacyClients();
+    const Field& getMethod() { return method; };
+    const Field& getUri();
+    const Field& getUriNormLegacy();
 
 private:
     static const StrCode methodList[];
index f4bf98755f53b4811df6034af8b9fdf9f02f23dd..70121533e4dd4a83d1f0057b36835d6ef6f8a343 100644 (file)
 #include "snort.h"
 #include "nhttp_enum.h"
 #include "nhttp_msg_status.h"
-#include "nhttp_msg_head.h"
+#include "nhttp_msg_request.h"
+#include "nhttp_msg_header.h"
 
 using namespace NHttpEnums;
 
 NHttpMsgStatus::NHttpMsgStatus(const uint8_t *buffer, const uint16_t bufSize, NHttpFlowData *sessionData_, SourceId sourceId_) :
-       NHttpMsgStart(buffer, bufSize, sessionData_, sourceId_) {
-    delete sessionData->startLine[SRC_SERVER];
-    sessionData->startLine[SRC_SERVER] = this;
+       NHttpMsgStart(buffer, bufSize, sessionData_, sourceId_), request(sessionData->requestLine) {
+    delete sessionData->statusLine;
+    sessionData->statusLine = this;
     delete sessionData->headers[SRC_SERVER];
     sessionData->headers[SRC_SERVER] = nullptr;
     delete sessionData->latestOther[SRC_SERVER];
@@ -132,8 +133,21 @@ void NHttpMsgStatus::updateFlow() {
 // Legacy support function. Puts message fields into the buffers used by old Snort.
 void NHttpMsgStatus::legacyClients() {
     ClearHttpBuffers();
-    if (statusCode.length > 0) SetHttpBuffer(HTTP_BUFFER_STAT_CODE, statusCode.start, (unsigned)statusCode.length);
-    if (reasonPhrase.length > 0) SetHttpBuffer(HTTP_BUFFER_STAT_MSG, reasonPhrase.start, (unsigned)reasonPhrase.length);
+    if ((request != nullptr) && (request->getMethod().length > 0)) {
+        SetHttpBuffer(HTTP_BUFFER_METHOD, request->getMethod().start, (unsigned)request->getMethod().length);
+    }
+    if ((request != nullptr) && (request->getUri().length > 0)) {
+        SetHttpBuffer(HTTP_BUFFER_RAW_URI, request->getUri().start, (unsigned)request->getUri().length);
+    }
+    if ((request != nullptr) && (request->getUriNormLegacy().length > 0)) {
+        SetHttpBuffer(HTTP_BUFFER_URI, request->getUriNormLegacy().start, (unsigned)request->getUriNormLegacy().length);
+    }
+    if (statusCode.length > 0) {
+        SetHttpBuffer(HTTP_BUFFER_STAT_CODE, statusCode.start, (unsigned)statusCode.length);
+    }
+    if (reasonPhrase.length > 0) {
+        SetHttpBuffer(HTTP_BUFFER_STAT_MSG, reasonPhrase.start, (unsigned)reasonPhrase.length);
+    }
 }
 
 
index e534121d18f08aa6eee3790e7e6f5bf198185215..2ea777a30d37d8306614b18aa5d1fecde9dae7d8 100644 (file)
@@ -51,6 +51,7 @@ private:
 
     Field statusCode;
     Field reasonPhrase;
+    NHttpMsgRequest* request;
 };
 
 #endif
index 071549796452555051f2d0ab0b8624bd1c9fd50e..847da436cb74b683cffe6ef5f868045df9163461 100644 (file)
@@ -30,6 +30,7 @@
 #include <string.h>
 #include <sys/types.h>
 #include "snort.h"
+#include "protocols/packet.h"
 #include "nhttp_enum.h"
 #include "nhttp_test_input.h"
 #include "nhttp_stream_splitter.h"
@@ -55,6 +56,22 @@ void NHttpStreamSplitter::createEvent(EventSid sid) {
     eventsGenerated |= 1 << (sid-1);
 }
 
+const StreamBuffer* NHttpStreamSplitter::reassemble(unsigned offset, const uint8_t* data, unsigned len, uint32_t flags, unsigned& copied) {
+    static THREAD_LOCAL StreamBuffer nhttp_buf;
+    if (flags & PKT_PDU_HEAD) {
+        sectionBuffer = new uint8_t[65536];
+    }
+    memcpy(sectionBuffer+offset, data, len);
+    copied = len;
+    if (flags & PKT_PDU_TAIL) {
+        process(sectionBuffer, offset + len, p->flow, to_server() ? SRC_CLIENT : SRC_SERVER);
+        nhttp_buf.data = sectionBuffer;
+        nhttp_buf.length = offset + len;
+        return &nhttp_buf;
+    }
+    return nullptr;
+}
+
 PAF_Status NHttpStreamSplitter::scan (Flow* flow, const uint8_t* data, uint32_t length, uint32_t flags, uint32_t* flushOffset) {
     // When the system begins providing TCP connection close information this won't always be false. &&&
     bool tcpClose = false;
index 607f8ab97067054f8d765265a46dd3d352fbffac..cd9be24efdc708cf1aa88139865240e1cfb1b893 100644 (file)
 #include "stream/stream_splitter.h"
 #include "nhttp_flow_data.h"
 
+class NHttpInspect;
+
 class NHttpStreamSplitter : public StreamSplitter {
 public:
-    NHttpStreamSplitter(bool isClientToServer) : StreamSplitter(isClientToServer) {};
+    NHttpStreamSplitter(bool isClientToServer, NHttpInspect* myInspector_) : StreamSplitter(isClientToServer), myInspector(myInspector_) {};
     PAF_Status scan(Flow* flow, const uint8_t* data, uint32_t length, uint32_t flags, uint32_t* flushOffset);
     bool is_paf() { return true; };
     uint32_t max() { return pafMax; };
+    const StreamBuffer* reassemble(unsigned offset, const uint8_t* data, unsigned len, uint32_t flags, unsigned& copied);
 private:
     void prepareFlush(NHttpFlowData* sessionData, uint32_t* flushOffset, NHttpEnums::SourceId sourceId, NHttpEnums::SectionType sectionType, bool tcpClose,
           uint64_t infractions, uint32_t numOctets);
     void createEvent(NHttpEnums::EventSid sid);
 
+    NHttpInspect* const myInspector;
+
+    uint8_t *sectionBuffer = nullptr;
     uint64_t eventsGenerated = 0;
     int64_t octetsSeen = 0;
     int numCrlf = 0;
index 21b8ecc43569277f21efa73399809dab0a7b720d..d9421a265fac92f48415dd659b3bba9d5545faaa 100644 (file)
@@ -40,7 +40,7 @@
 #include "nhttp_normalizers.h"
 #include "nhttp_head_norm.h"
 #include "nhttp_msg_request.h"
-#include "nhttp_msg_head.h"
+#include "nhttp_msg_header.h"
 #include "nhttp_module.h"
 #include "nhttp_uri_norm.h"
 
index dc83e70475b13d4efb71c36e89c2b68b24be7a7b..2567d856934df0e795af055eb2e0c9ad69ee673f 100644 (file)
@@ -118,7 +118,7 @@ SchemeId NHttpUri::getSchemeId() {
     return schemeId;
 }
 
-Field NHttpUri::getNormHost() {
+const Field& NHttpUri::getNormHost() {
     if (hostNorm.length != STAT_NOTCOMPUTE) return hostNorm;
     if (getHost().length < 0) {
         hostNorm.length = STAT_NOSOURCE;
@@ -128,7 +128,7 @@ Field NHttpUri::getNormHost() {
     return hostNorm;
 }
 
-Field NHttpUri::getNormPath() {
+const Field& NHttpUri::getNormPath() {
     if (pathNorm.length != STAT_NOTCOMPUTE) return pathNorm;
     if (getPath().length < 0) {
         pathNorm.length = STAT_NOSOURCE;
@@ -138,7 +138,7 @@ Field NHttpUri::getNormPath() {
     return pathNorm;
 }
 
-Field NHttpUri::getNormQuery() {
+const Field& NHttpUri::getNormQuery() {
     if (queryNorm.length != STAT_NOTCOMPUTE) return queryNorm;
     if (getQuery().length < 0) {
         queryNorm.length = STAT_NOSOURCE;
@@ -148,7 +148,7 @@ Field NHttpUri::getNormQuery() {
     return queryNorm;
 }
 
-Field NHttpUri::getNormFragment() {
+const Field& NHttpUri::getNormFragment() {
     if (fragmentNorm.length != STAT_NOTCOMPUTE) return fragmentNorm;
     if (getFragment().length < 0) {
         fragmentNorm.length = STAT_NOSOURCE;
@@ -222,7 +222,7 @@ void NHttpUri::parseAbsPath() {
 }
 
 // Glue normalized URI fields back together 
-Field NHttpUri::getNormLegacy() {
+const Field& NHttpUri::getNormLegacy() {
     if (legacyNorm.length != STAT_NOTCOMPUTE) return legacyNorm;
 
     if (getPath().length >= 0) UriNormalizer::normalize(path, pathNorm, true, scratchPad, pathInfractions);
index 07d384425cddfe4d95b6f56b6fcee3a84dceb4c6..65f350b999fa220f97373cef389b11b0aab32c4f 100644 (file)
@@ -42,16 +42,16 @@ class NHttpUri {
 public:
     NHttpUri(const uint8_t* start, int32_t length, NHttpEnums::MethodId method) : uri(length, start), methodId(method),
        scratchPad(2*length+200) {};
-    Field getUri() const { return uri; };
+    const Field& getUri() const { return uri; };
     NHttpEnums::UriType getUriType() { parseUri(); return uriType; };
-    Field getScheme() { parseUri(); return scheme; };
-    Field getAuthority() { parseUri(); return authority; };
-    Field getHost() { parseAuthority(); return host; };
-    Field getPort() { parseAuthority(); return port; };
-    Field getAbsPath() { parseUri(); return absPath; };
-    Field getPath() { parseAbsPath(); return path; };
-    Field getQuery() { parseAbsPath(); return query; };
-    Field getFragment() { parseAbsPath(); return fragment; };
+    const Field& getScheme() { parseUri(); return scheme; };
+    const Field& getAuthority() { parseUri(); return authority; };
+    const Field& getHost() { parseAuthority(); return host; };
+    const Field& getPort() { parseAuthority(); return port; };
+    const Field& getAbsPath() { parseUri(); return absPath; };
+    const Field& getPath() { parseAbsPath(); return path; };
+    const Field& getQuery() { parseAbsPath(); return query; };
+    const Field& getFragment() { parseAbsPath(); return fragment; };
 
     uint64_t getFormatInfractions() { parseUri(); return formatInfractions; };
     uint64_t getSchemeInfractions() { getSchemeId(); return schemeInfractions; };
@@ -64,12 +64,12 @@ public:
        getPortInfractions() | getPathInfractions() | getQueryInfractions() | getFragmentInfractions(); };
 
     NHttpEnums::SchemeId getSchemeId();
-    Field getNormHost();
+    const Field& getNormHost();
     int32_t getPortValue();
-    Field getNormPath();
-    Field getNormQuery();
-    Field getNormFragment();
-    Field getNormLegacy();
+    const Field& getNormPath();
+    const Field& getNormQuery();
+    const Field& getNormFragment();
+    const Field& getNormLegacy();
 
 private:
     static const StrCode schemeList[];