htb monitored root方式其中的一种(仅作记录)

快下班时候审出来的,目前root的第5种方式

nagios@monitored:~$ cat /usr/local/nagiosxi/scripts/backup_xi.sh
#!/bin/bash
#
# Creates a Full Backup of Nagios XI
# Copyright (c) 2011-2020 Nagios Enterprises, LLC. All rights reserved.
#BASEDIR=$(dirname $(readlink -f $0))
SBLOG="/usr/local/nagiosxi/var/components/scheduledbackups.log"
ts=`date +%s`# Import Nagios XI and xi-sys.cfg config vars
. $BASEDIR/../etc/xi-sys.cfg
eval $(php $BASEDIR/import_xiconfig.php)###############################
# USAGE / HELP
###############################
usage () {echo ""echo "Use this script to backup Nagios XI."echo ""echo " -n | --name              Set the name of the backup minus the .tar.gz"echo " -p | --prepend           Prepend a string to the .tar.gz name"echo " -a | --append            Append a string to the .tar.gz name"echo " -d | --directory         Change the directory to store the compressed backup"echo ""
}###############################
# ADDING LOGIC FOR NEW BACKUPS
###############################
while [ -n "$1" ]; docase "$1" in-h | --help)usageexit 0;;-n | --name)fullname=$2;;-p | --prepend)prepend=$2".";;-a | --append)append="."$2;;-d | --directory)rootdir=$2;;esacshift
doneecho "\nStarting new backup....\n"# Restart nagios to forcibly update retention.dat
$BASEDIR/manage_services.sh restart nagios
sleep 10if [ -z "$rootdir" ]; thenrootdir="/store/backups/nagiosxi"
fi# Move to root dir to store backups
cd "$rootdir"#############################
# SET THE NAME & TIME
#############################
name=$fullnameif [ -z "$fullname" ]; thenname="$prepend$ts$append"
fi# Clean the name
name=$(echo "$name" | sed -e 's/[^[:alnum:].|-]//g')# Get current Unix timestamp as name
if [ -z "$name" ]; thenname="$ts"
fi# My working directory
mydir=$rootdir/$name# Make directory for this specific backup
mkdir -p "$mydir"##############################
# BACKUP DIRS
############################### Only backup NagiosQL if it exists
if [ -d "/var/www/html/nagiosql" ]; thenecho "Backing up NagiosQL..."tar czfp "$mydir/nagiosql.tar.gz" /var/www/html/nagiosqltar czfp "$mydir/nagiosql-etc.tar.gz" /etc/nagiosql
fiecho "Backing up Nagios Core..."
tar czfp "$mydir/nagios.tar.gz" /usr/local/nagios# Backup ramdisk if it exists
if [ -f "/etc/sysconfig/nagios" ]; thenecho "Copying ramdisk configuration..."cp /etc/sysconfig/nagios "$mydir/ramdisk.nagios"
fiecho "Backing up Nagios XI..."
tar czfp "$mydir/nagiosxi.tar.gz" /usr/local/nagiosxiecho "Backing up MRTG..."
tar czfp "$mydir/mrtg.tar.gz" /var/lib/mrtg
cp /etc/mrtg/mrtg.cfg "$mydir/"
cp -r /etc/mrtg/conf.d "$mydir/"# SNMP configs and MIBS
echo "Backing up the SNMP directories"
tar czfp "$mydir/etc-snmp.tar.gz" /etc/snmp
tar czfp "$mydir/usr-share-snmp.tar.gz" /usr/share/snmpecho "Backing up NRDP..."
tar czfp "$mydir/nrdp.tar.gz" /usr/local/nrdpecho "Backing up Nagvis..." 
tar czfp "$mydir/nagvis.tar.gz" /usr/local/nagvisecho "Backing up nagios user home dir..." 
tar czfp "$mydir/home-nagios.tar.gz" /home/nagios##############################
# BACKUP DATABASES
##############################
echo "Backing up MySQL databases..."
mkdir -p "$mydir/mysql"
if [[ "$cfg__db_info__ndoutils__dbserver" == *":"* ]]; thenndoutils_dbport=`echo "$cfg__db_info__ndoutils__dbserver" | cut -f2 -d":"`ndoutils_dbserver=`echo "$cfg__db_info__ndoutils__dbserver" | cut -f1 -d":"`
elsendoutils_dbport='3306'ndoutils_dbserver="$cfg__db_info__ndoutils__dbserver"
fi
mysqldump -h "$ndoutils_dbserver" --port="$ndoutils_dbport" -u $cfg__db_info__ndoutils__user --password="$cfg__db_info__ndoutils__pwd" --add-drop-database -B $cfg__db_info__ndoutils__db > $mydir/mysql/nagios.sql
res=$?
if [ $res != 0 ]; thenecho "Error backing up MySQL database 'nagios' - check the password in this script!"rm -r "$mydir"exit $res;
fi
if [[ "$cfg__db_info__nagiosql__dbserver" == *":"* ]]; thennagiosql_dbport=`echo "$cfg__db_info__nagiosql__dbserver" | cut -f2 -d":"`nagiosql_dbserver=`echo "$cfg__db_info__nagiosql__dbserver" | cut -f1 -d":"`
elsenagiosql_dbport='3306'nagiosql_dbserver="$cfg__db_info__nagiosql__dbserver"
fi
mysqldump -h "$nagiosql_dbserver" --port="$nagiosql_dbport" -u $cfg__db_info__nagiosql__user --password="$cfg__db_info__nagiosql__pwd" --add-drop-database -B $cfg__db_info__nagiosql__db > $mydir/mysql/nagiosql.sql
res=$?
if [ $res != 0 ]; thenecho "Error backing up MySQL database 'nagiosql' - check the password in this script!"rm -r "$mydir"exit $res;
fi# Only backup PostgresQL if we are still using it 
if [ $cfg__db_info__nagiosxi__dbtype == "pgsql" ]; thenecho "Backing up PostgresQL databases..."mkdir -p "$mydir/pgsql"if [ -z $cfg__db_info__nagiosxi__dbserver ]; thencfg__db_info__nagiosxi__dbserver="localhost"fipg_dump -h $cfg__db_info__nagiosxi__dbserver -c -U $cfg__db_info__nagiosxi__user $cfg__db_info__nagiosxi__db > "$mydir/pgsql/nagiosxi.sql"res=$?if [ $res != 0 ]; thenecho "Error backing up PostgresQL database 'nagiosxi' !"rm -r "$mydir"exit $res;fi
elseif [[ "$cfg__db_info__nagiosxi__dbserver" == *":"* ]]; thennagiosxi_dbport=`echo "$cfg__db_info__nagiosxi__dbserver" | cut -f2 -d":"`nagiosxi_dbserver=`echo "$cfg__db_info__nagiosxi__dbserver" | cut -f1 -d":"`elsenagiosxi_dbport='3306'nagiosxi_dbserver="$cfg__db_info__nagiosxi__dbserver"fimysqldump -h "$nagiosxi_dbserver" --port="$nagiosxi_dbport" -u $cfg__db_info__nagiosxi__user --password="$cfg__db_info__nagiosxi__pwd" --add-drop-database -B $cfg__db_info__nagiosxi__db > $mydir/mysql/nagiosxi.sqlres=$?if [ $res != 0 ]; thenecho "Error backing up MySQL database 'nagiosxi' - check the password in this script!"rm -r "$mydir"exit $res;fi
fi##############################
# BACKUP CRONJOB ENTRIES
##############################
echo "Backing up cronjobs for Apache..."
mkdir -p "$mydir/cron"
if [[ "$distro" == "Ubuntu" ]] || [[ "$distro" == "Debian" ]]; thencp "/var/spool/cron/crontabs/$apacheuser" "$mydir/cron/apache"
elsecp /var/spool/cron/apache "$mydir/cron/apache"
fi##############################
# BACKUP SUDOERS
##############################
# Not necessary##############################
# BACKUP LOGROTATE
##############################
echo "Backing up logrotate config files..."
mkdir -p "$mydir/logrotate"
cp -rp /etc/logrotate.d/nagiosxi "$mydir/logrotate"##############################
# BACKUP APACHE CONFIG FILES
##############################
echo "Backing up Apache config files..."
mkdir -p "$mydir/httpd"
cp -rp "$httpdconfdir/nagios.conf" "$mydir/httpd"
cp -rp "$httpdconfdir/nagiosxi.conf" "$mydir/httpd"
cp -rp "$httpdconfdir/nagvis.conf" "$mydir/httpd"
cp -rp "$httpdconfdir/nrdp.conf" "$mydir/httpd"if [ -d "/etc/apache2/sites-available" ]; thencp -rp /etc/apache2/sites-available/default-ssl.conf "$mydir/httpd"
elsecp -rp "$httpdconfdir/ssl.conf" "$mydir/httpd"
fi##############################
# COMPRESS BACKUP
##############################
echo "Compressing backup..."
tar czfp "$name.tar.gz" "$name"
rm -rf "$name"# Change ownership
chown "$nagiosuser:$nagiosgroup" "$name.tar.gz"if [ -s "$name.tar.gz" ];thenecho " "echo "==============="echo "BACKUP COMPLETE"echo "==============="echo "Backup stored in $rootdir/$name.tar.gz"exit 0;
elseecho " "echo "==============="echo "BACKUP FAILED"echo "==============="echo "File was not created at $rootdir/$name.tar.gz"rm -r "$mydir"exit 1;
fi

