suricata
detect-ssh-software.c
Go to the documentation of this file.
1/* Copyright (C) 2007-2016 Open Information Security Foundation
2 *
3 * You can copy, redistribute or modify this Program under the terms of
4 * the GNU General Public License version 2 as published by the Free
5 * Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * version 2 along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 */
17
18/**
19 * \ingroup sshlayer
20 *
21 * @{
22 */
23
24
25/**
26 * \file
27 *
28 * \author Victor Julien <victor@inliniac.net>
29 *
30 * Implements support ssh_software sticky buffer
31 */
32
33#include "suricata-common.h"
34#include "threads.h"
35#include "decode.h"
36
37#include "detect.h"
38#include "detect-parse.h"
39#include "detect-engine.h"
41#include "detect-engine-mpm.h"
42#include "detect-engine-state.h"
45
46#include "app-layer.h"
47#include "app-layer-parser.h"
48#include "app-layer-ssh.h"
49#include "detect-ssh-software.h"
50#include "rust.h"
51
52#define KEYWORD_NAME "ssh.software"
53#define KEYWORD_NAME_LEGACY "ssh_software"
54#define KEYWORD_DOC "ssh-keywords.html#ssh-software"
55#define BUFFER_NAME "ssh_software"
56#define BUFFER_DESC "ssh software field"
57static int g_buffer_id = 0;
58
59static InspectionBuffer *GetSshData(DetectEngineThreadCtx *det_ctx,
60 const DetectEngineTransforms *transforms, Flow *_f,
61 const uint8_t flow_flags, void *txv, const int list_id)
62{
63 SCEnter();
64
65 InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id);
66
67 if (buffer->inspect == NULL) {
68 const uint8_t *software = NULL;
69 uint32_t b_len = 0;
70
71 if (SCSshTxGetSoftware(txv, &software, &b_len, flow_flags) != 1)
72 return NULL;
73 if (software == NULL || b_len == 0) {
74 SCLogDebug("SSH software version not set");
75 return NULL;
76 }
77
79 det_ctx, list_id, buffer, software, b_len, transforms);
80 }
81
82 return buffer;
83}
84
85static int DetectSshSoftwareSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg)
86{
87 if (SCDetectBufferSetActiveList(de_ctx, s, g_buffer_id) < 0)
88 return -1;
89
91 return -1;
92
93 return 0;
94}
95
96
@ ALPROTO_SSH
int SCDetectBufferSetActiveList(DetectEngineCtx *de_ctx, Signature *s, const int list)
void InspectionBufferSetupAndApplyTransforms(DetectEngineThreadCtx *det_ctx, const int list_id, InspectionBuffer *buffer, const uint8_t *data, const uint32_t data_len, const DetectEngineTransforms *transforms)
setup the buffer with our initial data
InspectionBuffer * InspectionBufferGet(DetectEngineThreadCtx *det_ctx, const int list_id)
void DetectAppLayerMpmRegister(const char *name, int direction, int priority, PrefilterRegisterFunc PrefilterRegister, InspectionBufferGetDataPtr GetData, AppProto alproto, int tx_min_progress)
register an app layer keyword for mpm
int PrefilterGenericMpmRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id)
@ DETECT_SSH_SOFTWARE
Data structures and function prototypes for keeping state for the detection engine.
void DetectBufferTypeSetDescriptionByName(const char *name, const char *desc)
uint8_t DetectEngineInspectBufferGeneric(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const DetectEngineAppInspectionEngine *engine, const Signature *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
Do the content inspection & validation for a signature.
void DetectAppLayerInspectEngineRegister(const char *name, AppProto alproto, uint32_t dir, int progress, InspectEngineFuncPtr Callback, InspectionBufferGetDataPtr GetData)
Registers an app inspection engine.
int DetectBufferTypeGetByName(const char *name)
int SCDetectSignatureSetAppProto(Signature *s, AppProto alproto)
SigTableElmt * sigmatch_table
#define KEYWORD_NAME_LEGACY
void DetectSshSoftwareRegister(void)
#define KEYWORD_DOC
#define BUFFER_DESC
#define BUFFER_NAME
#define KEYWORD_NAME
#define SIGMATCH_NOOPT
Definition detect.h:1651
#define SIG_FLAG_TOCLIENT
Definition detect.h:272
#define SIGMATCH_INFO_STICKY_BUFFER
Definition detect.h:1676
#define SIG_FLAG_TOSERVER
Definition detect.h:271
DetectEngineCtx * de_ctx
main detection engine ctx
Definition detect.h:932
Flow data structure.
Definition flow.h:356
const char * url
Definition detect.h:1462
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition detect.h:1441
uint16_t flags
Definition detect.h:1450
const char * desc
Definition detect.h:1461
const char * alias
Definition detect.h:1460
const char * name
Definition detect.h:1459
Signature container.
Definition detect.h:668
#define SCEnter(...)
Definition util-debug.h:277
#define SCLogDebug(...)
Definition util-debug.h:275