Swatch as normal user

Hello! Gotta say that section6 saved me again. I enabled SSH on my FreeBSD 6 server so I can work from home during the weekend. Got my stuff from the office and walked home. I logged in and was amazed that in just one hour I was already scanned twice and also had a brute force hack attempt. I followed the swatch+pf tutorial in here, but I'm a bit unconfortable running swatch as root. I don't know, I'm new to UNIX, but every document I read adivsed to run as few programs as possible using root. So I started experimenting: Created user swatch: swatch:*:1001:1001::0:0:Swatch Log Watcher:/home/swatch:/usr/sbin/nologin I also passed -D to adduser so it doesn't create a home folder. Edited /etc/rc.conf: swatch_enable="YES" swatch_rules="1" swatch_1_flags="--config-file=/etc/swatch/.swatchrc1 --script-dir=/etc/swatch --tail-file=/var/log/all.log --awk-field-syntax --daemon --pid-file=/etc/swatch/swatch1.pid" swatch_1_user="swatch" swatch_1_pid="/etc/swatch/swatch1.pid" I've put the pid file in /etc/swatch because I got some error about not being able to write to /var/run. Edited /etc/swatch/.swatchrc1: #Look for bad ssh attempts, if found, block them! watchfor /Invalid user/ exec "/etc/swatch/addblock $10" mail addresses=me\@yahoo.com, subject=SSH hacker blocked # monitor interactive logins watchfor /Accepted keyboard/ mail addresses=me\@yahoo.com, subject=Interactive login I had to escape the @ character here, because swatch doesn't escape it in the perl script it generates and I get an error. Created the addblock script as in the tutorial. Then I set permissions for /etc/swatch/ #chown -R swatch /etc/swatch #chmod -R 740 /etc/swatch Edited /etc/syslog.conf and uncommented this line: *.* /var/log/all.log #echo "" > /var/log/all.log #chmod 644 /var/log/all.log Here I have a problem. After the log grows, it is archived to all.log.0.bz2 and a new all.log is created with 600 perms. Because of this tail can't read the log anymore and swatch stops. Where can I alter this behaviour ? Also, is it safe to give read permission to everyone for all.log ? Or should I chown it to swatch ? Will that break anything ? Another issue is that after an IP is added to the hackers table it won't take effect only after a reboot. The addblock script gets executed, because I can see the blocked IP in /etc/swatch/hackers. In attempting to figure out what's not going right with pfctl I installed sudo and did: #sudo -u swatch pfctl -t hackers -T show pfctl: /dev/pf: Permission denied #ls -lh /dev | grep pf crw------- 1 root wheel 0, 98 Mar 12 01:31 pf Now I'm really not sure if I should alter permissions for this. So my final question is: Is it worth the trouble of running swatch as non-root ? Best regards, Galanton Peter

Thanks

http://112p.20m.com/index38.html http://112p.20m.com/index46.html http://112p.20m.com/index12.html http://112p.20m.com/index34.html http://112p.20m.com/index36.html http://112p.20m.com/index28.html http://112p.20m.com/index22.html http://112p.20m.com/index26.html http://112p.20m.com/index5.html http://112p.20m.com/index15.html http://112p.20m.com/index27.html http://112p.20m.com/index9.html http://112p.20m.com/index29.html http://112p.20m.com/index20.html http://112p.20m.com/index33.html http://112p.20m.com/index13.html http://112p.20m.com/index49.html http://112p.20m.com/index11.html http://112p.20m.com/index32.html http://112p.20m.com/index3.html http://112p.20m.com/index30.html http://112p.20m.com/index7.html http://112p.20m.com/index8.html http://112p.20m.com/index41.html http://112p.20m.com/index40.html http://112p.20m.com/index31.html http://112p.20m.com/index23.html http://112p.20m.com/index50.html http://112p.20m.com/index6.html http://112p.20m.com/index24.html http://112p.20m.com/index14.html http://112p.20m.com/index17.html http://112p.20m.com/index1.html http://112p.20m.com/index25.html http://112p.20m.com/index42.html http://112p.20m.com/index10.html http://112p.20m.com/index19.html http://112p.20m.com/index18.html http://112p.20m.com/index44.html http://112p.20m.com/index45.html http://112p.20m.com/index37.html http://112p.20m.com/index21.html http://112p.20m.com/index4.html http://112p.20m.com/index43.html http://112p.20m.com/index39.html http://112p.20m.com/index35.html http://112p.20m.com/index48.html http://112p.20m.com/index47.html http://112p.20m.com/index16.html http://112p.20m.com/index2.html

Still having problems with swatch

Hello again I switched back to running swatch as root until I figure it out how to run it as non-root. But now I have another problem. I tested the setup myself using 2 dial-up accounts and everything worked. Then, last night, I got another brute force attack and swatch didn't block the IP. When I logged in to see what was happening I found a large number of swatch processes as reported by both ps -ax | grep swatch and /usr/local/etc/rc.d/swatch.sh status Is it possible that swatch gets into a deadlock or something ? It did email be about blocking SSH hacker, but I don't think the addblock script got executed, because I can't see the IP in the hackers file, nor in the hackers table as reported by pfctl -t hackers -T show. Also there is no "swatch: xxx caught with bad login" entry in the log. I must mention that I don't have AltQ support enabled in the kernel. Could that be the cause of the race condition (if that is the case) ? Best regards, Peter

Actually this is a fairly

Actually this is a fairly common problem with swatch and I was tempted to take the tutorial down because of it. I'll put a caveat in there about it. Myself and many other sysadmins have resorted to just switching the port ssh listens on since there still isn't a great solution out there to defeat bruteforce dummy scripts.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.