其中

# Restart nagios to forcibly update retention.dat
$BASEDIR/manage_services.sh restart nagios
sleep 10

会重启nagios服务,看下manage_services.sh

nagios@monitored:~$ cat /usr/local/nagiosxi/scripts/manage_services.sh
#!/bin/bash
#
# Manage Services (start/stop/restart)
# Copyright (c) 2015-2020 Nagios Enterprises, LLC. All rights reserved.
#
# =====================
# Built to allow start/stop/restart of services using the proper method based on
# the actual version of operating system.
#
# Examples:
# ./manage_services.sh start httpd
# ./manage_services.sh restart mysqld
# ./manage_services.sh checkconfig nagios
#BASEDIR=$(dirname $(readlink -f $0))# Import xi-sys.cfg config vars
. $BASEDIR/../etc/xi-sys.cfg# Things you can do
first=("start" "stop" "restart" "status" "reload" "checkconfig" "enable" "disable")
second=("postgresql" "httpd" "mysqld" "nagios" "ndo2db" "npcd" "snmptt" "ntpd" "crond" "shellinaboxd" "snmptrapd" "php-fpm")# Helper functions
# -----------------------contains () {local array="$1[@]"local seeking=$2local in=1for element in "${!array}"; doif [[ "$element" == "$seeking" ]]; thenin=0breakfidonereturn $in
}# Verify to avoid abuse
# -----------------------# Check to verify the proper usage format
# ($1 = action, $2 = service name)if ! contains first "$1"; thenecho "First parameter must be one of: ${first[*]}"exit 1
fiif ! contains second "$2"; thenecho "Second parameter must be one of: ${second[*]}"exit 1
fiaction=$1# if service name is defined in xi-sys.cfg use that name
# else use name passed
if [ "$2" != "php-fpm" ] && [ ! -z "${!2}" ];thenservice=${!2}
elseservice=$2
fi# if the action is status, add -n 0 to args to stop journal output
# on CentOS/RHEL 7 systems
args=""
if [ "$action" == "status" ]; thenargs="-n 0"
fi# Special case for ndo2db since we don't use it anymore
if [ "$service" == "ndo2db" ]; thenecho "OK - Nagios XI 5.7 uses NDO3 build in and no longer uses the ndo2db service"exit 0
fi# Run the command
# -----------------------# CentOS / Red Hatif [ "$distro" == "CentOS" ] || [ "$distro" == "RedHatEnterpriseServer" ] || [ "$distro" == "EnterpriseEnterpriseServer" ] || [ "$distro" == "OracleServer" ]; then# Check for enable/disable verbif [ "$action" == "enable" ] || [ "$action" == "disable" ]; thenif [ `command -v systemctl` ]; then`which systemctl` --no-pager "$action" "$service"elif [ `command -v chkconfig` ]; thenchkconfig_path=`which chkconfig`if [ "$action" == "enable" ]; then"$chkconfig_path" --add "$service"return_code=$?elif [ "$action" == "disable" ]; then"$chkconfig_path" --del "$service"return_code=$?fifiexit $return_codefiif [ `command -v systemctl` ]; then`which systemctl` --no-pager "$action" "$service" $argsreturn_code=$?if [ "$service" == "mysqld" ] && [ $return_code -ne 0 ]; thenservice="mariadb"`which systemctl` "$action" "$service" $argsreturn_code=$?fielif [ ! `command -v service` ]; then"/etc/init.d/$service" "$action"return_code=$?else`which service` "$service" "$action"return_code=$?fi
fi# OpenSUSE / SUSE Enterpriseif [ "$distro" == "SUSE LINUX" ]; thenif [ "$dist" == "suse11" ]; then`which service` "$service" "$action"return_code=$?fi
fi# Ubuntu / Debianif [ "$distro" == "Debian" ] || [ "$distro" == "Ubuntu" ]; then# Adjust the shellinabox service, no trailing 'd' in Debian/Ubuntuif [ "$service" == "shellinaboxd" ]; thenservice="shellinabox"fiif [ `command -v systemctl` ]; then`which systemctl` --no-pager "$action" "$service" $argsreturn_code=$?else`which service` "$service" "$action"return_code=$?fi
fi# Others?exit $return_code

