Home
Download

Open Source

Projects
Patches

System Integration

Notes
SRPMs

The Beholder multi-function server

This document describes how to build Beholder, a multi-function server. Beholder runs on commodity router hardware and provides a number of features:

We build Beholder on top of OpenWrt because of the distribution's simplicity and small size. Beholder is made up of roughly 90 packages, and its programs and configurations take up less than 40 MB of storage space. Here we assume that Beholder will run within the confines of a Xen hypervisor.

Establish the Beholder VM

Perform the following steps on the Xen Dom0 host to establish the VM which will host Beholder:

  1. Obtain the x86_64 OpenWrt image at https://downloads.lede-project.org/releases/17.01.1/targets/x86/64/lede-17.01.1-x86-64-combined-ext4.img.gz.
  2. Uncompress the image and place it at /var/lib/xen/images/beholder-lede-17.01.1-x86-64-combined-ext4.img on the Xen Dom0 host.
  3. Create a disk image to serve as the server's large data store (see our notes on platform virtualization) and name it /var/lib/xen/images/beholder-data.qcow.
  4. Write the following at /etc/xen/vm-beholder.cfg on the Xen Dom0 host (replace XX:XX:XX:XX:XX:XX):
    name    = "beholder"
    memory  =  1024
    vcpus   =  1
    builder = "hvm"
    vif     = [ "model=e1000,script=vif-bridge,bridge=xenbr0,mac=XX:XX:XX:XX:XX:XX" ]
    disk    = [ "tap2:tapdisk:aio:/var/lib/xen/images/beholder-lede-17.01.1-x86-64-combined-ext4.img,xvda,w" ]
    serial  = "pty"
    

Software installation

Perform the following steps on Beholder:

  1. Set the root password: passwd.
  2. Remove unnecessary packages:
    opkg remove \
            dnsmasq \
            kmod-ppp \
            kmod-pppoe \
            kmod-pppox \
            kmod-r8169 \
    	logd \
    	luci \
            luci-app-firewall \
            luci-base \
            luci-lib-ip \
            luci-lib-nixio \
            luci-proto-ipv6 \
            luci-proto-ppp \
            luci-theme-bootstrap \
            mtd \
            odhcpd \
            ppp \
            ppp-mod-pppoe \
            r8169-firmware \
            uhttpd-mod-ubus \
    	uhttpd
    
  3. Configure networking by writing /etc/config/network:
    config interface loopback
    	option ifname lo
    	option proto static
    	option ipaddr 127.0.0.1
    	option netmask 255.0.0.0
    
    config interface lan
    	option ifname eth0
    	option proto dhcp
    
  4. Install the necessary software:
    opkg update
    opkg install \
    	snort \
    	freifunk-watchdog \	
    	syslog-ng \
    	zoneinfo-core \
    	zoneinfo-northamerica
    
  5. Install a public SSH key at /etc/dropbear/authorized_keys.

