Skip to content

Commit 9ebdcb1

Browse files
authored
Linux安全检查脚本
1 parent 3f22902 commit 9ebdcb1

File tree

8 files changed

+1911
-0
lines changed

8 files changed

+1911
-0
lines changed

Diff for: buying_linuxcheck.sh

+1,803
Large diffs are not rendered by default.

Diff for: del.exp

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/expect
2+
set ipadd [lindex $argv 0]
3+
set username [lindex $argv 1]
4+
set userpasswd [lindex $argv 2]
5+
set rootpasswd [lindex $argv 3]
6+
set timeout 10
7+
spawn ssh $username@$ipadd
8+
expect {
9+
"password" {send "$userpasswd\r";exp_continue}
10+
"*from*" {send "su - root\r";exp_continue}
11+
"*assword*" {send "$rootpasswd\r";exp_continue}
12+
"*]#" {send "rm -rf /tmp/*${ipadd}* /tmp/buying_linuxcheck.sh\r"}
13+
}
14+
expect eof

Diff for: get.exp

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/expect
2+
set ipadd [lindex $argv 0]
3+
set username [lindex $argv 1]
4+
set userpasswd [lindex $argv 2]
5+
set timeout 10
6+
spawn scp $username@$ipadd:/tmp/*${ipadd}* /tmp/
7+
expect {
8+
"password" {send "$userpasswd\r"}
9+
}
10+
expect eof

Diff for: hosts.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
192.168.78.129:root:P@ssw0rd:P@ssw0rd

Diff for: login.sh

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
echo "安徽三实捕影Linux安全检查与应急响应工具"
3+
echo "Version:1.2"
4+
echo "Author:飞鸟"
5+
echo "Mail:liuquyong112@gmail.com"
6+
echo "Date:2019-02-19"
7+
8+
cat <<EOF
9+
*************************************************************************************
10+
功能与使用说明:
11+
1.此脚本主要功能用来实现一键对远程服务器进行安全检查
12+
2.使用时只需要将远程服务器的IP、账号、密码放到hosts.txt文本中,运行sh login.sh或chmod +x login.sh;./login.sh即可自动进行安全检查
13+
3.有的Linux系统不允许使用root账号直接登录,因此前期需要测试或与用户沟通是否允许root直接登录
14+
3.1 如果允许使用root直接登录,可以将root账号密码直接写到hosts.txt文本中
15+
3.2 如果不允许使用root账号直接登录,需要增加一个可以登录的账号到hosts.txt文件中,此账号需要有对/tmp目录的读写权限,具体格式参考hosts.txt文本的说明
16+
4.远程服务器的检查内容均放在/tmp/buying_${ipadd}_${date}目录下
17+
5.检查结束后会将远程服务器的检查结果打包放到本地的/tmp目录下,同时会删除远程服务器上的检查脚本与结果
18+
*************************************************************************************
19+
EOF
20+
for i in `cat hosts.txt`
21+
do
22+
#远程IP地址
23+
ipadd=`echo $i | awk -F "[:]" '{print $1}'`
24+
#普通用户,如果root允许登录,这里面可以是root账号
25+
username=`echo $i | awk -F "[:]" '{print $2}'`
26+
#普通用户密码,如果root允许登录,这里面可以是root密码
27+
userpasswd=`echo $i | awk -F "[:]" '{print $3}'`
28+
#root用户密码
29+
rootpasswd=`echo $i | awk -F "[:]" '{print $4}'`
30+
#上传检查脚本buying_linuxcheck.sh
31+
expect put.exp $ipadd $username $userpasswd
32+
#登陆执行检查脚本buying_linuxcheck.sh
33+
expect sh.exp $ipadd $username $userpasswd $rootpasswd
34+
#从远程拿取结果
35+
expect get.exp $ipadd $username $userpasswd
36+
#删除远程服务器的检查结果和检查脚本
37+
expect del.exp $ipadd $username $userpasswd $rootpasswd
38+
done

Diff for: put.exp

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/expect
2+
set ipadd [lindex $argv 0]
3+
set username [lindex $argv 1]
4+
set userpasswd [lindex $argv 2]
5+
set timeout 10
6+
spawn scp buying_linuxcheck.sh $username@$ipadd:/tmp/
7+
expect {
8+
"yes/no" {send "yes\r";exp_continue}
9+
"password" {send "$userpasswd\r"}
10+
}
11+
expect eof

Diff for: readme.txt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
�ű�˵����
2+
1.����Ŀ¼�����ļ������뵽һ̨�Լ��ı���linux����ͬһĿ¼��
3+
2.��������IP����ͨ�˺š���ͨ�˺����롢root�������ΰ����¸�ʽд�뵽hosts.txt�У�ע�⡰:����Ϊhosts.txt�ķָ�������
4+
5+
192.168.1.81:user:123456:nothing
6+
192.168.1.10:user:123456:nothing
7+
192.168.1.11:user:123456:nothing
8+
9+
3.ִ��sh login.sh,�ű����Զ������ϴ�checklinux.sh��������/tmpĿ¼�£������Զ�ִ�к��Զ��ϴ����������linux������
10+
4.��󽫷������ϴ��Ľű��ͽ���Զ�ɾ��
11+
12+
13+
(ע�⣺���ű�������linuxϵͳ)

Diff for: sh.exp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/expect
2+
set ipaddr [lindex $argv 0]
3+
set username [lindex $argv 1]
4+
set userpasswd [lindex $argv 2]
5+
set rootpasswd [lindex $argv 3]
6+
set timeout 10
7+
spawn ssh $username@$ipaddr
8+
expect {
9+
"yse/no" {send "yes\r";exp_continue}
10+
"*password*" {send "$userpasswd\r";exp_continue}
11+
"*from*" {send "su - root\r"}
12+
}
13+
expect "Password"
14+
send "$rootpasswd\r"
15+
expect "*]#"
16+
send "chmod 777 /tmp/buying_linuxcheck.sh\r"
17+
send "sh /tmp/buying_linuxcheck.sh\r"
18+
send "exit\r"
19+
send "exit\r"
20+
interact
21+

0 commit comments

Comments
 (0)