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

Rust add external parsers 3 #2798

Closed
wants to merge 6 commits into from
Closed
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
8 changes: 8 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,8 @@
dnl AC_ARG_ENABLE(rust, AS_HELP_STRING([--enable-rust], [Enable Rust]),
dnl [enable_rust="$enableval"], [enable_rust=no])
AC_ARG_ENABLE([rust], AS_HELP_STRING([--enable-rust], [Enable Experimental Rust support]))
AC_ARG_ENABLE([rust_experimental], AS_HELP_STRING([--enable-rust-experimental], [Enable support for experimental Rus parsers]))


rust_vendor_comment="# "
have_rust_vendor="no"
Expand Down Expand Up @@ -2016,6 +2018,7 @@
fi

AM_CONDITIONAL([HAVE_RUST], [test "x$enable_rust" = "xyes"])
AM_CONDITIONAL([HAVE_RUST_EXTERNAL], [test "x$enable_rust_experimental" = "xyes"])
AC_SUBST(rust_vendor_comment)
AM_CONDITIONAL([HAVE_RUST_VENDOR], [test "x$have_rust_vendor" = "xyes"])

Expand All @@ -2026,6 +2029,10 @@
echo " for building the distribution"
echo " To install: cargo install cargo-vendor"
fi

if test "x$enable_rust_experimental" = "xyes"; then
AC_DEFINE([HAVE_RUST_EXTERNAL],[1],[Enable support for experimental Rust parsers])
fi
fi
AM_CONDITIONAL([HAVE_CARGO_VENDOR], [test "x$HAVE_CARGO_VENDOR" != "xno"])

Expand Down Expand Up @@ -2141,6 +2148,7 @@ SURICATA_BUILD_CONF="Suricata Configuration:
Libnet support: ${enable_libnet}

Rust support (experimental): ${enable_rust}
Experimental Rust parsers: ${enable_rust_experimental}

Suricatasc install: ${enable_python}

Expand Down
3 changes: 2 additions & 1 deletion rules/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ tls-events.rules \
modbus-events.rules \
app-layer-events.rules \
files.rules \
dnp3-events.rules
dnp3-events.rules \
ntp-events.rules
9 changes: 9 additions & 0 deletions rules/ntp-events.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# NTP app layer event rules
#
# SID's fall in the 2222000+ range. See https://redmine.openinfosecfoundation.org/projects/suricata/wiki/AppLayer
#
# These sigs fire at most once per connection.
#
alert ntp any any -> any any (msg:"SURICATA NTP malformed request data"; flow:to_server; app-layer-event:ntp.malformed_data; classtype:protocol-command-decode; sid:2222000; rev:1;)
alert ntp any any -> any any (msg:"SURICATA NTP malformed response data"; flow:to_client; app-layer-event:ntp.malformed_data; classtype:protocol-command-decode; sid:2222001; rev:1;)

3 changes: 3 additions & 0 deletions rust/Cargo.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ debug = true

[features]
lua = []
experimental = ["ntp-parser"]

[dependencies]
nom = "~3.0"
libc = "~0.2.0"
crc = "~1.4.0"

ntp-parser = { version = "^0", optional = true }
4 changes: 4 additions & 0 deletions rust/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ if HAVE_LUA
FEATURES += lua
endif

if HAVE_RUST_EXTERNAL
FEATURES += experimental
endif

all-local:
if HAVE_PYTHON
cd $(top_srcdir)/rust && CARGO_TARGET_DIR=$(abs_builddir)/target \
Expand Down
10 changes: 8 additions & 2 deletions rust/gen-c-headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@

"libc::c_void": "void",

"libc::c_char": "char",
"libc::c_int": "int",
"c_int": "int",
"libc::int8_t": "int8_t",
Expand All @@ -77,10 +78,13 @@
"DNSTransaction": "RSDNSTransaction",
"NFSState": "NFSState",
"NFSTransaction": "NFSTransaction",
"NTPState": "NTPState",
"NTPTransaction": "NTPTransaction",
"JsonT": "json_t",
"DetectEngineState": "DetectEngineState",
"core::DetectEngineState": "DetectEngineState",
"core::AppLayerDecoderEvents": "AppLayerDecoderEvents",
"core::AppLayerEventType": "AppLayerEventType",
"CLuaState": "lua_State",
"Store": "Store",
}
Expand All @@ -99,12 +103,14 @@ def convert_type(rs_type):
if mod in [
"*mut",
"* mut",
"*const",
"* const",
"&mut",
"&'static mut",
]:
return "%s *" % (type_map[rtype])
elif mod in [
"*const",
"* const"]:
return "const %s *" % (type_map[rtype])
elif mod in [
"*mut *const",
"*mut*const"]:
Expand Down
5 changes: 5 additions & 0 deletions rust/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ pub enum Flow {}
pub enum DetectEngineState {}
pub enum AppLayerDecoderEvents {}

// From app-layer-events.h
pub type AppLayerEventType = libc::c_int;
pub const APP_LAYER_EVENT_TYPE_TRANSACTION : i32 = 1;
pub const APP_LAYER_EVENT_TYPE_PACKET : i32 = 2;

// From stream.h.
pub const STREAM_TOSERVER: u8 = 0x04;
pub const STREAM_TOCLIENT: u8 = 0x08;
Expand Down
3 changes: 3 additions & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ pub mod lua;

pub mod dns;
pub mod nfs;

#[cfg(feature = "experimental")]
pub mod ntp;
20 changes: 20 additions & 0 deletions rust/src/ntp/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* Copyright (C) 2017 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
* Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* version 2 along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/

// written by Pierre Chifflier <chifflier@wzdftpd.net>

pub mod ntp;
Loading