CentOS7安装升级Python3

CentOS7安装升级Python3
一、查看默认的Python版本
默认安装的python2
[root@server ~]# python
Python 2.7.5 (default, Oct 14 2020, 14:45:30)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@server ~]# python3
bash: python3: 未找到命令...
相似命令是: 'python'
[root@server ~]# pip -V
bash: pip: 未找到命令..
[root@server ~]# pip3 -V
bash: pip3: 未找到命令...
[root@server ~]#.
[root@server ~]#
[root@server ~]# ll -lsh /usr/bin/python*
   0 lrwxrwxrwx. 1 root root    7 1月   8 2022 /usr/bin/python -> python2
   0 lrwxrwxrwx. 1 root root    9 1月   8 2022 /usr/bin/python2 -> python2.7
8.0K -rwxr-xr-x. 1 root root 7.0K 10月 14 2020 /usr/bin/python2.7
[root@server ~]#

二、yum方式安装的python3
[root@server ~]# yum install python3

[root@server ~]# pip -V
bash: pip: 未找到命令...
[root@server ~]# pip3 -V
pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)
[root@server ~]# python3
Python 3.6.8 (default, Nov 14 2023, 16:29:52)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

查看软连接
[root@server ~]# ll -lsh /usr/bin/python*
   0 lrwxrwxrwx. 1 root root    7 1月   8 2022 /usr/bin/python -> python2
   0 lrwxrwxrwx. 1 root root    9 1月   8 2022 /usr/bin/python2 -> python2.7
8.0K -rwxr-xr-x. 1 root root 7.0K 10月 14 2020 /usr/bin/python2.7
   0 lrwxrwxrwx  1 root root    9 1月  12 15:16 /usr/bin/python3 -> python3.6
 12K -rwxr-xr-x  2 root root  12K 11月 15 00:31 /usr/bin/python3.6
 12K -rwxr-xr-x  2 root root  12K 11月 15 00:31 /usr/bin/python3.6m
[root@server ~]#

三、编译安装更高版本的python3
[root@server ~]# tar zxvf Python-3.7.0.tgz
[root@server ~]# cd Python-3.7.0/
[root@server Python-3.7.0]# ls
aclocal.m4    configure     Grammar     Lib      Makefile.pre.in  Objects  PCbuild        Python      Tools
config.guess  configure.ac  Include     LICENSE  Misc             Parser   Programs       README.rst
config.sub    Doc           install-sh  Mac      Modules          PC       pyconfig.h.in  setup.py
[root@server Python-3.7.0]# ./configure --prefix=/usr/local/python3

// 执行完会到最后会提示如下信息。
If you want a release build with all stable optimizations active (PGO, etc),
please run ./configure --enable-optimizations


// 安装前先安装一下依赖包,已安装忽略
[root@server Python-3.7.0]# yum install libffi-devel zlib* -y
//3.7版本需要安装libffi-devel包否则报错,Module Not Found Error: No module named '_ctypes'


[root@server Python-3.7.0]# ./configure --prefix=/usr/local/python3 --enable-optimizations
[root@server Python-3.7.0]# make && make install

四、创建软连接
[root@server Python-3.7.0]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln: 无法创建符号链接"/usr/bin/python3": 文件已存在
[root@server Python-3.7.0]#

[root@server ~]# rm -rf /usr/bin/python3
[root@server ~]# ll -lsh /usr/bin/python*
   0 lrwxrwxrwx. 1 root root    7 1月   8 2022 /usr/bin/python -> python2
   0 lrwxrwxrwx. 1 root root    9 1月   8 2022 /usr/bin/python2 -> python2.7
8.0K -rwxr-xr-x. 1 root root 7.0K 10月 14 2020 /usr/bin/python2.7
 12K -rwxr-xr-x  2 root root  12K 11月 15 00:31 /usr/bin/python3.6
 12K -rwxr-xr-x  2 root root  12K 11月 15 00:31 /usr/bin/python3.6m
[root@server ~]#
[root@server ~]# python3
Python 3.6.8 (default, Nov 14 2023, 16:29:52)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@server ~]#

[root@server Python-3.7.0]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
[root@server Python-3.7.0]#
[root@server ~]# ll -lsh /usr/bin/python*
   0 lrwxrwxrwx. 1 root root    7 1月   8 2022 /usr/bin/python -> python2
   0 lrwxrwxrwx. 1 root root    9 1月   8 2022 /usr/bin/python2 -> python2.7
8.0K -rwxr-xr-x. 1 root root 7.0K 10月 14 2020 /usr/bin/python2.7
   0 lrwxrwxrwx  1 root root   30 1月  12 17:30 /usr/bin/python3 -> /usr/local/python3/bin/python3
 12K -rwxr-xr-x  2 root root  12K 11月 15 00:31 /usr/bin/python3.6
 12K -rwxr-xr-x  2 root root  12K 11月 15 00:31 /usr/bin/python3.6m
