linux ssh secure 查看登錄日志,獲取登錄失敗的地址
ECS信息

規(guī)格:2vCPUs | 4GiB | kc1.large.2
鏡像:openEuler 20.03 64bit with ARM | 公共鏡像
linux ssh secure 查看登錄日志,獲取登錄失敗信息
# cd /var/log # ls -lh | grep secure -rw-------. 1 root root 5.3M Oct 6 19:58 secure -rw------- 1 root root 4.3M Oct 2 03:12 secure-20211002 # stat secure File: secure Size: 5546688 Blocks: 10848 IO Block: 4096 regular file Device: fd02h/64770d Inode: 657617 Links: 1 Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2021-10-06 19:59:18.103630401 +0800 Modify: 2021-10-06 19:58:38.538911690 +0800 Change: 2021-10-06 19:58:38.538911690 +0800 Birth: 2020-05-18 10:35:20.984000000 +0800
IP部分已隱藏
# cat secure | grep "authentication failure" > /home/ssh_authentication_failure.txt # head ssh_authentication_failure.txt -n 5 Oct 2 03:13:42 ecs-4eee sshd[18747]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=XXX.XXX.XXX.XXX Oct 2 03:16:13 ecs-4eee sshd[18758]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=XXX.XXX.XXX.XXX Oct 2 03:18:48 ecs-4eee sshd[18760]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=XXX.XXX.XXX.XXX Oct 2 03:21:17 ecs-4eee sshd[18763]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=XXX.XXX.XXX.XXX Oct 2 03:23:55 ecs-4eee sshd[18766]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=XXX.XXX.XXX.XXX # wc -l ssh_authentication_failure.txt 28697 ssh_authentication_failure.txt
使用python提取其中的ip地址
import re regex = re.compile("rhost=(.+\d)") ip_list = [] with open("ssh_authentication_failure.txt", "r") as file: while True: log = file.readline() if len(log) == 0: break ip_list.extend(regex.findall(log)) black_ip_list = list(set(ip_list)) for ip in black_ip_list: print(ip) print(len(ip_list)) print(len(black_ip_list))
......部分截取 + 地址已隱藏 XXX.XXX.XXX.XXX XXX.XXX.XXX.XXX 28697 108
生成地址名單后,就該考慮安全加固的事情了
學(xué)習(xí)資料
彈性云服務(wù)器 ECS
openEuler-官網(wǎng)
openEuler-B站
openEuler-慕課
openEuler-文檔
鯤鵬社區(qū)
歡迎各位同學(xué)一起來交流學(xué)習(xí)心得^_^
Linux openEuler
版權(quán)聲明:本文內(nèi)容由網(wǎng)絡(luò)用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔(dān)相應(yīng)法律責(zé)任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實(shí)的內(nèi)容,請聯(lián)系我們jiasou666@gmail.com 處理,核實(shí)后本網(wǎng)站將在24小時內(nèi)刪除侵權(quán)內(nèi)容。
版權(quán)聲明:本文內(nèi)容由網(wǎng)絡(luò)用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔(dān)相應(yīng)法律責(zé)任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實(shí)的內(nèi)容,請聯(lián)系我們jiasou666@gmail.com 處理,核實(shí)后本網(wǎng)站將在24小時內(nèi)刪除侵權(quán)內(nèi)容。