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bd, 0x26, 0x33, 0xd4, 0xa1, 0xbb, 0x1c,
- 0x9d, 0x8e, 0xfe, 0x03, 0x51, 0xaa, 0xf2, 0x71, 0xf4, 0x01, 0x00, 0x00
+const uint8_t rule_18758[] =
+{
+0x61, 0x6C, 0x65, 0x72, 0x74, 0x20, 0x74, 0x63, 0x70, 0x20, 0x24, 0x48,
+0x4F, 0x4D, 0x45, 0x5F, 0x4E, 0x45, 0x54, 0x20, 0x61, 0x6E, 0x79, 0x20,
+0x2D, 0x3E, 0x20, 0x24, 0x45, 0x58, 0x54, 0x45, 0x52, 0x4E, 0x41, 0x4C,
+0x5F, 0x4E, 0x45, 0x54, 0x20, 0x24, 0x48, 0x54, 0x54, 0x50, 0x5F, 0x50,
+0x4F, 0x52, 0x54, 0x53, 0x0A, 0x28, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x6D,
+0x73, 0x67, 0x3A, 0x22, 0x46, 0x49, 0x4C, 0x45, 0x2D, 0x49, 0x44, 0x45,
+0x4E, 0x54, 0x49, 0x46, 0x59, 0x20, 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73,
+0x6F, 0x66, 0x74, 0x20, 0x57, 0x69, 0x6E, 0x64, 0x6F, 0x77, 0x73, 0x20,
+0x56, 0x69, 0x73, 0x75, 0x61, 0x6C, 0x20, 0x42, 0x61, 0x73, 0x69, 0x63,
+0x20, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x20, 0x66, 0x69, 0x6C, 0x65,
+0x20, 0x64, 0x6F, 0x77, 0x6E, 0x6C, 0x6F, 0x61, 0x64, 0x20, 0x72, 0x65,
+0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20,
+0x6D, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x3A, 0x73, 0x65, 0x72,
+0x76, 0x69, 0x63, 0x65, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3B, 0x0A, 0x20,
+0x20, 0x20, 0x20, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6E, 0x63, 0x65,
+0x3A, 0x75, 0x72, 0x6C, 0x2C, 0x65, 0x6E, 0x2E, 0x77, 0x69, 0x6B, 0x69,
+0x70, 0x65, 0x64, 0x69, 0x61, 0x2E, 0x6F, 0x72, 0x67, 0x2F, 0x77, 0x69,
+0x6B, 0x69, 0x2F, 0x56, 0x62, 0x73, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20,
+0x63, 0x6C, 0x61, 0x73, 0x73, 0x74, 0x79, 0x70, 0x65, 0x3A, 0x6D, 0x69,
+0x73, 0x63, 0x2D, 0x61, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x3B,
+0x0A, 0x20, 0x20, 0x20, 0x20, 0x73, 0x69, 0x64, 0x3A, 0x31, 0x38, 0x37,
+0x35, 0x38, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x76, 0x3A,
+0x38, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x73, 0x6F, 0x69, 0x64, 0x3A,
+0x33, 0x7C, 0x31, 0x38, 0x37, 0x35, 0x38, 0x3B, 0x0A, 0x23, 0x20, 0x65,
+0x76, 0x65, 0x72, 0x79, 0x74, 0x68, 0x69, 0x6E, 0x67, 0x20, 0x61, 0x62,
+0x6F, 0x76, 0x65, 0x20, 0x61, 0x70, 0x70, 0x65, 0x61, 0x72, 0x73, 0x20,
+0x69, 0x6E, 0x20, 0x73, 0x74, 0x75, 0x62, 0x0A, 0x23, 0x20, 0x74, 0x68,
+0x65, 0x20, 0x66, 0x6F, 0x6C, 0x6C, 0x6F, 0x77, 0x69, 0x6E, 0x67, 0x20,
+0x64, 0x65, 0x74, 0x65, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x6F, 0x70,
+0x74, 0x69, 0x6F, 0x6E, 0x73, 0x20, 0x61, 0x72, 0x65, 0x20, 0x6E, 0x6F,
+0x74, 0x20, 0x69, 0x6E, 0x20, 0x73, 0x74, 0x75, 0x62, 0x0A, 0x20, 0x20,
+0x20, 0x20, 0x66, 0x6C, 0x6F, 0x77, 0x3A, 0x74, 0x6F, 0x5F, 0x73, 0x65,
+0x72, 0x76, 0x65, 0x72, 0x2C, 0x65, 0x73, 0x74, 0x61, 0x62, 0x6C, 0x69,
+0x73, 0x68, 0x65, 0x64, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x68, 0x74,
+0x74, 0x70, 0x5F, 0x75, 0x72, 0x69, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20,
+0x63, 0x6F, 0x6E, 0x74, 0x65, 0x6E, 0x74, 0x3A, 0x22, 0x2E, 0x76, 0x62,
+0x73, 0x22, 0x2C, 0x20, 0x6E, 0x6F, 0x63, 0x61, 0x73, 0x65, 0x3B, 0x0A,
+0x20, 0x20, 0x20, 0x20, 0x70, 0x63, 0x72, 0x65, 0x3A, 0x22, 0x2F, 0x5C,
+0x78, 0x32, 0x65, 0x76, 0x62, 0x73, 0x28, 0x5B, 0x5C, 0x3F, 0x5C, 0x78,
+0x35, 0x63, 0x5C, 0x78, 0x32, 0x66, 0x5D, 0x7C, 0x24, 0x29, 0x2F, 0x73,
+0x6D, 0x69, 0x22, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x73, 0x6F, 0x3A,
+0x65, 0x76, 0x61, 0x6C, 0x3B, 0x0A, 0x29, 0x0A,
};
-unsigned int sid_18758_gz_len = 372;
+const unsigned rule_18758_len = 0;
#include <zlib.h>
#include <list>
+#include <iomanip>
#include <iostream>
+#include <sstream>
using namespace std;
#include "snort_types.h"
// so rules
//-------------------------------------------------------------------------
-#define GZIP_WBITS 31
+// FIXIT-L eliminate this arbitrary limit on rule text size
+const unsigned max_rule = 128000;
+static uint8_t so_buf[max_rule];
+
+static const uint8_t* compress(const string& text, unsigned& len)
+{
+ const char* s = text.c_str();
+ z_stream stream;
+
+ stream.next_in = (Bytef*)s;
+ stream.avail_in = text.size();
+
+ stream.next_out = so_buf;
+ stream.avail_out = max_rule;
+
+ stream.zalloc = nullptr;
+ stream.zfree = nullptr;
+
+ stream.total_in = 0;
+ stream.total_out = 0;
+
+ len = 0;
+
+ if ( deflateInit(&stream, Z_DEFAULT_COMPRESSION) != Z_OK )
+ return nullptr;
+
+ if ( deflate(&stream, Z_FINISH) == Z_STREAM_END )
+ len= stream.total_out;
+
+ deflateEnd(&stream);
+ return so_buf;
+}
// FIXIT-L make this into a general utility for one shot decompress
// and add class for stream decompress
-const char* uncompress(const uint8_t* data, unsigned len)
+static const char* expand(const uint8_t* data, unsigned len)
{
- const unsigned max_rule = 65536;
- static char buf[max_rule];
-
z_stream stream;
stream.next_in = (Bytef*)data;
stream.avail_in = (uInt)len;
- stream.next_out = (Bytef*)buf;
+ stream.next_out = (Bytef*)so_buf;
stream.avail_out = (uInt)(max_rule - 1);
stream.zalloc = nullptr;
stream.total_in = 0;
stream.total_out = 0;
- if ( inflateInit2(&stream, GZIP_WBITS) != Z_OK )
+ if ( inflateInit(&stream) != Z_OK )
return nullptr;
if ( inflate(&stream, Z_SYNC_FLUSH) != Z_STREAM_END )
return nullptr;
assert(stream.total_out < max_rule);
- buf[stream.total_out] = '\0';
+ so_buf[stream.total_out] = '\0';
- return buf;
+ return (char*)so_buf;
+}
+
+//-------------------------------------------------------------------------
+
+static void strvrt(const string& text, string& data)
+{
+ unsigned len = 0;
+ const uint8_t* d = compress(text, len);
+
+ // lose the zlib header
+ assert(len > 2 && d[0] == 0x78 && d[1] == 0x9C);
+ d += 2;
+ len -= 2;
+
+ data.assign((char*)d, len);
+
+ // FIXIT-H choose random byte for xor
+ uint8_t key = 0xA5;
+
+ for ( unsigned i = 0; i < len; i++ )
+ data[i] ^= key;
+
+ data.append(1, (char)key);
+}
+
+static const char* revert(const uint8_t* data, unsigned len)
+{
+ if ( !len )
+ return (char*)data;
+
+ uint8_t key = data[--len];
+ string s((char*)data, len);
+
+ for ( unsigned i = 0; i < len-1; i++ )
+ s[i] ^= key;
+
+ // force the zlib header
+ s.insert(0, "\x78\x9C");
+
+ return expand((uint8_t*)s.c_str(), s.size());
}
//-------------------------------------------------------------------------
if ( !api )
return nullptr;
- const char* rule = uncompress(api->rule, api->length);
+ if ( !api->length )
+ return nullptr;
+
+ const char* rule = revert(api->rule, api->length);
if ( !rule )
return nullptr;
for ( auto* p : s_rules )
{
const char* s;
- const char* rule = uncompress(p->rule, p->length);
+ const char* rule = revert(p->rule, p->length);
if ( !rule )
continue;
continue;
// FIXIT-L strip newlines (optional?)
- string stub(rule, ++s-rule);
- cout << stub << ")" << endl;
+ if ( !p->length )
+ cout << rule << endl;
+ else
+ {
+ string stub(rule, ++s-rule);
+ cout << stub << ")" << endl;
+ }
++c;
}
if ( !c )
cerr << "no rules to dump" << endl;
}
+static void get_var(const string& s, string& v)
+{
+ v.clear();
+ size_t pos = s.find("soid");
+
+ if ( pos == string::npos )
+ return;
+
+ pos = s.find("|", pos+1);
+
+ if ( pos == string::npos )
+ return;
+
+ size_t end = s.find(";", ++pos);
+
+ if ( end == string::npos )
+ return;
+
+ v = s.substr(pos, end-pos);
+}
+
+void SoManager::rule_to_hex(const char*)
+{
+ stringstream buffer;
+ buffer << cin.rdbuf();
+ string text = buffer.str();
+
+ unsigned idx;
+ string data;
+ strvrt(text, data);
+
+ string var;
+ get_var(text, var);
+
+ cout << "const uint8_t rule_" << var;
+ cout << "[] =" << endl;
+ cout << "{" << endl;
+ cout << hex << uppercase;
+
+ for ( idx = 0; idx < data.size(); idx++ )
+ {
+ if ( idx && !(idx % 12) )
+ cout << endl;
+
+ uint8_t u = data[idx];
+ cout << "0x" << setfill('0') << setw(2) << hex << (int)u << ", ";
+ }
+ if ( idx % 16 )
+ cout << endl;
+
+ cout << dec;
+ cout << "};" << endl;
+ cout << "const unsigned rule_" << var << "_len = ";
+ cout << data.size() << ";" << endl;
+}
+
+void SoManager::rule_to_text(const char*)
+{
+ stringstream buffer;
+ buffer << cin.rdbuf();
+ string text = buffer.str();
+
+ unsigned len = text.size(), idx;
+ const uint8_t* data = (uint8_t*)text.c_str();
+
+ string var;
+ get_var(text, var);
+
+ cout << "const uint8_t rule_" << var;
+ cout << "[] =" << endl;
+ cout << "{" << endl;
+ cout << hex << uppercase;
+
+ for ( idx = 0; idx < len; idx++ )
+ {
+ if ( idx && !(idx % 12) )
+ cout << endl;
+ cout << "0x" << setfill('0') << setw(2) << (unsigned)data[idx] << ", ";
+ }
+ if ( idx % 16 )
+ cout << endl;
+
+ cout << dec;
+ cout << "};" << endl;
+ cout << "const unsigned rule_" << var;
+ cout << "_len = 0;" << endl;
+}
+