[root@server ~]#

查看新版本
[root@server ~]# python3
Python 3.7.0 (default, Jan 12 2024, 17:25:19)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>


五、添加到PATH
vim ~/.bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

#PATH=$PATH:$HOME/bin
PATH=$PATH:$HOME/bin:/usr/local/python3/bin

export PATH

//修改生效
source ~/.bash_profile

六、检查python3和pip,升级pip,有可能网速卡,多试几次
[root@server ~]# python3 -V
Python 3.7.0
[root@server ~]#
[root@server Python-3.7.0]# pip3 -V
pip 10.0.1 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)
[root@server ~]#


[root@server Python-3.7.0]# pip3 install --upgrade pip
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/pip/
Collecting pip

  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fa0937f0ac8>: Failed to establish a newconnection: [Errno 101] 网络不可达')':
/packages/15/aa/3f4c7bcee2057a76562a5b33ecbd199be08cdb4443a02e26bd2c3cf6fc39/pip-23.3.2-py3-none-any.whl

  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fa0937f05c0>: Failed to establish a newconnection: [Errno 101] 网络不可达')': /packages/15/aa/3f4c7bcee2057a76562a5b33ecbd199be08cdb4443a02e26bd2c3cf6fc39/pip-23.3.2-py3-none-any.whl

  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out. (read timeout=15)")': /packages/15/aa/3f4c7bcee2057a76562a5b33ecbd199be08cdb4443a02e26bd2c3cf6fc39/pip-23.3.2-py3-none-any.whl

  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out. (read timeout=15)")': /packages/15/aa/3f4c7bcee2057a76562a5b33ecbd199be08cdb4443a02e26bd2c3cf6fc39/pip-23.3.2-py3-none-any.whl

  Downloading https://files.pythonhosted.org/packages/15/aa/3f4c7bcee2057a76562a5b33ecbd199be08cdb4443a02e26bd2c3cf6fc39/pip-23.3.2-py3-none-any.whl (2.1MB)
    100% |████████████████████████████████| 2.1MB 11kB/s
Installing collected packages: pip
  Found existing installation: pip 10.0.1
    Uninstalling pip-10.0.1:
      Successfully uninstalled pip-10.0.1
Successfully installed pip-23.3.2
[root@server Python-3.7.0]#

[root@server Python-3.7.0]# pip3 -V
pip 23.3.2 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)
[root@server Python-3.7.0]#

### 文件上传绕过%00截断漏洞解决方案 #### 背景介绍 文件上传中的`%00`截断漏洞主要存在于较旧版本的PHP环境中,在这些环境下,如果`magic_quotes_gpc=off`,则可以通过特定手段绕过文件名验证机制。然而,随着技术的发展,现代Web应用框架和服务器端编程语言对此类攻击已经有了较为完善的防护措施。 #### 技术细节分析 对于低于PHP 5.2.4版本的情况,并且当`php.ini`中设置为`magic_quotes_gpc=off`时,可以尝试使用`%00`字符来终止字符串解析[^5]。具体来说: - **GET请求**:浏览器会自动解码URL参数中的特殊字符; - **POST请求**:不会自动解码表单数据中的特殊字符;因此为了实现`%00`的效果,需要将它编码成`%25%30%30`形式发送给服务器,或者直接在Burp Suite这样的工具里手动编辑HTTP报文,把相应的字节改成十六进制表示法下的`00`[^1]。 #### 实际案例说明 在一个典型的场景中,假设存在一个允许用户上传图片的应用程序,该应用程序试图通过检查文件扩展名为`.jpg`或其他图像格式的方式来阻止恶意脚本上传。此时,攻击者可以选择构造如下类型的文件名:“`evil.php.jpg\0.png`”。当服务器接收到这个文件并尝试处理其路径时,遇到第一个出现的NULL(`\0`)就会停止进一步解释剩余部分,最终可能导致只保存了面的部分——即带有PHP代码的有效载荷被当作合法图片存储下来[^2]。 #### 防护建议 为了避免上述风险,开发者应当采取以下预防措施: - 升级至最新稳定版的开发平台和技术栈; - 启用适当的全配置选项(如开启`magic_quotes_gpc`),尽管这并不是推荐的做法因为更好的实践是在代码层面做更严格的输入过滤; - 应用多层防御原则,比如结合端JavaScript验证加上服务端逻辑双重确认。 ```python import os.path def validate_filename(filename): allowed_extensions = [&#39;.png&#39;, &#39;.jpeg&#39;] # Remove any null bytes from filename to prevent truncation attacks. clean_name = "".join([c for c in filename if ord(c) != 0]) ext = os.path.splitext(clean_name)[1].lower() return ext in allowed_extensions and not ".." in clean_name ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值