Numpy库的学习

定义:移除指定数据中长度为 1 的轴;
形式:numpy.squeeze(a, axis=None);
参数:a 是输入的数据;axis 目前我也就用到 int,用于删除指定维度的轴,该轴长应当为 1,否则会引发错误。

>>> import numpy as np
>>> a = np.arange(3).reshape(1,3,1)
>>> print(a)
[[[0]
  [1]
  [2]]]
>>> b = np.squeeze(a)
b 变成了一个数组
>>> print(b,b.shape)
[0 1 2] (3,)
把 c 的第 0 维的轴长为 1 的轴去掉
>>> c = np.squeeze(a,0)
>>> print(c,c.shape)
[[0]
 [1]
 [2]] (3, 1)
>>> d = np.array([[666]])
np.squeeze(d) 返回的一个的数组,只不过是一个数字而已
>>> print(np.squeeze(d))
666
>>> print(type(np.squeeze(d)))
<class 'numpy.ndarray'>
>>> print(np.squeeze(d)[()])
666
>>> print(type(np.squeeze(d)[()]))
<class 'numpy.int32'>

参数定义:numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0)

  • endpoint : bool, optional.If True, stop is the last sample. Otherwise, it is not included. *Default is True.

函数定义
Return evenly spaced numbers over a specified interval.
返回指定间隔内均匀分布的数字

[En]

Returns evenly distributed numbers within a specified interval

Returns num evenly spaced samples, calculated over the interval [start, stop].
在 [start, stop] 个区间内返回 num 个均匀分布的数字

The endpoint of the interval can optionally be excluded.
该区间的终点可以选择性地选择是否包括在内。

[En]

The endpoint of the interval can selectively choose whether or not to be included.

>>> import numpy as np
>>> a = np.linspace(0,1,num=5,endpoint=False)
endpoint 默认是 True ,如果需要的话,要显式地声明为 False
>>> print(a)
[0.  0.2 0.4 0.6 0.8]
>>> np.linspace(0,1,num=5)
array([0.  , 0.25, 0.5 , 0.75, 1.  ])
>>> np.linspace(0,1,num=5,endpoint=False,retstep=True)
(array([0. , 0.2, 0.4, 0.6, 0.8]), 0.2)
>>> a1,b1 = np.linspace(0,1,5,endpoint=False,retstep=True)
>>> print(a1,b1)
[0.  0.2 0.4 0.6 0.8] 0.2

Original: https://blog.csdn.net/Mr_Yuwen_Yin/article/details/124230913
Author: 硕欧巴
Title: Numpy库的学习



相关阅读

Title: [HCTF 2018]admin

来到题目的主页面,看到主页右面有一个下拉框,有登陆,注册功能,注册个用户再说,登陆后有编辑、更改密码、登出功能。

Numpy库的学习
源码中hint提示不是admin,题目肯定是想让我们登陆admin用户,在更改密码页面源码中有一个github地址,去看一下github

Numpy库的学习
是一个flask项目下载下来审计一下,先看下路由routes.py
index函数
@app.route('/')
@app.route('/index')
def index():
    return render_template('index.html', title = 'hctf')

Numpy库的学习
当用户为admin时才输出falg,看下登陆注册其它函数
@app.route('/register', methods = ['GET', 'POST'])
def register():

    if current_user.is_authenticated:
        return redirect(url_for('index'))

    form = RegisterForm()
    if request.method == 'POST':
        name = strlower(form.username.data)
        if session.get('image').lower() != form.verify_code.data.lower():
            flash('Wrong verify code.')
            return render_template('register.html', title = 'register', form=form)
        if User.query.filter_by(username = name).first():
            flash('The username has been registered')
            return redirect(url_for('register'))
        user = User(username=name)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('register successful')
        return redirect(url_for('login'))
    return render_template('register.html', title = 'register', form = form)

@app.route('/login', methods = ['GET', 'POST'])
def login():
    if current_user.is_authenticated:
        return redirect(url_for('index'))

    form = LoginForm()
    if request.method == 'POST':
        name = strlower(form.username.data)
        session['name'] = name
        user = User.query.filter_by(username=name).first()
        if user is None or not user.check_password(form.password.data):
            flash('Invalid username or password')
            return redirect(url_for('login'))
        login_user(user, remember=form.remember_me.data)
        return redirect(url_for('index'))
    return render_template('login.html', title = 'login', form = form)

@app.route('/logout')
def logout():
    logout_user()
    return redirect('/index')

@app.route('/change', methods = ['GET', 'POST'])
def change():
    if not current_user.is_authenticated:
        return redirect(url_for('login'))
    form = NewpasswordForm()
    if request.method == 'POST':
        name = strlower(session['name'])
        user = User.query.filter_by(username=name).first()
        user.set_password(form.newpassword.data)
        db.session.commit()
        flash('change successful')
        return redirect(url_for('index'))
    return render_template('change.html', title = 'change', form = form)

Unicode欺骗

简单的代码审计后发现登陆、注册、更改密码函数都使用了strlower函数,在末尾定义了strlower函数,这突破口不就来了

def strlower(username):
    username = nodeprep.prepare(username)
    return username

nodeprep.prepare函数从twisted

from twisted.words.protocols.jabber.xmpp_stringprep import nodeprep

requirements.txt中看一下版本吧

Numpy库的学习
百度了一下twisted已经22.4.0版本,nodeprep.prepare函数对unicode编码处理后得到正常的字符
也就是说nodeprep.prepare函数对unicode的ᴬ转换为A,当再次调用nodeprep.prepare函数时就会转换为a
这样先创建个ᴬdmin用户,当登陆时调用nodeprep.prepare函数将用户名转换为Admin。
在修改密码中同样也调用了nodeprep.prepare函数,我们将其修改密码,就是修改了admin用户的密码

