⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 is_spammer.bash

📁 BASH Shell 编程 经典教程 《高级SHELL脚本编程》中文版
💻 BASH
📖 第 1 页 / 共 5 页
字号:
            list_server=( ${default_servers[@]} )            _list_cnt=${#list_server[@]}            echo 'Using default blacklist server list.'            echo 'Search depth limit: '${indirect}            ;;        2)            if ! setup_input $1    # Needs error checking.            then                pend_release                $_log_dump                exit 1            fi            if ! setup_servers $2  # Needs error checking.            then                pend_release                $_log_dump                exit 1            fi            echo 'Search depth limit: '${indirect}            ;;        *)            pend_func usage            pend_release            $_log_dump            exit 1            ;;    esac    return 0}# A general purpose debug tool.# list_array &lt;array_name&gt;list_array() {    [ $# -eq 1 ] || return 1  # One argument required.    local -a _la_lines    set -f    local IFS=${NO_WSP}    eval _la_lines=\(\ \$\{$1\[@\]\}\ \)    echo    echo "Element count "${#_la_lines[@]}" array "${1}    local _ln_cnt=${#_la_lines[@]}    for (( _i = 0; _i < ${_ln_cnt}; _i++ ))    do        echo 'Element '$_i' >'${_la_lines[$_i]}'<'    done    set +f    return 0}# # # 'Hunt the Spammer' program code # # #pend_init                               # Ready stack engine.pend_func credits                       # Last thing to print.# # # Deal with user # # #live_log_die                            # Setup debug trace log.data_capture                            # Setup data capture file.echodo_user_args $@# # # Haven't exited yet - There is some hope # # ## Discovery group - Execution engine is LIFO - pend# in reverse order of execution._hs_RC=0                                # Hunt the Spammer return codepend_mark    pend_func report_pairs              # Report name-address pairs.    # The two detail_* are mutually recursive functions.    # They also pend expand_* functions as required.    # These two (the last of ???) exit the recursion.    pend_func detail_each_address       # Get all resources of addresses.    pend_func detail_each_name          # Get all resources of names.    #  The two expand_* are mutually recursive functions,    #+ which pend additional detail_* functions as required.    pend_func expand_input_address 1    # Expand input names by address.    pend_func expand_input_name 1       # #xpand input addresses by name.    # Start with a unique set of names and addresses.    pend_func unique_lines uc_address uc_address    pend_func unique_lines uc_name uc_name    # Separate mixed input of names and addresses.    pend_func split_inputpend_release# # # Pairs reported -- Unique list of IP addresses foundecho_ip_cnt=${#known_address[@]}if [ ${#list_server[@]} -eq 0 ]then    echo 'Blacklist server list empty, none checked.'else    if [ ${_ip_cnt} -eq 0 ]    then        echo 'Known address list empty, none checked.'    else        _ip_cnt=${_ip_cnt}-1   # Start at top.        echo 'Checking Blacklist servers.'        for (( _ip = _ip_cnt ; _ip >= 0 ; _ip-- ))        do            pend_func check_lists $( printf '%q\n' ${known_address[$_ip]} )        done    fifipend_release$_dot_dump                   # Graphics file dump$_log_dump                   # Execution traceecho############################### Example output from script ###############################:<<-'_is_spammer_outputs_'./is_spammer.bash 0 web4.alojamentos7.comStarting with domain name >web4.alojamentos7.com<Using default blacklist server list.Search depth limit: 0.:....::::...:::...:::.......::..::...:::.......::Known network pairs.    66.98.208.97             web4.alojamentos7.com.    66.98.208.97             ns1.alojamentos7.com.    69.56.202.147            ns2.alojamentos.ws.    66.98.208.97             alojamentos7.com.    66.98.208.97             web.alojamentos7.com.    69.56.202.146            ns1.alojamentos.ws.    69.56.202.146            alojamentos.ws.    66.235.180.113           ns1.alojamentos.org.    66.235.181.192           ns2.alojamentos.org.    66.235.180.113           alojamentos.org.    66.235.180.113           web6.alojamentos.org.    216.234.234.30           ns1.theplanet.com.    12.96.160.115            ns2.theplanet.com.    216.185.111.52           mail1.theplanet.com.    69.56.141.4              spooling.theplanet.com.    216.185.111.40           theplanet.com.    216.185.111.40           www.theplanet.com.    216.185.111.52           mail.theplanet.com.Checking Blacklist servers.    Checking address 66.98.208.97        Records from dnsbl.sorbs.net            "Spam Received See: http://www.dnsbl.sorbs.net/lookup.shtml?66.98.208.97"    Checking address 69.56.202.147    Checking address 69.56.202.146    Checking address 66.235.180.113    Checking address 66.235.181.192    Checking address 216.185.111.40    Checking address 216.234.234.30    Checking address 12.96.160.115    Checking address 216.185.111.52    Checking address 69.56.141.4Advanced Bash Scripting Guide: is_spammer.bash, v2, 2004-msz_is_spammer_outputs_exit ${_hs_RC}#####################################################  The script ignores everything from here on down ##+ because of the 'exit' command, just above.      #####################################################Quickstart========== Prerequisites  Bash version 2.05b or 3.00 (bash --version)  A version of Bash which supports arrays. Array   support is included by default Bash configurations.  'dig,' version 9.x.x (dig $HOSTNAME, see first line of output)  A version of dig which supports the +short options.   See: dig_wrappers.bash for details. Optional Prerequisites  'named,' a local DNS caching program. Any flavor will do.  Do twice: dig $HOSTNAME   Check near bottom of output for: SERVER: 127.0.0.1#53  That means you have one running. Optional Graphics Support  'date,' a standard *nix thing. (date -R)  dot Program to convert graphic description file to a   diagram. (dot -V)  A part of the Graph-Viz set of programs.  See: [http://www.research.att.com/sw/tools/graphviz||GraphViz]  'dotty,' a visual editor for graphic description files.  Also a part of the Graph-Viz set of programs. Quick StartIn the same directory as the is_spammer.bash script; Do: ./is_spammer.bash Usage Details1. Blacklist server choices.  (a) To use default, built-in list: Do nothing.  (b) To use your own list:     i. Create a file with a single Blacklist server        domain name per line.    ii. Provide that filename as the last argument to         the script.  (c) To use a single Blacklist server: Last argument       to the script.  (d) To disable Blacklist lookups:    i. Create an empty file (touch spammer.nul)       Your choice of filename.    ii. Provide the filename of that empty file as the         last argument to the script.2. Search depth limit.  (a) To use the default value of 2: Do nothing.  (b) To set a different limit:       A limit of 0 means: no limit.    i. export SPAMMER_LIMIT=1       or whatever limit you want.    ii. OR provide the desired limit as the first        argument to the script.3. Optional execution trace log.  (a) To use the default setting of no log output: Do nothing.  (b) To write an execution trace log:      export SPAMMER_TRACE=spammer.log      or whatever filename you want.4. Optional graphic description file.  (a) To use the default setting of no graphic file: Do nothing.  (b) To write a Graph-Viz graphic description file:      export SPAMMER_DATA=spammer.dot      or whatever filename you want.5. Where to start the search.  (a) Starting with a single domain name:    i. Without a command line search limit: First        argument to script.    ii. With a command line search limit: Second         argument to script.  (b) Starting with a single IP address:    i. Without a command line search limit: First        argument to script.    ii. With a command line search limit: Second         argument to script.  (c) Starting with (mixed) multiple name(s) and/or address(es):      Create a file with one name or address per line.      Your choice of filename.    i. Without a command line search limit: Filename as        first argument to script.    ii. With a command line search limit: Filename as         second argument to script.6. What to do with the display output.  (a) To view display output on screen: Do nothing.  (b) To save display output to a file: Redirect stdout to a filename.  (c) To discard display output: Redirect stdout to /dev/null.7. Temporary end of decision making.    press RETURN    wait (optionally, watch the dots and colons).8. Optionally check the return code.  (a) Return code 0: All OK  (b) Return code 1: Script setup failure  (c) Return code 2: Something was blacklisted.9. Where is my graph (diagram)?The script does not directly produce a graph (diagram). It only produces a graphic description file. You can process the graphic descriptor file that was output with the 'dot' program.Until you edit that descriptor file, to describe the relationships you want shown, all that you will get is a bunch of labeled name and address nodes.All of the script's discovered relationships are within a comment block in the graphic descriptor file, each with a descriptive heading.The editing required to draw a line between a pair of nodes from the information in the descriptor file may be done with a text editor. Given these lines somewhere in the descriptor file:# Known domain name nodesN0000 [label="guardproof.info."] ;N0002 [label="third.guardproof.info."] ;# Known address nodesA0000 [label="61.141.32.197"] ;/*# Known name->address edgesNA0000 third.guardproof.info. 61.141.32.197# Known parent->child edgesPC0000 guardproof.info. third.guardproof.info. */Turn that into the following lines by substituting node identifiers into the relationships:# Known domain name nodesN0000 [label="guardproof.info."] ;N0002 [label="third.guardproof.info."] ;# Known address nodesA0000 [label="61.141.32.197"] ;# PC0000 guardproof.info. third.guardproof.info.N0000->N0002 ;# NA0000 third.guardproof.info. 61.141.32.197N0002->A0000 ;/*# Known name->address edgesNA0000 third.guardproof.info. 61.141.32.197# Known parent->child edgesPC0000 guardproof.info. third.guardproof.info. */Process that with the 'dot' program, and you have your first network diagram.In addition to the conventional graphic edges, the descriptor file includes similar format pair-data that describes services, zone records (sub-graphs?), blacklisted addresses, and other things which might be interesting to include in your graph. This additional information could be displayed as different node shapes, colors, line sizes, etc.The descriptor file can also be read and edited by a Bash script (of course). You should be able to find most of the functions required within the "is_spammer.bash" script.# End Quickstart.Additional Note========== ====Michael Zick points out that there is a "makeviz.bash" interactiveWeb site at rediris.es. Can't give the full 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -