IDF实验室Writeup之PPC

0x01简单编程-字符统计

这里这里 → http://ctf.idf.cn/game/pro/37

考察基本的网络编程,这用我用Python写了个脚本,运行即可得出flag

#-*- coding:utf-8 -*-

import urllib,urllib2,re
import cookielib

url="http://ctf.idf.cn/game/pro/37/"

#抓取cookie
jar=cookielib.CookieJar()  
opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))
rep=opener.open(url)
page=rep.read()

#正则匹配
text=re.findall(r"t.*t<hr />",page) 
#计算结果,然后post发送
key=str(text[1].count('w'))+str(text[1].count('o'))+str(text[1].count('l'))+str(text[1].count('d'))+str(text[1].count('y'))
data={"anwser":key}
data=urllib.urlencode(data)
result=opener.open(url,data)
print result.read()

wctf{timeout_prog}

0x02谁是卧底

武林中某知名杀手在一次任务中失败,然后逃窜到了人群中,当时那个社会并没有我们现在这么发达,满地都是文盲,而这些文盲甚至连一句完整的英文都说不出来,所以其实只要用心去发现,就会很容易发现这个稍微有些文化的杀手是谁哦~答案wctf{杀手的英文名}

人群→ http://pan.baidu.com/s/1bnq6nmR

密码: 988u

下载下来是一个很大的文本文件,用txt一打开就蹦了,看来要编程处理了。先用vim打开看看,发现整个5.32M的文件只有一行,于是决定,先写个脚本将这个巨大的字符串先分行,每行长度一百,这个代码没有保存。效果如下:

然后开始做字频统计,下了一个“最常用英语词汇3000个.pdf”,然后在这http://www.pdfdo.com/pdf-to-txt.aspx转换成txt文件,这里我直接把这个字典分型给大家

链接:http://pan.baidu.com/s/1mgrKmZA 密码:gf0d

然后用下面这段程序开始统计每行的单词频率(这个代码写的比较丑,就重点看思路了。。。(* ̄3 ̄)╭)

f1 = open('2.txt')
num = 0
line = 0
i = 0
temp = 0
for line1 in f1:  #从刚才生成的那个文件里一行一行的读取,处理
    if(temp>num):  #记录下当前频率最大的那一行
        line = i
        num = temp
    i += 1
    temp = 0
    f2 = open('3000.txt')
    for line2 in f2:  #打开字典文件
        line2 = line2.strip('n').split()  #再对每行进行拆分,因为要一个单词一个单词的查找
        for line3 in line2:
            temp += line1.count(line3)

print line,num  #输出行数和当前行匹配的单词个数
print "Done!"

本来以为会很慢,结果1分钟就出结果了,

31977 33
Done!

在vim下直接找到31977行,然后看到

其中有一句

what will you see if you throw the but terout the window

这是个谜语,百度一下,最终的flag为:

wctf{butterfly}

0x02Fuck your brain

++++++++++++[>++++>+++++>++++++>+++++++>++++++++>+++++++++>++++++++++<<<<<<<-]>>>>+++.<-----.>---.<+++.>>>>+++.<<<<----.>>>++++++.<<<<<+++.--.>>>>>----.<<<++++.<<+++.>>>>+++.>---.>++.

这是brain fuck语言。。。下载一个brain fuck解释器即可,C++源代码如下:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
    FILE *input = fopen(argv[1], "r");
    char source[LEN] = {0};
    char runtime[LEN] = {0};
    char *sptr, *wptr;
    int pos = 0;
    int wflag = 0;
    int line = 1, col = 0, wline, wcol;
    sptr = source;
    while (wflag || EOF!=fscanf(input, "%c", sptr))
    {
        if (!wflag)
            ++col;
        else
            ++wcol;
        switch (*sptr)
        {
            case '>' :
                ++pos;
                break;
            case '<' :
                if (--pos <0)
                {
                    printf("%d : %d : ERROR: Illegal pointer valuen", line, col);
                    return 1;
                }
                break;
            case '+' :
                ++runtime[pos];
                if (runtime[pos] < 0 || runtime[pos] > 255)
                {
                    if (!wflag)
                        printf("%d : %d : ERROR: Illegal valuen", line, col);
                    else
                        printf("%d : %d : ERROR: Illegal valuen", wline, wcol);
                    return 1;
                }
                break;
            case '-' :
                --runtime[pos];
                if (runtime[pos] < 0 || runtime[pos] > 255)
                {
                    if (!wflag)
                        printf("%d : %d : ERROR: Illegal valuen", line, col);
                    else
                        printf("%d : %d : ERROR: Illegal valuen", wline, wcol);
                    return 0;
                }
                break;
            case '.' :
                putchar(runtime[pos]);
                break;
            case ',' :
                runtime[pos]=getchar();
                break;
            case '[' :
                if (runtime[pos])
                    wptr = sptr-1;
                else
                    wflag = 0;
                wline = line;
                wcol = col;
                break;
            case ']' :
                sptr = wptr;
                wflag = 1;
                line = wline;
                col = wcol;
                break;
            case 'n' :
                if (!wflag)
                {
                    ++line;
                    col = 0;
                }
                else
                {
                    ++wline;
                    wcol = 0;
                }
                break;
        }
        ++sptr;
    }
    fclose(input);
    return 0;
}

将brain fuck语句保存在.bf文件文件,然后执行bf.exe 1.bf,即可得出结果
WCTF{Br31nF4ck}

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注