注册ᴬdmin用户主页显示的为Admin用户

Numpy库的学习
登陆admin账号密码为刚才修改的密码,拿到flag

弱口令

此非预期解
直接登陆用户admin密码为123
此题还可以使用flask的session伪造但也是非预期解,github上有flask的加解密脚本跑一下也可以得到flag

专注,勤学,慎思。戒骄戒躁,谦虚谨慎

Original: https://blog.csdn.net/qq_45924653/article/details/124331486
Author: 她叫常玉莹
Title: [HCTF 2018]admin

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/320610/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • python读取音频文件的几种方式

    今天也要加油鸭!冲冲冲😊 由于本人研究的音频方面,一开始读取音频文件的时候就遇到了一些问题,比如,这个函数返回的是numpy,另外一个函数返回tensor,巴拉巴拉等等问题,所以在…

    Python 2023年1月12日
    027
  • 强化学习-学习笔记9 | Multi-Step-TD-Target

    这篇笔记依然属于TD算法的范畴。Multi-Step-TD-Target 是对 TD算法的改进。 9. Multi-Step-TD-Target 9.1 Review Sarsa …

    Python 2023年2月1日
    011
  • python之Matplotlib

    1.数据可视化是什么? 数据可视化是将数据转换为图形或表格等信息图像,以更直观的方式显示和呈现数据。可视化就是用图形的手段有效地表达,准确、高效、简洁、全面地传递某些信息,甚至帮助…

    Python 2023年1月14日
    022
  • 几亿人都在玩的谷歌小恐龙游戏,全世界最高分是 99999?你呢?

    前言 “越努力越幸运鸭💦💦,记得每天进步一点点哦!” ——Python是世界上最好的语言 Everybody 大家好~(也不清楚我的开头的单词写错没,懒.j…

    Python 2023年1月20日
    029
  • python基础:小白自学pandas–DataFrame数据读取的方法

    一、直接用方括号[]取下标读取,DataFrame[列标签][行标签] 二、用DataFrame.loc[行标签,列标签]按照行/列标签名index读取 三、用DataFrame….

    Python 2022年12月29日
    051
  • RSA加密算法

    前言 公钥加密算法(RSA)是首个适用以签名作为加密的算法。被用于银行网上支付、电商交易。RSA是Rivest、Shamir、Adleman三位数学家的缩写。其数学原理是大整数因数…

    2022年8月22日
    0156
  • 爬虫(24)Scrapy练习 苏宁图书案例

    文章目录 第二十二章 Scrapy练习 苏宁图书案例 * 1. 创建项目 2. 获取首页大分类 3. 找分类 4. 获取小分类 5. 进入小分类 6. 获取每本书的信息 7. 向详…

    Python 2023年1月26日
    025
  • 基于HBuilderX+UniApp+ThorUI的手机端前端开发处理

    现在的很多程序应用,基本上都是需要多端覆盖,因此基于一个Web API的后端接口,来构建多端应用,如微信、H5、APP、WInForm、BS的Web管理端等都是常见的应用。本篇随笔…

    Python 2023年1月31日
    020
  • Flask 自建扩展

    开源发布准备 * 1. 添加文档字符串与注释后的完整代码 """ Flask-Share # ~~~~~~~~~~~~~~ Create social…

    Python 2023年2月6日
    029
  • TensorRT&Sample&Python[fc_plugin_caffe_mnist]

    本文是基于TensorRT 5.0.2基础上,关于其内部的fc_plugin_caffe_mnist例子的分析和介绍。本例子相较于前面例子的不同在于,其还包含cpp代码,且此时依赖…

    2022年8月14日
    0140
  • django 数据库 get_or_create函数update_or_create函数

    1、返回值是tuple的问题 返回的是tuple:(对象, 是否是创建的) 2、如果查询到就返回,如果没查询到就向数据库加入新的对象。 e.g. size = Size.objec…

    Python 2022年12月27日
    054
  • 利用python进行数据分析 | pandas入门

    Series是一种一维的数组型对象,它包含了一个值序列,并且包含了数据标签,称为索引 该结构能够存储各种数据类型,比如字符数,整数,浮点数,python对象等 Series用nam…

    Python 2022年12月29日
    044
  • Scrapy管道(pipeline)的使用

    之前我们在scrapy入门使用一节中学习了管道的基本使用,接下来我们深入的学习scrapy管道的使用 继续完善wangyi爬虫,在 pipelines.py代码中完善 import…

    Python 2023年1月25日
    016
  • python报错集

    本人学python有段时间了,无论是基础部分、爬虫、连接硬件,还是写简单的接口;多多少少会遇到一些报错问题。但一直没总结,导致很多时候会犯同样的错。所以在这里会慢慢总结一下自己在使…

    Python 2023年1月5日
    050
  • Java IO流 – 字节流的使用详细介绍

    文章目录 * – IO流的基本介绍 – 字节流的使用 – + 文件字节输入流 + * 创建字节输入流 * 每次读取一个字节 * 每次读取一个数组…

    Python 2023年2月5日
    022
  • python安装scrapy时,遇到 ERROR: Command errored out with exit status 1:…的问题

    今天在windows上安装scrapy库时,遇到了如上的问题,查询了如下博文: https://blog.csdn.net/weixin_44517500/article/deta…

    Python 2023年1月25日
    036
最近整理资源【免费获取】:   👉 程序员最新必读书单  | 👏 互联网各方向面试题下载 | ✌️计算机核心资源汇总