Configuring Snort

  1. Download the community Snort rules from https://www.snort.org/downloads/community/community-rules.tar.gz, and install them at /etc/snort/rules/. Uncomment the appropriate lines in /etc/snort/rules/community.rules.
  2. Download the open Emerging Threats Snort rules from https://rules.emergingthreats.net/open/snort-2.9.0/emerging.rules.tar.gz, and install them at /etc/snort/rules/. Uncomment the appropriate lines in /etc/snort/rules/emerging.conf.
  3. /etc/config/snort:
    config snort snort
    	option config_file /etc/snort/snort.conf
    	option interface eth0
    
  4. /etc/snort/snort.conf:

    This configuration is similar to the one shipped with Snort, except it drops comments, makes use of the community and emerging threats rule sets, adjusts some file paths, configures sfportscan, drops the use of the reputation preprocessor, drops the use of dynamicrules, and drops the use of threshold.conf.

    # Step #1: Set the network variables.  For more information, see README.variables
    
    ipvar HOME_NET any
    ipvar EXTERNAL_NET any
    ipvar DNS_SERVERS $HOME_NET
    ipvar SMTP_SERVERS $HOME_NET
    ipvar HTTP_SERVERS $HOME_NET
    ipvar SQL_SERVERS $HOME_NET
    ipvar TELNET_SERVERS $HOME_NET
    ipvar SSH_SERVERS $HOME_NET
    ipvar FTP_SERVERS $HOME_NET
    ipvar SIP_SERVERS $HOME_NET
    
    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]
    portvar SHELLCODE_PORTS !80
    portvar ORACLE_PORTS 1024:
    portvar SSH_PORTS 22
    portvar FTP_PORTS [21]
    portvar SIP_PORTS [5060,5061,5600]
    portvar FILE_DATA_PORTS [$HTTP_PORTS,110,143]
    portvar GTP_PORTS [2123,2152,3386]
    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]
    
    var PREPROC_RULE_PATH /etc/snort/preproc_rules
    var RULE_PATH /etc/snort/rules
    
    # Step #2: Configure the decoder.  For more information, see README.decode
    
    config disable_decode_alerts
    config disable_tcpopt_experimental_alerts
    config disable_tcpopt_obsolete_alerts
    config disable_tcpopt_ttcp_alerts
    config disable_tcpopt_alerts
    config disable_ipopt_alerts
    config checksum_mode: all
    config set_uid: nobody        
    config set_gid: nogroup
    
    # Step #3: Configure the base detection engine.  For more information, see  README.decode
    
    config pcre_match_limit: 3500
    config pcre_match_limit_recursion: 1500
    config detection: search-method ac-split search-optimize max-pattern-len 20
    config event_queue: max_queue 8 log 5 order_events content_length
    config paf_max: 16000
    
    # Step #4: Configure dynamic loaded libraries.  
    
    dynamicpreprocessor directory /usr/lib/snort_dynamicpreprocessor/
    dynamicengine /usr/lib/snort_dynamicengine/libsf_engine.so
    
    # Step #5: Configure preprocessors
    
    preprocessor normalize_ip4
    preprocessor normalize_tcp: ips ecn stream
    preprocessor normalize_icmp4
    preprocessor normalize_ip6
    preprocessor normalize_icmp6
    preprocessor frag3_global: max_frags 65536
    preprocessor frag3_engine: policy windows detect_anomalies overlap_limit 10 min_fragment_length 100 \
                               timeout 180
    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: 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
    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
    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
    preprocessor bo
    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
    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 }
    preprocessor sfportscan: proto { all } scan_type { all } sense_level { low }
    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
    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$"]
    preprocessor dns: ports { 53 } enable_rdata_overflow
    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
    preprocessor sensitive_data: alert_threshold 25
    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 
    preprocessor imap: \
       ports { 143 } \
       b64_decode_depth 0 \
       qp_decode_depth 0 \
       bitenc_decode_depth 0 \
       uu_decode_depth 0
    preprocessor pop: \
       ports { 110 } \
       b64_decode_depth 0 \
       qp_decode_depth 0 \
       bitenc_decode_depth 0 \
       uu_decode_depth 0
    preprocessor modbus: ports { 502 }
    preprocessor dnp3: ports { 20000 } \
       memcap 262144 \
       check_crc
    
    # Step #6: Configure output plugins
    
    output alert_syslog: LOG_AUTH LOG_ALERT
    include classification.config
    include reference.config
    
    # Step #7: Customize your rule set
    
    include $RULE_PATH/community.rules
    include $RULE_PATH/emerging.conf
    
    # Step #8: Customize your preprocessor and decoder alerts
    
    # Step #9: Customize your Shared Object Snort Rules
    

Configure the firewall

  1. /etc/config/firewall:
    config defaults
            option drop_invalid 1
            option input ACCEPT
            option output ACCEPT
            option forward ACCEPT
    
    config zone
            option name lan
            option network lan
            option input ACCEPT
            option output ACCEPT
            option forward DROP
    

Configure basic system settings

  1. /etc/config/system:
    config system
            option hostname beholder.EXAMPLE.COM
            option timezone EST5EDT,M3.2.0,M11.1.0
    
    config timeserver ntp
            list server     0.openwrt.pool.ntp.org
            list server     1.openwrt.pool.ntp.org
            list server     2.openwrt.pool.ntp.org
            list server     3.openwrt.pool.ntp.org
            option enabled 1
            option enable_server 0
    
  2. /etc/config/freifunk-watchdog:
    config process
            option process dropbear
            option initscript /etc/init.d/dropbear
    
    config process
            option process ntpd
            option initscript /etc/init.d/ntpd
    
    config process
            option process snort
            option initscript /etc/init.d/snort
    
  3. /etc/config/network:
    config interface loopback
            option ifname lo
            option proto static
            option ipaddr 127.0.0.1
            option netmask 255.0.0.0
    
    config interface lan
            option ifname eth0
            option proto dhcp
    
  4. /etc/config/dropbear:
    config dropbear
            option PasswordAuth 'off'
            option RootPasswordAuth 'off'
            option Port         '22'
    

Forwarding packets to Snort host

Once Snort is running, you will want to forward a copy of network packets to the Snort host. The tee feature of netfilter can perform this work. To configure an OpenWrt router to forward a copy of each packet to the Snort host at beholder.EXAMPLE.COM, add the following to /etc/firewall.user on the router (replace EXAMPLE.COM):

iptables -t mangle -A POSTROUTING ! -s beholder.EXAMPLE.COM \
       ! -d beholder.EXAMPLE.COM -j TEE --gateway beholder.EXAMPLE.COM
Email: www@flyn.org — ✉ 6110 Campfire Court; Columbia, Maryland 21045; USA