能看到会是识别完系统做对应的服务操作,其实等同于是一个systemctl
有趣的是$BASEDIR/manage_services.sh restart nagios会重启nagios服务

systemctl status nagios能看到服务的位置

Process: 8416 ExecStartPre=/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 

这个是有权限修改的

-rwxrwxrwx 1 nagios nagios 16864 Jan 17 05:09 /usr/local/nagios/bin/nagios

所以重新编译一个丢进去让她启动弹shell回来就行
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/634648.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

SCI 2区论文:医疗保健中心训练有素的脑膜瘤分割模型的性能测试-基于四个回顾性多中心数据集的二次分析

基本信息 标题:Performance Test of a Well-Trained Model for Meningioma Segmentation in Health Care Centers: Secondary Analysis Based on Four Retrospective Multicenter Data Sets中文标题:医疗保健中心训练有素的脑膜瘤分割模型的性能测试&am…

PE解释器之PE文件结构(二)

接下来的内容是对IMAGE_OPTIONAL_HEADER32中的最后一个成员DataDirectory,虽然他只是一个结构体数组,每个结构体的大小也不过是个字节,但是它却是PE文件中最重要的成员。PE装载器通过查看它才能准确的找到某个函数或某个资源。 一&#xff1…

软件测试|sqlalchemy一对一关系详解

