// debug stuff
//-------------------------------------------------------------------------
-#ifdef DEBUG_MSGS
static const char* smb_com_strings[SMB_MAX_NUM_COMS] =
{
"Create Directory", // 0x00
const char* get_smb_com_string(uint8_t b)
{ return smb_com_strings[b]; }
-#endif
Dce2Smb1SessionData::Dce2Smb1SessionData(const Packet* p,
const dce2SmbProtoConf* proto) : Dce2SmbSessionData(p, proto)
ssd.max_file_depth = max_file_depth;
ssd.sd = sd;
ssd.policy = policy;
- debug_logf(dce_smb_trace, p, "smb1 session created\n");
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_DEBUG_LEVEL, p, "smb1 session created\n");
memory::MemoryCap::update_allocations(sizeof(*this));
}
{
tcp_file_tracker = nullptr;
flow_key = get_smb2_flow_key(tcp_flow->key);
- debug_logf(dce_smb_trace, p, "smb2 session created\n");
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_DEBUG_LEVEL, p, "smb2 session created\n");
memory::MemoryCap::update_allocations(sizeof(*this));
}
if (smb_data + SMB2_ ## cmd ## _ ## type ## _STRUC_SIZE - 1 > end) \
{ \
dce2_smb_stats.v2_ ## counter ## _hdr_err++; \
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET, \
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_ERROR_LEVEL, GET_CURRENT_PACKET, \
"%s : smb data beyond end detected\n", \
smb2_command_string[command]); \
return; \
if (SMB2_COMMAND_TYPE(ERROR, RESPONSE) and Smb2Error(smb_hdr)) \
{ \
dce2_smb_stats.v2_ ## counter ## _err_resp++; \
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET, "%s_RESP: error\n", \
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_INFO_LEVEL, GET_CURRENT_PACKET, "%s_RESP: error\n", \
smb2_command_string[command]); \
return; \
} \
#define SMB2_HANDLE_INVALID_STRUC_SIZE(counter) \
{ \
dce2_smb_stats.v2_ ## counter ## _inv_str_sz++; \
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET, "%s: invalid struct size\n", \
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_ERROR_LEVEL \
+ , GET_CURRENT_PACKET, "%s: invalid struct size\n", \
smb2_command_string[command]); \
return; \
}
uint16_t command = alignedNtohs(&(smb_hdr->command));
uint64_t session_id = Smb2Sid(smb_hdr);
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET,
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_INFO_LEVEL, GET_CURRENT_PACKET,
"%s : flow %" PRIu32 " mid %" PRIu64 " sid %" PRIu64 " tid %" PRIu32 "\n",
(command < SMB2_COM_MAX ? smb2_command_string[command] : "unknown"),
flow_key, Smb2Mid(smb_hdr), session_id, Smb2Tid(smb_hdr));
p->flow->server_port , snort_protocol_id_smb, fd, false, true);
if (result < 0)
+ {
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_CRITICAL_LEVEL, GET_CURRENT_PACKET,
+ "Failed to create expected smb flow\n");
delete fd;
+ }
}
}
}
// Check header length
if (data_len < sizeof(NbssHdr) + SMB2_HEADER_LENGTH)
{
- debug_logf(dce_smb_trace, p, "Header error with data length %d\n",data_len);
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_CRITICAL_LEVEL,
+ p, "Header error with data length %d\n",data_len);
dce2_smb_stats.v2_hdr_err++;
return;
}
{
dce_alert(GID_DCE2, DCE2_SMB_BAD_NEXT_COMMAND_OFFSET,
(dce2CommonStats*)&dce2_smb_stats, sd);
- debug_logf(dce_smb_trace, p, "bad next command offset\n");
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID,
+ TRACE_ERROR_LEVEL, p, "bad next command offset\n");
dce2_smb_stats.v2_bad_next_cmd_offset++;
return;
}
if (compound_request_index > get_smb_max_compound())
{
dce2_smb_stats.v2_cmpnd_req_lt_crossed++;
- debug_logf(dce_smb_trace, p, "compound request limit"
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID,
+ TRACE_INFO_LEVEL, p, "compound request limit"
" reached %" PRIu8 "\n",compound_request_index);
return;
}
tcp_file_tracker_mutex.lock();
if ( tcp_file_tracker and tcp_file_tracker->accepting_raw_data_from(flow_key))
{
- debug_logf(dce_smb_trace, p, "processing raw data for file id %" PRIu64 "\n",
+ SMB_DEBUG(dce_smb_trace,DEFAULT_TRACE_OPTION_ID, TRACE_INFO_LEVEL, p, "processing raw data for file id %" PRIu64 "\n",
tcp_file_tracker->get_file_id());
tcp_file_tracker->process_data(flow_key, data_ptr, data_len);
tcp_file_tracker->stop_accepting_raw_data_from(flow_key);
}
else
{
- debug_logf(dce_smb_trace, p, "not processing raw data\n");
+ SMB_DEBUG(dce_smb_trace,DEFAULT_TRACE_OPTION_ID, TRACE_INFO_LEVEL, p, "not processing raw data\n");
}
tcp_file_tracker_mutex.unlock();
}
processing_flow = (Dce2Smb2SessionData*)current_flow_data->get_smb_session_data();
}
file_flow_key = processing_flow->get_flow_key();
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_INFO_LEVEL, GET_CURRENT_PACKET,
+ "updating the processing flow key to %u\n", file_flow_key);
}
return std::make_pair(switched, processing_flow);
}
auto updated_flow = update_processing_flow();
Flow* flow = updated_flow.second->get_tcp_flow();
FileContext* file = get_smb_file_context(flow, file_name_hash, file_id, true);
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET, "set file info: file size %"
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_INFO_LEVEL, GET_CURRENT_PACKET, "set file info: file size %"
PRIu64 " fid %" PRIu64 " file_name_hash %" PRIu64 " file context "
"%sfound\n", size_v, file_id, file_name_hash, (file ? "" : "not "));
if (file)
}
if (ignore)
+ {
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_ERROR_LEVEL, p,
+ "file name not set , ignored\n");
return true;
+ }
if (file_size and file_offset > file_size)
{
- debug_logf(dce_smb_trace, p, "file_process: bad offset\n");
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_ERROR_LEVEL, p, "file_process: bad offset\n");
dce_alert(GID_DCE2, DCE2_SMB_INVALID_FILE_OFFSET, (dce2CommonStats*)
&dce2_smb_stats, *(current_flow->get_dce2_session_data()));
}
auto updated_flow = update_processing_flow(current_flow);
Dce2Smb2SessionData* processing_flow = updated_flow.second;
- debug_logf(dce_smb_trace, p, "file_process fid %" PRIu64 " data_size %"
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_INFO_LEVEL, p,"file_process fid %" PRIu64 " data_size %"
PRIu32 " offset %" PRIu64 "\n", file_id, data_size, file_offset);
FileFlows* file_flows = FileFlows::get_file_flows(processing_flow->get_tcp_flow());
if (!file_flows)
+ {
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_CRITICAL_LEVEL, p, "file_flows not found\n");
return true;
+ }
if (updated_flow.first)
{
process_file_mutex.unlock();
if (!continue_processing)
{
- debug_logf(dce_smb_trace, p, "file_process completed\n");
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_INFO_LEVEL, p, "file_process completed\n");
return false;
}
{
if (smb_module_is_up)
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET, "file tracker %" PRIu64
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_DEBUG_LEVEL, GET_CURRENT_PACKET, "file tracker %" PRIu64
" file name hash %" PRIu64 " terminating\n", file_id, file_name_hash);
}
file_id(file_idv), file_size(0), file_name_hash(0), file_name(nullptr),
direction(FILE_DOWNLOAD), parent_tree(p_tree)
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET,
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_DEBUG_LEVEL, GET_CURRENT_PACKET,
"file tracker %" PRIu64 " created\n", file_id);
}
Dce2Smb2RequestTracker(uint64_t file_id_v, uint64_t offset_v = 0)
: fname(nullptr), fname_len(0), file_id(file_id_v), offset(offset_v)
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET, "request tracker created\n");
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_DEBUG_LEVEL, GET_CURRENT_PACKET, "request tracker created\n");
}
Dce2Smb2RequestTracker(char* fname_v, uint16_t fname_len_v)
: fname(fname_v), fname_len(fname_len_v), file_id(0), offset(0)
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET, "request tracker created\n");
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_DEBUG_LEVEL, GET_CURRENT_PACKET, "request tracker created\n");
}
~Dce2Smb2RequestTracker()
{
if (smb_module_is_up)
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET, "request tracker terminating\n");
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_DEBUG_LEVEL, GET_CURRENT_PACKET, "request tracker terminating\n");
}
if (fname)
snort_free(fname);
case SMB2_COM_CREATE:
if (!tree and SMB2_CMD_TYPE_REQUEST == command_type)
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET,
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID,
+ TRACE_INFO_LEVEL, GET_CURRENT_PACKET,
"%s_REQ: mid-stream session detected\n",
smb2_command_string[command]);
tree = connect_tree(tree_id, current_flow_key);
if (!tree)
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET,
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID,
+ TRACE_INFO_LEVEL, GET_CURRENT_PACKET,
"%s_REQ: insert tree tracker failed\n",
smb2_command_string[command]);
}
tree->process(command, command_type, smb_header, end, current_flow_key);
else
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET,
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID,
+ TRACE_ERROR_LEVEL, GET_CURRENT_PACKET,
"%s: tree tracker missing\n", smb2_command_string[command]);
dce2_smb_stats.v2_tree_ignored++;
}
(-1 == current_flow->get_max_file_depth()) and
(-1 == current_flow->get_smb_file_depth()))
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET, "Not inserting TID (%u) "
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID,
+ TRACE_INFO_LEVEL, GET_CURRENT_PACKET, "Not inserting TID (%u) "
"because it's not IPC and not inspecting normal file data.\n", tree_id);
dce2_smb_stats.v2_tree_cnct_ignored++;
return nullptr;
{
if (smb_module_is_up)
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET,
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID,
+ TRACE_DEBUG_LEVEL, GET_CURRENT_PACKET,
"session tracker %" PRIu64 " terminating\n", session_id);
}
session_id = key.sid;
session_key = key;
reload_prune = false;
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET, "session tracker %" PRIu64
- " created\n", session_id);
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_DEBUG_LEVEL, GET_CURRENT_PACKET,
+ "session tracker %" PRIu64 "created\n", session_id);
}
~Dce2Smb2SessionTracker();
else
{
dce2_smb_stats.v2_stinf_req_ftrkr_misng++;
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET, "%s_REQ: ftracker missing\n",
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_ERROR_LEVEL,
+ GET_CURRENT_PACKET, "%s_REQ: ftracker missing\n",
smb2_command_string[SMB2_COM_SET_INFO]);
}
}
else
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET, "%s_REQ: header error\n",
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_INFO_LEVEL,
+ GET_CURRENT_PACKET, "%s_REQ: header error\n",
smb2_command_string[SMB2_COM_SET_INFO]);
dce2_smb_stats.v2_stinf_req_hdr_err++;
}
if (!file_tracker)
{
dce2_smb_stats.v2_cls_req_ftrkr_misng++;
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET, "%s_REQ: ftracker missing %" PRIu64 "\n",
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_ERROR_LEVEL,
+ GET_CURRENT_PACKET, "%s_REQ: ftracker missing %" PRIu64 "\n",
smb2_command_string[SMB2_COM_CLOSE], file_id);
return;
}
file_size = alignedNtohq((const uint64_t*)(&(create_res_hdr->end_of_file)));
if (create_res_hdr->file_attributes & SMB2_CREATE_RESPONSE_DIRECTORY)
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET, "%s_RESP: not processing for directory\n",
- smb2_command_string[SMB2_COM_CREATE]);
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_DEBUG_LEVEL,
+ GET_CURRENT_PACKET, "%s_RESP: not processing for directory\n",
+ smb2_command_string[SMB2_COM_CREATE]);
close_file(file_id);
}
else
}
else
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET, "%s_RESP: req tracker missing\n",
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_ERROR_LEVEL, GET_CURRENT_PACKET, "%s_RESP: req tracker missing\n",
smb2_command_string[SMB2_COM_CREATE]);
dce2_smb_stats.v2_crt_rtrkr_misng++;
}
const Smb2CreateRequestHdr* create_req_hdr = (const Smb2CreateRequestHdr*)smb_data;
if (alignedNtohs(&(create_req_hdr->name_offset)) <= SMB2_HEADER_LENGTH)
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET, "%s_REQ: name_offset %" PRIu16 "\n",
- smb2_command_string[SMB2_COM_CREATE], create_req_hdr->name_offset);
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_ERROR_LEVEL,
+ GET_CURRENT_PACKET, "%s_REQ: name_offset %" PRIu16 "\n",
+ smb2_command_string[SMB2_COM_CREATE], create_req_hdr->name_offset);
dce2_smb_stats.v2_crt_req_hdr_err++;
return;
}
if (!file_name_size or (file_name_offset >= end) or
(file_name_offset + file_name_size > end))
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET,
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_ERROR_LEVEL, GET_CURRENT_PACKET,
"%s_REQ: invalid file name data seen with size %" PRIu16 "\n",
smb2_command_string[SMB2_COM_CREATE], file_name_size);
dce2_smb_stats.v2_crt_inv_file_data++;
Dce2Smb2RequestTracker* create_request = new Dce2Smb2RequestTracker(file_name, name_len);
if (!store_request(message_id, current_flow_key, create_request))
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET, "SMB2_COM_CREATE_REQ: store failed\n");
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_CRITICAL_LEVEL,
+ GET_CURRENT_PACKET, "SMB2_COM_CREATE_REQ: store failed\n");
delete create_request;
}
//check if file_id is available form a durable reconnect request.
uint64_t file_id = get_durable_file_id(create_req_hdr, end);
if (file_id)
{
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_INFO_LEVEL,
+ GET_CURRENT_PACKET, "requested file_id %lu\n", file_id);
Dce2Smb2FileTracker* file_tracker = find_file(file_id);
if (!file_tracker)
{
Dce2Smb2RequestTracker* read_request = find_request(message_id, current_flow_key);
if (!read_request)
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET,
- "SMB2_COM_READ_RESP: request tracker missing\n");
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_ERROR_LEVEL,
+ GET_CURRENT_PACKET, "SMB2_COM_READ_RESP: request tracker missing\n");
dce2_smb_stats.v2_read_rtrkr_misng++;
return;
}
+
uint16_t data_offset = alignedNtohs((const uint16_t*)(&(read_resp_hdr->data_offset)));
Dce2Smb2SessionData* current_flow = parent_session->get_flow(current_flow_key);
if (data_offset + (const uint8_t*)smb_header > end)
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET, "SMB2_COM_READ_RESP: bad offset\n");
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_ERROR_LEVEL,
+ GET_CURRENT_PACKET, "SMB2_COM_READ_RESP: bad offset\n");
if (current_flow)
dce_alert(GID_DCE2, DCE2_SMB_BAD_OFF, (dce2CommonStats*)&dce2_smb_stats,
*current_flow->get_dce2_session_data());
}
else
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET,
- "SMB2_COM_READ_RESP: file tracker missing\n");
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_ERROR_LEVEL,
+ GET_CURRENT_PACKET, "SMB2_COM_READ_RESP: file tracker missing\n");
}
}
Dce2Smb2RequestTracker* read_request = new Dce2Smb2RequestTracker(file_id, offset);
if (!store_request(message_id, current_flow_key, read_request))
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET, "SMB2_COM_READ_REQ: store failed\n");
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_CRITICAL_LEVEL,
+ GET_CURRENT_PACKET, "SMB2_COM_READ_REQ: store failed\n");
delete read_request;
}
Dce2Smb2FileTracker* file_tracker = find_file(file_id);
Dce2Smb2SessionData* current_flow = parent_session->get_flow(current_flow_key);
if (file_tracker)
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET,
- "SMB2_COM_READ_REQ: start accepting Raw Data\n");
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_INFO_LEVEL,
+ GET_CURRENT_PACKET, "SMB2_COM_READ_REQ: start accepting Raw Data\n");
file_tracker->accept_raw_data_from(current_flow,offset);
}
else
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET,
- "SMB2_COM_READ_REQ: file tracker missing\n");
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_ERROR_LEVEL,
+ GET_CURRENT_PACKET, "SMB2_COM_READ_REQ: file tracker missing\n");
}
}
if ((alignedNtohs((const uint16_t*)(&(write_req_hdr->data_offset))) +
(const uint8_t*)smb_header > end) and current_flow)
{
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_ERROR_LEVEL,
+ GET_CURRENT_PACKET, "SMB2_COM_WRITE_REQ: bad offset\n");
dce_alert(GID_DCE2, DCE2_SMB_BAD_OFF, (dce2CommonStats*)&dce2_smb_stats,
*current_flow->get_dce2_session_data());
}
Dce2Smb2RequestTracker* write_request = new Dce2Smb2RequestTracker(file_id);
if (!store_request(message_id, current_flow_key, write_request))
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET, "SMB2_COM_WRITE_REQ: store failed\n");
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_ERROR_LEVEL,
+ GET_CURRENT_PACKET, "SMB2_COM_WRITE_REQ: store failed\n");
delete write_request;
}
const uint8_t* file_data = (const uint8_t*)write_req_hdr + SMB2_WRITE_REQUEST_STRUC_SIZE - 1;
}
else
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET,
- "SMB2_COM_WRITE_REQ: file tracker missing\n");
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_ERROR_LEVEL,
+ GET_CURRENT_PACKET,"SMB2_COM_WRITE_REQ: file tracker missing\n");
}
}
if (SMB2_CMD_TYPE_REQUEST == command_type and current_flow and
pending_requests >= current_flow->get_max_outstanding_requests())
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET,
- "%s_REQ: max req exceeded\n", smb2_command_string[command]);
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_ERROR_LEVEL,
+ GET_CURRENT_PACKET, "%s_REQ: max req exceeded\n", smb2_command_string[command])
dce_alert(GID_DCE2, DCE2_SMB_MAX_REQS_EXCEEDED, (dce2CommonStats*)&dce2_smb_stats,
*current_flow->get_dce2_session_data());
return;
if (SMB2_CMD_TYPE_ERROR_RESPONSE == command_type)
{
dce2_smb_stats.v2_crt_err_resp++;
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET,
- "%s_RESP: error\n", smb2_command_string[command]);
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_INFO_LEVEL,
+ GET_CURRENT_PACKET, "%s_RESP: error\n", smb2_command_string[command]);
}
else if (SMB2_CMD_TYPE_REQUEST == command_type)
{
if (SMB2_SHARE_TYPE_DISK != share_type)
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET, "%s_REQ:"
- "processed for ipc share\n", smb2_command_string[command]);
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_DEBUG_LEVEL,
+ GET_CURRENT_PACKET, "%s_REQ: processed for ipc share\n", smb2_command_string[command]);
dce2_smb_stats.v2_crt_req_ipc++;
}
process_create_request(message_id, current_flow_key, smb_header, end);
if (SMB2_CMD_TYPE_ERROR_RESPONSE == command_type)
{
dce2_smb_stats.v2_read_err_resp++;
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET,
- "%s_RESP: error\n", smb2_command_string[command]);
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_INFO_LEVEL,
+ GET_CURRENT_PACKET, "%s_RESP: error\n", smb2_command_string[command]);
Dce2Smb2RequestTracker* request = find_request(message_id, current_flow_key);
if (request)
close_file(request->get_file_id());
if (SMB2_CMD_TYPE_ERROR_RESPONSE == command_type)
{
dce2_smb_stats.v2_wrt_err_resp++;
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET,
- "%s_RESP: error\n", smb2_command_string[command]);
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_INFO_LEVEL,
+ GET_CURRENT_PACKET, "%s_RESP: error\n", smb2_command_string[command]);
Dce2Smb2RequestTracker* request = find_request(message_id, current_flow_key);
if (request)
close_file(request->get_file_id());
case SMB2_COM_IOCTL:
if (SMB2_CMD_TYPE_ERROR_RESPONSE == command_type)
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET,
- "%s_RESP: error\n", smb2_command_string[command]);
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_INFO_LEVEL,
+ GET_CURRENT_PACKET, "%s_RESP: error\n", smb2_command_string[command]);
}
else if (SMB2_SHARE_TYPE_DISK != share_type)
{
{
if (smb_module_is_up)
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET, "tree tracker %" PRIu32 " terminating\n",
- tree_id);
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_DEBUG_LEVEL,
+ GET_CURRENT_PACKET, "tree tracker %" PRIu32 " terminating\n", tree_id);
}
if (co_tracker != nullptr)
{
if (smb_module_is_up)
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET,
- "cleanup pending requests for below MIDs:\n");
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_DEBUG_LEVEL,
+ GET_CURRENT_PACKET, "cleanup pending requests for below MIDs:\n");
}
for (auto it_request : active_requests)
{
if (smb_module_is_up)
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET, "mid %" PRIu64 "\n",
- it_request.first.mid);
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_DEBUG_LEVEL,
+ GET_CURRENT_PACKET, "mid %" PRIu64 "\n", it_request.first.mid);
}
delete it_request.second;
}
Dce2Smb2TreeTracker(uint32_t tree_id_v, Dce2Smb2SessionTracker* p_session, uint8_t sharetype)
: tree_id(tree_id_v), share_type(sharetype), parent_session(p_session)
{
- debug_logf(dce_smb_trace, GET_CURRENT_PACKET,
- "tree tracker %" PRIu32 " created\n", tree_id);
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_DEBUG_LEVEL,
+ GET_CURRENT_PACKET, "tree tracker %" PRIu32 " created\n", tree_id);
if (share_type != SMB2_SHARE_TYPE_DISK)
{
co_tracker = (DCE2_CoTracker*)snort_calloc(sizeof(DCE2_CoTracker));
#define DCE2_SMB_NAME "dce_smb"
#define DCE2_SMB_HELP "dce over smb inspection"
+#define SMB_DEBUG(module_name, module_id, log_level, p, ...) \
+ trace_logf(log_level, module_name , module_id, p, __VA_ARGS__);
+
#define DCE2_SMB_ID 0xff534d42 /* \xffSMB */
#define DCE2_SMB2_ID 0xfe534d42 /* \xfeSMB */
#define DCE2_SMB_ID_SIZE 4
}
else
{
- debug_logf(dce_smb_trace, p, "non-smb packet detected\n");
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_DEBUG_LEVEL,
+ p, "non-smb packet detected with dsize as %u\n", p->dsize);
}
}
const TraceOption* Dce2SmbModule::get_trace_options() const
{
-#ifndef DEBUG_MSGS
- return nullptr;
-#else
static const TraceOption dce_smb_trace_options(nullptr, 0, nullptr);
return &dce_smb_trace_options;
-#endif
}
const RuleMap* Dce2SmbModule::get_rules() const
uint32_t flags, uint32_t* fp)
{
DCE2_PafSmbData* pfdata = &state;
- return dce2_smb_paf(pfdata, pkt->flow, data, len, flags, fp);
+ StreamSplitter::Status ps = dce2_smb_paf(pfdata, pkt->flow, data, len, flags, fp);
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_DEBUG_LEVEL, pkt,
+ "Dce2SmbSplitter scan with length %u and status %d\n", len, ps);
+ return ps;
}
if (DCE2_SsnIsWindowsPolicy(&ssd->sd)
&& ssd->cur_rtracker->ftracker->fp_byte_mode)
{
- debug_log(dce_smb_trace, DetectionEngine::get_current_packet(),
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_ERROR_LEVEL,
+ DetectionEngine::get_current_packet(),
"Pipe is in byte mode - TRANS_TRANSACT_NMPIPE won't work\n");
return DCE2_RET__ERROR;
}
&& (DCE2_SmbTransactionGetName(nb_ptr, nb_len,
byte_count, SmbUnicode(smb_hdr)) != DCE2_RET__SUCCESS))
{
- debug_log(dce_smb_trace, DetectionEngine::get_current_packet(),
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_ERROR_LEVEL,
+ DetectionEngine::get_current_packet(),
"Failed to validate pipe name for Samba.\n");
return DCE2_RET__ERROR;
}
if (DCE2_ComInfoIsRequest(com_info)
&& !DCE2_SmbIsTransactionComplete(ttracker))
{
- debug_log(dce_smb_trace, DetectionEngine::get_current_packet(),
- "Got new transaction request "
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_ERROR_LEVEL,
+ DetectionEngine::get_current_packet(), "Got new transaction request "
"that matches an in progress transaction - not inspecting.\n");
return DCE2_RET__ERROR;
}
if (DCE2_ComInfoIsRequest(com_info)
&& (DCE2_ComInfoWordCount(com_info) != 16))
{
- debug_log(dce_smb_trace, DetectionEngine::get_current_packet(),
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_ERROR_LEVEL,
+ DetectionEngine::get_current_packet(),
"\\PIPE\\LANMAN request - not inspecting\n");
return DCE2_RET__IGNORE;
}
if (DCE2_ComInfoIsRequest(com_info)
&& !DCE2_SmbIsTransactionComplete(ttracker))
{
- debug_log(dce_smb_trace, DetectionEngine::get_current_packet(),
- "Got new transaction request "
- "that matches an in progress transaction - not inspecting.\n");
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_ERROR_LEVEL,
+ DetectionEngine::get_current_packet(), "Got new transaction request "
+ "that matches an in progress transaction - not inspecting.\n");
return DCE2_RET__ERROR;
}
if (DCE2_ComInfoIsRequest(com_info)
&& !DCE2_SmbIsTransactionComplete(ttracker))
{
- debug_log(dce_smb_trace, DetectionEngine::get_current_packet(),
- "Got new transaction request "
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_ERROR_LEVEL,
+ DetectionEngine::get_current_packet(), "Got new transaction request "
"that matches an in progress transaction - not inspecting.\n");
return DCE2_RET__ERROR;
}
if ( !is_ipc and
ssd->max_file_depth == -1 and DCE2_ScSmbFileDepth((dce2SmbProtoConf*)ssd->sd.config) == -1 )
{
- debug_logf(dce_smb_trace, DetectionEngine::get_current_packet(),
- "Not inserting TID (%hu) "
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_INFO_LEVEL,
+ DetectionEngine::get_current_packet(), "Not inserting TID (%hu) "
"because it's not IPC and not inspecting normal file data.\n", tid);
return;
}
if (!file_flows->file_process(p, data_ptr, (int)data_len, position, upload,
ftracker->file_name_hash))
{
- debug_logf(dce_smb_trace, p, "File API returned FAILURE for (0x%02X) %s\n",
- ftracker->fid_v1, upload ? "UPLOAD" : "DOWNLOAD");
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_ERROR_LEVEL,
+ p, "File API returned FAILURE for (0x%02X) %s\n",
+ ftracker->fid_v1, upload ? "UPLOAD" : "DOWNLOAD");
// Failure. Abort tracking this file under file API
return DCE2_RET__ERROR;
}
else if (ftracker->ff_file_offset < ftracker->ff_bytes_processed)
{
- debug_logf(dce_smb_trace, DetectionEngine::get_current_packet(),
- "File offset %" PRIu64 " is less than bytes processed %"
- PRIu64 " - aborting.\n", ftracker->ff_file_offset,
- ftracker->ff_bytes_processed);
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_INFO_LEVEL,
+ DetectionEngine::get_current_packet(), "File offset %" PRIu64 " is less than bytes processed %"
+ PRIu64 " - aborting.\n", ftracker->ff_file_offset,
+ ftracker->ff_bytes_processed);
DCE2_SmbAbortFileAPI(ssd);
DCE2_SmbSetNewFileAPIFileTracker(ssd);
com_info.cmd_size = 0;
com_info.byte_count = 0;
DCE2_SmbCheckCommand(ssd, smb_hdr, smb_com, nb_ptr, nb_len, com_info);
- debug_logf(dce_smb_trace, DetectionEngine::get_current_packet(),
- "Processing command: %s (0x%02X)\n", get_smb_com_string(smb_com), smb_com);
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_INFO_LEVEL,
+ DetectionEngine::get_current_packet(),
+ "Processing command: %s (0x%02X)\n", get_smb_com_string(smb_com), smb_com);
// Note that even if the command shouldn't be processed, some of
// the command functions need to know and do cleanup or some other
if (smb_com2 == SMB_COM_NO_ANDX_COMMAND)
break;
- debug_logf(dce_smb_trace, DetectionEngine::get_current_packet(),
- "Chained SMB command: %s\n", get_smb_com_string(smb_com2));
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_DEBUG_LEVEL,
+ DetectionEngine::get_current_packet(),
+ "Chained SMB command: %s\n", get_smb_com_string(smb_com2));
num_chained++;
if (DCE2_ScSmbMaxChain((dce2SmbProtoConf*)ssd->sd.config) &&
if (smb_com < 0 or smb_com > 255) return nullptr;
- debug_logf(dce_smb_trace, DetectionEngine::get_current_packet(),
- "SMB command: %s (0x%02X)\n", get_smb_com_string(smb_com), smb_com);
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_INFO_LEVEL,
+ DetectionEngine::get_current_packet(),
+ "SMB command: %s (0x%02X)\n", get_smb_com_string(smb_com), smb_com);
if (smb_com_funcs[smb_com] == nullptr)
{
if (!DCE2_GcIsLegacyMode((dce2SmbProtoConf*)ssd->sd.config))
{
// Upgrade connection to SMBv2
- debug_log(dce_smb_trace, p, "upgrading to smb2 session\n");
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_INFO_LEVEL,
+ p, "upgrading to smb2 session\n");
Dce2SmbFlowData* fd = (Dce2SmbFlowData*)p->flow->get_flow_data(
Dce2SmbFlowData::inspector_id);
if (fd)
rtracker = DCE2_SmbInspect(ssd, smb_hdr);
if (rtracker == nullptr)
{
- debug_log(dce_smb_trace, p, "Not inspecting SMB packet.\n");
+ SMB_DEBUG(dce_smb_trace, DEFAULT_TRACE_OPTION_ID, TRACE_INFO_LEVEL,
+ p, "Not inspecting SMB packet.\n");
if (DCE2_BufferIsEmpty(*seg_buf))
{
#include "main/thread.h"
#define DEFAULT_TRACE_LOG_LEVEL 1
+#define TRACE_CRITICAL_LEVEL 2
+#define TRACE_ERROR_LEVEL 3
+#define TRACE_INFO_LEVEL 6
+#define TRACE_DEBUG_LEVEL 7
#define DEFAULT_TRACE_OPTION_ID 0
#define DEFAULT_TRACE_OPTION_NAME "all"