演⽰csrf漏洞和ssrf漏洞,并说明两者的区别
ssrf
如下,提示接受url参数,并且没有任何过滤,这里可能存在ssrf
使用POST方式测试百度,确定存在ssrf
因为存在ssrf,可以访问只有本地才能访问的文件,拿到flag
CSRF
这里以DVWA的靶场为例
使用Yakit抓包
发到FUZZ模块并生成POC
将POC复制在POC.html下,模拟受害者点击
刚刚通过csrf漏洞将密码改为12345678,现在看是否成功
总结,csrf攻击的更多是客户端,且利用条件苛刻,需要用户点击,并且还需要提前构造可以利用的数据包,可以尝试结合xss漏洞,降低攻击难度
ssrf攻击的更多是服务端,可以通过ssrf进行内网的端口和存活探测,并且很多应用可能对来自内网的攻击没有足够防护
演⽰使⽤存储型XSS盗取cookie
存储型XSS多发生在留言板,评论区等处
通过xss平台接受xss
管理员查看留言时就加载了JS,发生了XSS攻击
获取cookie后,就可以借助cookie登录
⼿动注⼊出sqlilab靶场第⼀关数据库名称
通过1和2-1判断是字符型还是数字型
两次结果不同,是字符型,通过报错知道闭合是‘
通过order by判断字段为3
?id=-1' union select 1,2,3--+,判断回显点为2,3
演⽰sqlmap --os-shell
演⽰⾃⼰所学的中间件解析漏洞
写一个图片马
将木马上传
忘记打开文件包含选项了
可以看到,png文件的php代码成功执行,在php的文件包含include中,文件的PHP代码自动执行
演⽰使⽤命令执⾏漏洞写⼊⼀句话⽊⻢
应急响应
1. history查看操作历史
2. 查看secure日志:cat /var/log/secure
3. 查看定时任务是否异常
4. 通过find查找最近几分钟之内新增的,发生变化的文件
5. 通过top查看进程详细占用信息
6. 查看/etc/passwd是否有新增的root用户
尝试解释什么是反序列化漏洞,PHP的反序列化和java的反序列化有什么区别
反序列化漏洞是利用程序在反序列化时,通过链式调用,最终执行了可以被攻击者控制的参数,php的反序列化更多是魔法函数在反序列化时调用了危险方法,最终被攻击者利用,Java反序列化通常是因为开发者重写了readobject方法,攻击者通过寻找利用链实现任意方法函数调用
分析dvwa靶场命令执⾏漏洞⾼难度和不可能完成的级别代码,解释⾥⾯函数的作 ⽤
high
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// Get input
$target = trim($_REQUEST[ 'ip' ]);
trim 去除字符串两端的空白字符
// Set blacklist
$substitutions = array(
'&' => '',
';' => '',
'| ' => '',
'-' => '',
'$' => '',
'(' => '',
')' => '',
'`' => '',
'||' => '',
);
定义过滤规则,过滤这些字符,替换为空
// Remove any of the charactars in the array (blacklist).
$target = str_replace( array_keys( $substitutions ), $substitutions, $target );
过滤
// Determine OS and execute the ping command.
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
// Windows
$cmd = shell_exec( 'ping ' . $target );
}
执行危险函数shell_exec,采用字符串拼接的方式
else {
// *nix
$cmd = shell_exec( 'ping -c 4 ' . $target );
}
// Feedback for the end user
echo "<pre>{$cmd}</pre>";
将结果输出
}
?>
impossible
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// Check Anti-CSRF token
checkToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' );
检测token
// Get input
$target = $_REQUEST[ 'ip' ];
$target = stripslashes( $target );
// Split the IP into 4 octects
$octet = explode( ".", $target );
将输入的IP用.分隔开
// Check IF each octet is an integer
if( ( is_numeric( $octet[0] ) ) && ( is_numeric( $octet[1] ) ) && ( is_numeric( $octet[2] ) ) && ( is_numeric( $octet[3] ) ) && ( sizeof( $octet ) == 4 ) ) {
// If all 4 octets are int's put the IP back together.
$target = $octet[0] . '.' . $octet[1] . '.' . $octet[2] . '.' . $octet[3];
检测是否是。分割成4部分,在最后用.拼接目标
// Determine OS and execute the ping command.
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
// Windows
$cmd = shell_exec( 'ping ' . $target );
}
else {
// *nix
$cmd = shell_exec( 'ping -c 4 ' . $target );
}
// Feedback for the end user
echo "<pre>{$cmd}</pre>";
}
else {
// Ops. Let the user name theres a mistake
echo '<pre>ERROR: You have entered an invalid IP.</pre>';
}
}
// Generate Anti-CSRF token
generateSessionToken();
?>
为pikachu的ssrf漏洞⽂件编写的防御代码如下,解释含义
通过explode函数,将url以.分割,如果分割的第二段不是php,就终止程序