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

Next/20220523/v1 #7423

Merged
merged 8 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
30 changes: 15 additions & 15 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ jobs:
- name: Cleaning up
run: rm -rf libhtp suricata-update suricata-verify
- name: Uploading prep archive
uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8
with:
name: prep
path: .
Expand All @@ -137,7 +137,7 @@ jobs:
cargo install --target x86_64-unknown-linux-musl --debug cbindgen
cp $HOME/.cargo/bin/cbindgen .
- name: Uploading prep archive
uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8
with:
name: prep
path: .
Expand Down Expand Up @@ -249,7 +249,7 @@ jobs:
run: |
mkdir dist
mv suricata-*.tar.gz dist
- uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535
- uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8
name: Uploading distribution
with:
name: dist
Expand Down Expand Up @@ -319,10 +319,10 @@ jobs:
- run: tar xf prep/suricata-verify.tar.gz
- run: python3 ./suricata-verify/run.py -q

fedora-35:
name: Fedora 35 (debug, clang, asan, wshadow, rust-strict)
fedora-36:
name: Fedora 36 (debug, clang, asan, wshadow, rust-strict)
runs-on: ubuntu-latest
container: fedora:35
container: fedora:36
needs: [prepare-deps, prepare-cbindgen]
steps:

Expand Down Expand Up @@ -406,10 +406,10 @@ jobs:
- run: test -e /usr/local/bin/libsuricata-config
- run: test ! -e /usr/local/lib/libsuricata.so

fedora-34:
name: Fedora 34 (debug, clang, asan, wshadow, rust-strict)
fedora-35:
name: Fedora 35 (debug, clang, asan, wshadow, rust-strict)
runs-on: ubuntu-latest
container: fedora:34
container: fedora:35
needs: [prepare-deps, prepare-cbindgen]
steps:

Expand Down Expand Up @@ -493,10 +493,10 @@ jobs:
- run: test -e /usr/local/bin/libsuricata-config
- run: test ! -e /usr/local/lib/libsuricata.so

fedora-33:
name: Fedora 33 (debug, clang, asan, wshadow, rust-strict)
fedora-34:
name: Fedora 34 (debug, clang, asan, wshadow, rust-strict)
runs-on: ubuntu-latest
container: fedora:33
container: fedora:34
needs: [prepare-deps, prepare-cbindgen]
steps:

Expand Down Expand Up @@ -567,10 +567,10 @@ jobs:
- name: Running suricata-verify
run: python3 ./suricata-verify/run.py -q

fedora-34-no-jansson:
name: Fedora 34 (no jansson)
fedora-35-no-jansson:
name: Fedora 35 (no jansson)
runs-on: ubuntu-latest
container: fedora:34
container: fedora:35
needs: [prepare-deps, prepare-cbindgen]
steps:

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cifuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
dry-run: false
sanitizer: ${{ matrix.sanitizer }}
- name: Upload Crash
uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8
if: failure()
with:
name: ${{ matrix.sanitizer }}-artifacts
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/commits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
make -ik distclean > /dev/null
done
- run: sccache -s
- uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535
- uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8
name: Uploading build log
if: always()
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/scorecards-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ jobs:

# Upload the results as artifacts (optional).
- name: "Upload artifact"
uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535 # v2.3.1
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v2.3.1
with:
name: SARIF file
path: results.sarif
retention-days: 5

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@7502d6e991ca767d2db617bfd823a1ed925a0d59 # v1.0.26
uses: github/codeql-action/upload-sarif@a3a6c128d771b6b9bdebb1c9d0583ebd2728a108 # v1.0.26
with:
sarif_file: results.sarif
21 changes: 19 additions & 2 deletions rust/src/dcerpc/dcerpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 02110-1301, USA.
*/

use crate::applayer::*;
use crate::applayer::{self, *};
use crate::core::{self, *};
use crate::dcerpc::parser;
use nom7::error::{Error, ErrorKind};
Expand Down Expand Up @@ -186,6 +186,13 @@ pub struct DCERPCTransaction {
pub tx_data: AppLayerTxData,
}

impl Transaction for DCERPCTransaction {
fn id(&self) -> u64 {
// need +1 to match state.tx_id
self.id + 1
}
}

