当前位置:网站首页>Strength comparison vulnerability of PHP based on hash algorithm
Strength comparison vulnerability of PHP based on hash algorithm
2022-04-23 08:52:00 【quan9i】
List of articles
Preface
The article is synchronized with my personal blog https://quan9i.top/phpcompare
Looking at some ctf I found that most of the simple questions used == and === these , Therefore, it is necessary to summarize and learn , I hope it can be solved directly the next time I see it , The knowledge is summarized as follows , I hope it will be helpful to the masters who are learning
The hash algorithm
The definition of hash algorithm is as follows
The hash algorithm (Hash) Also known as digest algorithm (Digest), Its function is : Calculate any set of input data , Get a fixed length
Output summary . The most important feature of hash algorithm is : The same input must get the same output ; Different input probabilities lead to different outputs .
Commonly used hash algorithms are :
Algorithm Output length ( position ) Output length ( byte )
MD5 128 bits 16 bytes
SHA-1 160 bits 20 bytes
RipeMD-160 160 bits 20 bytes
SHA-256 256 bits 32 bytes
SHA-512 512 bits 64 bytes
php Hash algorithm
There is a hash algorithm. The special form obtained after encryption is 0e+xxx( Numbers ) The combination of . and php When dealing with such characters , Unify and regard it as 0, Test the following


The reason for this , Because php The representation method of scientific counting in is similar to this , Take a chestnut , To the power of ten use php To show that is 1e10, Two × To the power of ten Namely 2e10, Test the following

Now let's look at 0exxx such , that php It will be regarded as scientific counting , So as to 0×10 Of xxx Power To calculate , At this point, we can see , No matter how it counts, it is 0, Therefore, the two values are equal
php Weak comparison
php Weak comparison refers to == such , Two == Its calculation method is to convert it into the same type first , recompute , This is equivalent to that it only compares values at this time , So there is php Weak comparison vulnerability , We have thus achieved a bypass
0X01
<?php
if($_POST['a']!=$_POST['b']&& md5($_POST['a'])==md5($_POST['b'])){
die("success!");
}
else
{
echo"hacker";
}
show_source(__FILE__);
?>
It can be seen that the condition is that the two are not equal, but md5 The value needs to be quite , We know md5 Is a kind of hash algorithm , So now we think of using 0e This method is used to bypass , So we need to find a few strings , Let it md5 Encrypted as 0e Such , After learning the notes of other masters , We know that the following strings are md5 Encrypted as 0e Format
aabg7XSs
aabC9RqS
s878926199a
QNKCDZO
240610708
The test results are as follows

So here we can use these to bypass

0X02
<?php
$flag='flag{quan9i is best}';
if ($_GET['name']!=$_GET['pwd']){
if (md5($_GET['name'])==md5($_GET['pwd'])){
echo $flag;
}
}
?>
You can see that you first compare whether the user name and password have the same value , At the same time, connect the two separately md5 encryption , Then make a weak comparison , There was no problem , But it's used here md5 encryption ,md5 If we encrypt, we will think of 0e, At this time, use those passing through md5 After encryption, it becomes 0e Format , You can bypass

php Strong comparison
<?php
if($_POST['a']!==$_POST['b']&& md5($_POST['a'])===md5($_POST['b'])){
die("success!");
}
?>
Strong comparison refers to ===, At this time, not only the detection value , And check whether it is the same type , Therefore, the above method cannot be used to bypass
, If you bypass here, you need to use an array ,, We know php in md5 The function requires that what we put in it should be string Type of , If we put an array here , It will neither report an error , Its value will not be parsed , At this time, both reported the same error , Does that constitute equality , Our array is in echo The output is array, after md5 After encryption, all are null, So you can bypass , Test the following

, Therefore, we construct here as follows payload You can bypass
a[]=1&b[]=2

版权声明
本文为[quan9i]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230818385632.html
边栏推荐
- Failed to prepare device for development
- PLC point table (register address and point table definition) cracking detection scheme -- convenient for industrial Internet data acquisition
- Research purpose, construction goal, construction significance, technological innovation, technological effect
- GUI编程简介 swing
- Withholding agent
- Noyer électronique stm32 Introduction à l'Internet des objets 30 étapes notes I. différences entre la Bibliothèque Hal et la Bibliothèque standard
- xctf刷题小记
- Use include in databinding
- OneFlow学习笔记:从Functor到OpExprInterpreter
- Chris LATTNER, father of llvm: the golden age of compilers
猜你喜欢

Star Trek's strong attack opens the dream linkage between metacosmic virtual reality

Star Trek强势来袭 开启元宇宙虚拟与现实的梦幻联动

洋桃電子STM32物聯網入門30步筆記一、HAL庫和標准庫的區別

Automatic differentiation and higher order derivative in deep learning framework

After a circle, I sorted out this set of interview questions..

LLVM之父Chris Lattner:编译器的黄金时代

L2-022 重排链表 (25 分)(map+结构体模拟)

valgrind和kcachegrind使用運行分析

Introduction to matlab

Non duplicate data values of two MySQL query tables
随机推荐
BK3633 规格书
Go语言自学系列 | golang结构体指针
swagger文档导出自定义v2/api-docs拦截
【精品】利用动态代理实现事务统一管理 二
微信:获取单个标签所有人
STM32 uses Hal library. The overall structure and function principle are introduced
Notes on 30 steps of introduction to Internet of things of yangtao electronics STM32 III. Explanation of new cubeide project and setting
引用传递1
LeetCode_DFS_中等_1254. 统计封闭岛屿的数目
Complete binary search tree (30 points)
K210 learning notes (II) serial communication between k210 and stm32
Restore binary tree (25 points)
uni-app和微信小程序中的getCurrentPages()
在sqli-liabs学习SQL注入之旅(第十一关~第二十关)
tsdf +mvs
2022-04-22 openebs cloud native storage
Swagger document export custom V2 / API docs interception
Single chip microcomputer nixie tube stopwatch
cadence的工艺角仿真、蒙特卡洛仿真、PSRR
1099 建立二叉搜索树 (30 分)