Undefined variable in the string: $EXTERNAL_NET - windows
i am trying to sniff a pcap file using snort rules (windows 10 command line)
here is my command
snort -r challenge.pcap -c rules\exploit.rules
but it gives me an error
here is the error
Initializing rule chains...
ERROR: rules\exploit-kit.rules(24)
Undefined variable in the string: $EXTERNAL_NET.
Fatal Error, Quitting.. Could not create the registry key.
here is my conf file
#--------------------------------------------------
# VRT Rule Packages Snort.conf
#
# For more information visit us at:
# http://www.snort.org Snort Website
# http://vrt-blog.snort.org/ Sourcefire VRT Blog
#
# Mailing list Contact: snort-users#lists.snort.org
# False Positive reports: fp#sourcefire.com
# Snort bugs: bugs#snort.org
#
# Compatible with Snort Versions:
# VERSIONS : 2.9.20
#
# Snort build options:
# OPTIONS : --enable-gre --enable-mpls --enable-targetbased --enable-ppm --enable-perfprofiling --enable-zlib --enable-active-response --enable-normalizer --enable-reload --enable-react --enable-flexresp3
#
# Additional information:
# This configuration file enables active response, to run snort in
# test mode -T you are required to supply an interface -i <interface>
# or test mode will fail to fully validate the configuration and
# exit with a FATAL error
#--------------------------------------------------
###################################################
# This file contains a sample snort configuration.
# You should take the following steps to create your own custom configuration:
#
# 1) Set the network variables.
# 2) Configure the decoder
# 3) Configure the base detection engine
# 4) Configure dynamic loaded libraries
# 5) Configure preprocessors
# 6) Configure output plugins
# 7) Customize your rule set
# 8) Customize preprocessor and decoder rule set
# 9) Customize shared object rule set
###################################################
###################################################
# Step #1: Set the network variables. For more information, see README.variables
###################################################
# Setup the network addresses you are protecting
ipvar HOME_NET 192.168.1.1/24
# Set up the external network addresses. Leave as "any" in most situations
ipvar EXTERNAL_NET any
# List of DNS servers on your network
ipvar DNS_SERVERS $HOME_NET
# List of SMTP servers on your network
ipvar SMTP_SERVERS $HOME_NET
# List of web servers on your network
ipvar HTTP_SERVERS $HOME_NET
# List of sql servers on your network
ipvar SQL_SERVERS $HOME_NET
# List of telnet servers on your network
ipvar TELNET_SERVERS $HOME_NET
# List of ssh servers on your network
ipvar SSH_SERVERS $HOME_NET
# List of ftp servers on your network
ipvar FTP_SERVERS $HOME_NET
# List of sip servers on your network
ipvar SIP_SERVERS $HOME_NET
# List of ports you run web servers on
portvar HTTP_PORTS [80,81,311,383,591,593,901,1220,1414,1741,1830,2301,2381,2809,3037,3128,3702,4343,4848,5250,6988,7000,7001,7144,7145,7510,7777,7779,8000,8008,8014,8028,8080,8085,8088,8090,8118,8123,8180,8181,8243,8280,8300,8800,8888,8899,9000,9060,9080,9090,9091,9443,9999,11371,34443,34444,41080,50002,55555]
# List of ports you want to look for SHELLCODE on.
portvar SHELLCODE_PORTS !80
# List of ports you might see oracle attacks on
portvar ORACLE_PORTS 1024:
# List of ports you want to look for SSH connections on:
portvar SSH_PORTS 22
# List of ports you run ftp servers on
portvar FTP_PORTS [21,2100,3535]
# List of ports you run SIP servers on
portvar SIP_PORTS [5060,5061,5600]
# List of file data ports for file inspection
portvar FILE_DATA_PORTS [$HTTP_PORTS,110,143]
# List of GTP ports for GTP preprocessor
portvar GTP_PORTS [2123,2152,3386]
# other variables, these should not be modified
ipvar AIM_SERVERS [64.12.24.0/23,64.12.28.0/23,64.12.161.0/24,64.12.163.0/24,64.12.200.0/24,205.188.3.0/24,205.188.5.0/24,205.188.7.0/24,205.188.9.0/24,205.188.153.0/24,205.188.179.0/24,205.188.248.0/24]
# Path to your rules files (this can be a relative path)
# Note for Windows users: You are advised to make this an absolute path,
# such as: c:\snort\rules
var RULE_PATH C:\Snort\rules
#var SO_RULE_PATH ../so_rules
var PREPROC_RULE_PATH c:\Snort\preproc_rules
# If you are using reputation preprocessor set these
# Currently there is a bug with relative paths, they are relative to where snort is
# not relative to snort.conf like the above variables
# This is completely inconsistent with how other vars work, BUG 89986
# Set the absolute path appropriately
var WHITE_LIST_PATH c:\Snort\rules
var BLACK_LIST_PATH c:\Snort\rules
###################################################
# Step #2: Configure the decoder. For more information, see README.decode
###################################################
# Stop generic decode events:
config disable_decode_alerts
# Stop Alerts on experimental TCP options
config disable_tcpopt_experimental_alerts
# Stop Alerts on obsolete TCP options
config disable_tcpopt_obsolete_alerts
# Stop Alerts on T/TCP alerts
config disable_tcpopt_ttcp_alerts
# Stop Alerts on all other TCPOption type events:
config disable_tcpopt_alerts
# Stop Alerts on invalid ip options
config disable_ipopt_alerts
# Alert if value in length field (IP, TCP, UDP) is greater th elength of the packet
# config enable_decode_oversized_alerts
# Same as above, but drop packet if in Inline mode (requires enable_decode_oversized_alerts)
# config enable_decode_oversized_drops
# Configure IP / TCP checksum mode
config checksum_mode: all
# Configure maximum number of flowbit references. For more information, see README.flowbits
# config flowbits_size: 64
# Configure ports to ignore
# config ignore_ports: tcp 21 6667:6671 1356
# config ignore_ports: udp 1:17 53
# Configure active response for non inline operation. For more information, see REAMDE.active
# config response: eth0 attempts 2
# Configure DAQ related options for inline operation. For more information, see README.daq
#
# config daq: <type>
# config daq_dir: <dir>
# config daq_mode: <mode>
# config daq_var: <var>
#
# <type> ::= pcap | afpacket | dump | nfq | ipq | ipfw
# <mode> ::= read-file | passive | inline
# <var> ::= arbitrary <name>=<value passed to DAQ
# <dir> ::= path as to where to look for DAQ module so's
# Configure specific UID and GID to run snort as after dropping privs. For more information see snort -h command line options
#
# config set_gid:
# config set_uid:
# Configure default snaplen. Snort defaults to MTU of in use interface. For more information see README
#
# config snaplen:
#
# Configure default bpf_file to use for filtering what traffic reaches snort. For more information see snort -h command line options (-F)
#
# config bpf_file:
#
# Configure default log directory for snort to log to. For more information see snort -h command line options (-l)
#
config logdir: c:\Snort\log
###################################################
# Step #3: Configure the base detection engine. For more information, see README.decode
###################################################
# Configure PCRE match limitations
config pcre_match_limit: 3500
config pcre_match_limit_recursion: 1500
# Configure the detection engine See the Snort Manual, Configuring Snort - Includes - Config
config detection: search-method ac-split search-optimize max-pattern-len 20
# Configure the event queue. For more information, see README.event_queue
config event_queue: max_queue 8 log 5 order_events content_length
###################################################
## Configure GTP if it is to be used.
## For more information, see README.GTP
####################################################
# config enable_gtp
###################################################
# Per packet and rule latency enforcement
# For more information see README.ppm
###################################################
# Per Packet latency configuration
#config ppm: max-pkt-time 250, \
# fastpath-expensive-packets, \
# pkt-log
# Per Rule latency configuration
#config ppm: max-rule-time 200, \
# threshold 3, \
# suspend-expensive-rules, \
# suspend-timeout 20, \
# rule-log alert
###################################################
# Configure Perf Profiling for debugging
# For more information see README.PerfProfiling
###################################################
#config profile_rules: print all, sort avg_ticks
#config profile_preprocs: print all, sort avg_ticks
###################################################
# Configure protocol aware flushing
# For more information see README.stream5
###################################################
config paf_max: 16000
###################################################
# Step #4: Configure dynamic loaded libraries.
# For more information, see Snort Manual, Configuring Snort - Dynamic Modules
###################################################
# path to dynamic preprocessor libraries
dynamicpreprocessor directory c:\Snort\lib\snort_dynamicpreprocessor
# path to base preprocessor engine
dynamicengine C:\Snort\lib\snort_dynamicengine\sf_engine.dll
# path to dynamic rules libraries
#dynamicdetection directory /usr/local/lib/snort_dynamicrules
###################################################
# Step #5: Configure preprocessors
# For more information, see the Snort Manual, Configuring Snort - Preprocessors
###################################################
# GTP Control Channle Preprocessor. For more information, see README.GTP
# preprocessor gtp: ports { 2123 3386 2152 }
# Inline packet normalization. For more information, see README.normalize
# Does nothing in IDS mode
#preprocessor normalize_ip4
#preprocessor normalize_tcp: ips ecn stream
#preprocessor normalize_icmp4
#preprocessor normalize_ip6
#preprocessor normalize_icmp6
# Target-based IP defragmentation. For more inforation, see README.frag3
preprocessor frag3_global: max_frags 65536
preprocessor frag3_engine: policy windows detect_anomalies overlap_limit 10 min_fragment_length 100 timeout 180
# Target-Based stateful inspection/stream reassembly. For more inforation, see README.stream5
preprocessor stream5_global: track_tcp yes, \
track_udp yes, \
track_icmp no, \
max_tcp 262144, \
max_udp 131072, \
max_active_responses 2, \
min_response_seconds 5
preprocessor stream5_tcp: log_asymmetric_traffic no, policy windows, \
detect_anomalies, require_3whs 180, \
overlap_limit 10, small_segments 3 bytes 150, timeout 180, \
ports client 21 22 23 25 42 53 79 109 110 111 113 119 135 136 137 139 143 \
161 445 513 514 587 593 691 1433 1521 1741 2100 3306 6070 6665 6666 6667 6668 6669 \
7000 8181 32770 32771 32772 32773 32774 32775 32776 32777 32778 32779, \
ports both 80 81 311 383 443 465 563 591 593 636 901 989 992 993 994 995 1220 1414 1830 2301 2381 2809 3037 3128 3702 4343 4848 5250 6988 7907 7000 7001 7144 7145 7510 7802 7777 7779 \
7801 7900 7901 7902 7903 7904 7905 7906 7908 7909 7910 7911 7912 7913 7914 7915 7916 \
7917 7918 7919 7920 8000 8008 8014 8028 8080 8085 8088 8090 8118 8123 8180 8243 8280 8300 8800 8888 8899 9000 9060 9080 9090 9091 9443 9999 11371 34443 34444 41080 50002 55555
preprocessor stream5_udp: timeout 180
# performance statistics. For more information, see the Snort Manual, Configuring Snort - Preprocessors - Performance Monitor
# preprocessor perfmonitor: time 300 file /var/snort/snort.stats pktcnt 10000
# HTTP normalization and anomaly detection. For more information, see README.http_inspect
preprocessor http_inspect: global iis_unicode_map unicode.map 1252 compress_depth 65535 decompress_depth 65535
preprocessor http_inspect_server: server default \
http_methods { GET POST PUT SEARCH MKCOL COPY MOVE LOCK UNLOCK NOTIFY POLL BCOPY BDELETE BMOVE LINK UNLINK OPTIONS HEAD DELETE TRACE TRACK CONNECT SOURCE SUBSCRIBE UNSUBSCRIBE PROPFIND PROPPATCH BPROPFIND BPROPPATCH RPC_CONNECT PROXY_SUCCESS BITS_POST CCM_POST SMS_POST RPC_IN_DATA RPC_OUT_DATA RPC_ECHO_DATA } \
chunk_length 500000 \
server_flow_depth 0 \
client_flow_depth 0 \
post_depth 65495 \
oversize_dir_length 500 \
max_header_length 750 \
max_headers 100 \
max_spaces 200 \
small_chunk_length { 10 5 } \
ports { 80 81 311 383 591 593 901 1220 1414 1741 1830 2301 2381 2809 3037 3128 3702 4343 4848 5250 6988 7000 7001 7144 7145 7510 7777 7779 8000 8008 8014 8028 8080 8085 8088 8090 8118 8123 8180 8181 8243 8280 8300 8800 8888 8899 9000 9060 9080 9090 9091 9443 9999 11371 34443 34444 41080 50002 55555 } \
non_rfc_char { 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 } \
enable_cookie \
extended_response_inspection \
inspect_gzip \
normalize_utf \
unlimited_decompress \
normalize_javascript \
apache_whitespace no \
ascii no \
bare_byte no \
directory no \
double_decode no \
iis_backslash no \
iis_delimiter no \
iis_unicode no \
multi_slash no \
utf_8 no \
u_encode yes \
webroot no
# ONC-RPC normalization and anomaly detection. For more information, see the Snort Manual, Configuring Snort - Preprocessors - RPC Decode
preprocessor rpc_decode: 111 32770 32771 32772 32773 32774 32775 32776 32777 32778 32779 no_alert_multiple_requests no_alert_large_fragments no_alert_incomplete
# Back Orifice detection.
#preprocessor bo
# FTP / Telnet normalization and anomaly detection. For more information, see README.ftptelnet
preprocessor ftp_telnet: global inspection_type stateful encrypted_traffic no check_encrypted
preprocessor ftp_telnet_protocol: telnet \
ayt_attack_thresh 20 \
normalize ports { 23 } \
detect_anomalies
preprocessor ftp_telnet_protocol: ftp server default \
def_max_param_len 100 \
ports { 21 2100 3535 } \
telnet_cmds yes \
ignore_telnet_erase_cmds yes \
ftp_cmds { ABOR ACCT ADAT ALLO APPE AUTH CCC CDUP } \
ftp_cmds { CEL CLNT CMD CONF CWD DELE ENC EPRT } \
ftp_cmds { EPSV ESTA ESTP FEAT HELP LANG LIST LPRT } \
ftp_cmds { LPSV MACB MAIL MDTM MIC MKD MLSD MLST } \
ftp_cmds { MODE NLST NOOP OPTS PASS PASV PBSZ PORT } \
ftp_cmds { PROT PWD QUIT REIN REST RETR RMD RNFR } \
ftp_cmds { RNTO SDUP SITE SIZE SMNT STAT STOR STOU } \
ftp_cmds { STRU SYST TEST TYPE USER XCUP XCRC XCWD } \
ftp_cmds { XMAS XMD5 XMKD XPWD XRCP XRMD XRSQ XSEM } \
ftp_cmds { XSEN XSHA1 XSHA256 } \
alt_max_param_len 0 { ABOR CCC CDUP ESTA FEAT LPSV NOOP PASV PWD QUIT REIN STOU SYST XCUP XPWD } \
alt_max_param_len 200 { ALLO APPE CMD HELP NLST RETR RNFR STOR STOU XMKD } \
alt_max_param_len 256 { CWD RNTO } \
alt_max_param_len 400 { PORT } \
alt_max_param_len 512 { SIZE } \
chk_str_fmt { ACCT ADAT ALLO APPE AUTH CEL CLNT CMD } \
chk_str_fmt { CONF CWD DELE ENC EPRT EPSV ESTP HELP } \
chk_str_fmt { LANG LIST LPRT MACB MAIL MDTM MIC MKD } \
chk_str_fmt { MLSD MLST MODE NLST OPTS PASS PBSZ PORT } \
chk_str_fmt { PROT REST RETR RMD RNFR RNTO SDUP SITE } \
chk_str_fmt { SIZE SMNT STAT STOR STRU TEST TYPE USER } \
chk_str_fmt { XCRC XCWD XMAS XMD5 XMKD XRCP XRMD XRSQ } \
chk_str_fmt { XSEM XSEN XSHA1 XSHA256 } \
cmd_validity ALLO < int [ char R int ] > \
cmd_validity EPSV < [ { char 12 | char A char L char L } ] > \
cmd_validity MACB < string > \
cmd_validity MDTM < [ date nnnnnnnnnnnnnn[.n[n[n]]] ] string > \
cmd_validity MODE < char ASBCZ > \
cmd_validity PORT < host_port > \
cmd_validity PROT < char CSEP > \
cmd_validity STRU < char FRPO [ string ] > \
cmd_validity TYPE < { char AE [ char NTC ] | char I | char L [ number ] } >
preprocessor ftp_telnet_protocol: ftp client default \
max_resp_len 256 \
bounce yes \
ignore_telnet_erase_cmds yes \
telnet_cmds yes
# SMTP normalization and anomaly detection. For more information, see README.SMTP
preprocessor smtp: ports { 25 465 587 691 } \
inspection_type stateful \
b64_decode_depth 0 \
qp_decode_depth 0 \
bitenc_decode_depth 0 \
uu_decode_depth 0 \
log_mailfrom \
log_rcptto \
log_filename \
log_email_hdrs \
normalize cmds \
normalize_cmds { ATRN AUTH BDAT CHUNKING DATA DEBUG EHLO EMAL ESAM ESND ESOM ETRN EVFY } \
normalize_cmds { EXPN HELO HELP IDENT MAIL NOOP ONEX QUEU QUIT RCPT RSET SAML SEND SOML } \
normalize_cmds { STARTTLS TICK TIME TURN TURNME VERB VRFY X-ADAT X-DRCP X-ERCP X-EXCH50 } \
normalize_cmds { X-EXPS X-LINK2STATE XADR XAUTH XCIR XEXCH50 XGEN XLICENSE XQUE XSTA XTRN XUSR } \
max_command_line_len 512 \
max_header_line_len 1000 \
max_response_line_len 512 \
alt_max_command_line_len 260 { MAIL } \
alt_max_command_line_len 300 { RCPT } \
alt_max_command_line_len 500 { HELP HELO ETRN EHLO } \
alt_max_command_line_len 255 { EXPN VRFY ATRN SIZE BDAT DEBUG EMAL ESAM ESND ESOM EVFY IDENT NOOP RSET } \
alt_max_command_line_len 246 { SEND SAML SOML AUTH TURN ETRN DATA RSET QUIT ONEX QUEU STARTTLS TICK TIME TURNME VERB X-EXPS X-LINK2STATE XADR XAUTH XCIR XEXCH50 XGEN XLICENSE XQUE XSTA XTRN XUSR } \
valid_cmds { ATRN AUTH BDAT CHUNKING DATA DEBUG EHLO EMAL ESAM ESND ESOM ETRN EVFY } \
valid_cmds { EXPN HELO HELP IDENT MAIL NOOP ONEX QUEU QUIT RCPT RSET SAML SEND SOML } \
valid_cmds { STARTTLS TICK TIME TURN TURNME VERB VRFY X-ADAT X-DRCP X-ERCP X-EXCH50 } \
valid_cmds { X-EXPS X-LINK2STATE XADR XAUTH XCIR XEXCH50 XGEN XLICENSE XQUE XSTA XTRN XUSR } \
xlink2state { enabled }
# Portscan detection. For more information, see README.sfportscan
preprocessor sfportscan: proto { all } memcap { 10000000 } sense_level { low }
# ARP spoof detection. For more information, see the Snort Manual - Configuring Snort - Preprocessors - ARP Spoof Preprocessor
# preprocessor arpspoof
# preprocessor arpspoof_detect_host: 192.168.40.1 f0:0f:00:f0:0f:00
# SSH anomaly detection. For more information, see README.ssh
preprocessor ssh: server_ports { 22 } \
autodetect \
max_client_bytes 19600 \
max_encrypted_packets 20 \
max_server_version_len 100 \
enable_respoverflow enable_ssh1crc32 \
enable_srvoverflow enable_protomismatch
# SMB / DCE-RPC normalization and anomaly detection. For more information, see README.dcerpc2
preprocessor dcerpc2: memcap 102400, events [co ]
preprocessor dcerpc2_server: default, policy WinXP, \
detect [smb [139,445], tcp 135, udp 135, rpc-over-http-server 593], \
autodetect [tcp 1025:, udp 1025:, rpc-over-http-server 1025:], \
smb_max_chain 3, smb_invalid_shares ["C$", "D$", "ADMIN$"]
# DNS anomaly detection. For more information, see README.dns
preprocessor dns: ports { 53 } enable_rdata_overflow
# SSL anomaly detection and traffic bypass. For more information, see README.ssl
preprocessor ssl: ports { 443 465 563 636 989 992 993 994 995 7801 7802 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 }, trustservers, noinspect_encrypted
# SDF sensitive data preprocessor. For more information see README.sensitive_data
preprocessor sensitive_data: alert_threshold 25
# SIP Session Initiation Protocol preprocessor. For more information see README.sip
preprocessor sip: max_sessions 40000, \
ports { 5060 5061 5600 }, \
methods { invite \
cancel \
ack \
bye \
register \
options \
refer \
subscribe \
update \
join \
info \
message \
notify \
benotify \
do \
qauth \
sprack \
publish \
service \
unsubscribe \
prack }, \
max_uri_len 512, \
max_call_id_len 80, \
max_requestName_len 20, \
max_from_len 256, \
max_to_len 256, \
max_via_len 1024, \
max_contact_len 512, \
max_content_len 2048
# IMAP preprocessor. For more information see README.imap
preprocessor imap: \
ports { 143 } \
b64_decode_depth 0 \
qp_decode_depth 0 \
bitenc_decode_depth 0 \
uu_decode_depth 0
# POP preprocessor. For more information see README.pop
preprocessor pop: \
ports { 110 } \
b64_decode_depth 0 \
qp_decode_depth 0 \
bitenc_decode_depth 0 \
uu_decode_depth 0
# Modbus preprocessor. For more information see README.modbus
preprocessor modbus: ports { 502 }
# DNP3 preprocessor. For more information see README.dnp3
preprocessor dnp3: ports { 20000 } \
memcap 262144 \
check_crc
# Reputation preprocessor. For more information see README.reputation
preprocessor reputation: \
memcap 500, \
priority whitelist, \
nested_ip inner, \
whitelist $WHITE_LIST_PATH\whitelist.rules, \
blacklist $BLACK_LIST_PATH\blacklist.rules
###################################################
# Step #6: Configure output plugins
# For more information, see Snort Manual, Configuring Snort - Output Modules
###################################################
# unified2
# Recommended for most installs
# output unified2: filename merged.log, limit 128, nostamp, mpls_event_types, vlan_event_types
# Additional configuration for specific types of installs
# output alert_unified2: filename snort.alert, limit 128, nostamp
# output log_unified2: filename snort.log, limit 128, nostamp
# syslog
# output alert_syslog: LOG_AUTH LOG_ALERT
# pcap
# output log_tcpdump: tcpdump.log
# metadata reference data. do not modify these lines
include classification.config
include reference.config
###################################################
# Step #7: Customize your rule set
# For more information, see Snort Manual, Writing Snort Rules
#
# NOTE: All categories are enabled in this conf file
###################################################
# site specific rules
include $RULE_PATH\local.rules
include $RULE_PATH\app-detect.rules
include $RULE_PATH\attack-responses.rules
include $RULE_PATH\backdoor.rules
include $RULE_PATH\bad-traffic.rules
include $RULE_PATH\blacklist.rules
include $RULE_PATH\botnet-cnc.rules
include $RULE_PATH\browser-chrome.rules
include $RULE_PATH\browser-firefox.rules
include $RULE_PATH\browser-ie.rules
include $RULE_PATH\browser-other.rules
include $RULE_PATH\browser-plugins.rules
include $RULE_PATH\browser-webkit.rules
include $RULE_PATH\chat.rules
include $RULE_PATH\content-replace.rules
include $RULE_PATH\ddos.rules
include $RULE_PATH\dns.rules
include $RULE_PATH\dos.rules
include $RULE_PATH\experimental.rules
include $RULE_PATH\exploit-kit.rules
include $RULE_PATH\exploit.rules
include $RULE_PATH\file-executable.rules
include $RULE_PATH\file-flash.rules
include $RULE_PATH\file-identify.rules
include $RULE_PATH\file-image.rules
include $RULE_PATH\file-multimedia.rules
include $RULE_PATH\file-office.rules
include $RULE_PATH\file-other.rules
include $RULE_PATH\file-pdf.rules
include $RULE_PATH\finger.rules
include $RULE_PATH\ftp.rules
include $RULE_PATH\icmp-info.rules
include $RULE_PATH\icmp.rules
include $RULE_PATH\imap.rules
include $RULE_PATH\indicator-compromise.rules
include $RULE_PATH\indicator-obfuscation.rules
include $RULE_PATH\indicator-shellcode.rules
include $RULE_PATH\info.rules
include $RULE_PATH\malware-backdoor.rules
include $RULE_PATH\malware-cnc.rules
include $RULE_PATH\malware-other.rules
include $RULE_PATH\malware-tools.rules
include $RULE_PATH\misc.rules
include $RULE_PATH\multimedia.rules
include $RULE_PATH\mysql.rules
include $RULE_PATH\netbios.rules
include $RULE_PATH\nntp.rules
include $RULE_PATH\oracle.rules
include $RULE_PATH\os-linux.rules
include $RULE_PATH\os-other.rules
include $RULE_PATH\os-solaris.rules
include $RULE_PATH\os-windows.rules
include $RULE_PATH\other-ids.rules
include $RULE_PATH\p2p.rules
include $RULE_PATH\phishing-spam.rules
include $RULE_PATH\policy-multimedia.rules
include $RULE_PATH\policy-other.rules
include $RULE_PATH\policy.rules
include $RULE_PATH\policy-social.rules
include $RULE_PATH\policy-spam.rules
include $RULE_PATH\pop2.rules
include $RULE_PATH\pop3.rules
include $RULE_PATH\protocol-finger.rules
include $RULE_PATH\protocol-ftp.rules
include $RULE_PATH\protocol-icmp.rules
include $RULE_PATH\protocol-imap.rules
include $RULE_PATH\protocol-pop.rules
include $RULE_PATH\protocol-services.rules
include $RULE_PATH\protocol-voip.rules
include $RULE_PATH\pua-adware.rules
include $RULE_PATH\pua-other.rules
include $RULE_PATH\pua-p2p.rules
include $RULE_PATH\pua-toolbars.rules
include $RULE_PATH\rpc.rules
include $RULE_PATH\rservices.rules
include $RULE_PATH\scada.rules
include $RULE_PATH\scan.rules
include $RULE_PATH\server-apache.rules
include $RULE_PATH\server-iis.rules
include $RULE_PATH\server-mail.rules
include $RULE_PATH\server-mssql.rules
include $RULE_PATH\server-mysql.rules
include $RULE_PATH\server-oracle.rules
include $RULE_PATH\server-other.rules
include $RULE_PATH\server-webapp.rules
include $RULE_PATH\shellcode.rules
include $RULE_PATH\smtp.rules
include $RULE_PATH\snmp.rules
include $RULE_PATH\specific-threats.rules
include $RULE_PATH\spyware-put.rules
include $RULE_PATH\sql.rules
include $RULE_PATH\telnet.rules
include $RULE_PATH\tftp.rules
include $RULE_PATH\virus.rules
include $RULE_PATH\voip.rules
include $RULE_PATH\web-activex.rules
include $RULE_PATH\web-attacks.rules
include $RULE_PATH\web-cgi.rules
include $RULE_PATH\web-client.rules
include $RULE_PATH\web-coldfusion.rules
include $RULE_PATH\web-frontpage.rules
include $RULE_PATH\web-iis.rules
include $RULE_PATH\web-misc.rules
include $RULE_PATH\web-php.rules
include $RULE_PATH\x11.rules
###################################################
# Step #8: Customize your preprocessor and decoder alerts
# For more information, see README.decoder_preproc_rules
###################################################
# decoder and preprocessor event rules
include $PREPROC_RULE_PATH\preprocessor.rules
include $PREPROC_RULE_PATH\decoder.rules
include $PREPROC_RULE_PATH\sensitive-data.rules
###################################################
# Step #9: Customize your Shared Object Snort Rules
# For more information, see http://vrt-blog.snort.org/2009/01/using-vrt-certified-shared-object-rules.html
###################################################
# dynamic library rules
# include $SO_RULE_PATH/bad-traffic.rules
# include $SO_RULE_PATH/chat.rules
# include $SO_RULE_PATH/dos.rules
# include $SO_RULE_PATH/exploit.rules
# include $SO_RULE_PATH/icmp.rules
# include $SO_RULE_PATH/imap.rules
# include $SO_RULE_PATH/misc.rules
# include $SO_RULE_PATH/multimedia.rules
# include $SO_RULE_PATH/netbios.rules
# include $SO_RULE_PATH/nntp.rules
# include $SO_RULE_PATH/p2p.rules
# include $SO_RULE_PATH/smtp.rules
# include $SO_RULE_PATH/snmp.rules
# include $SO_RULE_PATH/specific-threats.rules
# include $SO_RULE_PATH/web-activex.rules
# include $SO_RULE_PATH/web-client.rules
# include $SO_RULE_PATH/web-iis.rules
# include $SO_RULE_PATH/web-misc.rules
# Event thresholding or suppression commands. See threshold.conf
include threshold.conf
Thank you
I had the same problem as you and I had solved it.
You should append configuration file path to -c option, instead of *.rules file. It will include your rule sets in it.
PS: You'd better follow the steps in snort.conf, Step #7 will give you some advice.
Hope that will help you : )
Related
Telegraf SNMP plugin Error: IF-MIB::ifTable: Unknown Object Identifier
Steps followed to installed SNMP manager and agent on ec2 sudo apt-get update sudo apt-get install snmp snmp-mibs-downloader sudo apt-get update sudo apt-get install snmpd I opened sudo nano /etc/snmp/snmp.conf and commented the following line: #mibs : Then I went into the configuration file and modified file as below: sudo nano /etc/snmp/snmpd.conf Listen for connections from the local system only agentAddress udp:127.0.0.1:161 <--- commented this part. Listen for connections on all interfaces (both IPv4 and IPv6) agentAddress udp:161,udp6:[::1]:161 <--remove the comment from this line to make it work. using below command I can get snmp data snmpwalk -v 2c -c public 127.0.0.1 . From inside docker container as well I can get the data snmpwalk -v 2c -c public host.docker.internal . Docker-compose: telegraf_snmp: image: telegraf:1.22.1 container_name: telegraf_snmp restart: always depends_on: - influxdb networks: - analytics extra_hosts: - "host.docker.internal:host-gateway" # ports: # - "161:161/udp" volumes: - /mnt/telegraf/snmp:/var/lib/telegraf - ./etc/telegraf/snmp/:/etc/telegraf/snmp/ env_file: - secrets.env environment: INFLUXDB_URL: http://influxdb:8086 command: --config-directory /etc/telegraf/snmp/telegraf.d --config /etc/telegraf/snmp/telegraf.conf links: - influxdb logging: options: max-size: "10m" max-file: "3" Telegraf Input conf: [[inputs.snmp]] ## Agent addresses to retrieve values from. ## format: agents = ["<scheme://><hostname>:<port>"] ## scheme: optional, either udp, udp4, udp6, tcp, tcp4, tcp6. ## default is udp ## port: optional ## example: agents = ["udp://127.0.0.1:161"] ## agents = ["tcp://127.0.0.1:161"] ## agents = ["udp4://v4only-snmp-agent"] # agents = ["udp://127.0.0.1:161"] agents = ["udp://host.docker.internal:161"] ## Timeout for each request. timeout = "15s" ## SNMP version; can be 1, 2, or 3. version = 2 ## SNMP community string. community = "public" ## Agent host tag # agent_host_tag = "agent_host" ## Number of retries to attempt. retries = 3 ## The GETBULK max-repetitions parameter. # max_repetitions = 10 ## SNMPv3 authentication and encryption options. ## ## Security Name. # sec_name = "myuser" ## Authentication protocol; one of "MD5", "SHA", or "". # auth_protocol = "MD5" ## Authentication password. # auth_password = "pass" ## Security Level; one of "noAuthNoPriv", "authNoPriv", or "authPriv". # sec_level = "authNoPriv" ## Context Name. # context_name = "" ## Privacy protocol used for encrypted messages; one of "DES", "AES", "AES192", "AES192C", "AES256", "AES256C", or "". ### Protocols "AES192", "AES192", "AES256", and "AES256C" require the underlying net-snmp tools ### to be compiled with --enable-blumenthal-aes (http://www.net-snmp.org/docs/INSTALL.html) # priv_protocol = "" ## Privacy password used for encrypted messages. # priv_password = "" ## Add fields and tables defining the variables you wish to collect. This ## example collects the system uptime and interface variables. Reference the ## full plugin documentation for configuration details. [[inputs.snmp.field]] oid = "RFC1213-MIB::sysUpTime.0" name = "uptime" [[inputs.snmp.field]] oid = "RFC1213-MIB::sysName.0" name = "source" is_tag = true [[inputs.snmp.table]] oid = "IF-MIB::ifTable" name = "interface" inherit_tags = ["source"] [[inputs.snmp.table.field]] oid = "IF-MIB::ifDescr" name = "ifDescr" is_tag = true Telegraf logs: Cannot find module (IF-MIB): At line 1 in (none) IF-MIB::ifTable: Unknown Object Identifier: exit status 2 2022-09-09T10:10:09Z I! Starting Telegraf 1.22.1 2022-09-09T10:10:09Z I! Loaded inputs: snmp 2022-09-09T10:10:09Z I! Loaded aggregators: 2022-09-09T10:10:09Z I! Loaded processors: 2022-09-09T10:10:09Z I! Loaded outputs: file influxdb_v2 2022-09-09T10:10:09Z I! Tags enabled: host=7a38697f4527 2022-09-09T10:10:09Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"7a38697f4527", Flush Interval:10s 2022-09-09T10:10:09Z E! [telegraf] Error running agent: could not initialize input inputs.snmp: initializing table interface: translating: MIB search path: /root/.snmp/mibs:/usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf Cannot find module (IF-MIB): At line 1 in (none) IF-MIB::ifTable: Unknown Object Identifier: exit status 2 2022-09-09T10:10:11Z I! Starting Telegraf 1.22.1 2022-09-09T10:10:11Z I! Loaded inputs: snmp 2022-09-09T10:10:11Z I! Loaded aggregators: 2022-09-09T10:10:11Z I! Loaded processors: 2022-09-09T10:10:11Z I! Loaded outputs: file influxdb_v2 2022-09-09T10:10:11Z I! Tags enabled: host=7a38697f4527 2022-09-09T10:10:11Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"7a38697f4527", Flush Interval:10s 2022-09-09T10:10:11Z E! [telegraf] Error running agent: could not initialize input inputs.snmp: initializing table interface: translating: MIB search path: /root/.snmp/mibs:/usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf Cannot find module (IF-MIB): At line 1 in (none) IF-MIB::ifTable: Unknown Object Identifier: exit status 2 But in telegraf I get above error. I checked the mibs directory using ls /usr/share/snmp/mibs I cannot find IF-MIB file here even after installing $ sudo apt-get install snmp-mibs-downloader $ sudo download-mibs How can I resolve this issue ? Do I need to follow some additional steps ? SNMP Plugin in telegraf should able to pull the data from SNMP
Why do comments invalidate my Makefile commands?
I'm trying to add some comments to my Makefile but am seeing some odd behavior that I don't understand. The following succeeds with a make plan-all: plan-all: \ plan-master \ plan-log-archive \ plan-shared \ plan-audit \ However, if I try to add comments: plan-all: \ # -------------------- # Global Accounts | # -------------------- plan-master \ plan-log-archive \ plan-shared \ plan-audit \ I get a failure: make: plan-master: No such file or directory
There is no way to add comments into a logical line that uses backslashes. It can't be done. You can either add them before the rule, or you can use multiple rules instead of backslashes: # -------------------- # Global Accounts | # -------------------- plan-all: \ plan-master \ plan-log-archive \ plan-shared \ plan-audit \ or # -------------------- # Global Accounts | # -------------------- plan-all: \ plan-master # ------------------- # Other Accounts | # ------------------- plan-all: \ plan-log-archive \ plan-shared \ plan-audit \
Configuring 3proxy Socks5 behind NAT network - error 12
I'm trying to configure 3proxy server using this guide (I've already used it on OHV hosting and it works just nice!), now trying to start 3proxy behind NAT, and have error 12 of 3proxy which means 12 - failed to bind() Where is mistake and what I'm doing wrong? Internal IP: 172.16.20.50 External IP: 82.118.227.155 NAT Ports: 5001-5020 Here are my entire config: ###################### ##3Proxy.cfg Content## ###################### ##Main## #Starting 3proxy as a service/daemon daemon #DNS Servers to resolve domains and for the local DNS cache #that providers faster resolution for cached entries nserver 8.8.8.8 nserver 1.1.1.1 nscache 65536 #Authentication #CL = Clear Text, CR = Encrypted Passswords (MD5) #Add MD5 users with MD5 passwords with "" (see below) #users "user:CR:$1$lFDGlder$pLRb4cU2D7GAT58YQvY49." users 3proxy:CL:hidden #Logging log /var/log/3proxy/3proxy.log D logformat "- +_L%t.%. %N.%p %E %U %C:%c %R:%r %O %I %h %T" #logformat "-""+_L%C - %U [%d/%o/%Y:%H:%M:%S %z] ""%T"" %E %I" rotate 30 #Auth type #auth strong = username & password auth strong #Binding address external 82.118.227.155 internal 172.16.20.50 #SOCKS5 auth strong flush allow 3proxy maxconn 1000 socks -p5011 User 3proxy created, access to 3proxy granted. Logs, which means connection established, but no traffic transfered (0/0): [root#bgvpn113 ~]# tail -f /var/log/3proxy/3proxy.log.2018.05.14 1526329023.448 SOCK5.5011 00012 3proxy MY_LOCAL_IP:21151 88.212.201.205:443 0 0 0 CONNECT_88.212.201.205:443 1526329023.458 SOCK5.5011 00012 3proxy MY_LOCAL_IP:21154 88.212.201.205:443 0 0 0 CONNECT_88.212.201.205:443 1526329023.698 SOCK5.5011 00012 3proxy MY_LOCAL_IP:21158 88.212.201.205:443 0 0 0 CONNECT_88.212.201.205:443 1526329037.419 SOCK5.5011 00012 3proxy MY_LOCAL_IP:21162 195.201.201.32:443 0 0 0 CONNECT_195.201.201.32:443 1526329037.669 SOCK5.5011 00012 3proxy MY_LOCAL_IP:21164 195.201.201.32:443 0 0 0 CONNECT_195.201.201.32:443
Mistake was in outside IP. I set both ips to 172.16.20.50 and it started to work!
How should I set "bw" options for acoustic model adaption?
In tutorials it has written this command: ~~~ ./bw \ -hmmdir en-us \ -moddeffn en-us/mdef.txt \ -ts2cbfn .ptm. \ -feat 1s_c_d_dd \ -svspec 0-12/13-25/26-38 \ -cmn current \ -agc none \ -dictfn cmudict-en-us.dict \ -ctlfn arctic20.fileids \ -lsnfn arctic20.transcription \ -accumdir . ~~~ But I checked my feat.params and it has this content: ~~~ -lowerf 130 -upperf 6800 -nfilt 25 -transform dct -lifter 22 -feat 1s_c_d_dd -svspec 0-12/13-25/26-38 -agc none -cmn current -varnorm no -model ptm -cmninit 40,3,-1 ~~~ I don't know how should I config these options? I am trying to config acoustic model for contunuous speaking. I got my model from here: https://sourceforge.net/projects/cmusphinx/files/Acoustic%20and%20Language%20Models/US%20English/cmusphinx-en-us-ptm-5.2.tar.gz/download And tried to configure the above command like this: ./bw -hmmdir en-us -moddeffn en-us/mdef.txt -ts2cbfn .cont. -feat 1s_c_d_dd -cmn current -agc none -dictfn cmudict-en-us.dict -ctlfn robot_train.fileids -lsnfn robot_train.transcription -accumdir -lda feature_transform . But I get these error messages: INFO: main.c(229): Compiled on Mar 22 2018 at 12:54:02 ERROR: "cmd_ln.c", line 607: Unknown argument name 'feature_transform' ERROR: "cmd_ln.c", line 704: Failed to parse arguments list ERROR: "cmd_ln.c", line 753: Failed to parse arguments list, forced exit
I changed my model to this file (from the ptm model that tutorial linked to it) : https://sourceforge.net/projects/cmusphinx/files/Acoustic%20and%20Language%20Models/US%20English/cmusphinx-en-us-5.2.tar.gz/download Then I removed the -lda feature_transform from my command, and it worked!
Minimal web server using netcat
I'm trying to set up a minimal web server using netcat (nc). When the browser calls up localhost:1500, for instance, it should show the result of a function (date in the example below, but eventually it'll be a python or c program that yields some data). My little netcat web server needs to be a while true loop in bash, possibly as simple as this: while true ; do echo -e "HTTP/1.1 200 OK\n\n $(date)" | nc -l -p 1500 ; done When I try this the browser shows the currently available data during the moment when nc starts. I want the browser displays the data during the moment the browser requests it, though. How can I achieve this?
Try this: while true ; do nc -l -p 1500 -c 'echo -e "HTTP/1.1 200 OK\n\n $(date)"'; done The -cmakes netcat execute the given command in a shell, so you can use echo. If you don't need echo, use -e. For further information on this, try man nc. Note, that when using echo there is no way for your program (the date-replacement) to get the browser request. So you probably finally want to do something like this: while true ; do nc -l -p 1500 -e /path/to/yourprogram ; done Where yourprogram must do the protocol stuff like handling GET, sending HTTP 200 etc.
I had the problem where I wanted to return the result of executing a bash command: $ while true; do { echo -e 'HTTP/1.1 200 OK\r\n'; sh test; } | nc -l 8080; done NOTE: This command was taken from: http://www.razvantudorica.com/08/web-server-in-one-line-of-bash This executes a bash script and returns the result to a browser client connecting to the server running this command on port 8080. My script does this: $ nano test #!/bin/bash echo "************PRINT SOME TEXT***************\n" echo "Hello World!!!" echo "\n" echo "Resources:" vmstat -S M echo "\n" echo "Addresses:" echo "$(ifconfig)" echo "\n" echo "$(gpio readall)" and my web browser is showing ************PRINT SOME TEXT*************** Hello World!!! Resources: procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu---- r b swpd free buff cache si so bi bo in cs us sy id wa 0 0 0 314 18 78 0 0 2 1 306 31 0 0 100 0 Addresses: eth0 Link encap:Ethernet HWaddr b8:27:eb:86:e8:c5 inet addr:192.168.1.83 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:27734 errors:0 dropped:0 overruns:0 frame:0 TX packets:26393 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1924720 (1.8 MiB) TX bytes:3841998 (3.6 MiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) GPIOs: +----------+-Rev2-+------+--------+------+-------+ | wiringPi | GPIO | Phys | Name | Mode | Value | +----------+------+------+--------+------+-------+ | 0 | 17 | 11 | GPIO 0 | IN | Low | | 1 | 18 | 12 | GPIO 1 | IN | Low | | 2 | 27 | 13 | GPIO 2 | IN | Low | | 3 | 22 | 15 | GPIO 3 | IN | Low | | 4 | 23 | 16 | GPIO 4 | IN | Low | | 5 | 24 | 18 | GPIO 5 | IN | Low | | 6 | 25 | 22 | GPIO 6 | IN | Low | | 7 | 4 | 7 | GPIO 7 | IN | Low | | 8 | 2 | 3 | SDA | IN | High | | 9 | 3 | 5 | SCL | IN | High | | 10 | 8 | 24 | CE0 | IN | Low | | 11 | 7 | 26 | CE1 | IN | Low | | 12 | 10 | 19 | MOSI | IN | Low | | 13 | 9 | 21 | MISO | IN | Low | | 14 | 11 | 23 | SCLK | IN | Low | | 15 | 14 | 8 | TxD | ALT0 | High | | 16 | 15 | 10 | RxD | ALT0 | High | | 17 | 28 | 3 | GPIO 8 | ALT2 | Low | | 18 | 29 | 4 | GPIO 9 | ALT2 | Low | | 19 | 30 | 5 | GPIO10 | ALT2 | Low | | 20 | 31 | 6 | GPIO11 | ALT2 | Low | +----------+------+------+--------+------+-------+
Add -q 1 to the netcat command line: while true; do echo -e "HTTP/1.1 200 OK\n\n $(date)" | nc -l -p 1500 -q 1 done
The problem you are facing is that nc does not know when the web client is done with its request so it can respond to the request. A web session should go something like this. TCP session is established. Browser Request Header: GET / HTTP/1.1 Browser Request Header: Host: www.google.com Browser Request Header: \n #Note: Browser is telling Webserver that the request header is complete. Server Response Header: HTTP/1.1 200 OK Server Response Header: Content-Type: text/html Server Response Header: Content-Length: 24 Server Response Header: \n #Note: Webserver is telling browser that response header is complete Server Message Body: <html>sample html</html> Server Message Body: \n #Note: Webserver is telling the browser that the requested resource is finished. The server closes the TCP session. Lines that begin with "\n" are simply empty lines without even a space and contain nothing more than a new line character. I have my bash httpd launched by xinetd, xinetd tutorial. It also logs date, time, browser IP address, and the entire browser request to a log file, and calculates Content-Length for the Server header response. user#machine:/usr/local/bin# cat ./bash_httpd #!/bin/bash x=0; Log=$( echo -n "["$(date "+%F %T %Z")"] $REMOTE_HOST ")$( while read I[$x] && [ ${#I[$x]} -gt 1 ];do echo -n '"'${I[$x]} | sed -e's,.$,",'; let "x = $x + 1"; done ; ); echo $Log >> /var/log/bash_httpd Message_Body=$(echo -en '<html>Sample html</html>') echo -en "HTTP/1.0 200 OK\nContent-Type: text/html\nContent-Length: ${#Message_Body}\n\n$Message_Body" To add more functionality, you could incorporate. METHOD=$(echo ${I[0]} |cut -d" " -f1) REQUEST=$(echo ${I[0]} |cut -d" " -f2) HTTP_VERSION=$(echo ${I[0]} |cut -d" " -f3) If METHOD = "GET" ]; then case "$REQUEST" in "/") Message_Body="HTML formatted home page stuff" ;; /who) Message_Body="HTML formatted results of who" ;; /ps) Message_Body="HTML formatted results of ps" ;; *) Message_Body= "Error Page not found header and content" ;; esac fi Happy bashing!
Another way to do this while true; do (echo -e 'HTTP/1.1 200 OK\r\n'; echo -e "\n\tMy website has date function" ; echo -e "\t$(date)\n") | nc -lp 8080; done Let's test it with 2 HTTP request using curl In this example, 172.16.2.6 is the server IP Address. Server Side admin#server:~$ while true; do (echo -e 'HTTP/1.1 200 OK\r\n'; echo -e "\n\tMy website has date function" ; echo -e "\t$(date)\n") | nc -lp 8080; done GET / HTTP/1.1 Host: 172.16.2.6:8080 User-Agent: curl/7.48.0 Accept: */* GET / HTTP/1.1 Host: 172.16.2.6:8080 User-Agent: curl/7.48.0 Accept: */* Client Side user#client:~$ curl 172.16.2.6:8080 My website has date function Tue Jun 13 18:00:19 UTC 2017 user#client:~$ curl 172.16.2.6:8080 My website has date function Tue Jun 13 18:00:24 UTC 2017 user#client:~$ If you want to execute another command, feel free to replace $(date).
I had the same need/problem but nothing here worked for me (or I didn't understand everything), so this is my solution. I post my minimal_http_server.sh (working with my /bin/bash (4.3.11) but not /bin/sh because of the redirection): rm -f out mkfifo out trap "rm -f out" EXIT while true do cat out | nc -l 1500 > >( # parse the netcat output, to build the answer redirected to the pipe "out". export REQUEST= while read -r line do line=$(echo "$line" | tr -d '\r\n') if echo "$line" | grep -qE '^GET /' # if line starts with "GET /" then REQUEST=$(echo "$line" | cut -d ' ' -f2) # extract the request elif [ -z "$line" ] # empty line / end of request then # call a script here # Note: REQUEST is exported, so the script can parse it (to answer 200/403/404 status code + content) ./a_script.sh > out fi done ) done And my a_script.sh (with your need): #!/bin/bash echo -e "HTTP/1.1 200 OK\r" echo "Content-type: text/html" echo date
mkfifo pipe; while true ; do #use read line from pipe to make it blocks before request comes in, #this is the key. { read line<pipe;echo -e "HTTP/1.1 200 OK\r\n";echo $(date); } | nc -l -q 0 -p 8080 > pipe; done
Here is a beauty of a little bash webserver, I found it online and forked a copy and spruced it up a bit - it uses socat or netcat I have tested it with socat -- it is self-contained in one-script and generates its own configuration file and favicon. By default it will start up as a web enabled file browser yet is easily configured by the configuration file for any logic. For files it streams images and music (mp3's), video (mp4's, avi, etc) -- I have tested streaming various file types to Linux,Windows and Android devices including a smartwatch! I think it streams better than VLC actually. I have found it useful for transferring files to remote clients who have no access beyond a web browser e.g. Android smartwatch without needing to worry about physically connecting to a USB port. If you want to try it out just copy and paste it to a file named bashttpd, then start it up on the host with $> bashttpd -s Then you can go to any other computer (presuming the firewall is not blocking inbound tcp connections to port 8080 -- the default port, you can change the port to whatever you want using the global variables at the top of the script). http://bashttpd_server_ip:8080 #!/usr/bin/env bash ############################################################################# ########################################################################### ### bashttpd v 1.12 ### ### Original author: Avleen Vig, 2012 ### Reworked by: Josh Cartwright, 2012 ### Modified by: A.M.Danischewski, 2015 ### Issues: If you find any issues leave me a comment at ### http://scriptsandoneliners.blogspot.com/2015/04/bashttpd-self-contained-bash-webserver.html ### ### This is a simple Bash based webserver. By default it will browse files and allows for ### retrieving binary files. ### ### It has been tested successfully to view and stream files including images, mp3s, ### mp4s and downloading files of any type including binary and compressed files via ### any web browser. ### ### Successfully tested on various browsers on Windows, Linux and Android devices (including the ### Android Smartwatch ZGPAX S8). ### ### It handles favicon requests by hardcoded favicon image -- by default a marathon ### runner; change it to whatever you want! By base64 encoding your favorit favicon ### and changing the global variable below this header. ### ### Make sure if you have a firewall it allows connections to the port you plan to ### listen on (8080 by default). ### ### By default this program will allow for the browsing of files from the ### computer where it is run. ### ### Make sure you are allowed connections to the port you plan to listen on ### (8080 by default). Then just drop it on a host machine (that has bash) ### and start it up like this: ### ### $192.168.1.101> bashttpd -s ### ### On the remote machine you should be able to browse and download files from the host ### server via any web browser by visiting: ### ### http://192.168.1.101:8080 ### #### This program requires (to work to full capacity) by default: ### socat or netcat (w/ '-e' option - on Ubuntu netcat-traditional) ### tree - useful for pretty directory listings ### If you are using socat, you can type: bashttpd -s ### ### to start listening on the LISTEN_PORT (default is 8080), you can change ### the port below. ### E.g. nc -lp 8080 -e ./bashttpd ## <-- If your nc has the -e option. ### E.g. nc.traditional -lp 8080 -e ./bashttpd ### E.g. bashttpd -s -or- socat TCP4-LISTEN:8080,fork EXEC:bashttpd ### ### Copyright (C) 2012, Avleen Vig <avleen#gmail.com> ### ### Permission is hereby granted, free of charge, to any person obtaining a copy of ### this software and associated documentation files (the "Software"), to deal in ### the Software without restriction, including without limitation the rights to ### use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of ### the Software, and to permit persons to whom the Software is furnished to do so, ### subject to the following conditions: ### ### The above copyright notice and this permission notice shall be included in all ### copies or substantial portions of the Software. ### ### THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ### IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS ### FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR ### COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER ### IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ### CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ### ########################################################################### ############################################################################# ### CHANGE THIS TO WHERE YOU WANT THE CONFIGURATION FILE TO RESIDE declare -r BASHTTPD_CONF="/tmp/bashttpd.conf" ### CHANGE THIS IF YOU WOULD LIKE TO LISTEN ON A DIFFERENT PORT declare -i LISTEN_PORT=8080 ## If you are on AIX, IRIX, Solaris, or a hardened system redirecting ## to /dev/random will probably break, you can change it to /dev/null. declare -a DUMP_DEV="/dev/random" ## Just base64 encode your favorite favicon and change this to whatever you want. declare -r FAVICON="AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAADg4+3/srjc/5KV2P+ortn/xMrj/6Ch1P+Vl9f/jIzc/3572f+CgNr/fnzP/3l01f+Ih9r/h4TZ/8fN4//P1Oj/3uPr/7O+1v+xu9X/u8XY/9bi6v+UmdD/XV26/3F1x/+GitT/VVXC/3x/x/+HjNT/lp3Z/6633f/E0eD/2ePr/+bt8v/U4+v/0uLp/9Xj6//Z5e3/oKbX/0pJt/9maML/cHLF/3p8x//T3+n/3Ofu/9vo7//W5Oz/0uHq/9zn7f/j6vD/1OLs/8/f6P/R4Oj/1OPr/7jA4f9KSbf/Skm3/3p/yf/U4ez/1ePq/9rn7//Z5e3/0uHp/87e5//a5Ov/5Ovw/9Hf6v/T4uv/1OLp/9bj6/+kq9r/Skq3/0pJt/+cotb/zdnp/9jl7f/a5u//1+Ts/9Pi6v/O3ub/2uXr/+bt8P/Q3un/0eDq/9bj7P/Z5u7/r7jd/0tKt/9NTLf/S0u2/8zW6v/c5+//2+fv/9bj6//S4un/zt3m/9zm7P/k7PD/1OPr/9Li7P/V5Oz/2OXt/9jl7v+HjM3/lZvT/0tKt/+6w+L/2ebu/9fk7P/V4+v/0uHq/83d5v/a5ev/5ezw/9Pi6v/U4+z/1eXs/9bj6//b5+//vsjj/1hYvP9JSLb/horM/9nk7P/X5e3/1eTs/9Pi6v/P3uf/2eXr/+Tr7//O3+n/0uLr/9Xk7P/Y5e3/w8/k/7XA3/9JR7f/SEe3/2lrw//G0OX/1uLr/9Xi7P/T4ev/0N/o/9zn7f/k7PD/zN3p/8rd5v/T4ur/1ePt/5We0/+0w9//SEe3/0pKt/9OTrf/p7HZ/7fD3//T4uv/0N/o/9Hg6f/d5+3/5ezw/9Li6//T4uv/2ubu/8PQ5f9+hsr/ucff/4eOzv+Ei8z/rLja/8zc6P/I1+b/0OLq/8/f6P/Q4Oj/3eft/+bs8f/R4On/0+Lq/9Tj6v/T4Ov/wM7h/9Df6f/M2uf/z97q/9Dg6f/Q4On/1OPr/9Tj6//S4ur/0ODp/93o7f/n7vH/0N/o/8/f5//P3+b/2OXt/9zo8P/c6fH/zdjn/7fB3/+3weD/1eLs/9nn7//V5Oz/0+Lr/9Pi6//e6O7/5u3x/9Pi6v/S4en/0uLp/9Tj6//W4+v/3Ojw/9rm7v9vccT/wcvm/9rn7//X5Oz/0uHq/9Hg6f/S4er/3uju/+bt8f/R4On/0uHp/9Xk6//Y5u7/1OTs/9bk7P/W5Ov/XFy9/2lrwf/a5+//1uPr/9Pi6v/U4er/0eHq/93o7v/v8vT/5ezw/+bt8f/o7vL/6e/z/+jv8v/p7/L/6e/y/9XZ6//IzOX/6e7y/+nv8v/o7vL/5+7x/+ft8f/r8PP/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==" declare -i DEBUG=1 declare -i VERBOSE=0 declare -a REQUEST_HEADERS declare REQUEST_URI="" declare -a HTTP_RESPONSE=( [200]="OK" [400]="Bad Request" [403]="Forbidden" [404]="Not Found" [405]="Method Not Allowed" [500]="Internal Server Error") declare DATE=$(date +"%a, %d %b %Y %H:%M:%S %Z") declare -a RESPONSE_HEADERS=( "Date: $DATE" "Expires: $DATE" "Server: Slash Bin Slash Bash" ) function warn() { ((${VERBOSE})) && echo "WARNING: $#" >&2; } function chk_conf_file() { [ -r "${BASHTTPD_CONF}" ] || { cat >"${BASHTTPD_CONF}" <<'EOF' # # bashttpd.conf - configuration for bashttpd # # The behavior of bashttpd is dictated by the evaluation # of rules specified in this configuration file. Each rule # is evaluated until one is matched. If no rule is matched, # bashttpd will serve a 500 Internal Server Error. # # The format of the rules are: # on_uri_match REGEX command [args] # unconditionally command [args] # # on_uri_match: # On an incoming request, the URI is checked against the specified # (bash-supported extended) regular expression, and if encounters a match the # specified command is executed with the specified arguments. # # For additional flexibility, on_uri_match will also pass the results of the # regular expression match, ${BASH_REMATCH[#]} as additional arguments to the # command. # # unconditionally: # Always serve via the specified command. Useful for catchall rules. # # The following commands are available for use: # # serve_file FILE # Statically serves a single file. # # serve_dir_with_tree DIRECTORY # Statically serves the specified directory using 'tree'. It must be # installed and in the PATH. # # serve_dir_with_ls DIRECTORY # Statically serves the specified directory using 'ls -al'. # # serve_dir DIRECTORY # Statically serves a single directory listing. Will use 'tree' if it is # installed and in the PATH, otherwise, 'ls -al' # # serve_dir_or_file_from DIRECTORY # Serves either a directory listing (using serve_dir) or a file (using # serve_file). Constructs local path by appending the specified root # directory, and the URI portion of the client request. # # serve_static_string STRING # Serves the specified static string with Content-Type text/plain. # # Examples of rules: # # on_uri_match '^/issue$' serve_file "/etc/issue" # # When a client's requested URI matches the string '/issue', serve them the # contents of /etc/issue # # on_uri_match 'root' serve_dir / # # When a client's requested URI has the word 'root' in it, serve up # a directory listing of / # # DOCROOT=/var/www/html # on_uri_match '/(.*)' serve_dir_or_file_from "$DOCROOT" # When any URI request is made, attempt to serve a directory listing # or file content based on the request URI, by mapping URI's to local # paths relative to the specified "$DOCROOT" # #unconditionally serve_static_string 'Hello, world! You can configure bashttpd by modifying bashttpd.conf.' DOCROOT=/ on_uri_match '/(.*)' serve_dir_or_file_from # More about commands: # # It is possible to somewhat easily write your own commands. An example # may help. The following example will serve "Hello, $x!" whenever # a client sends a request with the URI /say_hello_to/$x: # # serve_hello() { # add_response_header "Content-Type" "text/plain" # send_response_ok_exit <<< "Hello, $2!" # } # on_uri_match '^/say_hello_to/(.*)$' serve_hello # # Like mentioned before, the contents of ${BASH_REMATCH[#]} are passed # to your command, so its possible to use regular expression groups # to pull out info. # # With this example, when the requested URI is /say_hello_to/Josh, serve_hello # is invoked with the arguments '/say_hello_to/Josh' 'Josh', # (${BASH_REMATCH[0]} is always the full match) EOF warn "Created bashttpd.conf using defaults. Please review and configure bashttpd.conf before running bashttpd again." # exit 1 } } function recv() { ((${VERBOSE})) && echo "< $#" >&2; } function send() { ((${VERBOSE})) && echo "> $#" >&2; echo "$*"; } function add_response_header() { RESPONSE_HEADERS+=("$1: $2"); } function send_response_binary() { local code="$1" local file="${2}" local transfer_stats="" local tmp_stat_file="/tmp/_send_response_$$_" send "HTTP/1.0 $1 ${HTTP_RESPONSE[$1]}" for i in "${RESPONSE_HEADERS[#]}"; do send "$i" done send if ((${VERBOSE})); then ## Use dd since it handles null bytes dd 2>"${tmp_stat_file}" < "${file}" transfer_stats=$(<"${tmp_stat_file}") echo -en ">> Transferred: ${file}\n>> $(awk '/copied/{print}' <<< "${transfer_stats}")\n" >&2 rm "${tmp_stat_file}" else ## Use dd since it handles null bytes dd 2>"${DUMP_DEV}" < "${file}" fi } function send_response() { local code="$1" send "HTTP/1.0 $1 ${HTTP_RESPONSE[$1]}" for i in "${RESPONSE_HEADERS[#]}"; do send "$i" done send while IFS= read -r line; do send "${line}" done } function send_response_ok_exit() { send_response 200; exit 0; } function send_response_ok_exit_binary() { send_response_binary 200 "${1}"; exit 0; } function fail_with() { send_response "$1" <<< "$1 ${HTTP_RESPONSE[$1]}"; exit 1; } function serve_file() { local file="$1" local CONTENT_TYPE="" case "${file}" in *\.css) CONTENT_TYPE="text/css" ;; *\.js) CONTENT_TYPE="text/javascript" ;; *) CONTENT_TYPE=$(file -b --mime-type "${file}") ;; esac add_response_header "Content-Type" "${CONTENT_TYPE}" CONTENT_LENGTH=$(stat -c'%s' "${file}") add_response_header "Content-Length" "${CONTENT_LENGTH}" ## Use binary safe transfer method since text doesn't break. send_response_ok_exit_binary "${file}" } function serve_dir_with_tree() { local dir="$1" tree_vers tree_opts basehref x ## HTML 5 compatible way to avoid tree html from generating favicon ## requests in certain browsers, such as browsers in android smartwatches. =) local no_favicon=" <link href=\"data:image/x-icon;base64,${FAVICON}\" rel=\"icon\" type=\"image/x-icon\" />" local tree_page="" local base_server_path="/${2%/}" [ "$base_server_path" = "/" ] && base_server_path=".." local tree_opts="--du -h -a --dirsfirst" add_response_header "Content-Type" "text/html" # The --du option was added in 1.6.0. "/${2%/*}" read _ tree_vers x < <(tree --version) tree_page=$(tree -H "$base_server_path" -L 1 "${tree_opts}" -D "${dir}") tree_page=$(sed "5 i ${no_favicon}" <<< "${tree_page}") [[ "${tree_vers}" == v1.6* ]] send_response_ok_exit <<< "${tree_page}" } function serve_dir_with_ls() { local dir="$1" add_response_header "Content-Type" "text/plain" send_response_ok_exit < \ <(ls -la "${dir}") } function serve_dir() { local dir="$1" # If `tree` is installed, use that for pretty output. which tree &>"${DUMP_DEV}" && \ serve_dir_with_tree "$#" serve_dir_with_ls "$#" fail_with 500 } function urldecode() { [ "${1%/}" = "" ] && echo "/" || echo -e "$(sed 's/%\([[:xdigit:]]\{2\}\)/\\\x\1/g' <<< "${1%/}")"; } function serve_dir_or_file_from() { local URL_PATH="${1}/${3}" shift URL_PATH=$(urldecode "${URL_PATH}") [[ $URL_PATH == *..* ]] && fail_with 400 # Serve index file if exists in requested directory [[ -d "${URL_PATH}" && -f "${URL_PATH}/index.html" && -r "${URL_PATH}/index.html" ]] && \ URL_PATH="${URL_PATH}/index.html" if [[ -f "${URL_PATH}" ]]; then [[ -r "${URL_PATH}" ]] && \ serve_file "${URL_PATH}" "$#" || fail_with 403 elif [[ -d "${URL_PATH}" ]]; then [[ -x "${URL_PATH}" ]] && \ serve_dir "${URL_PATH}" "$#" || fail_with 403 fi fail_with 404 } function serve_static_string() { add_response_header "Content-Type" "text/plain" send_response_ok_exit <<< "$1" } function on_uri_match() { local regex="$1" shift [[ "${REQUEST_URI}" =~ $regex ]] && \ "$#" "${BASH_REMATCH[#]}" } function unconditionally() { "$#" "$REQUEST_URI"; } function main() { local recv="" local line="" local REQUEST_METHOD="" local REQUEST_HTTP_VERSION="" chk_conf_file [[ ${UID} = 0 ]] && warn "It is not recommended to run bashttpd as root." # Request-Line HTTP RFC 2616 $5.1 read -r line || fail_with 400 line=${line%%$'\r'} recv "${line}" read -r REQUEST_METHOD REQUEST_URI REQUEST_HTTP_VERSION <<< "${line}" [ -n "${REQUEST_METHOD}" ] && [ -n "${REQUEST_URI}" ] && \ [ -n "${REQUEST_HTTP_VERSION}" ] || fail_with 400 # Only GET is supported at this time [ "${REQUEST_METHOD}" = "GET" ] || fail_with 405 while IFS= read -r line; do line=${line%%$'\r'} recv "${line}" # If we've reached the end of the headers, break. [ -z "${line}" ] && break REQUEST_HEADERS+=("${line}") done } if [[ ! -z "{$1}" ]] && [ "${1}" = "-s" ]; then socat TCP4-LISTEN:${LISTEN_PORT},fork EXEC:"${0}" else main source "${BASHTTPD_CONF}" fail_with 500 fi
LOL, a super lame hack, but at least curl and firefox accepts it: while true ; do (dd if=/dev/zero count=10000;echo -e "HTTP/1.1\n\n $(date)") | nc -l 1500 ; done You better replace it soon with something proper! Ah yes, my nc were not exactly the same as yours, it did not like the -p option.
If you're using Apline Linux, the BusyBox netcat is slightly different: while true; do nc -l -p 8080 -e sh -c 'echo -e "HTTP/1.1 200 OK\n\n$(date)"'; done And another way using printf: while true; do nc -l -p 8080 -e sh -c "printf 'HTTP/1.1 200 OK\n\n%s' \"$(date)\""; done
while true; do (echo -e 'HTTP/1.1 200 OK\r\nConnection: close\r\n';) | timeout 1 nc -lp 8080 ; done Closes connection after 1 sec, so curl doesn't hang on it.
Type in nc -h and see if You have -e option available. If yes, You can create a script, for example: script.sh echo -e "HTTP/1.1 200 OK\n\n $(date)" and run it like this: while true ; do nc -l -p 1500 -e script.sh; done Note that -e option needs to be enabled at compilation to be available.
I think the problem that all the solution listed doesn't work, is intrinsic in the nature of http service, the every request established is with a different client and the response need to be processed in a different context, every request must fork a new instance of response... The current solution I think is the -e of netcat but I don't know why doesn't work... maybe is my nc version that I test on openwrt... with socat it works.... I try this https://github.com/avleen/bashttpd and it works, but I must run the shell script with this command. socat tcp-l:80,reuseaddr,fork EXEC:bashttpd & The socat and netcat samples on github doesn't works for me, but the socat that I used works.
Actually, the best way to close gracefully the connection is to send the Content-Length header like following. Client (like curl will close the connection after receiving the data. DATA="Date: $(date)"; LENGTH=$(echo $DATA | wc -c); echo -e "HTTP/1.1 200 OK\nContent-Length: ${LENGTH}\n\n${DATA}" | nc -l -p 8000;
On OSX you can use : while true; do echo -e "HTTP/1.1 200 OK\n\n $(date)" | nc -l localhost 1500 ; done