1. 'Linux: Monitor a Directory for Files'

    Mon 22 March 2010

    Inotify is a mechanism in the Linux kernel that reports when a file system event occurs.

    The inotifywait comand line utility can be used in shell scripts to monitor directories for new files. It can also be used to monitor files for changes. Inotifywait must be installed and is often not part of the base installation of your Linux distro. However, if you need to monitor a directory or some task like that, it is worth the effort. (apt-get install inotify-tools).

    Here is how you use it:

    inotifywait -m -r -e close_write /tmp/ | while read LINE; do echo $LINE | awk '{ print $1 $3 }'; done

    Let's dissect this example one part at a time. The most interesting part is this:

    inotifywait -m -r -e close_write /tmp/

    What happens here? First, inotifywait monitors the /tmp directory. The monitoring mode is specified with the -m option, otherwise inotifywait would exit after the first event. The -r option specifies recursion, beware of large directory trees. The -e option is the most important part. You only want to be notified of new files if they are complete. So only after a close_write event should your script be notified of an event. A 'create' event for example, should not cause your script to perform any action, because the file would not be ready yet.

    The remaining part of the example is just to get output like this:

    /tmp/test1234/blablaf

    /tmp/test123

    /tmp/random.bin

    This output can be used to use as an argument to other scripts or functions, in order to perform some kind of action on this file.

    This mechanism is specific to Linux. So it is not a OS independent solution.

    If you have any comments email me, see the About page for contact details.
  2. 'Syslog: The Hidden Security Risk'

    Thu 18 March 2010

    People sometimes forget that there are also a number of UDP-based services that may pose a threat to the security of your systems. SNMP is a well-known service, notorious for being configured with a default password (or community string).

    But there is another service that is often not seen as a risk. This is the syslog service. Syslog is used on virtually all UNIX-like platform for logging messages of the system to one or more log files to disk. The syslog service often listens on the network, on UDP-port 514. Please note that syslog does not perform any authentication of data that is sent to it.

    So what does this mean?

    An attacker can:

    1. Create a denial-of-service condition (DoS) by sending large amounts of data to the syslog service, filling up disk space.

    2. Once the disk is full, logs can no longer be saved, thus any attack that would leave a trail within the logs would go unnoticed.

    3. by sending large amounts of specially crafted messages, an attacker can cause chaos if logs are monitored by intrusion detection systems or other systems that create alerts.

    How to attack? Just use netcat:

    nc -u [IP-address] 514

    Once you are connected, anything you type will be logged in a log file.

    How to mitigate this issue?

    1. Firewall access to UDP-port 514

    2. Make sure that the syslog service does not listen on the network if not required, only on localhost.

    Tagged as : Uncategorized
    If you have any comments email me, see the About page for contact details.

Page 83 / 115