impl DCERPCTransaction {
pub fn new() -> Self {
return Self {
Expand Down Expand Up @@ -316,6 +323,16 @@ pub struct DCERPCState {
pub flow: Option<*const core::Flow>,
}

impl State<DCERPCTransaction> for DCERPCState {
fn get_transaction_count(&self) -> usize {
self.transactions.len()
}

fn get_transaction_by_index(&self, index: usize) -> Option<&DCERPCTransaction> {
self.transactions.get(index)
}
}

impl DCERPCState {
pub fn new() -> Self {
return Self {
Expand Down Expand Up @@ -1349,7 +1366,7 @@ pub unsafe extern "C" fn rs_dcerpc_register_parser() {
localstorage_new: None,
localstorage_free: None,
get_files: None,
get_tx_iterator: None,
get_tx_iterator: Some(applayer::state_get_tx_iterator::<DCERPCState, DCERPCTransaction>),
get_tx_data: rs_dcerpc_get_tx_data,
apply_tx_config: None,
flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
Expand Down
6 changes: 5 additions & 1 deletion src/app-layer-detect-proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,11 @@ static AppProto AppLayerProtoDetectPPGetProto(Flow *f, const uint8_t *buf, uint3
} else {
/* first try the destination port */
pp_port_dp = AppLayerProtoDetectGetProbingParsers(alpd_ctx.ctx_pp, ipproto, dp);
alproto_masks = &f->probing_parser_toclient_alproto_masks;
if (dir == idir) {
// do not update alproto_masks to let a chance to second packet
// for instance when sending a junk packet to a DNS server
alproto_masks = &f->probing_parser_toclient_alproto_masks;
}
if (pp_port_dp != NULL) {
SCLogDebug("toclient - Probing parser found for destination port %"PRIu16, dp);

Expand Down
77 changes: 59 additions & 18 deletions src/app-layer.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,9 @@ int AppLayerHandleTCPData(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx,

/* if we don't know the proto yet and we have received a stream
* initializer message, we run proto detection.
* We receive 2 stream init msgs (one for each direction) but we
* only run the proto detection once. */
* We receive 2 stream init msgs (one for each direction), we
* only run the proto detection for both and emit an event
* in the case protocols mismatch. */
if (alproto == ALPROTO_UNKNOWN && (flags & STREAM_START)) {
DEBUG_VALIDATE_BUG_ON(FlowChangeProto(f));
/* run protocol detection */
Expand Down Expand Up @@ -785,42 +786,86 @@ int AppLayerHandleTCPData(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx,
int AppLayerHandleUdp(ThreadVars *tv, AppLayerThreadCtx *tctx, Packet *p, Flow *f)
{
SCEnter();
AppProto *alproto;
AppProto *alproto_otherdir;

if (f->alproto == ALPROTO_FAILED) {
if (f->alproto_ts == ALPROTO_FAILED && f->alproto_tc == ALPROTO_FAILED) {
SCReturnInt(0);
}

int r = 0;
uint8_t flags = 0;
if (p->flowflags & FLOW_PKT_TOSERVER) {
flags |= STREAM_TOSERVER;
alproto = &f->alproto_ts;
alproto_otherdir = &f->alproto_tc;
} else {
flags |= STREAM_TOCLIENT;
alproto = &f->alproto_tc;
alproto_otherdir = &f->alproto_ts;
}

AppLayerProfilingReset(tctx);

/* if the protocol is still unknown, run detection */
if (f->alproto == ALPROTO_UNKNOWN) {
if (*alproto == ALPROTO_UNKNOWN) {
SCLogDebug("Detecting AL proto on udp mesg (len %" PRIu32 ")",
p->payload_len);

bool reverse_flow = false;
PACKET_PROFILING_APP_PD_START(tctx);
f->alproto = AppLayerProtoDetectGetProto(tctx->alpd_tctx,
f, p->payload, p->payload_len,
IPPROTO_UDP, flags, &reverse_flow);
*alproto = AppLayerProtoDetectGetProto(
tctx->alpd_tctx, f, p->payload, p->payload_len, IPPROTO_UDP, flags, &reverse_flow);
PACKET_PROFILING_APP_PD_END(tctx);

if (f->alproto != ALPROTO_UNKNOWN) {
AppLayerIncFlowCounter(tv, f);

if (p->flowflags & FLOW_PKT_TOSERVER) {
f->alproto_ts = f->alproto;
} else {
f->alproto_tc = f->alproto;
switch (*alproto) {
case ALPROTO_UNKNOWN:
if (*alproto_otherdir != ALPROTO_UNKNOWN) {
// Use recognized side
f->alproto = *alproto_otherdir;
// do not keep ALPROTO_UNKNOWN for this side so as not to loop
*alproto = *alproto_otherdir;
if (*alproto_otherdir == ALPROTO_FAILED) {
SCLogDebug("ALPROTO_UNKNOWN flow %p", f);
}
} else {
// First side of protocol is unknown
*alproto = ALPROTO_FAILED;
}
break;
case ALPROTO_FAILED:
if (*alproto_otherdir != ALPROTO_UNKNOWN) {
// Use recognized side
f->alproto = *alproto_otherdir;
if (*alproto_otherdir == ALPROTO_FAILED) {
SCLogDebug("ALPROTO_UNKNOWN flow %p", f);
}
}
// else wait for second side of protocol
break;
default:
if (*alproto_otherdir != ALPROTO_UNKNOWN && *alproto_otherdir != ALPROTO_FAILED) {
if (*alproto_otherdir != *alproto) {
AppLayerDecoderEventsSetEventRaw(
&p->app_layer_events, APPLAYER_MISMATCH_PROTOCOL_BOTH_DIRECTIONS);
// data already sent to parser, we cannot change the protocol to use the one
// of the server
}
} else {
f->alproto = *alproto;
}
}
if (*alproto_otherdir == ALPROTO_UNKNOWN) {
if (f->alproto == ALPROTO_UNKNOWN) {
// so as to increase stat about .app_layer.flow.failed_udp
f->alproto = ALPROTO_FAILED;
}
// If the other side is unknown, this is the first packet of the flow
AppLayerIncFlowCounter(tv, f);
}

// parse the data if we recognized one protocol
if (f->alproto != ALPROTO_UNKNOWN && f->alproto != ALPROTO_FAILED) {
if (reverse_flow) {
SCLogDebug("reversing flow after proto detect told us so");
PacketSwap(p);
Expand All @@ -832,10 +877,6 @@ int AppLayerHandleUdp(ThreadVars *tv, AppLayerThreadCtx *tctx, Packet *p, Flow *
r = AppLayerParserParse(tv, tctx->alp_tctx, f, f->alproto,
flags, p->payload, p->payload_len);
PACKET_PROFILING_APP_END(tctx, f->alproto);
} else {
f->alproto = ALPROTO_FAILED;
AppLayerIncFlowCounter(tv, f);
SCLogDebug("ALPROTO_UNKNOWN flow %p", f);
}
PACKET_PROFILING_APP_STORE(tctx, p);
/* we do only inspection in one direction, so flag both
Expand Down
2 changes: 1 addition & 1 deletion src/detect-engine-alert.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ void AlertQueueAppend(DetectEngineThreadCtx *det_ctx, const Signature *s, Packet
/* we must grow the alert queue */
if (pos == AlertQueueExpand(det_ctx)) {
/* this means we failed to expand the queue */
det_ctx->p->alerts.discarded++;
p->alerts.discarded++;
return;
}
}
Expand Down
16 changes: 11 additions & 5 deletions src/detect-engine-loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,22 @@ char *DetectLoadCompleteSigPath(const DetectEngineCtx *de_ctx, const char *sig_f
return NULL;
}

if (strlen(de_ctx->config_prefix) > 0) {
/* If we have a configuration prefix, only use it if the primary configuration node
* is not marked as final, as that means it was provided on the command line with
* a --set. */
ConfNode *default_rule_path = ConfGetNode("default-rule-path");
if ((!default_rule_path || !default_rule_path->final) && strlen(de_ctx->config_prefix) > 0) {
snprintf(varname, sizeof(varname), "%s.default-rule-path",
de_ctx->config_prefix);
} else {
snprintf(varname, sizeof(varname), "default-rule-path");
default_rule_path = ConfGetNode(varname);
}
if (default_rule_path) {
defaultpath = default_rule_path->val;
}

/* Path not specified */
if (PathIsRelative(sig_file)) {
if (ConfGet(varname, &defaultpath) == 1) {
if (defaultpath) {
SCLogDebug("Default path: %s", defaultpath);
size_t path_len = sizeof(char) * (strlen(defaultpath) +
strlen(sig_file) + 2);
Expand All @@ -93,7 +99,7 @@ char *DetectLoadCompleteSigPath(const DetectEngineCtx *de_ctx, const char *sig_f
strlcat(path, "/", path_len);
#endif
strlcat(path, sig_file, path_len);
} else {
} else {
path = SCStrdup(sig_file);
if (unlikely(path == NULL))
return NULL;
Expand Down