Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: how to install fail2ban on a WL700g

  1. #1
    Join Date
    Aug 2007
    Location
    Austria
    Posts
    52

    how to install fail2ban on a WL700g

    Quote Originally Posted by medsource View Post
    Here's a list of 'wants.' Granted I've got most of these already running ...

    Fail2ban for disabling bruteforce attacks
    ...
    could you please explain how you've built and installed fail2ban on your router ?

    brgds

    --
    tiwag

  2. #2
    Quote Originally Posted by tiwag View Post
    could you please explain how you've built and installed fail2ban on your router ?

    brgds

    --
    tiwag
    Firstly you need python installed (2.4 and 2.5)

    Then download the fail2ban sw from their server (http://www.fail2ban.org/wiki/index.php/Main_Page)

    Install it (you'll have to mod the setup.cfg script to run python2.5 as the environment and to the opt directory)

    After that you need to do some tweaking...

    To get it to run you need to modify the three core files: fail2ban-client, fail2ban-server and fail2ban-regex (they should be in the /opt/bin directory... if not then move them there).

    Each file references the /usr/share/fail2ban directory for the core components (it's like line 30ish). All you have to do is replace the /usr/share/fail2ban in each of the three files with /opt/fail2ban (which should be your install directory). To test if it's running ok all you have to do is type fail2ban-client -d (you don't need the python statement as it was set at install when you modified setup.cfg to use python2.5 as the environment).

    If it works it will display the current jail.conf settings. Then if your jail.conf settings are ok you can launch the application by typing fail2ban-client start (with the -c /[dir]/ if you didn't switch the location of the config files in the fail2ban-client file in the /opt/bin directory). Also make sure that the logging is to the correct location (I put it to the syslog) and that the logging level is correct (3 for runtime 4 for debug).

    Hope this gets you off the ground.

  3. #3
    Join Date
    Aug 2007
    Location
    Austria
    Posts
    52

    how to install fail2ban on a WL700g

    Quote Originally Posted by medsource View Post
    Firstly you need python installed (2.4 and 2.5)

    Then download the fail2ban sw from their server (http://www.fail2ban.org/wiki/index.php/Main_Page)

    Install it (you'll have to mod the setup.cfg script to run python2.5 as the environment and to the opt directory)

    After that you need to do some tweaking...

    To get it to run you need to modify the three core files: fail2ban-client, fail2ban-server and fail2ban-regex (they should be in the /opt/bin directory... if not then move them there).

    Each file references the /usr/share/fail2ban directory for the core components (it's like line 30ish). All you have to do is replace the /usr/share/fail2ban in each of the three files with /opt/fail2ban (which should be your install directory). To test if it's running ok all you have to do is type fail2ban-client -d (you don't need the python statement as it was set at install when you modified setup.cfg to use python2.5 as the environment).

    If it works it will display the current jail.conf settings. Then if your jail.conf settings are ok you can launch the application by typing fail2ban-client start (with the -c /[dir]/ if you didn't switch the location of the config files in the fail2ban-client file in the /opt/bin directory). Also make sure that the logging is to the correct location (I put it to the syslog) and that the logging level is correct (3 for runtime 4 for debug).

    Hope this gets you off the ground.
    thanks medsource,

    you could post your modified fail2ban files package here,
    then we wouldn't need to investigate the same issues ever and ever again.

    brgds

    --
    tiwag

  4. #4
    Join Date
    Aug 2007
    Location
    Austria
    Posts
    52
    i got it installed, basically it works with python 2.4 too,
    at least it showed me the configuration settings with using
    Code:
    $ fail2ban-client -d
    but i didn't get it working, during the configuration phase
    i had to do some reboots of my Wl700g and somehow i
    managed to brick my asus. first it got crazy with constantly
    rebooting and after resetting the device all configuration of
    my shares was lost.

    will see if i can retrieve my config somehow

    brgds
    Last edited by tiwag; 24-08-2007 at 10:47.
    tiwag

  5. #5
    Quote Originally Posted by tiwag View Post
    i got it installed, basically it works with python 2.4 too,
    at least it showed me the configuration settings with using
    Code:
    $ fail2ban-client -d
    but i didn't get it working, during the configuration phase
    i had to do some reboots of my Wl700g and somehow i
    managed to brick my asus. first it got crazy with constantly
    rebooting and after resetting the device all configuration of
    my shares was lost.

    will see if i can retrieve my config somehow

    brgds
    What errors appeared in your syslog? what logging level were you using? did the same thing happen when installing / running under python2.5? Did you modify the jail.conf before running in non-debug mode?

  6. #6
    Join Date
    Aug 2007
    Location
    Austria
    Posts
    52
    hi medsource

    got everything on my router working again

    my problem wasn't related to the configuration of fail2ban,
    now i know, that since i had edited the root user's homepath,
    then my WL700g got crazy on reboot.

    now i want to work further on getting fail2ban to work.

    my problem is, how can i get dropbear and vsftp to write their
    log entries into a logfile, which can be read by fail2ban ?

    any solution which wouldn't disable the standard syslog provided
    by syslogd, and access with logread command would be preferred.
    i tried using syslog-ng which basically works, but syslogd and klogd
    have to be disabled if syslog-ng shall be used.

    medsource, how did you manage this issue ?

    thanks && brgds
    tiwag

  7. #7
    Quote Originally Posted by tiwag View Post
    hi medsource

    got everything on my router working again

    my problem wasn't related to the configuration of fail2ban,
    now i know, that since i had edited the root user's homepath,
    then my WL700g got crazy on reboot.

    now i want to work further on getting fail2ban to work.

    my problem is, how can i get dropbear and vsftp to write their
    log entries into a logfile, which can be read by fail2ban ?

    any solution which wouldn't disable the standard syslog provided
    by syslogd, and access with logread command would be preferred.
    i tried using syslog-ng which basically works, but syslogd and klogd
    have to be disabled if syslog-ng shall be used.

    medsource, how did you manage this issue ?

    thanks && brgds
    I changed, in the vsftpd.conf file, the location and method of the logging. I set it (if memory serves correct) to /var/tmp/log and called it ftp.log (I think). I then set a cron job to run a script to check the size of the log and purge it if it got too big (I think it was set to 200kb).

    I too would have loved fail2ban to just peruse the syslog, but I never found a way to do that. Anyway, using a true log file (on the ramdisk so spindown is preserved) works.

  8. #8
    Join Date
    Aug 2007
    Location
    Austria
    Posts
    52
    any other one, who has some other ideas

    (maybe with tested and working scriptfiles
    and precise instructions, what has to be changed where,
    instead of "maybe could be working when my brain remembers correctly" )


    sorry medsource, but you are way too unspecific !
    therefore of no great help.

    brgds
    tiwag

  9. #9
    Quote Originally Posted by tiwag View Post
    any other one, who has some other ideas

    (maybe with tested and working scriptfiles
    and precise instructions, what has to be changed where,
    instead of "maybe could be working when my brain remembers correctly" )


    sorry medsource, but you are way too unspecific !
    therefore of no great help.

    brgds
    <rant>

    Well, that lovely public bash really makes me want to check my config files and cron scripts WHEN I GET HOME TO WHERE MY WL-700GE IS to help you out.

    Maybe you should learn to ask politely and not behave like a complete ass. Methinks your results might be better.

    </rant>

  10. #10
    Join Date
    Aug 2007
    Location
    Austria
    Posts
    52
    Quote Originally Posted by medsource View Post
    <rant>

    Well, that lovely public bash really makes me want to check my config files and cron scripts WHEN I GET HOME TO WHERE MY WL-700GE IS to help you out.

    Maybe you should learn to ask politely and not behave like a complete ass. Methinks your results might be better.

    </rant>


    looking politely forward ...

    just a small reminder to what i requested a few times already ...
    Quote Originally Posted by tiwag View Post
    thanks medsource,

    you could post your modified fail2ban files package here,
    then we wouldn't need to investigate the same issues ever and ever again.

    brgds

    --
    tiwag


    anyhow, i made some progress in the meanwhile

    i got syslog-ng working, which produces nice logfiles, which can be read by fail2ban.
    at the moment i'm working to find out, which are the least common settings for syslog-ng,
    in order to produce a /opt/var/log/auth.log where dropbear and vsftp logins are collected,
    and all the other necessary stuff goes to /opt/var/log/syslog
    and all the unnecessary stuff is silently dropped.

    brgds
    Last edited by tiwag; 04-09-2007 at 23:35.
    tiwag

  11. #11
    Quote Originally Posted by tiwag View Post

    i got syslog-ng working, which produces nice logfiles, which can be read by fail2ban.
    at the moment i'm working to find out, which are the least common settings for syslog-ng,
    in order to produce a /opt/var/log/auth.log where dropbear and vsftp logins are collected,
    and all the other necessary stuff goes to /opt/var/log/syslog
    and all the unnecessary stuff is silently dropped.

    brgds
    You might run into a problem with that log location for two reasons...

    1) Unless /opt/var/log is cramfs (need to check the mount point for that) then everytime you experience an attack this data will get written to the drive and will negate spindown on the HD (granted if you are not using spindown then this is not an issue).

    2) Make sure you set a size limit for the log files (syslog-ng SHOULD be able to do this; but I have never used it so I can't say for sure) else the log files (at least vsftpd) will get large over time (speed of increase in size depending on how heavy you are getting hit or how often you use ftp).

  12. #12
    To those who pine for the days of velcro shoes...

    If you want to preserve the spindown option for the HDD you will need to send the vsftpd log file to a location that IS using cramfs (ram disk). I chose the directory /var/log and named the file vsftpd.log

    In order to get vsftpd to spit out the log file so that fail2ban can read it, vsftpd.conf (I recommend putting it in /opt/etc for simplicity) needs to be edited to contain these lines:

    xferlog_enable=YES
    vsftpd_log_file=/var/log/vsftpd.log
    log_ftp_protocol=YES
    xferlog_std_format=NO
    syslog_enable=NO
    dual_log_enable=NO

    In fail2ban edit the jail.conf file to point to /tmp/var/log/vsftpd.log as the log file to parse in the vsftpd section (yes, I know the "tmp" is not in the vsftpd.conf section... it works as written so deal with it).

    To prevent the logfile from getting too large you can either purge the file by hand (boring) or use a script to do it for you (sexy). I called mine logcheck (placed it in the /opt/sbin directory and made it executable using the "chmod 755 logcheck" command).

    Here's the code
    Code:
    #!/bin/sh
    filesize=`wc -c < /tmp/var/log/vsftpd.log`
    # echo "vsftpd.log filesize is:" $filesize
    if [ $filesize -gt 204800 ]
    then
    # echo "log file too big"
    rm /tmp/var/log/vsftpd.log
    touch /tmp/var/log/vsftpd.log
    fail2ban-client reload
    # else
    # echo "log file size ok"
    fi
    I then added this script to run periodically using CRON. Yes, you'll need to install CRON just like any other ipkg (you know... type "ipkg install cron"). CRON is heavily documented on the ol' interweb and will not be discussed here!

    Here's what I added to my crontab. It tells CRON to run logcheck every hour.

    Code:
    SHELL=/bin/sh
    PATH=/opt/sbin:/opt/bin:/sbin:/bin:/usr/sbin:/usr/bin
    MAILTO=""
    HOME=/
    # ---------- ---------- Default is Empty ---------- ---------- #
    0 0-23/1 * * * logcheck
    You will need to edit your rc.local to launch the items (in order) once testing is successful (for reboots and power outages etc so you won't have to do this by hand every time).
    Here's how I do it (these are the last three calls before the ending "fi" in rc.local):

    Code:
    # Start fail2ban for FTP DDOS thwarting
    touch /tmp/var/log/vsftpd.log
    fail2ban-client start
    sleep 5
    
    # start cron
    cron
    
    # Restart the ftpserver
    killall vsftpd
    vsftpd /opt/etc/vsftpd.conf
    There are other parts of fail2ban to configure in the jail.conf but they are well documented on their home site and are personal to your own topography (same goes for some items in vsftpd.conf); but, if you must see mine...

    vsftpd.conf
    Code:
    # Example config file /etc/vsftpd.conf
    #
    # The default compiled in settings are fairly paranoid. This sample file
    # loosens things up a bit, to make the ftp daemon more usable.
    # Please see vsftpd.conf.5 for all compiled in defaults.
    #
    # READ THIS: This example file is NOT an exhaustive list of vsftpd options.
    # Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
    # capabilities.
    #
    # Allow anonymous FTP? (Beware - allowed by default if you comment this out).
    anonymous_enable=YES
    nopriv_user=root
    #
    # Uncomment this to allow local users to log in.
    local_enable=YES
    #
    # Uncomment this to enable any form of FTP write command.
    write_enable=YES
    #
    # Default umask for local users is 077. You may wish to change this to 022,
    # if your users expect that (022 is used by most other ftpd's)
    local_umask=022
    #
    # Uncomment this to allow the anonymous FTP user to upload files. This only
    # has an effect if the above global write enable is activated. Also, you will
    # obviously need to create a directory writable by the FTP user.
    anon_upload_enable=YES
    #
    # Uncomment this if you want the anonymous FTP user to be able to create
    # new directories.
    anon_mkdir_write_enable=YES
    anon_other_write_enable=YES
    anon_world_readable_only=NO
    #
    # Activate directory messages - messages given to remote users when they
    # go into a certain directory.
    dirmessage_enable=YES
    #
    # Activate logging of uploads/downloads.
    xferlog_enable=YES
    #
    # Make sure PORT transfer connections originate from port 20 (ftp-data).
    connect_from_port_20=YES
    #
    # If you want, you can arrange for uploaded anonymous files to be owned by
    # a different user. Note! Using "root" for uploaded files is not
    # recommended!
    #chown_uploads=YES
    #chown_username=whoever
    #
    # You may override where the log file goes if you like. The default is shown
    # below.
    #xferlog_file=/var/log/vsftpd.log
    vsftpd_log_file=/var/log/vsftpd.log
    log_ftp_protocol=YES
    #
    # If you want, you can have your log file in standard ftpd xferlog format
    #xferlog_std_format=YES
    xferlog_std_format=NO
    #
    # You may change the default value for timing out an idle session.
    idle_session_timeout=600
    #
    # You may change the default value for timing out a data connection.
    data_connection_timeout=120
    #
    # It is recommended that you define on your system a unique user which the
    # ftp server can use as a totally isolated and unprivileged user.
    #nopriv_user=ftpsecure
    #
    # Enable this and the server will recognise asynchronous ABOR requests. Not
    # recommended for security (the code is non-trivial). Not enabling it,
    # however, may confuse older FTP clients.
    #async_abor_enable=YES
    #
    # By default the server will pretend to allow ASCII mode but in fact ignore
    # the request. Turn on the below options to have the server actually do ASCII
    # mangling on files when in ASCII mode.
    # Beware that turning on ascii_download_enable enables malicious remote parties
    # to consume your I/O resources, by issuing the command "SIZE /big/file" in
    # ASCII mode.
    # These ASCII options are split into upload and download because you may wish
    # to enable ASCII uploads (to prevent uploaded scripts etc. from breaking),
    # without the DoS risk of SIZE and ASCII downloads. ASCII mangling should be
    # on the client anyway..
    #ascii_upload_enable=YES
    #ascii_download_enable=YES
    #
    # You may fully customise the login banner string:
    # ftpd_banner=Welcome to the Repository Digital Archive FTP service.
    ftpd_banner=Welcome
    #
    # You may specify a file of disallowed anonymous e-mail addresses. Apparently
    # useful for combatting certain DoS attacks.
    #deny_email_enable=YES
    # (default follows)
    #banned_email_file=/etc/vsftpd.banned_emails
    #
    # You may specify an explicit list of local users to chroot() to their home
    # directory. If chroot_local_user is YES, then this list becomes a list of
    # users to NOT chroot().
    #chroot_list_enable=YES
    # (default follows)
    #chroot_list_file=/etc/vsftpd.chroot_list
    #
    # You may activate the "-R" option to the builtin ls. This is disabled by
    # default to avoid remote users being able to cause excessive I/O on large
    # sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
    # the presence of the "-R" option, so there is a strong case for enabling it.
    #ls_recurse_enable=YES
    #dual_log_enable=YES
    #ftp_username=guest
    syslog_enable=NO
    listen=YES
    #tunable_dirlist_enable=YES
    secure_chroot_dir=/
    chroot_local_user=YES
    #session_support=YES
    # xxx
    enable_iconv=YES
    local_charset=UTF-8
    remote_charset=CP950
    # xxx
    # guest_enable=YES
    # guest_username=guest
    max_clients=5
    #local_max_rate=48000
    force_dot_files=NO
    pasv_enable=NO
    # xxx
    jail.conf (the default and vsftpd sections only as I have the others turned off)
    Code:
    # Fail2Ban configuration file
    #
    # Author: Cyril Jaquier
    #
    # $Revision: 552 $
    #
    
    # The DEFAULT allows a global definition of the options. They can be override
    # in each jail afterwards.
    
    [DEFAULT]
    
    # "ignoreip" can be an IP address, a CIDR mask or a DNS host. Fail2ban will not
    # ban a host which matches an address in this list. Several addresses can be
    # defined using space separator.
    ignoreip = 127.0.0.1
    
    # "bantime" is the number of seconds that a host is banned.
    bantime  = 900
    
    # A host is banned if it has generated "maxretry" during the last "findtime"
    # seconds.
    findtime  = 30
    
    # "maxretry" is the number of failures before a host get banned.
    maxretry = 10
    
    # "backend" specifies the backend used to get files modification. Available
    # options are "gamin", "polling" and "auto". This option can be overridden in
    # each jail too (use "gamin" for a jail and "polling" for another).
    #
    # gamin:   requires Gamin (a file alteration monitor) to be installed. If Gamin
    #          is not installed, Fail2ban will use polling.
    # polling: uses a polling algorithm which does not require external libraries.
    # auto:    will choose Gamin if available and polling otherwise.
    backend = auto
    
    
    # This jail corresponds to the standard configuration in Fail2ban 0.6.
    
    [vsftpd-iptables]
    
    enabled  = true
    filter   = vsftpd
    action   = iptables[name=VSFTPD, port=ftp, protocol=tcp]
    #           mail-whois[name=VSFTPD, dest=yourmail@mail.com]
    logpath  = /tmp/var/log/vsftpd.log
    maxretry = 10
    bantime  = 900
    ...and now my fingers are bleeding!

  13. #13
    Join Date
    Aug 2007
    Location
    Austria
    Posts
    52

    Thumbs up

    Quote Originally Posted by medsource View Post
    To those who pine for the days of velcro shoes...
    ...
    ...and now my fingers are bleeding!
    well done, thanks a lot, very useful informations.

    brgds
    tiwag

  14. #14
    Join Date
    Apr 2006
    Location
    Heesch, Netherlands
    Posts
    118
    Not that I'm interested in fail2ban (I use the "time between fails", and "disconnect after 3 failures" variables in vsftpd.conf) but why don't you use logrotate to keep the logfile small?

    Anyway, great howto, for when I need it some time

  15. #15
    Quote Originally Posted by mistraller View Post
    Not that I'm interested in fail2ban (I use the "time between fails", and "disconnect after 3 failures" variables in vsftpd.conf) but why don't you use logrotate to keep the logfile small?

    Anyway, great howto, for when I need it some time
    I'm assuming you are using the new vsftpd in the oleg optware repository? If so, yeah it does work in that mode, though it does seem to break the nice tie-in that the asus flavor has with the GUI user security / directory access interface. I already had this working with the asus version so I figured less of a headache for me on the user management side by not upgrading.

    As for why I'm not using logrotate? Well, that runs as a cron job also. My solution just seemed simpler (less resources at runtime at least).

Page 1 of 2 12 LastLast

Similar Threads

  1. Инструкция по настройке роутера WL-500gP с нуля
    By OlegI in forum Russian Discussion - РУССКИЙ (RU)
    Replies: 1259
    Last Post: 10-02-2011, 22:25
  2. Русские имена торрентов
    By Mirage-net in forum Russian Discussion - РУССКИЙ (RU)
    Replies: 110
    Last Post: 18-06-2010, 15:16
  3. Install softs even you can't install ipkg
    By once in forum SL-1000 Q&A
    Replies: 0
    Last Post: 21-06-2007, 07:50
  4. Ctcs install
    By fisha in forum WL-HDD Q&A
    Replies: 0
    Last Post: 30-08-2006, 13:48
  5. Install python; no success?!
    By ikerstges in forum WL-500g Q&A
    Replies: 4
    Last Post: 07-03-2006, 15:36

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •