• If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.
Xin chào ! Nếu đây là lần đầu tiên bạn đến với diễn đàn, xin vui lòng danh ra một phút bấm vào đây để đăng kí và tham gia thảo luận cùng VnPro.

Announcement

Collapse
No announcement yet.

Cấu hình cảnh báo qua email khi user Root ssh vào hệ thống

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cấu hình cảnh báo qua email khi user Root ssh vào hệ thống

    Sử dụng chương trình sendEmail.pl để giúp gửi mail khi user root đăng nhập hệ hống
    Download http://up.4share.vn/f/7e4c4d4647474b4e/sendEmail.txt
    Cấu hình log ssh server để hiển thị finger nào đăng nhập với quyền root
    SyslogFacility AUTHPRIV
    LogLevel VERBOSE
    RSAAuthentication yes
    PubkeyAuthentication yes
    AuthorizedKeysFile /root/.ssh/authorized_keys
    PermitEmptyPasswords no
    PasswordAuthentication no
    ChallengeResponseAuthentication no
    Thêm trong file /root/.bashrc
    USER_LOGIN=$(who | tail -n 1 | awk -F " " '{print $1}')
    DATE=$(who | tail -n 1 | awk -F " " '{print $3}')
    TIME=$(who | tail -n 1 | awk -F " " '{print $4}')
    IP=$(who | tail -n 1 | awk -F " " '{print $5}')
    METHOD=$(who | tail -n 1 | awk -F " " '{print $2}')
    FROM="mail1@domain.com"
    TO="mail2@domain.com"
    FINGER=$(tail -n 3 /var/log/secure | grep "Found matching RSA key:" | awk -F " " '{print $10}')
    SUBJECT="ALERT LOGIN"
    MESSAGE="ALERT LOGIN: $USER access to Server by $METHOD from $IP at $TIME $DATE, finger=> $FINGER"
    /root/sendEmail.pl -f "$FROM" -t "$TO" -u "$SUBJECT" -m "$MESSAGE"
    Tạo các cặp private và public key để đăng nhập không cần password
    #cd /root/.ssh
    #ssh-keygen -t rsa -C rsa-key-root1
    #ssh-keygen -t rsa -C rsa-key-root2
    Kiểm tra finger
    #ssh-keygen -lf id_rsa_root1.pub
    #ssh-keygen -lf id_rsa_root2.pub
    Ta được 2 cặp khóa public và private, ghi 2 khóa public vào file authorized_keys
    #cat id_rsa_root1.pub id_rsa_root2 .pub > authorized_keys
    Sau đó thử đăng nhập vào quyền root nhưng với 2 key private khác nhau bằng chương trình putty, ta nhận được 2 email với user root đăng nhập nhưng với 2 finger khác nhau.
    Bằng cách phân phối các key private tương ứng từng người, ta có thể biết được người nào đăng nhập vào hệ thống với quyền root.
    --------------------------------------------
    Mới tập sự, xin các pro chỉ giáo. #:-S
Working...
X