简介 SQLAlchemy 是一个强大的 Python ORM(对象关系映射)库,它允许我们将数据库表映射到 Python 对象,并提供了丰富的关系模型来处理不同类型的关系,包括一对一关系。在本文中,我们将深入探讨 SQLAlchemy …

Ubuntu使用QtCreator + CMake 开发C/C++程序

平台 OS: Ubuntu 20.04 cmake: 3.16.3 IDE: Qt Creator 4.11.1 Based on Qt 5.14.1 (GCC 5.3.1 20160406 (Red Hat 5.3.1-6), 64 bit) Built on Feb 5 2020 12:48:30 From revision b2ddeacfb5 Copyright 2008-2019 The Qt Company Ltd. All rights reserved. The program …

Hugging Face怎么通过国内镜像去进行模型下载(hf-mirror.com)

一、引言 Hugging Face 🤗是一家专注于自然语言处理(NLP)技术的公司,以其开源贡献和先进的机器学习模型而闻名。该公司最著名的产品是 Transformers 库,这是一个广泛使用的 Python 库,它提供了大量预训练模…

(Bean实例化的基本流程 )学习Spring的第六天

Bean实例化的基本流程 其实可以解释为三个过程: 1 . 有关Bean的信息被封装成一个map集合 : DeanDefinitionMap . key为Bean的名称 , value为有关<bena>标签的信息 2 . Spring框架对这个存储Bean信息的Map进行遍历 , 进行创建对象 , 把创建好的对象存储到另一个Map集合里…

深入理解 Kubernetes Ingress:路由流量、负载均衡和安全性配置

Kubernetes Ingress 是 Kubernetes 集群中外部流量管理的重要组件。它为用户提供了一种直观而强大的方式&#xff0c;通过定义规则和配置&#xff0c;来控制外部流量的路由和访问。 1. 什么是 Ingress&#xff1f; 在 Kubernetes 中&#xff0c;Ingress 是一种 API 资源&#…

取代房子,中国又一种资本在崛起(深度)

我一直有一个观点&#xff1a;经济形势好的时候&#xff0c;只要不是夕阳行业&#xff0c;做什么都能过得不错。经济形势差的时候&#xff0c;对于个人来说&#xff0c;拼的就是学习能力。 10年前&#xff0c;在市场上很吃香的是MBA&#xff0c;那时候企业需要高速发展&#x…

JVM工作原理与实战(二十):直接内存

