|
|
|
|
@ -1473,6 +1473,10 @@ void AppLayerParserStatePrintDetails(AppLayerParserState *pstate)
|
|
|
|
|
#ifdef AFLFUZZ_APPLAYER
|
|
|
|
|
int AppLayerParserRequestFromFile(uint8_t ipproto, AppProto alproto, char *filename)
|
|
|
|
|
{
|
|
|
|
|
struct timeval ts;
|
|
|
|
|
memset(&ts, 0, sizeof(ts));
|
|
|
|
|
gettimeofday(&ts, NULL);
|
|
|
|
|
|
|
|
|
|
int result = 1;
|
|
|
|
|
Flow *f = NULL;
|
|
|
|
|
TcpSession ssn;
|
|
|
|
|
@ -1495,7 +1499,8 @@ int AppLayerParserRequestFromFile(uint8_t ipproto, AppProto alproto, char *filen
|
|
|
|
|
f->protomap = FlowGetProtoMapping(f->proto);
|
|
|
|
|
f->alproto = alproto;
|
|
|
|
|
|
|
|
|
|
uint8_t buffer[64];
|
|
|
|
|
uint8_t buffer[65536];
|
|
|
|
|
uint32_t cnt = 0;
|
|
|
|
|
|
|
|
|
|
#ifdef AFLFUZZ_PERSISTANT_MODE
|
|
|
|
|
while (__AFL_LOOP(1000)) {
|
|
|
|
|
@ -1513,10 +1518,16 @@ int AppLayerParserRequestFromFile(uint8_t ipproto, AppProto alproto, char *filen
|
|
|
|
|
if (size < sizeof(buffer))
|
|
|
|
|
done = 1;
|
|
|
|
|
|
|
|
|
|
char outfilename[256];
|
|
|
|
|
snprintf(outfilename, sizeof(outfilename), "dump/%u-%u.%u",
|
|
|
|
|
(unsigned int)ts.tv_sec, (unsigned int)ts.tv_usec, cnt);
|
|
|
|
|
FILE *out_fp = fopen(outfilename, "w");
|
|
|
|
|
BUG_ON(out_fp == NULL);
|
|
|
|
|
(void)fwrite(buffer, size, 1, out_fp);
|
|
|
|
|
fclose(out_fp);
|
|
|
|
|
//SCLogInfo("result %u done %d start %d", (uint)result, done, start);
|
|
|
|
|
|
|
|
|
|
uint8_t flags = STREAM_TOSERVER;
|
|
|
|
|
|
|
|
|
|
if (start--) {
|
|
|
|
|
flags |= STREAM_START;
|
|
|
|
|
}
|
|
|
|
|
@ -1527,6 +1538,8 @@ int AppLayerParserRequestFromFile(uint8_t ipproto, AppProto alproto, char *filen
|
|
|
|
|
|
|
|
|
|
(void)AppLayerParserParse(NULL, alp_tctx, f, alproto, flags,
|
|
|
|
|
buffer, size);
|
|
|
|
|
cnt++;
|
|
|
|
|
|
|
|
|
|
if (done)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
@ -1537,6 +1550,79 @@ int AppLayerParserRequestFromFile(uint8_t ipproto, AppProto alproto, char *filen
|
|
|
|
|
}
|
|
|
|
|
#endif /* AFLFUZZ_PERSISTANT_MODE */
|
|
|
|
|
|
|
|
|
|
/* if we get here there was no crash, so we can remove our files */
|
|
|
|
|
uint32_t x = 0;
|
|
|
|
|
for (x = 0; x < cnt; x++) {
|
|
|
|
|
char rmfilename[256];
|
|
|
|
|
snprintf(rmfilename, sizeof(rmfilename), "dump/%u-%u.%u",
|
|
|
|
|
(unsigned int)ts.tv_sec, (unsigned int)ts.tv_usec, x);
|
|
|
|
|
unlink(rmfilename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
|
|
|
|
|
end:
|
|
|
|
|
if (alp_tctx != NULL)
|
|
|
|
|
AppLayerParserThreadCtxFree(alp_tctx);
|
|
|
|
|
if (f != NULL) {
|
|
|
|
|
FlowFree(f);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* load a serie of files generated by DecoderParseDataFromFile() in
|
|
|
|
|
* the same order as it was produced. */
|
|
|
|
|
int AppLayerParserRequestFromFileSerie(uint8_t ipproto, AppProto alproto, char *fileprefix)
|
|
|
|
|
{
|
|
|
|
|
uint32_t cnt = 0;
|
|
|
|
|
int start = 1;
|
|
|
|
|
int result = 1;
|
|
|
|
|
Flow *f = NULL;
|
|
|
|
|
TcpSession ssn;
|
|
|
|
|
AppLayerParserThreadCtx *alp_tctx = AppLayerParserThreadCtxAlloc();
|
|
|
|
|
|
|
|
|
|
memset(&ssn, 0, sizeof(ssn));
|
|
|
|
|
|
|
|
|
|
f = SCCalloc(1, sizeof(Flow));
|
|
|
|
|
if (f == NULL)
|
|
|
|
|
goto end;
|
|
|
|
|
FLOW_INITIALIZE(f);
|
|
|
|
|
|
|
|
|
|
f->flags |= FLOW_IPV4;
|
|
|
|
|
f->src.addr_data32[0] = 0x01020304;
|
|
|
|
|
f->dst.addr_data32[0] = 0x05060708;
|
|
|
|
|
f->sp = 10000;
|
|
|
|
|
f->dp = 80;
|
|
|
|
|
f->protoctx = &ssn;
|
|
|
|
|
f->proto = ipproto;
|
|
|
|
|
f->protomap = FlowGetProtoMapping(f->proto);
|
|
|
|
|
f->alproto = alproto;
|
|
|
|
|
|
|
|
|
|
uint8_t buffer[65536];
|
|
|
|
|
|
|
|
|
|
char filename[256];
|
|
|
|
|
snprintf(filename, sizeof(filename), "dump/%s.%u", fileprefix, cnt);
|
|
|
|
|
FILE *fp;
|
|
|
|
|
while ((fp = fopen(filename, "r")) != NULL)
|
|
|
|
|
{
|
|
|
|
|
memset(buffer, 0, sizeof(buffer));
|
|
|
|
|
|
|
|
|
|
size_t size = fread(&buffer, 1, sizeof(buffer), fp);
|
|
|
|
|
|
|
|
|
|
uint8_t flags = STREAM_TOSERVER;
|
|
|
|
|
if (start--) {
|
|
|
|
|
flags |= STREAM_START;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(void)AppLayerParserParse(NULL, alp_tctx, f, alproto, flags,
|
|
|
|
|
buffer, size);
|
|
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
cnt++;
|
|
|
|
|
|
|
|
|
|
snprintf(filename, sizeof(filename), "dump/%s.%u", fileprefix, cnt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
|
|
|
|
|
end:
|
|
|
|
|
@ -1550,6 +1636,10 @@ end:
|
|
|
|
|
|
|
|
|
|
int AppLayerParserFromFile(uint8_t ipproto, AppProto alproto, char *filename)
|
|
|
|
|
{
|
|
|
|
|
struct timeval ts;
|
|
|
|
|
memset(&ts, 0, sizeof(ts));
|
|
|
|
|
gettimeofday(&ts, NULL);
|
|
|
|
|
|
|
|
|
|
int result = 1;
|
|
|
|
|
Flow *f = NULL;
|
|
|
|
|
TcpSession ssn;
|
|
|
|
|
@ -1572,7 +1662,8 @@ int AppLayerParserFromFile(uint8_t ipproto, AppProto alproto, char *filename)
|
|
|
|
|
f->protomap = FlowGetProtoMapping(f->proto);
|
|
|
|
|
f->alproto = alproto;
|
|
|
|
|
|
|
|
|
|
uint8_t buffer[64];
|
|
|
|
|
uint8_t buffer[65536];
|
|
|
|
|
uint32_t cnt = 0;
|
|
|
|
|
|
|
|
|
|
#ifdef AFLFUZZ_PERSISTANT_MODE
|
|
|
|
|
while (__AFL_LOOP(1000)) {
|
|
|
|
|
@ -1591,6 +1682,13 @@ int AppLayerParserFromFile(uint8_t ipproto, AppProto alproto, char *filename)
|
|
|
|
|
if (size < sizeof(buffer))
|
|
|
|
|
done = 1;
|
|
|
|
|
|
|
|
|
|
char outfilename[256];
|
|
|
|
|
snprintf(outfilename, sizeof(outfilename), "dump/%u-%u.%u",
|
|
|
|
|
(unsigned int)ts.tv_sec, (unsigned int)ts.tv_usec, cnt);
|
|
|
|
|
FILE *out_fp = fopen(outfilename, "w");
|
|
|
|
|
BUG_ON(out_fp == NULL);
|
|
|
|
|
(void)fwrite(buffer, size, 1, out_fp);
|
|
|
|
|
fclose(out_fp);
|
|
|
|
|
//SCLogInfo("result %u done %d start %d", (uint)result, done, start);
|
|
|
|
|
|
|
|
|
|
uint8_t flags = 0;
|
|
|
|
|
@ -1612,6 +1710,9 @@ int AppLayerParserFromFile(uint8_t ipproto, AppProto alproto, char *filename)
|
|
|
|
|
|
|
|
|
|
(void)AppLayerParserParse(NULL, alp_tctx, f, alproto, flags,
|
|
|
|
|
buffer, size);
|
|
|
|
|
|
|
|
|
|
cnt++;
|
|
|
|
|
|
|
|
|
|
if (done)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
@ -1622,7 +1723,88 @@ int AppLayerParserFromFile(uint8_t ipproto, AppProto alproto, char *filename)
|
|
|
|
|
}
|
|
|
|
|
#endif /* AFLFUZZ_PERSISTANT_MODE */
|
|
|
|
|
|
|
|
|
|
/* if we get here there was no crash, so we can remove our files */
|
|
|
|
|
uint32_t x = 0;
|
|
|
|
|
for (x = 0; x < cnt; x++) {
|
|
|
|
|
char rmfilename[256];
|
|
|
|
|
snprintf(rmfilename, sizeof(rmfilename), "dump/%u-%u.%u",
|
|
|
|
|
(unsigned int)ts.tv_sec, (unsigned int)ts.tv_usec, x);
|
|
|
|
|
unlink(rmfilename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
end:
|
|
|
|
|
if (alp_tctx != NULL)
|
|
|
|
|
AppLayerParserThreadCtxFree(alp_tctx);
|
|
|
|
|
if (f != NULL) {
|
|
|
|
|
FlowFree(f);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* load a serie of files generated by DecoderParseDataFromFile() in
|
|
|
|
|
* the same order as it was produced. */
|
|
|
|
|
int AppLayerParserFromFileSerie(uint8_t ipproto, AppProto alproto, char *fileprefix)
|
|
|
|
|
{
|
|
|
|
|
uint32_t cnt = 0;
|
|
|
|
|
int start = 1;
|
|
|
|
|
int result = 1;
|
|
|
|
|
Flow *f = NULL;
|
|
|
|
|
TcpSession ssn;
|
|
|
|
|
AppLayerParserThreadCtx *alp_tctx = AppLayerParserThreadCtxAlloc();
|
|
|
|
|
|
|
|
|
|
memset(&ssn, 0, sizeof(ssn));
|
|
|
|
|
|
|
|
|
|
f = SCCalloc(1, sizeof(Flow));
|
|
|
|
|
if (f == NULL)
|
|
|
|
|
goto end;
|
|
|
|
|
FLOW_INITIALIZE(f);
|
|
|
|
|
|
|
|
|
|
f->flags |= FLOW_IPV4;
|
|
|
|
|
f->src.addr_data32[0] = 0x01020304;
|
|
|
|
|
f->dst.addr_data32[0] = 0x05060708;
|
|
|
|
|
f->sp = 10000;
|
|
|
|
|
f->dp = 80;
|
|
|
|
|
f->protoctx = &ssn;
|
|
|
|
|
f->proto = ipproto;
|
|
|
|
|
f->protomap = FlowGetProtoMapping(f->proto);
|
|
|
|
|
f->alproto = alproto;
|
|
|
|
|
|
|
|
|
|
uint8_t buffer[65536];
|
|
|
|
|
int flip = 0;
|
|
|
|
|
char filename[256];
|
|
|
|
|
snprintf(filename, sizeof(filename), "dump/%s.%u", fileprefix, cnt);
|
|
|
|
|
FILE *fp;
|
|
|
|
|
while ((fp = fopen(filename, "r")) != NULL)
|
|
|
|
|
{
|
|
|
|
|
memset(buffer, 0, sizeof(buffer));
|
|
|
|
|
|
|
|
|
|
size_t size = fread(&buffer, 1, sizeof(buffer), fp);
|
|
|
|
|
|
|
|
|
|
uint8_t flags = 0;
|
|
|
|
|
if (flip) {
|
|
|
|
|
flags = STREAM_TOCLIENT;
|
|
|
|
|
flip = 0;
|
|
|
|
|
} else {
|
|
|
|
|
flags = STREAM_TOSERVER;
|
|
|
|
|
flip = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (start--) {
|
|
|
|
|
flags |= STREAM_START;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(void)AppLayerParserParse(NULL, alp_tctx, f, alproto, flags,
|
|
|
|
|
buffer, size);
|
|
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
cnt++;
|
|
|
|
|
|
|
|
|
|
snprintf(filename, sizeof(filename), "dump/%s.%u", fileprefix, cnt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
|
|
|
|
|
end:
|
|
|
|
|
if (alp_tctx != NULL)
|
|
|
|
|
AppLayerParserThreadCtxFree(alp_tctx);
|
|
|
|
|
@ -1631,6 +1813,7 @@ end:
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* AFLFUZZ_APPLAYER */
|
|
|
|
|
|
|
|
|
|
/***** Unittests *****/
|
|
|
|
|
|