Skip to content

Commit

Permalink
Linux安全检查脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
feiniao112 authored Apr 28, 2019
1 parent 3f22902 commit 9ebdcb1
Show file tree
Hide file tree
Showing 8 changed files with 1,911 additions and 0 deletions.
1,803 changes: 1,803 additions & 0 deletions buying_linuxcheck.sh

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions del.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/expect
set ipadd [lindex $argv 0]
set username [lindex $argv 1]
set userpasswd [lindex $argv 2]
set rootpasswd [lindex $argv 3]
set timeout 10
spawn ssh $username@$ipadd
expect {
"password" {send "$userpasswd\r";exp_continue}
"*from*" {send "su - root\r";exp_continue}
"*assword*" {send "$rootpasswd\r";exp_continue}
"*]#" {send "rm -rf /tmp/*${ipadd}* /tmp/buying_linuxcheck.sh\r"}
}
expect eof
10 changes: 10 additions & 0 deletions get.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/expect
set ipadd [lindex $argv 0]
set username [lindex $argv 1]
set userpasswd [lindex $argv 2]
set timeout 10
spawn scp $username@$ipadd:/tmp/*${ipadd}* /tmp/
expect {
"password" {send "$userpasswd\r"}
}
expect eof
1 change: 1 addition & 0 deletions hosts.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
192.168.78.129:root:P@ssw0rd:P@ssw0rd
38 changes: 38 additions & 0 deletions login.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
echo "安徽三实捕影Linux安全检查与应急响应工具"
echo "Version:1.2"
echo "Author:飞鸟"
echo "Mail:[email protected]"
echo "Date:2019-02-19"

cat <<EOF
*************************************************************************************
功能与使用说明:
1.此脚本主要功能用来实现一键对远程服务器进行安全检查
2.使用时只需要将远程服务器的IP、账号、密码放到hosts.txt文本中,运行sh login.sh或chmod +x login.sh;./login.sh即可自动进行安全检查
3.有的Linux系统不允许使用root账号直接登录,因此前期需要测试或与用户沟通是否允许root直接登录
3.1 如果允许使用root直接登录,可以将root账号密码直接写到hosts.txt文本中
3.2 如果不允许使用root账号直接登录,需要增加一个可以登录的账号到hosts.txt文件中,此账号需要有对/tmp目录的读写权限,具体格式参考hosts.txt文本的说明
4.远程服务器的检查内容均放在/tmp/buying_${ipadd}_${date}目录下
5.检查结束后会将远程服务器的检查结果打包放到本地的/tmp目录下,同时会删除远程服务器上的检查脚本与结果
*************************************************************************************
EOF
for i in `cat hosts.txt`
do
#远程IP地址
ipadd=`echo $i | awk -F "[:]" '{print $1}'`
#普通用户,如果root允许登录,这里面可以是root账号
username=`echo $i | awk -F "[:]" '{print $2}'`
#普通用户密码,如果root允许登录,这里面可以是root密码
userpasswd=`echo $i | awk -F "[:]" '{print $3}'`
#root用户密码
rootpasswd=`echo $i | awk -F "[:]" '{print $4}'`
#上传检查脚本buying_linuxcheck.sh
expect put.exp $ipadd $username $userpasswd
#登陆执行检查脚本buying_linuxcheck.sh
expect sh.exp $ipadd $username $userpasswd $rootpasswd
#从远程拿取结果
expect get.exp $ipadd $username $userpasswd
#删除远程服务器的检查结果和检查脚本
expect del.exp $ipadd $username $userpasswd $rootpasswd
done
11 changes: 11 additions & 0 deletions put.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/expect
set ipadd [lindex $argv 0]
set username [lindex $argv 1]
set userpasswd [lindex $argv 2]
set timeout 10
spawn scp buying_linuxcheck.sh $username@$ipadd:/tmp/
expect {
"yes/no" {send "yes\r";exp_continue}
"password" {send "$userpasswd\r"}
}
expect eof
13 changes: 13 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
�ű�˵����
1.����Ŀ¼�����ļ������뵽һ̨�Լ��ı���linux����ͬһĿ¼��
2.��������IP����ͨ�˺š���ͨ�˺����롢root�������ΰ����¸�ʽд�뵽hosts.txt�У�ע�⡰:����Ϊhosts.txt�ķָ�������

192.168.1.81:user:123456:nothing
192.168.1.10:user:123456:nothing
192.168.1.11:user:123456:nothing

3.ִ��sh login.sh,�ű����Զ������ϴ�checklinux.sh��������/tmpĿ¼�£������Զ�ִ�к��Զ��ϴ����������linux������
4.��󽫷������ϴ��Ľű��ͽ���Զ�ɾ��


(ע�⣺���ű�������linuxϵͳ)
21 changes: 21 additions & 0 deletions sh.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/expect
set ipaddr [lindex $argv 0]
set username [lindex $argv 1]
set userpasswd [lindex $argv 2]
set rootpasswd [lindex $argv 3]
set timeout 10
spawn ssh $username@$ipaddr
expect {
"yse/no" {send "yes\r";exp_continue}
"*password*" {send "$userpasswd\r";exp_continue}
"*from*" {send "su - root\r"}
}
expect "Password"
send "$rootpasswd\r"
expect "*]#"
send "chmod 777 /tmp/buying_linuxcheck.sh\r"
send "sh /tmp/buying_linuxcheck.sh\r"
send "exit\r"
send "exit\r"
interact

0 comments on commit 9ebdcb1

Please sign in to comment.