专栏导航 JVM工作原理与实战 RabbitMQ入门指南 从零开始了解大数据 目录 专栏导航 前言 一、直接内存 1.直接内存作用 二、在直接内存上创建数据 总结 前言 JVM作为Java程序的运行环境&#xff0c;其负责解释和执行字节码&#xff0c;管理内存&#xff0c;确保安全&…

Spring Cloud详细入门使用

文章目录 Spring Cloud服务注册与发现EurekaServer 启动服务注册服务发现 NacosServer启动 (nacos2.2.0)服务注册服务发现服务集群命名空间配置中心集群搭建 负载均衡RPC远程过程调用Feign使用 网关路由断言工厂网关过滤工厂跨域处理全局跨域配置单个微服务跨域配置 限流 熔断 …

Codeforces Round 919 (Div. 2) A~E

A. Satisfying Constraints(模拟) 题意&#xff1a; 给出 n n n个限制条件&#xff0c;问有多少个数字 k k k同时满足这些限制条件。 限制条件分为以下三种&#xff1a; k k k必须大于等于给出的一些数字 x x x k k k必须小于等于给出的一些数字 x x x k k k不能与给出的…

定时器开发基础

1定时器的基本概述 通过滴漏和漏沙瓶这两个例子简单讲述定时器的基本工作原理。 STM32的常见的定时器资源&#xff1a; 系统嘀嗒定时器SysTick、看门狗定时器WatchDog、实时时钟RTC、基本定时器、通用定时器、高级定时器。 系统嘀嗒定时器SysTick &#xff1a;这是一个集成在C…

JavaScript 自定义分页组件

仿boostrap 前端分页组件的实现 一 写一个前端自定义分页组件&#xff0c;需要考虑以下问题 需要一个<ul id"pagination"></ul>标签 total; // 总数据的数量 pageSize; // 一页显示数量 pageIndex; // 当前页 二 实现细节 编写html文件 index.html…

蓝桥杯(C++ 整数删除 优先队列 )

优先队列&#xff1a; 优先队列具有队列的所有特性&#xff0c;包括队列的基本操作&#xff0c;只是在这基础上添加了内部的一个排序&#xff0c;它本质是一个堆实现的。 1.头文件&定义 #include <queue> #include <functional> //greater<>// 定义 p…

2023 年顶级前端工具

谁不喜欢一个好的前端工具&#xff1f;在本综述中&#xff0c;您将找到去年流行的有用的前端工具&#xff0c;它们将帮助您加快开发工作流程。让我们深入了解一下&#xff01; 在过去的 12 个月里&#xff0c;我在我的时事通讯 Web Tools Weekly 中分享了数百种工具。我为前端…

经典数据库练习题及答案

数据表介绍 --1.学生表 Student(SId,Sname,Sage,Ssex) --SId 学生编号,Sname 学生姓名,Sage 出生年月,Ssex 学生性别 --2.课程表 Course(CId,Cname,TId) --CId 课程编号,Cname 课程名称,TId 教师编号 --3.教师表 Teacher(TId,Tname) --TId 教师编号,Tname 教师姓名 --4.成绩…

JavaScript DOM可以做什么?

1、通过id获取标签元素 DOM是文档对象模型&#xff0c;它提供了一些属性和方法来方便我们操作document对象&#xff0c;比如getElementById()方法可以通过某个标签元素的id来获取这个标签元素 // 用法 window.document.getElementById(id); // 例子 <!DOCTYPE html> &l…

深度学习模型之yolov8实例分割模型TesorRT部署-python版本

1 模型转换 从github上下载官方yolov8版本&#xff0c;当前使用的版本是2023年9月份更新的版本&#xff0c;作者一直在更新。官网地址 2 加载模型 模型的训练和测试在官方文档上&#xff0c;有详细的说明&#xff0c;yolov8中文文档这里不做过多说明&#xff0c;v8现在训练是…

智能驾驶新浪潮:SSD与UFS存储技术如何破浪前行?-UFS篇

如果说SSD是赛道上的超级跑车&#xff0c;那UFS更像是专为智能汽车定制的高性能轻量化赛车。UFS采用串行接口技术&#xff0c;像是闪电侠一样&#xff0c;将数据传输的速度推向新高&#xff0c;大幅缩短了系统启动时间和应用程序加载时间&#xff0c;这对追求即时反应的ADAS系统…