Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect http uri sv 3725 v1 #11307

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/app-layer-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,20 @@ int AppLayerParserParse(ThreadVars *tv, AppLayerParserThreadCtx *alp_tctx, Flow
uint32_t consumed = input_len;
const uint8_t direction = (flags & STREAM_TOSERVER) ? 0 : 1;

#ifdef UNSAFE_DUMMY_SVTEST_CONVERSION
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this commit is too messy to get merged

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing the messy commit then :-)

FILE *tf = fopen("test.fpc", "a");
// header fpc to port 80
if (flags & STREAM_TOSERVER) {
fwrite("\x00", 1, 1, tf);
} else {
// s2c
fwrite("\x01", 1, 1, tf);
}
fwrite(input, input_len, 1, tf);
fwrite("FPC0", 4, 1, tf);
fclose(tf);
#endif

/* we don't have the parser registered for this protocol */
if (p->StateAlloc == NULL) {
if (f->proto == IPPROTO_TCP) {
Expand Down
6 changes: 6 additions & 0 deletions src/detect-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -2297,6 +2297,12 @@ Signature *SigInit(DetectEngineCtx *de_ctx, const char *sigstr)
{
SCEnter();

#ifdef UNSAFE_DUMMY_SVTEST_CONVERSION
// append sigstr to "test.rules"
FILE *f = fopen("test.rules", "a");
fprintf(f, "%s\n", sigstr);
fclose(f);
#endif
uint32_t oldsignum = de_ctx->signum;
de_ctx->sigerror_ok = false;
de_ctx->sigerror_silent = false;
Expand Down
42 changes: 41 additions & 1 deletion src/util-unittest.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
#include "util-debug.h"
#include "util-time.h"
#include "conf.h"
#ifdef UNSAFE_DUMMY_SVTEST_CONVERSION
#include "util-path.h"
#endif

#include "stream-tcp.h"
#include "stream-tcp-reassemble.h"
Expand Down Expand Up @@ -209,8 +212,45 @@ uint32_t UtRunTests(const char *regex_arg)
TimeModeSetOffline();
TimeSetToCurrentTime();

#ifdef UNSAFE_DUMMY_SVTEST_CONVERSION
if ((chdir("lolt")) < 0) {
printf("fail chdir\n");
break;
}
SCDefaultMkDir(ut->name);
if ((chdir(ut->name)) < 0) {
printf("fail chdir2\n");
break;
}
remove("test.rules");
remove("test.fpc");
remove("README.md");
remove("test.yaml");
FILE *f = fopen("test.fpc", "wb");
// header fpc to port 80
fwrite("FPC\x80\x12\x34\x00\x50", 8, 1, f);
fclose(f);
f = fopen("README.md", "wb");
// header fpc to port 80
fprintf(f, "# Description\n\nTranslation of unit test %s\n", ut->name);
fclose(f);
f = fopen("test.yaml", "wb");
// header fpc to port 80
fprintf(f, "requires:\n min-version: 8.0.0\n\n");
fprintf(f, "args:\n - -k none --set stream.inline=true\n\n");
fprintf(f, "checks:\n - filter:\n count: 1\n match:\n "
"event_type: alert\n alert.signature_id: 1\n");
fclose(f);
#endif
ret = ut->TestFn();

#ifdef UNSAFE_DUMMY_SVTEST_CONVERSION
// run ../bounty/fuzzpcap/build/fpc_bin lolt/UriTestSig01/test.fpc >
// lolt/UriTestSig01/test.pcap
if ((chdir("../..")) < 0) {
printf("fail chdir\n");
break;
}
#endif
if (StreamTcpMemuseCounter() != 0) {
printf("STREAM MEMORY IN USE %"PRIu64"\n", StreamTcpMemuseCounter());
ret = 0;
Expand Down