Pages

Saturday, March 15, 2014

Simple shell script to block failed ssh attempts


It’s annoying having scripts and bots attempting to ssh into your pbx server. If you have proper passwords they don’t stand a chance of getting in, but it’s not satisfying to ignore them while they create load and clutter up your log files with failed login messages.
There are many tools out there to monitor and block IP addresses that repeatedly attempt to connect. My needs were:
  • low memory (memory is precious on a VPS)
  • simple
  • customizable
After wasting time installing various complicated python and perl scripts, I found a clever use of awk that counts matches in a log file and I put together this simple shell script:
scan-secure.sh
#!/bin/sh

# scan /var/log/secure for ssh attempts
# use iptables to block the bad guys

# Looking for attempts on existing and non-existing users. For example:
# Nov  2 22:44:07 pbxer sshd[28318]: Failed password for root from 74.143.42.70 port 52416 ssh2
# Nov  3 00:06:57 pbxer sshd[31767]: Failed password for invalid user mat3 from 192.203.145.200 port 35841 ssh2

tail -1000 /var/log/secure | awk '/sshd/ && /Failed password for/ { if (/invalid user/) try[$13]++; else try[$11]++; }
END { for (h in try) if (try[h] > 4) print h; }' |
while read ip
do
 # note: check if IP is already blocked...
 /sbin/iptables -L -n | grep $ip > /dev/null
 if [ $? -eq 0 ] ; then
  # echo "already denied ip: [$ip]" ;
  true 
 else
  # echo "Subject: denying ip: $ip" | /usr/sbin/sendmail notify@email.com
  logger -p authpriv.notice "*** Blocking SSH attempt from: $ip"
  /sbin/iptables -I INPUT -s $ip -j DROP
 fi
done

awk does all the magic. It grabs relevant lines, splits the lines into tokens, stores IP addresses in a hash and counts how many times they were seen, and finally outputs all IP addresses that were seen more than four times.
For the first few days, it’s interesting to receive an email when IP addresses are banned. Add your email and comment out that line.
Once you’re sure that the script is working how you’d like, you can add it to cron so that it runs every few minutes. I found that every two minutes works for me.
 
crontab -e
# scan the secure log every 2 minutes
*/2 * * * * /root/scan-secure.sh
 
After a few months you might find that the iptables are started to get cluttered.
iptables -L -n
You can clean them out by “flushing” them.
iptables -F
Now sleep tight knowing that people aren’t continually coming by to see if you locked your doors.

Wednesday, February 5, 2014

Xử lý lỗi chữ bị dính liền khi mở file word được soạn thảo bởi office 2010

Nếu máy nào dùng office 2010 thì phải Sellect all, sau đó vào phần Set Languge để chọn mục "Do not check spelling and grammar". Mình đã thử nghiệm và thấy nếu đoạn nào đã tick vào mục này thì mở trên Office 2007 vô tư. Còn không để ý thì cũng bị vất vả xử lý cái lỗi dính liền chữ. Vậy nên ai dùng Office 2010 nhớ tick vào ô trên rùi save lại trước khi gửi cho người khác nhé. Nếu không sẽ có thằng lầm bầm chửi rủa mình đó!

Vậy thì giải pháp nào cho Office 2007 khi gặp phải đối tác Office 2010? Cũng may là mình đã tìm ra giải pháp. Mọi việc chỉ cần down file này về và cài đặt:
Nếu không mở được link trên thì vào: http://www.microsoft.com/download/en/details.aspx?id=3

Hướng dẫn cài đặt Office 2010 trên Windows XP SP2

Phiên bản office 2010 chỉ hỗ trợ từ XP sP3 trở lên nhưng các bạn sử dụng SP2 có thể sử dụng những thủ thuật sau để cài đặt bình thường

Bước 1: Vào Start -> run -> regedit

1. Go to Registry
2. HKEY_LOCAL_MACHINE\System\CurrentControlSet\Contro l\Windows
3. Change CSDVersion string value from 200 -> 300
4. Reboot

Wednesday, December 18, 2013

POST Beep Codes


POST Beep Codes
Beep CodesErrorProbable Causes
1Memory refresh failure.Defective system board.
2Error occurred in first 64 KB of main memory.Faulty DIMM or defective system board.
3Read or write error occurred in first 64 KB of main memory.Faulty DIMM.
4Timer on system board malfunctioned.Defective system board.
5Microprocessor error.Defective microprocesor.
6Gate A20 failure.Defective system board.
7Microprocessor-execption interrupt error.Defective microprocessor.
8Video memory read/write error.Missing or faulty video adapter.
9ROM checksum value does not match value encoded in system BIOS.Corrupted system BIOS program or defective system BIOS chip.
10NVRAM shutdown register read/write error.Defective system board.
11Cache memory error.Defective microprocessor or cache card.
1-2Video adapter failure.Faulty video adapter.
1-3No monitor connected.Loose video cable connection or defective video cable.
Faulty video adapter.

Monday, December 16, 2013

Hướng dẫn tạo USB-GPT cài win 7-8-8.1 boot chuẩn UEFI



Có nhiều cách để tạo 1 USB cài win, tool thì cũng có nhiều, nhưng mình vẫn thích nhất là "tay không bắt giặc" vì cách này nhanh nhất, chuẩn nhất, và cũng chủ động nhất, có thể các bạn chưa quen thì thấy là chậm hay loằng ngoằng, nhưng khi đã quen rồi thì tốc độ là số 1, vù cái đã xong.

Bắt đầu nào: chuẩn bị 1 em USB từ 4GB trở lên, file ISO win7/8 64-bit

Thursday, December 12, 2013

Các PAN Nec/Tokin


Các bệnh liên quan quan đến tụ điện Nec/Tokin thì đã quá "thường" rồi. Rất rất nhiều nơi đã đề cập, chỉ cách khắc phục. Nên lqv77 sẽ không nói lại, chỉ muốn note lại chút xíu thôi:

1. Pan này là do thủ phạm chính là tụ Nec/Tokin gây nên.

Tình trạng: Dùng Pin thì bình thường. <-- 4="" adpater="" b="" c="" ch="" d="" h="" i="" kh="" khi="" m="" n="" ng="" nh...="" nh="" nha.="" ok="" p="" ph="" pin="" r="" ra="" s="" sinh="" t="" th="" treo="" tri="" u.="" u="" v="" x="" y="">

Friday, December 6, 2013

Mainboard không lưu được Bios



1. Kiểm tra jump Cmos Battery (nếu có) đã set đúng chưa.
2. Hư hỏng mạch ổn áp cấp cho IC nhớ cấu hình. Xem hình.
3. Chết IC-thay, hoặc thối chân IC-hàn lại.