定义:移除指定数据中长度为 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
来到题目的主页面,看到主页右面有一个下拉框,有登陆,注册功能,注册个用户再说,登陆后有编辑、更改密码、登出功能。

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

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

当用户为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中看一下版本吧

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

登陆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/
转载文章受原作者版权保护。转载请注明原作者出处!